diff --git a/engine/core/core.gni b/engine/core/core.gni index 0d387f1b6dc..d02e107f52e 100644 --- a/engine/core/core.gni +++ b/engine/core/core.gni @@ -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", diff --git a/engine/core/fetch/ResourceLoadPriorityOptimizer.cpp b/engine/core/fetch/ResourceLoadPriorityOptimizer.cpp deleted file mode 100644 index bdb63a71b12..00000000000 --- a/engine/core/fetch/ResourceLoadPriorityOptimizer.cpp +++ /dev/null @@ -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 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(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; - } -} - -} diff --git a/engine/core/fetch/ResourceLoadPriorityOptimizer.h b/engine/core/fetch/ResourceLoadPriorityOptimizer.h deleted file mode 100644 index 7373bd5931f..00000000000 --- a/engine/core/fetch/ResourceLoadPriorityOptimizer.h +++ /dev/null @@ -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; - VisibilityStatus status; - int screenArea; - }; - - typedef HashMap, WTF::IntHash, WTF::UnsignedWithZeroKeyHashTraits > ImageResourceMap; - ImageResourceMap m_imageResources; - - typedef HashSet RenderObjectSet; - RenderObjectSet m_objects; -}; - -} - -#endif diff --git a/engine/core/frame/FrameView.cpp b/engine/core/frame/FrameView.cpp index 2adb01b7cc0..13bfc6b79e5 100644 --- a/engine/core/frame/FrameView.cpp +++ b/engine/core/frame/FrameView.cpp @@ -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); } diff --git a/engine/core/rendering/RenderBlock.cpp b/engine/core/rendering/RenderBlock.cpp index 652b626f033..1d0a01dc9ea 100644 --- a/engine/core/rendering/RenderBlock.cpp +++ b/engine/core/rendering/RenderBlock.cpp @@ -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& imageResources, const StyleImage* styleImage) -{ - if (styleImage && styleImage->cachedImage()) { - ImageResource* imageResource = styleImage->cachedImage(); - if (imageResource && !imageResource->isLoaded()) - imageResources.append(styleImage->cachedImage()); - } -} - -static void appendLayers(Vector& images, const FillLayer& styleLayer) -{ - for (const FillLayer* layer = &styleLayer; layer; layer = layer->next()) - appendImageIfNotNull(images, layer->image()); -} - -static void appendImagesFromStyle(Vector& 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 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 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::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; diff --git a/engine/core/rendering/RenderBlock.h b/engine/core/rendering/RenderBlock.h index c85b571839c..d0c03ac6432 100644 --- a/engine/core/rendering/RenderBlock.h +++ b/engine/core/rendering/RenderBlock.h @@ -228,7 +228,6 @@ protected: void dirtyForLayoutFromPercentageHeightDescendants(SubtreeLayoutScope&); virtual void layout() override; - virtual bool updateImageLoadingPriorities() override final; enum PositionedLayoutBehavior { DefaultLayout, diff --git a/engine/core/rendering/RenderImage.cpp b/engine/core/rendering/RenderImage.cpp index aa1bcd14fb4..752df66162c 100644 --- a/engine/core/rendering/RenderImage.cpp +++ b/engine/core/rendering/RenderImage.cpp @@ -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); diff --git a/engine/core/rendering/RenderImage.h b/engine/core/rendering/RenderImage.h index fb0280deab5..ec338227312 100644 --- a/engine/core/rendering/RenderImage.h +++ b/engine/core/rendering/RenderImage.h @@ -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"; } diff --git a/engine/core/rendering/RenderObject.cpp b/engine/core/rendering/RenderObject.cpp index 83f588de6e2..ba07891bcb8 100644 --- a/engine/core/rendering/RenderObject.cpp +++ b/engine/core/rendering/RenderObject.cpp @@ -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&) diff --git a/engine/core/rendering/RenderObject.h b/engine/core/rendering/RenderObject.h index d91919c7759..fd5be33d2bb 100644 --- a/engine/core/rendering/RenderObject.h +++ b/engine/core/rendering/RenderObject.h @@ -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(); }