From: enne@google.com Date: Wed, 22 Feb 2012 20:02:55 +0000 (+0000) Subject: Unreviewed, rolling out r108518. X-Git-Tag: 070512121124~12130 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e43e66a89a75aacf4462f1cd9d7c45a8b9bbe59e;p=profile%2Fivi%2Fwebkit-efl.git Unreviewed, rolling out r108518. http://trac.webkit.org/changeset/108518 https://bugs.webkit.org/show_bug.cgi?id=75864 Breaks surfaceOcclusionWithOverlappingSiblingSurfaces unit test. * WebCore.gypi: * platform/graphics/chromium/cc/CCLayerIterator.cpp: (WebCore): (WebCore::CCLayerIteratorActions::BackToFront::begin): (WebCore::CCLayerIteratorActions::BackToFront::end): (WebCore::CCLayerIteratorActions::BackToFront::next): (WebCore::CCLayerIteratorActions::FrontToBack::begin): (WebCore::CCLayerIteratorActions::FrontToBack::end): (WebCore::CCLayerIteratorActions::FrontToBack::next): (WebCore::CCLayerIteratorActions::FrontToBack::goToHighestInSubtree): * platform/graphics/chromium/cc/CCLayerIterator.h: (WebCore): (WebCore::CCLayerIterator::CCLayerIterator): (WebCore::CCLayerIterator::operator++): (WebCore::CCLayerIterator::operator==): (WebCore::CCLayerIterator::operator->): (WebCore::CCLayerIterator::operator*): (WebCore::CCLayerIterator::representsTargetRenderSurface): (WebCore::CCLayerIterator::representsContributingRenderSurface): (WebCore::CCLayerIterator::targetRenderSurfaceLayer): (CCLayerIterator): (BackToFront): (FrontToBack): * platform/graphics/chromium/cc/CCLayerIteratorPosition.h: Added. (WebCore): (CCLayerIteratorPositionValue): (WebCore::CCLayerIteratorPosition::CCLayerIteratorPosition): (CCLayerIteratorPosition): (WebCore::CCLayerIteratorPosition::currentLayer): (WebCore::CCLayerIteratorPosition::currentLayerRepresentsContributingRenderSurface): (WebCore::CCLayerIteratorPosition::currentLayerRepresentsTargetRenderSurface): (WebCore::CCLayerIteratorPosition::targetRenderSurfaceLayer): (WebCore::CCLayerIteratorPosition::targetRenderSurface): (WebCore::CCLayerIteratorPosition::targetRenderSurfaceChildren): (WebCore::CCLayerIteratorPosition::operator==): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@108532 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 794420c..d491e0b 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,47 @@ +2012-02-22 Adrienne Walker + + Unreviewed, rolling out r108518. + http://trac.webkit.org/changeset/108518 + https://bugs.webkit.org/show_bug.cgi?id=75864 + + Breaks surfaceOcclusionWithOverlappingSiblingSurfaces unit test. + + * WebCore.gypi: + * platform/graphics/chromium/cc/CCLayerIterator.cpp: + (WebCore): + (WebCore::CCLayerIteratorActions::BackToFront::begin): + (WebCore::CCLayerIteratorActions::BackToFront::end): + (WebCore::CCLayerIteratorActions::BackToFront::next): + (WebCore::CCLayerIteratorActions::FrontToBack::begin): + (WebCore::CCLayerIteratorActions::FrontToBack::end): + (WebCore::CCLayerIteratorActions::FrontToBack::next): + (WebCore::CCLayerIteratorActions::FrontToBack::goToHighestInSubtree): + * platform/graphics/chromium/cc/CCLayerIterator.h: + (WebCore): + (WebCore::CCLayerIterator::CCLayerIterator): + (WebCore::CCLayerIterator::operator++): + (WebCore::CCLayerIterator::operator==): + (WebCore::CCLayerIterator::operator->): + (WebCore::CCLayerIterator::operator*): + (WebCore::CCLayerIterator::representsTargetRenderSurface): + (WebCore::CCLayerIterator::representsContributingRenderSurface): + (WebCore::CCLayerIterator::targetRenderSurfaceLayer): + (CCLayerIterator): + (BackToFront): + (FrontToBack): + * platform/graphics/chromium/cc/CCLayerIteratorPosition.h: Added. + (WebCore): + (CCLayerIteratorPositionValue): + (WebCore::CCLayerIteratorPosition::CCLayerIteratorPosition): + (CCLayerIteratorPosition): + (WebCore::CCLayerIteratorPosition::currentLayer): + (WebCore::CCLayerIteratorPosition::currentLayerRepresentsContributingRenderSurface): + (WebCore::CCLayerIteratorPosition::currentLayerRepresentsTargetRenderSurface): + (WebCore::CCLayerIteratorPosition::targetRenderSurfaceLayer): + (WebCore::CCLayerIteratorPosition::targetRenderSurface): + (WebCore::CCLayerIteratorPosition::targetRenderSurfaceChildren): + (WebCore::CCLayerIteratorPosition::operator==): + 2012-02-22 Dan Bernstein REGRESSION (r62632): page-break-inside: avoid is ignored diff --git a/Source/WebCore/WebCore.gypi b/Source/WebCore/WebCore.gypi index 7b3dbd1..3c54103 100644 --- a/Source/WebCore/WebCore.gypi +++ b/Source/WebCore/WebCore.gypi @@ -3267,6 +3267,7 @@ 'platform/graphics/chromium/cc/CCLayerImpl.h', 'platform/graphics/chromium/cc/CCLayerIterator.cpp', 'platform/graphics/chromium/cc/CCLayerIterator.h', + 'platform/graphics/chromium/cc/CCLayerIteratorPosition.h', 'platform/graphics/chromium/cc/CCLayerQuad.cpp', 'platform/graphics/chromium/cc/CCLayerQuad.h', 'platform/graphics/chromium/cc/CCLayerSorter.cpp', diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCLayerIterator.cpp b/Source/WebCore/platform/graphics/chromium/cc/CCLayerIterator.cpp index 97d6d18..0767ff0 100644 --- a/Source/WebCore/platform/graphics/chromium/cc/CCLayerIterator.cpp +++ b/Source/WebCore/platform/graphics/chromium/cc/CCLayerIterator.cpp @@ -35,73 +35,73 @@ namespace WebCore { -template -void CCLayerIteratorActions::BackToFront::begin(CCLayerIterator& it) +template +void CCLayerIteratorActions::BackToFront::begin(CCLayerIteratorPosition& pos) { - it.m_targetRenderSurfaceLayerIndex = 0; - it.m_currentLayerIndex = CCLayerIteratorValue::LayerIndexRepresentingTargetRenderSurface; + pos.targetRenderSurfaceLayerIndex = 0; + pos.currentLayerIndex = CCLayerIteratorPositionValue::LayerIndexRepresentingTargetRenderSurface; m_highestTargetRenderSurfaceLayer = 0; } -template -void CCLayerIteratorActions::BackToFront::end(CCLayerIterator& it) +template +void CCLayerIteratorActions::BackToFront::end(CCLayerIteratorPosition& pos) { - it.m_targetRenderSurfaceLayerIndex = CCLayerIteratorValue::InvalidTargetRenderSurfaceLayerIndex; - it.m_currentLayerIndex = 0; + pos.targetRenderSurfaceLayerIndex = CCLayerIteratorPositionValue::InvalidTargetRenderSurfaceLayerIndex; + pos.currentLayerIndex = 0; } -template -void CCLayerIteratorActions::BackToFront::next(CCLayerIterator& it) +template +void CCLayerIteratorActions::BackToFront::next(CCLayerIteratorPosition& pos) { // If the current layer has a RS, move to its layer list. Otherwise, visit the next layer in the current RS layer list. - if (it.currentLayerRepresentsContributingRenderSurface()) { + if (pos.currentLayerRepresentsContributingRenderSurface()) { // Save our position in the childLayer list for the RenderSurface, then jump to the next RenderSurface. Save where we // came from in the next RenderSurface so we can get back to it. - it.targetRenderSurface()->m_currentLayerIndexHistory = it.m_currentLayerIndex; - int previousTargetRenderSurfaceLayer = it.m_targetRenderSurfaceLayerIndex; + pos.targetRenderSurface()->m_currentLayerIndexHistory = pos.currentLayerIndex; + int previousTargetRenderSurfaceLayer = pos.targetRenderSurfaceLayerIndex; - it.m_targetRenderSurfaceLayerIndex = ++m_highestTargetRenderSurfaceLayer; - it.m_currentLayerIndex = CCLayerIteratorValue::LayerIndexRepresentingTargetRenderSurface; + pos.targetRenderSurfaceLayerIndex = ++m_highestTargetRenderSurfaceLayer; + pos.currentLayerIndex = CCLayerIteratorPositionValue::LayerIndexRepresentingTargetRenderSurface; - it.targetRenderSurface()->m_targetRenderSurfaceLayerIndexHistory = previousTargetRenderSurfaceLayer; + pos.targetRenderSurface()->m_targetRenderSurfaceLayerIndexHistory = previousTargetRenderSurfaceLayer; } else { - ++it.m_currentLayerIndex; + ++pos.currentLayerIndex; - int targetRenderSurfaceNumChildren = it.targetRenderSurfaceChildren().size(); - while (it.m_currentLayerIndex == targetRenderSurfaceNumChildren) { + int targetRenderSurfaceNumChildren = pos.targetRenderSurfaceChildren().size(); + while (pos.currentLayerIndex == targetRenderSurfaceNumChildren) { // Jump back to the previous RenderSurface, and get back the position where we were in that list, and move to the next position there. - if (!it.m_targetRenderSurfaceLayerIndex) { + if (!pos.targetRenderSurfaceLayerIndex) { // End of the list - it.m_targetRenderSurfaceLayerIndex = CCLayerIteratorValue::InvalidTargetRenderSurfaceLayerIndex; - it.m_currentLayerIndex = 0; + pos.targetRenderSurfaceLayerIndex = CCLayerIteratorPositionValue::InvalidTargetRenderSurfaceLayerIndex; + pos.currentLayerIndex = 0; return; } - it.m_targetRenderSurfaceLayerIndex = it.targetRenderSurface()->m_targetRenderSurfaceLayerIndexHistory; - it.m_currentLayerIndex = it.targetRenderSurface()->m_currentLayerIndexHistory + 1; + pos.targetRenderSurfaceLayerIndex = pos.targetRenderSurface()->m_targetRenderSurfaceLayerIndexHistory; + pos.currentLayerIndex = pos.targetRenderSurface()->m_currentLayerIndexHistory + 1; - targetRenderSurfaceNumChildren = it.targetRenderSurfaceChildren().size(); + targetRenderSurfaceNumChildren = pos.targetRenderSurfaceChildren().size(); } } } -template -void CCLayerIteratorActions::FrontToBack::begin(CCLayerIterator& it) +template +void CCLayerIteratorActions::FrontToBack::begin(CCLayerIteratorPosition& pos) { - it.m_targetRenderSurfaceLayerIndex = 0; - it.m_currentLayerIndex = it.targetRenderSurfaceChildren().size() - 1; - goToHighestInSubtree(it); + pos.targetRenderSurfaceLayerIndex = 0; + pos.currentLayerIndex = pos.targetRenderSurfaceChildren().size() - 1; + goToHighestInSubtree(pos); } -template -void CCLayerIteratorActions::FrontToBack::end(CCLayerIterator& it) +template +void CCLayerIteratorActions::FrontToBack::end(CCLayerIteratorPosition& pos) { - it.m_targetRenderSurfaceLayerIndex = CCLayerIteratorValue::InvalidTargetRenderSurfaceLayerIndex; - it.m_currentLayerIndex = 0; + pos.targetRenderSurfaceLayerIndex = CCLayerIteratorPositionValue::InvalidTargetRenderSurfaceLayerIndex; + pos.currentLayerIndex = 0; } -template -void CCLayerIteratorActions::FrontToBack::next(CCLayerIterator& it) +template +void CCLayerIteratorActions::FrontToBack::next(CCLayerIteratorPosition& pos) { // Moves to the previous layer in the current RS layer list. Then we check if the // new current layer has its own RS, in which case there are things in that RS layer list that are higher, so @@ -109,61 +109,61 @@ void CCLayerIteratorActions::FrontToBack::next(CCLayerIteratorm_targetRenderSurfaceLayerIndexHistory; - it.m_currentLayerIndex = it.targetRenderSurface()->m_currentLayerIndexHistory; + pos.targetRenderSurfaceLayerIndex = pos.targetRenderSurface()->m_targetRenderSurfaceLayerIndexHistory; + pos.currentLayerIndex = pos.targetRenderSurface()->m_currentLayerIndexHistory; } } } -template -void CCLayerIteratorActions::FrontToBack::goToHighestInSubtree(CCLayerIterator& it) +template +void CCLayerIteratorActions::FrontToBack::goToHighestInSubtree(CCLayerIteratorPosition& pos) { - if (it.currentLayerRepresentsTargetRenderSurface()) + if (pos.currentLayerRepresentsTargetRenderSurface()) return; - while (it.currentLayerRepresentsContributingRenderSurface()) { + while (pos.currentLayerRepresentsContributingRenderSurface()) { // Save where we were in the current target surface, move to the next one, and save the target surface that we // came from there so we can go back to it. - it.targetRenderSurface()->m_currentLayerIndexHistory = it.m_currentLayerIndex; - int previousTargetRenderSurfaceLayer = it.m_targetRenderSurfaceLayerIndex; + pos.targetRenderSurface()->m_currentLayerIndexHistory = pos.currentLayerIndex; + int previousTargetRenderSurfaceLayer = pos.targetRenderSurfaceLayerIndex; - for (LayerType* layer = it.currentLayer(); it.targetRenderSurfaceLayer() != layer; ++it.m_targetRenderSurfaceLayerIndex) { } - it.m_currentLayerIndex = it.targetRenderSurfaceChildren().size() - 1; + for (LayerType* layer = pos.currentLayer(); pos.targetRenderSurfaceLayer() != layer; ++pos.targetRenderSurfaceLayerIndex) { } + pos.currentLayerIndex = pos.targetRenderSurfaceChildren().size() - 1; - it.targetRenderSurface()->m_targetRenderSurfaceLayerIndexHistory = previousTargetRenderSurfaceLayer; + pos.targetRenderSurface()->m_targetRenderSurfaceLayerIndexHistory = previousTargetRenderSurfaceLayer; } } // Declare each of the above functions for LayerChromium and CCLayerImpl classes so that they are linked. -template void CCLayerIteratorActions::BackToFront::begin(CCLayerIterator &); -template void CCLayerIteratorActions::BackToFront::end(CCLayerIterator&); -template void CCLayerIteratorActions::BackToFront::next(CCLayerIterator&); - -template void CCLayerIteratorActions::BackToFront::begin(CCLayerIterator&); -template void CCLayerIteratorActions::BackToFront::end(CCLayerIterator&); -template void CCLayerIteratorActions::BackToFront::next(CCLayerIterator&); - -template void CCLayerIteratorActions::FrontToBack::next(CCLayerIterator&); -template void CCLayerIteratorActions::FrontToBack::end(CCLayerIterator&); -template void CCLayerIteratorActions::FrontToBack::begin(CCLayerIterator&); -template void CCLayerIteratorActions::FrontToBack::goToHighestInSubtree(CCLayerIterator&); - -template void CCLayerIteratorActions::FrontToBack::next(CCLayerIterator&); -template void CCLayerIteratorActions::FrontToBack::end(CCLayerIterator&); -template void CCLayerIteratorActions::FrontToBack::begin(CCLayerIterator&); -template void CCLayerIteratorActions::FrontToBack::goToHighestInSubtree(CCLayerIterator&); +template void CCLayerIteratorActions::BackToFront::begin(CCLayerIteratorPosition&); +template void CCLayerIteratorActions::BackToFront::end(CCLayerIteratorPosition&); +template void CCLayerIteratorActions::BackToFront::next(CCLayerIteratorPosition&); + +template void CCLayerIteratorActions::BackToFront::begin(CCLayerIteratorPosition&); +template void CCLayerIteratorActions::BackToFront::end(CCLayerIteratorPosition&); +template void CCLayerIteratorActions::BackToFront::next(CCLayerIteratorPosition&); + +template void CCLayerIteratorActions::FrontToBack::next(CCLayerIteratorPosition&); +template void CCLayerIteratorActions::FrontToBack::end(CCLayerIteratorPosition&); +template void CCLayerIteratorActions::FrontToBack::begin(CCLayerIteratorPosition&); +template void CCLayerIteratorActions::FrontToBack::goToHighestInSubtree(CCLayerIteratorPosition&); + +template void CCLayerIteratorActions::FrontToBack::next(CCLayerIteratorPosition&); +template void CCLayerIteratorActions::FrontToBack::end(CCLayerIteratorPosition&); +template void CCLayerIteratorActions::FrontToBack::begin(CCLayerIteratorPosition&); +template void CCLayerIteratorActions::FrontToBack::goToHighestInSubtree(CCLayerIteratorPosition&); } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCLayerIterator.h b/Source/WebCore/platform/graphics/chromium/cc/CCLayerIterator.h index be985e1..8f412c4 100644 --- a/Source/WebCore/platform/graphics/chromium/cc/CCLayerIterator.h +++ b/Source/WebCore/platform/graphics/chromium/cc/CCLayerIterator.h @@ -25,7 +25,7 @@ #ifndef CCLayerIterator_h #define CCLayerIterator_h -#include "cc/CCLayerTreeHostCommon.h" +#include "cc/CCLayerIteratorPosition.h" #include #include @@ -82,78 +82,43 @@ namespace WebCore { ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Non-templated constants -struct CCLayerIteratorValue { - static const int InvalidTargetRenderSurfaceLayerIndex = -1; - // This must be -1 since the iterator action code assumes that this value can be - // reached by subtracting one from the position of the first layer in the current - // target surface's child layer list, which is 0. - static const int LayerIndexRepresentingTargetRenderSurface = -1; -}; - // An iterator class for walking over layers in the RenderSurface-Layer tree. template class CCLayerIterator { typedef CCLayerIterator CCLayerIteratorType; public: - CCLayerIterator() : m_renderSurfaceLayerList(0) { } + CCLayerIterator() { } static CCLayerIteratorType begin(const Vector >* renderSurfaceLayerList) { return CCLayerIteratorType(renderSurfaceLayerList, true); } static CCLayerIteratorType end(const Vector >* renderSurfaceLayerList) { return CCLayerIteratorType(renderSurfaceLayerList, false); } - CCLayerIteratorType& operator++() { m_actions.next(*this); return *this; } - bool operator==(const CCLayerIterator& other) const - { - return m_targetRenderSurfaceLayerIndex == other.m_targetRenderSurfaceLayerIndex - && m_currentLayerIndex == other.m_currentLayerIndex; - } + CCLayerIteratorType& operator++() { ASSERT(m_actions); m_actions->next(m_position); return *this; } + bool operator==(const CCLayerIteratorType& other) const { return m_position == other.m_position; } bool operator!=(const CCLayerIteratorType& other) const { return !(*this == other); } - LayerType* operator->() const { return currentLayer(); } - LayerType* operator*() const { return currentLayer(); } + LayerType* operator->() const { return m_position.currentLayer(); } + LayerType* operator*() const { return m_position.currentLayer(); } - bool representsTargetRenderSurface() const { return currentLayerRepresentsTargetRenderSurface(); } - bool representsContributingRenderSurface() const { return !representsTargetRenderSurface() && currentLayerRepresentsContributingRenderSurface(); } + bool representsTargetRenderSurface() const { return m_position.currentLayerRepresentsTargetRenderSurface(); } + bool representsContributingRenderSurface() const { return !representsTargetRenderSurface() && m_position.currentLayerRepresentsContributingRenderSurface(); } bool representsItself() const { return !representsTargetRenderSurface() && !representsContributingRenderSurface(); } - LayerType* targetRenderSurfaceLayer() const { return (*m_renderSurfaceLayerList)[m_targetRenderSurfaceLayerIndex].get(); } + LayerType* targetRenderSurfaceLayer() const { return m_position.targetRenderSurfaceLayer(); } private: CCLayerIterator(const Vector >* renderSurfaceLayerList, bool start) - : m_renderSurfaceLayerList(renderSurfaceLayerList) + : m_position(renderSurfaceLayerList) + , m_actions(adoptPtr(new IteratorActionType())) { if (start && !renderSurfaceLayerList->isEmpty()) - m_actions.begin(*this); + m_actions->begin(m_position); else - m_actions.end(*this); + m_actions->end(m_position); } - inline LayerType* currentLayer() const { return currentLayerRepresentsTargetRenderSurface() ? targetRenderSurfaceLayer() : targetRenderSurfaceChildren()[m_currentLayerIndex].get(); } - - inline bool currentLayerRepresentsContributingRenderSurface() const { return CCLayerTreeHostCommon::renderSurfaceContributesToTarget(currentLayer(), targetRenderSurfaceLayer()->id()); } - inline bool currentLayerRepresentsTargetRenderSurface() const { return m_currentLayerIndex == CCLayerIteratorValue::LayerIndexRepresentingTargetRenderSurface; } - - inline RenderSurfaceType* targetRenderSurface() const { return targetRenderSurfaceLayer()->renderSurface(); } - inline const Vector >& targetRenderSurfaceChildren() const { return targetRenderSurface()->layerList(); } - - IteratorActionType m_actions; - const Vector >* m_renderSurfaceLayerList; - - // The iterator's current position. - - // A position in the renderSurfaceLayerList. This points to a layer which owns the current target surface. - // This is a value from 0 to n-1 (n = size of renderSurfaceLayerList = number of surfaces). A value outside of - // this range (for example, CCLayerIteratorValue::InvalidTargetRenderSurfaceLayerIndex) is used to - // indicate a position outside the bounds of the tree. - int m_targetRenderSurfaceLayerIndex; - // A position in the list of layers that are children of the current target surface. When pointing to one of - // these layers, this is a value from 0 to n-1 (n = number of children). Since the iterator must also stop at - // the layers representing the target surface, this is done by setting the currentLayerIndex to a value of - // CCLayerIteratorValue::LayerRepresentingTargetRenderSurface. - int m_currentLayerIndex; - - friend struct CCLayerIteratorActions; + CCLayerIteratorPosition m_position; + OwnPtr m_actions; }; // Orderings for iterating over the RenderSurface-Layer tree. @@ -161,14 +126,14 @@ struct CCLayerIteratorActions { // Walks layers sorted by z-order from back to front. class BackToFront { public: - template - void begin(CCLayerIterator&); + template + void begin(CCLayerIteratorPosition&); - template - void end(CCLayerIterator&); + template + void end(CCLayerIteratorPosition&); - template - void next(CCLayerIterator&); + template + void next(CCLayerIteratorPosition&); private: int m_highestTargetRenderSurfaceLayer; @@ -177,18 +142,18 @@ struct CCLayerIteratorActions { // Walks layers sorted by z-order from front to back class FrontToBack { public: - template - void begin(CCLayerIterator&); + template + void begin(CCLayerIteratorPosition&); - template - void end(CCLayerIterator&); + template + void end(CCLayerIteratorPosition&); - template - void next(CCLayerIterator&); + template + void next(CCLayerIteratorPosition&); private: - template - void goToHighestInSubtree(CCLayerIterator&); + template + void goToHighestInSubtree(CCLayerIteratorPosition&); }; }; diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCLayerIteratorPosition.h b/Source/WebCore/platform/graphics/chromium/cc/CCLayerIteratorPosition.h new file mode 100644 index 0000000..b1f63c4 --- /dev/null +++ b/Source/WebCore/platform/graphics/chromium/cc/CCLayerIteratorPosition.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2012 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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 CCLayerIteratorPosition_h +#define CCLayerIteratorPosition_h + +#include "cc/CCLayerTreeHostCommon.h" + +#include +#include + +namespace WebCore { + +// Non-templated constants +struct CCLayerIteratorPositionValue { + static const int InvalidTargetRenderSurfaceLayerIndex = -1; + // This must be -1 since the iterator action code assumes that this value can be + // reached by subtracting one from the position of the first layer in the current + // target surface's child layer list, which is 0. + static const int LayerIndexRepresentingTargetRenderSurface = -1; +}; + +// A struct to hold the iterator's current position, which is passed to the various CCLayerIteratorAction functions, for them to +// read and update. This struct exists so the templated action functions don't need to access the CCLayerIterator class. +// +// There is a 1:1 relationship between an instance of the CCLayerIteratorPosition class and a CCLayerIteratorActions::Foo class, +// so an iterator action class can hold extra position data, if required, in its own class instance. +// +// The current position of the iterator is held in two integer variables. +// - The targetRenderSurfaceLayerIndex is a position in the renderSurfaceLayerList. This points to a layer which owns the current +// target surface. This is a value from 0 to n-1 (n = size of renderSurfaceLayerList = number of surfaces). A value outside of +// this range (for example, CCLayerIteratorPositionValue::InvalidTargetRenderSurfaceLayerIndex) is used to indicate a position +// outside the bounds of the tree. +// - The currentLayerIndex is a position in the list of layers that are children of the current target surface. When pointing to +// one of these layers, this is a value from 0 to n-1 (n = number of children). Since the iterator must also stop at the layers +// representing the target surface, this is done by setting the currentLayerIndex to a value of +// CCLayerIteratorPositionValue::LayerRepresentingTargetRenderSurface. +template +struct CCLayerIteratorPosition { + CCLayerIteratorPosition() : renderSurfaceLayerList(0) { } + explicit CCLayerIteratorPosition(const Vector >* renderSurfaceLayerList) : renderSurfaceLayerList(renderSurfaceLayerList) { } + + inline LayerType* currentLayer() const { return currentLayerRepresentsTargetRenderSurface() ? targetRenderSurfaceLayer() : targetRenderSurfaceChildren()[currentLayerIndex].get(); } + + inline bool currentLayerRepresentsContributingRenderSurface() const { return CCLayerTreeHostCommon::renderSurfaceContributesToTarget(currentLayer(), targetRenderSurfaceLayer()->id()); } + inline bool currentLayerRepresentsTargetRenderSurface() const { return currentLayerIndex == CCLayerIteratorPositionValue::LayerIndexRepresentingTargetRenderSurface; } + + inline LayerType* targetRenderSurfaceLayer() const { return (*renderSurfaceLayerList)[targetRenderSurfaceLayerIndex].get(); } + inline RenderSurfaceType* targetRenderSurface() const { return targetRenderSurfaceLayer()->renderSurface(); } + inline const Vector >& targetRenderSurfaceChildren() const { return targetRenderSurface()->layerList(); } + + inline bool operator==(const CCLayerIteratorPosition& other) const + { + return targetRenderSurfaceLayerIndex == other.targetRenderSurfaceLayerIndex + && currentLayerIndex == other.currentLayerIndex; + } + + const Vector >* renderSurfaceLayerList; + int targetRenderSurfaceLayerIndex; + int currentLayerIndex; +}; + +} // namespace WebCore + +#endif