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

Unified Diff: Source/core/rendering/RenderLayer.cpp

Issue 13467028: Add an intermediate function to generate 2 paint-order lists. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: addressing review comments Created 7 years, 8 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
« no previous file with comments | « Source/core/rendering/RenderLayer.h ('k') | Source/core/testing/Internals.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/rendering/RenderLayer.cpp
diff --git a/Source/core/rendering/RenderLayer.cpp b/Source/core/rendering/RenderLayer.cpp
index 002087445a3e37caf1f18c52c60962f6f4cc14a4..a458d915e953b993de5ed6570b513f072c50f5ea 100644
--- a/Source/core/rendering/RenderLayer.cpp
+++ b/Source/core/rendering/RenderLayer.cpp
@@ -100,6 +100,7 @@
#include "Settings.h"
#include "ShadowRoot.h"
#include "SourceGraphic.h"
+#include "StaticHashSetNodeList.h"
#include "StylePropertySet.h"
#include "StyleResolver.h"
#include "TextStream.h"
@@ -639,6 +640,230 @@ void RenderLayer::updateDescendantsAreContiguousInStackingOrderRecursive(const H
}
}
+static inline bool isPositionedContainer(const RenderLayer* layer)
+{
+ // FIXME: This is not in sync with containingBlock.
+ // RenderObject::canContainFixedPositionedObject() should probably be used
+ // instead.
+ RenderLayerModelObject* layerRenderer = layer->renderer();
+ return layer->isRootLayer() || layerRenderer->isPositioned() || layer->hasTransform();
+}
+
+enum StackingOrderDirection { FromBackground, FromForeground };
+
+// We'd like to be able to iterate through a single paint order list, but for
+// efficiency's sake, we hang onto two lists instead (namely, the pos and neg
+// z-order lists produced by CollectLayers). This function allows us to index
+// into these two lists as if they were one. It also allows us to index into
+// this virtual list either from the start or from the end (i.e., in either
+// stacking order direction).
+static const RenderLayer* getStackingOrderElementAt(const Vector<RenderLayer*>* posZOrderList, const Vector<RenderLayer*>* negZOrderList, const StackingOrderDirection direction, const size_t index)
+{
+ size_t negZOrderListSize = negZOrderList ? negZOrderList->size() : 0;
+
+ if (direction == FromBackground) {
+ if (index < negZOrderListSize)
+ return negZOrderList->at(index);
+
+ return posZOrderList->at(index - negZOrderListSize);
+ }
+
+ size_t posZOrderListSize = posZOrderList ? posZOrderList->size() : 0;
+
+ if (index < posZOrderListSize)
+ return posZOrderList->at(posZOrderListSize - index - 1);
+
+ return negZOrderList->at(negZOrderListSize - (index - posZOrderListSize) - 1);
+}
+
+// Compute what positive and negative z-order lists would look like before and
+// after promotion, so we can later ensure that proper stacking order is
+// preserved between the two sets of lists.
+//
+// A few examples:
+// c = currentLayer
+// - = negative z-order child of currentLayer
+// + = positive z-order child of currentLayer
+// a = positioned ancestor of currentLayer
+// x = any other RenderLayer in the list
+//
+// (a) xxxxx-----++a+++x
+// (b) xxx-----c++++++xx
+//
+//
+// Normally the current layer would be painted in the normal flow list if it
+// doesn't already appear in the positive z-order list. However, in the case
+// that the layer has a positioned ancestor, it will paint directly after the
+// positioned ancestor. In example (a), the current layer would be painted in
+// the middle of its own positive z-order children, so promoting would cause a
+// change in paint order (since a promoted layer will paint all of its positive
+// z-order children strictly after it paints itself).
+//
+// In example (b), it is ok to promote the current layer only if it does not
+// have a background. If it has a background, the background gets painted before
+// the layer's negative z-order children, so again, a promotion would cause a
+// change in paint order (causing the background to get painted after the
+// negative z-order children instead of before).
+void RenderLayer::collectBeforePromotionZOrderList(RenderLayer* ancestorStackingContext, OwnPtr<Vector<RenderLayer*> >& posZOrderListBeforePromote, OwnPtr<Vector<RenderLayer*> >& negZOrderListBeforePromote, size_t& posZOrderListSizeBeforePromote, size_t& negZOrderListSizeBeforePromote)
+{
+ // We can't use TemporaryChange<> here since m_needsCompositedScrolling and
+ // m_isNormalFlowOnly are both bitfields, so we have to do it the
+ // old-fashioned way.
+ bool oldNeedsCompositedScrolling = m_needsCompositedScrolling;
+ bool oldIsNormalFlowOnly = m_isNormalFlowOnly;
+
+ // Set the flag on the current layer, then rebuild ancestor stacking
+ // context's lists. This way, we can see the exact effects that promoting
+ // this layer would cause.
+ m_needsCompositedScrolling = false;
+ m_isNormalFlowOnly = shouldBeNormalFlowOnly();
+ ancestorStackingContext->rebuildZOrderLists(StopAtStackingContexts, posZOrderListBeforePromote, negZOrderListBeforePromote, 0);
+
+ m_needsCompositedScrolling = oldNeedsCompositedScrolling;
+ m_isNormalFlowOnly = oldIsNormalFlowOnly;
+
+
+ posZOrderListSizeBeforePromote = posZOrderListBeforePromote ? posZOrderListBeforePromote->size() : 0;
+ negZOrderListSizeBeforePromote = negZOrderListBeforePromote ? negZOrderListBeforePromote->size() : 0;
+
+ const RenderLayer* positionedAncestor = parent();
+ while (positionedAncestor && !isPositionedContainer(positionedAncestor) && !positionedAncestor->isStackingContext())
+ positionedAncestor = positionedAncestor->parent();
+ if (positionedAncestor && (!isPositionedContainer(positionedAncestor) || positionedAncestor->isStackingContext()))
+ positionedAncestor = 0;
+
+ bool currentLayerIsInPosZOrderListBeforePromote = false;
+
+ for (size_t index = 0; index < posZOrderListSizeBeforePromote; index++) {
+ if (posZOrderListBeforePromote->at(index) == this) {
+ currentLayerIsInPosZOrderListBeforePromote = true;
+ break;
+ }
+ }
+
+ // Insert this into the posZOrderListBeforePromote directly after the
+ // positioned ancestor, if there is one. Otherwise, add it to the very
+ // beginning.
+ //
+ // The current layer will appear in the z-order lists after promotion, so
+ // for a meaningful comparison, we must insert it in the z-order lists
+ // before promotion if it does not appear there already.
+ if (!currentLayerIsInPosZOrderListBeforePromote) {
+ if (!positionedAncestor) {
+ if (!posZOrderListBeforePromote)
+ posZOrderListBeforePromote = adoptPtr(new Vector<RenderLayer*>());
+
+ posZOrderListBeforePromote->prepend(this);
+ posZOrderListSizeBeforePromote++;
+ } else {
+ for (size_t index = 0; index < posZOrderListSizeBeforePromote; index++) {
+ if (posZOrderListBeforePromote->at(index) == positionedAncestor) {
+ posZOrderListBeforePromote->insert(index + 1, this);
+ posZOrderListSizeBeforePromote++;
+ break;
+ }
+ }
+ }
+ }
+}
+
+void RenderLayer::collectAfterPromotionZOrderList(RenderLayer* ancestorStackingContext, OwnPtr<Vector<RenderLayer*> >& posZOrderListAfterPromote, OwnPtr<Vector<RenderLayer*> >& negZOrderListAfterPromote, size_t& posZOrderListSizeAfterPromote, size_t& negZOrderListSizeAfterPromote)
+{
+ // We can't use TemporaryChange<> here since m_needsCompositedScrolling and
+ // m_isNormalFlowOnly are both bitfields, so we have to do it the
+ // old-fashioned way.
+ bool oldNeedsCompositedScrolling = m_needsCompositedScrolling;
+ bool oldIsNormalFlowOnly = m_isNormalFlowOnly;
+
+ // Set the flag on the current layer, then rebuild ancestor stacking
+ // context's lists. This way, we can see the exact effects that promoting
+ // this layer would cause.
+ m_isNormalFlowOnly = false;
+ m_needsCompositedScrolling = true;
+ ancestorStackingContext->rebuildZOrderLists(StopAtStackingContexts, posZOrderListAfterPromote, negZOrderListAfterPromote, this);
+
+ m_needsCompositedScrolling = oldNeedsCompositedScrolling;
+ m_isNormalFlowOnly = oldIsNormalFlowOnly;
+
+ posZOrderListSizeAfterPromote = posZOrderListAfterPromote ? posZOrderListAfterPromote->size() : 0;
+ negZOrderListSizeAfterPromote = negZOrderListAfterPromote ? negZOrderListAfterPromote->size() : 0;
+}
+
+#ifndef NDEBUG
+String RenderLayer::paintOrderListsAsText()
+{
+ OwnPtr<Vector<RenderLayer*> > posZOrderListBeforePromote;
+ OwnPtr<Vector<RenderLayer*> > negZOrderListBeforePromote;
+ OwnPtr<Vector<RenderLayer*> > posZOrderListAfterPromote;
+ OwnPtr<Vector<RenderLayer*> > negZOrderListAfterPromote;
+ size_t posZOrderListSizeBeforePromote, negZOrderListSizeBeforePromote, posZOrderListSizeAfterPromote, negZOrderListSizeAfterPromote;
+
+ RenderLayer* stackingContext = ancestorStackingContext();
+
+ if (!stackingContext)
+ return String();
+
+ collectBeforePromotionZOrderList(stackingContext, posZOrderListBeforePromote, negZOrderListBeforePromote, posZOrderListSizeBeforePromote, negZOrderListSizeBeforePromote);
+ collectAfterPromotionZOrderList(stackingContext, posZOrderListAfterPromote, negZOrderListAfterPromote, posZOrderListSizeAfterPromote, negZOrderListSizeAfterPromote);
+
+ size_t sizeBeforePromote = posZOrderListSizeBeforePromote + negZOrderListSizeBeforePromote;
+ size_t sizeAfterPromote = posZOrderListSizeAfterPromote + negZOrderListSizeAfterPromote;
+
+ TextStream ts;
+
+ ts << "Layer: " << this << " \"" << debugName() << "\", z-index: " << renderer()->style()->zIndex() << "\n";
+
+ ts << " stacking context's paint order list BEFORE promote:\n";
+ for (size_t index = 0; index < sizeBeforePromote; index++) {
+ const RenderLayer* layerBeforePromote = getStackingOrderElementAt(posZOrderListBeforePromote.get(), negZOrderListBeforePromote.get(), FromBackground, index);
+ ts << " " << layerBeforePromote << " \"" << layerBeforePromote->debugName() << "\", z-index: " << layerBeforePromote->renderer()->style()->zIndex() << "\n";
+ }
+
+ ts << " stacking context's paint order list AFTER promote:\n";
+ for (size_t index = 0; index < sizeAfterPromote; index++) {
+ const RenderLayer* layerAfterPromote = getStackingOrderElementAt(posZOrderListAfterPromote.get(), negZOrderListAfterPromote.get(), FromBackground, index);
+ ts << " " << layerAfterPromote << " \"" << layerAfterPromote->debugName() << "\", z-index: " << layerAfterPromote->renderer()->style()->zIndex() << "\n";
+ }
+
+ return ts.release();
+}
+#endif
+
+PassRefPtr<NodeList> RenderLayer::paintOrderList(PaintOrderListType type)
+{
+ OwnPtr<Vector<RenderLayer*> > posZOrderList;
+ OwnPtr<Vector<RenderLayer*> > negZOrderList;
+ size_t posZOrderListSize, negZOrderListSize;
+
+ RenderLayer* stackingContext = ancestorStackingContext();
+
+ if (!stackingContext)
+ return 0;
+
+ switch(type) {
+ case BeforePromote:
+ collectBeforePromotionZOrderList(stackingContext, posZOrderList, negZOrderList, posZOrderListSize, negZOrderListSize);
+ break;
+
+ case AfterPromote:
+ collectAfterPromotionZOrderList(stackingContext, posZOrderList, negZOrderList, posZOrderListSize, negZOrderListSize);
+ break;
+
+ default:
+ return 0;
+ }
+
+ size_t size = posZOrderListSize + negZOrderListSize;
+
+ ListHashSet<RefPtr<Node> > list;
+ for (size_t index = 0; index < size; index++) {
+ const RenderLayer* layer = getStackingOrderElementAt(posZOrderList.get(), negZOrderList.get(), FromBackground, index);
+ list.add(layer->renderer()->node());
+ }
+
+ return StaticHashSetNodeList::adopt(list);
+}
+
void RenderLayer::computeRepaintRects(const RenderLayerModelObject* repaintContainer, const RenderGeometryMap* geometryMap)
{
ASSERT(!m_visibleContentStatusDirty);
@@ -1268,12 +1493,6 @@ RenderLayer* RenderLayer::ancestorStackingContext() const
return ancestor;
}
-static inline bool isPositionedContainer(RenderLayer* layer)
-{
- RenderLayerModelObject* layerRenderer = layer->renderer();
- return layer->isRootLayer() || layerRenderer->isPositioned() || layer->hasTransform();
-}
-
static inline bool isFixedPositionedContainer(RenderLayer* layer)
{
return layer->isRootLayer() || layer->hasTransform();
@@ -5540,12 +5759,12 @@ void RenderLayer::rebuildZOrderLists()
m_zOrderListsDirty = false;
}
-void RenderLayer::rebuildZOrderLists(CollectLayersBehavior behavior, OwnPtr<Vector<RenderLayer*> >& posZOrderList, OwnPtr<Vector<RenderLayer*> >& negZOrderList)
+void RenderLayer::rebuildZOrderLists(CollectLayersBehavior behavior, OwnPtr<Vector<RenderLayer*> >& posZOrderList, OwnPtr<Vector<RenderLayer*> >& negZOrderList, const RenderLayer* layerToForceAsStackingContainer)
{
bool includeHiddenLayers = compositor()->inCompositingMode();
for (RenderLayer* child = firstChild(); child; child = child->nextSibling())
if (!m_reflection || reflectionLayer() != child)
- child->collectLayers(includeHiddenLayers, behavior, posZOrderList, negZOrderList);
+ child->collectLayers(includeHiddenLayers, behavior, posZOrderList, negZOrderList, layerToForceAsStackingContainer);
// Sort the two lists.
if (posZOrderList)
@@ -5590,7 +5809,7 @@ void RenderLayer::updateNormalFlowList()
m_normalFlowListDirty = false;
}
-void RenderLayer::collectLayers(bool includeHiddenLayers, CollectLayersBehavior behavior, OwnPtr<Vector<RenderLayer*> >& posBuffer, OwnPtr<Vector<RenderLayer*> >& negBuffer)
+void RenderLayer::collectLayers(bool includeHiddenLayers, CollectLayersBehavior behavior, OwnPtr<Vector<RenderLayer*> >& posBuffer, OwnPtr<Vector<RenderLayer*> >& negBuffer, const RenderLayer* layerToForceAsStackingContainer)
{
#if ENABLE(DIALOG_ELEMENT)
if (isInTopLayer())
@@ -5599,7 +5818,18 @@ void RenderLayer::collectLayers(bool includeHiddenLayers, CollectLayersBehavior
updateDescendantDependentFlags();
- bool isStacking = behavior == StopAtStackingContexts ? isStackingContext() : isStackingContainer();
+ bool isStacking = false;
+
+ switch (behavior) {
+ case StopAtStackingContexts:
+ isStacking = (this == layerToForceAsStackingContainer) || isStackingContext();
+ break;
+
+ case StopAtStackingContainers:
+ isStacking = (this == layerToForceAsStackingContainer) || isStackingContainer();
+ break;
+ }
+
// Overflow layers are just painted by their enclosing layers, so they don't get put in zorder lists.
bool includeHiddenLayer = includeHiddenLayers || (m_hasVisibleContent || (m_hasVisibleDescendant && isStacking));
if (includeHiddenLayer && !isNormalFlowOnly() && !isOutOfFlowRenderFlowThread()) {
@@ -5620,7 +5850,7 @@ void RenderLayer::collectLayers(bool includeHiddenLayers, CollectLayersBehavior
for (RenderLayer* child = firstChild(); child; child = child->nextSibling()) {
// Ignore reflections.
if (!m_reflection || reflectionLayer() != child)
- child->collectLayers(includeHiddenLayers, behavior, posBuffer, negBuffer);
+ child->collectLayers(includeHiddenLayers, behavior, posBuffer, negBuffer, layerToForceAsStackingContainer);
}
}
}
« no previous file with comments | « Source/core/rendering/RenderLayer.h ('k') | Source/core/testing/Internals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698