Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1211)

Unified Diff: Source/core/rendering/compositing/CompositedLayerMapping.cpp

Issue 183833020: Re-land "Drop background color optimization for composited layers" (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/rendering/compositing/CompositedLayerMapping.cpp
diff --git a/Source/core/rendering/compositing/CompositedLayerMapping.cpp b/Source/core/rendering/compositing/CompositedLayerMapping.cpp
index 3ce4290754caaf99725c2b7979cdb3f2ffe5c226..edb47d02a527e92d5f05479bc52c5492ad06d07d 100644
--- a/Source/core/rendering/compositing/CompositedLayerMapping.cpp
+++ b/Source/core/rendering/compositing/CompositedLayerMapping.cpp
@@ -346,7 +346,7 @@ void CompositedLayerMapping::updateCompositedBounds()
{
// We need to know if we draw content in order to update our bounds (this has an effect
// on whether or not descendands will paint into our backing). Update this value now.
- updateDrawsContent(isSimpleContainerCompositingLayer());
+ updateDrawsContent();
LayoutRect layerBounds = compositor()->calculateCompositedBounds(m_owningLayer, m_owningLayer);
@@ -514,7 +514,7 @@ bool CompositedLayerMapping::updateGraphicsLayerConfiguration()
m_graphicsLayer->setReplicatedByLayer(0);
}
- updateBackgroundColor(isSimpleContainerCompositingLayer());
+ updateBackgroundColor();
if (isDirectlyCompositedImage())
updateImageContents();
@@ -632,8 +632,6 @@ void CompositedLayerMapping::updateGraphicsLayerGeometry()
if (!hasActiveAnimationsOnCompositor(*renderer(), CSSPropertyOpacity))
updateOpacity(renderer()->style());
- bool isSimpleContainer = isSimpleContainerCompositingLayer();
-
m_owningLayer->updateDescendantDependentFlags();
// m_graphicsLayer is the corresponding GraphicsLayer for this RenderLayer and its non-compositing
@@ -851,9 +849,9 @@ void CompositedLayerMapping::updateGraphicsLayerGeometry()
updateIsRootForIsolatedGroup();
}
- updateContentsRect(isSimpleContainer);
- updateBackgroundColor(isSimpleContainer);
- updateDrawsContent(isSimpleContainer);
+ updateContentsRect();
+ updateBackgroundColor();
+ updateDrawsContent();
updateContentsOpaque();
updateAfterWidgetResize();
updateRenderingContext();
@@ -938,18 +936,12 @@ void CompositedLayerMapping::updateInternalHierarchy()
}
}
-void CompositedLayerMapping::updateContentsRect(bool isSimpleContainer)
+void CompositedLayerMapping::updateContentsRect()
{
- LayoutRect contentsRect;
- if (isSimpleContainer && renderer()->hasBackground())
- contentsRect = backgroundBox();
- else
- contentsRect = contentsBox();
-
- m_graphicsLayer->setContentsRect(pixelSnappedIntRect(contentsRect));
+ m_graphicsLayer->setContentsRect(pixelSnappedIntRect(contentsBox()));
}
-void CompositedLayerMapping::updateDrawsContent(bool isSimpleContainer)
+void CompositedLayerMapping::updateDrawsContent()
{
if (m_scrollingLayer) {
// We don't have to consider overflow controls, because we know that the scrollbars are drawn elsewhere.
@@ -964,7 +956,7 @@ void CompositedLayerMapping::updateDrawsContent(bool isSimpleContainer)
return;
}
- bool hasPaintedContent = containsPaintedContent(isSimpleContainer);
+ bool hasPaintedContent = containsPaintedContent();
if (hasPaintedContent && isAcceleratedCanvas(renderer())) {
CanvasRenderingContext* context = toHTMLCanvasElement(renderer()->node())->renderingContext();
// Content layer may be null if context is lost.
@@ -1498,45 +1490,9 @@ Color CompositedLayerMapping::rendererBackgroundColor() const
return backgroundRenderer->resolveColor(CSSPropertyBackgroundColor);
}
-void CompositedLayerMapping::updateBackgroundColor(bool isSimpleContainer)
+void CompositedLayerMapping::updateBackgroundColor()
{
- Color backgroundColor = rendererBackgroundColor();
- if (isSimpleContainer) {
- m_graphicsLayer->setContentsToSolidColor(backgroundColor);
- m_graphicsLayer->setBackgroundColor(Color::transparent);
- } else {
- m_graphicsLayer->setContentsToSolidColor(Color::transparent);
- m_graphicsLayer->setBackgroundColor(backgroundColor);
- }
-}
-
-static bool supportsDirectBoxDecorationsComposition(const RenderObject* renderer)
-{
- if (renderer->hasClip())
- return false;
-
- if (hasBoxDecorationsOrBackgroundImage(renderer->style()))
- return false;
-
- // FIXME: we should be able to allow backgroundComposite; However since this is not a common use case it has been deferred for now.
- if (renderer->style()->backgroundComposite() != CompositeSourceOver)
- return false;
-
- if (renderer->style()->backgroundClip() == TextFillBox)
- return false;
-
- return true;
-}
-
-bool CompositedLayerMapping::paintsBoxDecorations() const
-{
- if (!m_owningLayer->hasVisibleBoxDecorations())
- return false;
-
- if (!supportsDirectBoxDecorationsComposition(renderer()))
- return true;
-
- return false;
+ m_graphicsLayer->setBackgroundColor(rendererBackgroundColor());
}
bool CompositedLayerMapping::paintsChildren() const
@@ -1555,52 +1511,6 @@ static bool isCompositedPlugin(RenderObject* renderer)
return renderer->isEmbeddedObject() && toRenderEmbeddedObject(renderer)->allowsAcceleratedCompositing();
}
-// A "simple container layer" is a RenderLayer which has no visible content to render.
-// It may have no children, or all its children may be themselves composited.
-// This is a useful optimization, because it allows us to avoid allocating backing store.
-bool CompositedLayerMapping::isSimpleContainerCompositingLayer() const
-{
- RenderObject* renderObject = renderer();
- if (renderObject->hasMask()) // masks require special treatment
- return false;
-
- if (renderObject->isReplaced() && !isCompositedPlugin(renderObject))
- return false;
-
- if (paintsBoxDecorations() || paintsChildren())
- return false;
-
- if (renderObject->isRenderRegion())
- return false;
-
- if (renderObject->node() && renderObject->node()->isDocumentNode()) {
- // Look to see if the root object has a non-simple background
- RenderObject* rootObject = renderObject->document().documentElement() ? renderObject->document().documentElement()->renderer() : 0;
- if (!rootObject)
- return false;
-
- RenderStyle* style = rootObject->style();
-
- // Reject anything that has a border, a border-radius or outline,
- // or is not a simple background (no background, or solid color).
- if (hasBoxDecorationsOrBackgroundImage(style))
- return false;
-
- // Now look at the body's renderer.
- HTMLElement* body = renderObject->document().body();
- RenderObject* bodyObject = (body && body->hasLocalName(bodyTag)) ? body->renderer() : 0;
- if (!bodyObject)
- return false;
-
- style = bodyObject->style();
-
- if (hasBoxDecorationsOrBackgroundImage(style))
- return false;
- }
-
- return true;
-}
-
static bool hasVisibleNonCompositingDescendant(RenderLayer* parent)
{
if (!parent->hasVisibleDescendant())
@@ -1633,20 +1543,53 @@ bool CompositedLayerMapping::hasVisibleNonCompositingDescendantLayers() const
return hasVisibleNonCompositingDescendant(m_owningLayer);
}
-bool CompositedLayerMapping::containsPaintedContent(bool isSimpleContainer) const
+bool CompositedLayerMapping::containsPaintedContent() const
{
- if (isSimpleContainer || paintsIntoCompositedAncestor() || m_artificiallyInflatedBounds || m_owningLayer->isReflection())
+ if (paintsIntoCompositedAncestor() || m_artificiallyInflatedBounds || m_owningLayer->isReflection())
return false;
if (isDirectlyCompositedImage())
return false;
+ RenderObject* renderObject = renderer();
// FIXME: we could optimize cases where the image, video or canvas is known to fill the border box entirely,
// and set background color on the layer in that case, instead of allocating backing store and painting.
- if (renderer()->isVideo() && toRenderVideo(renderer())->shouldDisplayVideo())
+ if (renderObject->isVideo() && toRenderVideo(renderer())->shouldDisplayVideo())
return m_owningLayer->hasBoxDecorationsOrBackground();
- return true;
+ if (m_owningLayer->hasVisibleBoxDecorations())
+ return true;
+
+ if (renderObject->hasMask()) // masks require special treatment
+ return true;
+
+ if (renderObject->isReplaced() && !isCompositedPlugin(renderObject))
+ return true;
+
+ if (renderObject->isRenderRegion())
+ return true;
+
+ if (renderObject->node() && renderObject->node()->isDocumentNode() && renderObject->document().documentElement()) {
alokp 2014/03/04 17:44:39 Is there a need to check for renderObject->documen
dshwang 2014/03/04 18:56:13 it checks the third condition in the above "if sta
+ // Look to see if the root object has a non-simple background
+ RenderObject* rootObject = renderObject->document().documentElement()->renderer();
+ if (rootObject) {
dshwang 2014/03/04 17:12:29 now null-check resurrects
+ // Reject anything that has a border, a border-radius or outline,
+ // or is not a simple background (no background, or solid color).
+ if (hasBoxDecorationsOrBackgroundImage(rootObject->style()))
alokp 2014/03/04 17:44:39 this if block can be combined with the above: if (
dshwang 2014/03/04 18:56:13 Done.
+ return true;
+ }
+
+ // Now look at the body's renderer.
+ HTMLElement* body = renderObject->document().body();
+ RenderObject* bodyObject = (body && body->hasLocalName(bodyTag)) ? body->renderer() : 0;
+ if (bodyObject) {
alokp 2014/03/04 17:44:39 same here
dshwang 2014/03/04 18:56:13 Done.
+ if (hasBoxDecorationsOrBackgroundImage(bodyObject->style()))
+ return true;
+ }
+ }
+
+ // FIXME: it's O(n^2). A better solution is needed.
+ return paintsChildren();
}
// An image can be directly compositing if it's the sole content of the layer, and has no box decorations
@@ -1702,8 +1645,7 @@ void CompositedLayerMapping::updateImageContents()
// This is a no-op if the layer doesn't have an inner layer for the image.
m_graphicsLayer->setContentsToImage(image);
- bool isSimpleContainer = false;
- updateDrawsContent(isSimpleContainer);
+ updateDrawsContent();
// Image animation is "lazy", in that it automatically stops unless someone is drawing
// the image. So we have to kick the animation each time; this has the downside that the
@@ -1750,13 +1692,6 @@ LayoutRect CompositedLayerMapping::contentsBox() const
return contentsBox;
}
-IntRect CompositedLayerMapping::backgroundBox() const
-{
- LayoutRect backgroundBox = backgroundRect(renderer());
- backgroundBox.move(contentOffsetInCompostingLayer());
- return pixelSnappedIntRect(backgroundBox);
-}
-
GraphicsLayer* CompositedLayerMapping::parentForSublayers() const
{
if (m_scrollingContentsLayer)
« no previous file with comments | « Source/core/rendering/compositing/CompositedLayerMapping.h ('k') | Source/platform/graphics/GraphicsLayer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698