mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Remove ResourceLoadPriorityOptimizer.
We want to expose the ability to do this in the framework, not bake it into the platform. R=eseidel@chromium.org Review URL: https://codereview.chromium.org/710743006
This commit is contained in:
parent
36d65ae442
commit
0f803f8d3c
@ -683,8 +683,6 @@ sky_core_files = [
|
||||
"fetch/ResourceClientWalker.h",
|
||||
"fetch/ResourceFetcher.cpp",
|
||||
"fetch/ResourceFetcher.h",
|
||||
"fetch/ResourceLoadPriorityOptimizer.cpp",
|
||||
"fetch/ResourceLoadPriorityOptimizer.h",
|
||||
"fetch/ResourceLoader.cpp",
|
||||
"fetch/ResourceLoader.h",
|
||||
"fetch/ResourceLoaderOptions.h",
|
||||
|
||||
@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Google Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "core/fetch/ResourceLoadPriorityOptimizer.h"
|
||||
#include "core/rendering/RenderObject.h"
|
||||
#include "platform/TraceEvent.h"
|
||||
|
||||
#include "wtf/Vector.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
ResourceLoadPriorityOptimizer* ResourceLoadPriorityOptimizer::resourceLoadPriorityOptimizer()
|
||||
{
|
||||
DEFINE_STATIC_LOCAL(ResourceLoadPriorityOptimizer, s_renderLoadOptimizer, ());
|
||||
return &s_renderLoadOptimizer;
|
||||
}
|
||||
|
||||
ResourceLoadPriorityOptimizer::ResourceAndVisibility::ResourceAndVisibility(ImageResource* image, VisibilityStatus visibilityStatus, uint32_t screenArea)
|
||||
: imageResource(image)
|
||||
, status(visibilityStatus)
|
||||
, screenArea(screenArea)
|
||||
{
|
||||
}
|
||||
|
||||
ResourceLoadPriorityOptimizer::ResourceAndVisibility::~ResourceAndVisibility()
|
||||
{
|
||||
}
|
||||
|
||||
ResourceLoadPriorityOptimizer::ResourceLoadPriorityOptimizer()
|
||||
{
|
||||
}
|
||||
|
||||
ResourceLoadPriorityOptimizer::~ResourceLoadPriorityOptimizer()
|
||||
{
|
||||
}
|
||||
|
||||
void ResourceLoadPriorityOptimizer::addRenderObject(RenderObject* renderer)
|
||||
{
|
||||
m_objects.add(renderer);
|
||||
renderer->setHasPendingResourceUpdate(true);
|
||||
}
|
||||
|
||||
void ResourceLoadPriorityOptimizer::removeRenderObject(RenderObject* renderer)
|
||||
{
|
||||
if (!renderer->hasPendingResourceUpdate())
|
||||
return;
|
||||
m_objects.remove(renderer);
|
||||
renderer->setHasPendingResourceUpdate(false);
|
||||
}
|
||||
|
||||
void ResourceLoadPriorityOptimizer::updateAllImageResourcePriorities()
|
||||
{
|
||||
TRACE_EVENT0("blink", "ResourceLoadPriorityOptimizer::updateAllImageResourcePriorities");
|
||||
|
||||
m_imageResources.clear();
|
||||
|
||||
Vector<RenderObject*> objectsToRemove;
|
||||
for (RenderObjectSet::iterator it = m_objects.begin(); it != m_objects.end(); ++it) {
|
||||
RenderObject* obj = *it;
|
||||
if (!obj->updateImageLoadingPriorities()) {
|
||||
objectsToRemove.append(obj);
|
||||
}
|
||||
}
|
||||
m_objects.removeAll(objectsToRemove);
|
||||
|
||||
updateImageResourcesWithLoadPriority();
|
||||
}
|
||||
|
||||
void ResourceLoadPriorityOptimizer::updateImageResourcesWithLoadPriority()
|
||||
{
|
||||
for (ImageResourceMap::iterator it = m_imageResources.begin(); it != m_imageResources.end(); ++it) {
|
||||
ResourceLoadPriority priority = it->value->status == Visible ?
|
||||
ResourceLoadPriorityLow : ResourceLoadPriorityVeryLow;
|
||||
|
||||
if (priority != it->value->imageResource->resourceRequest().priority()) {
|
||||
it->value->imageResource->mutableResourceRequest().setPriority(priority, it->value->screenArea);
|
||||
it->value->imageResource->didChangePriority(priority, it->value->screenArea);
|
||||
}
|
||||
}
|
||||
m_imageResources.clear();
|
||||
}
|
||||
|
||||
void ResourceLoadPriorityOptimizer::notifyImageResourceVisibility(ImageResource* img, VisibilityStatus status, const LayoutRect& screenRect)
|
||||
{
|
||||
if (!img || img->isLoaded())
|
||||
return;
|
||||
|
||||
int screenArea = 0;
|
||||
if (!screenRect.isEmpty() && status == Visible)
|
||||
screenArea += static_cast<uint32_t>(screenRect.width() * screenRect.height());
|
||||
|
||||
ImageResourceMap::AddResult result = m_imageResources.add(img->identifier(), adoptPtr(new ResourceAndVisibility(img, status, screenArea)));
|
||||
if (!result.isNewEntry && status == Visible) {
|
||||
result.storedValue->value->status = status;
|
||||
result.storedValue->value->screenArea = status;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Google Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ResourceLoadPriorityOptimizer_h
|
||||
#define ResourceLoadPriorityOptimizer_h
|
||||
|
||||
#include "core/fetch/ImageResource.h"
|
||||
#include "core/fetch/ResourcePtr.h"
|
||||
#include "platform/geometry/LayoutRect.h"
|
||||
|
||||
#include "wtf/HashMap.h"
|
||||
#include "wtf/HashSet.h"
|
||||
#include "wtf/OwnPtr.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
class ResourceLoadPriorityOptimizer {
|
||||
public:
|
||||
enum VisibilityStatus {
|
||||
NotVisible,
|
||||
Visible,
|
||||
};
|
||||
void notifyImageResourceVisibility(ImageResource*, VisibilityStatus, const LayoutRect&);
|
||||
void updateAllImageResourcePriorities();
|
||||
void addRenderObject(RenderObject*);
|
||||
void removeRenderObject(RenderObject*);
|
||||
|
||||
static ResourceLoadPriorityOptimizer* resourceLoadPriorityOptimizer();
|
||||
|
||||
private:
|
||||
ResourceLoadPriorityOptimizer();
|
||||
~ResourceLoadPriorityOptimizer();
|
||||
|
||||
void updateImageResourcesWithLoadPriority();
|
||||
|
||||
struct ResourceAndVisibility {
|
||||
ResourceAndVisibility(ImageResource*, VisibilityStatus, uint32_t);
|
||||
~ResourceAndVisibility();
|
||||
ResourcePtr<ImageResource> imageResource;
|
||||
VisibilityStatus status;
|
||||
int screenArea;
|
||||
};
|
||||
|
||||
typedef HashMap<unsigned long, OwnPtr<ResourceAndVisibility>, WTF::IntHash<unsigned>, WTF::UnsignedWithZeroKeyHashTraits<unsigned> > ImageResourceMap;
|
||||
ImageResourceMap m_imageResources;
|
||||
|
||||
typedef HashSet<RenderObject*> RenderObjectSet;
|
||||
RenderObjectSet m_objects;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -32,7 +32,6 @@
|
||||
#include "core/dom/DocumentMarkerController.h"
|
||||
#include "core/editing/FrameSelection.h"
|
||||
#include "core/fetch/ResourceFetcher.h"
|
||||
#include "core/fetch/ResourceLoadPriorityOptimizer.h"
|
||||
#include "core/frame/FrameHost.h"
|
||||
#include "core/frame/LocalFrame.h"
|
||||
#include "core/frame/Settings.h"
|
||||
@ -291,8 +290,6 @@ void FrameView::performLayout(RenderObject* rootForThisLayout, bool inSubtreeLay
|
||||
rootForThisLayout->layout();
|
||||
gatherDebugLayoutRects(rootForThisLayout);
|
||||
|
||||
ResourceLoadPriorityOptimizer::resourceLoadPriorityOptimizer()->updateAllImageResourcePriorities();
|
||||
|
||||
lifecycle().advanceTo(DocumentLifecycle::AfterPerformLayout);
|
||||
}
|
||||
|
||||
|
||||
@ -30,7 +30,6 @@
|
||||
#include "core/dom/shadow/ShadowRoot.h"
|
||||
#include "core/editing/Editor.h"
|
||||
#include "core/editing/FrameSelection.h"
|
||||
#include "core/fetch/ResourceLoadPriorityOptimizer.h"
|
||||
#include "core/frame/FrameView.h"
|
||||
#include "core/frame/LocalFrame.h"
|
||||
#include "core/page/Page.h"
|
||||
@ -116,31 +115,6 @@ static void removeBlockFromDescendantAndContainerMaps(RenderBlock* block, Tracke
|
||||
}
|
||||
}
|
||||
|
||||
static void appendImageIfNotNull(Vector<ImageResource*>& imageResources, const StyleImage* styleImage)
|
||||
{
|
||||
if (styleImage && styleImage->cachedImage()) {
|
||||
ImageResource* imageResource = styleImage->cachedImage();
|
||||
if (imageResource && !imageResource->isLoaded())
|
||||
imageResources.append(styleImage->cachedImage());
|
||||
}
|
||||
}
|
||||
|
||||
static void appendLayers(Vector<ImageResource*>& images, const FillLayer& styleLayer)
|
||||
{
|
||||
for (const FillLayer* layer = &styleLayer; layer; layer = layer->next())
|
||||
appendImageIfNotNull(images, layer->image());
|
||||
}
|
||||
|
||||
static void appendImagesFromStyle(Vector<ImageResource*>& images, RenderStyle& blockStyle)
|
||||
{
|
||||
appendLayers(images, blockStyle.backgroundLayers());
|
||||
appendLayers(images, blockStyle.maskLayers());
|
||||
|
||||
appendImageIfNotNull(images, blockStyle.listStyleImage());
|
||||
appendImageIfNotNull(images, blockStyle.borderImageSource());
|
||||
appendImageIfNotNull(images, blockStyle.maskBoxImageSource());
|
||||
}
|
||||
|
||||
void RenderBlock::removeFromGlobalMaps()
|
||||
{
|
||||
if (gPercentHeightDescendantsMap)
|
||||
@ -275,15 +249,6 @@ void RenderBlock::styleDidChange(StyleDifference diff, const RenderStyle* oldSty
|
||||
// It's possible for our border/padding to change, but for the overall logical width of the block to
|
||||
// end up being the same. We keep track of this change so in layoutBlock, we can know to set relayoutChildren=true.
|
||||
m_hasBorderOrPaddingLogicalWidthChanged = oldStyle && diff.needsFullLayout() && needsLayout() && borderOrPaddingLogicalWidthChanged(oldStyle, newStyle);
|
||||
|
||||
// If the style has unloaded images, want to notify the ResourceLoadPriorityOptimizer so that
|
||||
// network priorities can be set.
|
||||
Vector<ImageResource*> images;
|
||||
appendImagesFromStyle(images, *newStyle);
|
||||
if (images.isEmpty())
|
||||
ResourceLoadPriorityOptimizer::resourceLoadPriorityOptimizer()->removeRenderObject(this);
|
||||
else
|
||||
ResourceLoadPriorityOptimizer::resourceLoadPriorityOptimizer()->addRenderObject(this);
|
||||
}
|
||||
|
||||
void RenderBlock::invalidateTreeIfNeeded(const PaintInvalidationState& paintInvalidationState)
|
||||
@ -886,39 +851,6 @@ void RenderBlock::layout()
|
||||
invalidateBackgroundObscurationStatus();
|
||||
}
|
||||
|
||||
bool RenderBlock::updateImageLoadingPriorities()
|
||||
{
|
||||
Vector<ImageResource*> images;
|
||||
appendImagesFromStyle(images, *style());
|
||||
|
||||
if (images.isEmpty())
|
||||
return false;
|
||||
|
||||
LayoutRect viewBounds = viewRect();
|
||||
LayoutRect objectBounds = absoluteContentBox();
|
||||
// The object bounds might be empty right now, so intersects will fail since it doesn't deal
|
||||
// with empty rects. Use LayoutRect::contains in that case.
|
||||
bool isVisible;
|
||||
if (!objectBounds.isEmpty())
|
||||
isVisible = viewBounds.intersects(objectBounds);
|
||||
else
|
||||
isVisible = viewBounds.contains(objectBounds);
|
||||
|
||||
ResourceLoadPriorityOptimizer::VisibilityStatus status = isVisible ?
|
||||
ResourceLoadPriorityOptimizer::Visible : ResourceLoadPriorityOptimizer::NotVisible;
|
||||
|
||||
LayoutRect screenArea;
|
||||
if (!objectBounds.isEmpty()) {
|
||||
screenArea = viewBounds;
|
||||
screenArea.intersect(objectBounds);
|
||||
}
|
||||
|
||||
for (Vector<ImageResource*>::iterator it = images.begin(), end = images.end(); it != end; ++it)
|
||||
ResourceLoadPriorityOptimizer::resourceLoadPriorityOptimizer()->notifyImageResourceVisibility(*it, status, screenArea);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderBlock::widthAvailableToChildrenHasChanged()
|
||||
{
|
||||
bool widthAvailableToChildrenHasChanged = m_hasBorderOrPaddingLogicalWidthChanged;
|
||||
|
||||
@ -228,7 +228,6 @@ protected:
|
||||
void dirtyForLayoutFromPercentageHeightDescendants(SubtreeLayoutScope&);
|
||||
|
||||
virtual void layout() override;
|
||||
virtual bool updateImageLoadingPriorities() override final;
|
||||
|
||||
enum PositionedLayoutBehavior {
|
||||
DefaultLayout,
|
||||
|
||||
@ -30,7 +30,6 @@
|
||||
|
||||
#include "core/editing/FrameSelection.h"
|
||||
#include "core/fetch/ImageResource.h"
|
||||
#include "core/fetch/ResourceLoadPriorityOptimizer.h"
|
||||
#include "core/fetch/ResourceLoader.h"
|
||||
#include "core/frame/LocalFrame.h"
|
||||
#include "core/html/HTMLImageElement.h"
|
||||
@ -54,7 +53,6 @@ RenderImage::RenderImage(Element* element)
|
||||
, m_imageDevicePixelRatio(1.0f)
|
||||
{
|
||||
updateAltText();
|
||||
ResourceLoadPriorityOptimizer::resourceLoadPriorityOptimizer()->addRenderObject(this);
|
||||
}
|
||||
|
||||
RenderImage* RenderImage::createAnonymous(Document* document)
|
||||
@ -471,36 +469,6 @@ void RenderImage::layout()
|
||||
}
|
||||
}
|
||||
|
||||
bool RenderImage::updateImageLoadingPriorities()
|
||||
{
|
||||
if (!m_imageResource || !m_imageResource->cachedImage() || m_imageResource->cachedImage()->isLoaded())
|
||||
return false;
|
||||
|
||||
LayoutRect viewBounds = viewRect();
|
||||
LayoutRect objectBounds = absoluteContentBox();
|
||||
|
||||
// The object bounds might be empty right now, so intersects will fail since it doesn't deal
|
||||
// with empty rects. Use LayoutRect::contains in that case.
|
||||
bool isVisible;
|
||||
if (!objectBounds.isEmpty())
|
||||
isVisible = viewBounds.intersects(objectBounds);
|
||||
else
|
||||
isVisible = viewBounds.contains(objectBounds);
|
||||
|
||||
ResourceLoadPriorityOptimizer::VisibilityStatus status = isVisible ?
|
||||
ResourceLoadPriorityOptimizer::Visible : ResourceLoadPriorityOptimizer::NotVisible;
|
||||
|
||||
LayoutRect screenArea;
|
||||
if (!objectBounds.isEmpty()) {
|
||||
screenArea = viewBounds;
|
||||
screenArea.intersect(objectBounds);
|
||||
}
|
||||
|
||||
ResourceLoadPriorityOptimizer::resourceLoadPriorityOptimizer()->notifyImageResourceVisibility(m_imageResource->cachedImage(), status, screenArea);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderImage::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const
|
||||
{
|
||||
RenderReplaced::computeIntrinsicRatioInformation(intrinsicSize, intrinsicRatio);
|
||||
|
||||
@ -70,7 +70,6 @@ protected:
|
||||
void paintIntoRect(GraphicsContext*, const LayoutRect&);
|
||||
virtual void paint(PaintInfo&, const LayoutPoint&) override final;
|
||||
virtual void layout() override;
|
||||
virtual bool updateImageLoadingPriorities() override final;
|
||||
|
||||
private:
|
||||
virtual const char* renderName() const override { return "RenderImage"; }
|
||||
|
||||
@ -34,7 +34,6 @@
|
||||
#include "core/editing/EditingBoundary.h"
|
||||
#include "core/editing/FrameSelection.h"
|
||||
#include "core/editing/htmlediting.h"
|
||||
#include "core/fetch/ResourceLoadPriorityOptimizer.h"
|
||||
#include "core/fetch/ResourceLoader.h"
|
||||
#include "core/frame/FrameView.h"
|
||||
#include "core/frame/LocalFrame.h"
|
||||
@ -2273,10 +2272,7 @@ void RenderObject::postDestroy()
|
||||
if (StyleImage* maskBoxImage = m_style->maskBoxImage().image())
|
||||
maskBoxImage->removeClient(this);
|
||||
}
|
||||
ResourceLoadPriorityOptimizer::resourceLoadPriorityOptimizer()->removeRenderObject(this);
|
||||
#if !ENABLE(OILPAN)
|
||||
delete this;
|
||||
#endif
|
||||
}
|
||||
|
||||
PositionWithAffinity RenderObject::positionForPoint(const LayoutPoint&)
|
||||
|
||||
@ -564,7 +564,6 @@ public:
|
||||
// Subclasses must reimplement this method to compute the size and position
|
||||
// of this object and all its descendants.
|
||||
virtual void layout() = 0;
|
||||
virtual bool updateImageLoadingPriorities() { return false; }
|
||||
void setHasPendingResourceUpdate(bool hasPendingResourceUpdate) { m_bitfields.setHasPendingResourceUpdate(hasPendingResourceUpdate); }
|
||||
bool hasPendingResourceUpdate() const { return m_bitfields.hasPendingResourceUpdate(); }
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user