一 CompositedLayer 综述
实际上,在M44以后,已经不存在实际上的CompositedLayer 这个对象,其实它就是DeprecatedPaintLayer,只是它的m_compositeReason是需要进行合成的。
详细可以查看CompositeReason.h,它详细列出了那些需要合成的类型。
二 CompositedLayer 的创建
在DeprecatedPaintLayerTree创建完毕后,整个文档还并不可见,还需要进行layout计算,layout计算会触发compositeReason的计算,它主要是遍历整个DeprecatedPaintLayerTree,
对其中的每一节点DeprecatedPaintLayer,计算其m_compositeReason属性值。代码调用栈如下:
Call Stack:
#0 blink::CompositingRequirementsUpdater::updateRecursive(
blink::DeprecatedPaintLayer * ancestorLayer, blink::DeprecatedPaintLayer * layer,
blink::CompositingRequirementsUpdater::OverlapMap & overlapMap,
blink::CompositingRequirementsUpdater::RecursionData & currentRecursionData,
bool & descendantHas3DTransform, WTF::Vector<blink::DeprecatedPaintLayer *,
0,WTF::DefaultAllocator> & unclippedDescendants,
blink::IntRect & absoluteDecendantBoundingBox)
#1 blink::CompositingRequirementsUpdater::update(blink::DeprecatedPaintLayer * root)
#2 blink::DeprecatedPaintLayerCompositor::updateIfNeeded()
#3 blink::DeprecatedPaintLayerCompositor::updateIfNeededRecursive()
#4 blink::FrameView::updateLayoutAndStyleForPaintingInternal()
#5 blink::FrameView::updateLayoutAndStyleForPainting()
#6 blink::PageAnimator::updateLayoutAndStyleForPainting(blink::LocalFrame * rootFrame)
#7 blink::PageWidgetDelegate::layout(blink::Page & page, blink::LocalFrame & root)
#8 blink::WebViewImpl::layout()
#9 content::RenderWidgetCompositor::Layout()
#10 cc::LayerTreeHost::Layout()
#11 cc::ThreadProxy::BeginMainFrame()
三 OverlapMap 重叠测试
class OverlapMapContainer {
public:
void add(const IntRect& bounds)
{
m_layerRects.append(bounds);
m_boundingBox.unite(bounds);
}
bool overlapsLayers(const IntRect& bounds) const
{
// Checking with the bounding box will quickly reject cases when
// layers are created for lists of items going in one direction and
// never overlap with each other.
if (!bounds.intersects(m_boundingBox))
return false;
for (unsigned i = 0; i < m_layerRects.size(); i++) {
if (m_layerRects[i].intersects(bounds))
return true;
}
return false;
}
void unite(const OverlapMapContainer& otherContainer)
{
m_layerRects.appendVector(otherContainer.m_layerRects);
m_boundingBox.unite(otherContainer.m_boundingBox);
}
private:
Vector<IntRect, 64> m_layerRects;
IntRect m_boundingBox;
};
class CompositingRequirementsUpdater::OverlapMap {
WTF_MAKE_NONCOPYABLE(OverlapMap);
public:
OverlapMap()
{
// Begin by assuming the root layer will be composited so that there
// is something on the stack. The root layer should also never get a
// finishCurrentOverlapTestingContext() call.
beginNewOverlapTestingContext();
}
void add(DeprecatedPaintLayer* layer, const IntRect& bounds)
{
ASSERT(!layer->isRootLayer());
if (bounds.isEmpty())
return;
// Layers do not contribute to overlap immediately--instead, they will
// contribute to overlap as soon as they have been recursively processed
// and popped off the stack.
ASSERT(m_overlapStack.size() >= 2);
m_overlapStack[m_overlapStack.size() - 2].add(bounds);
}
bool overlapsLayers(const IntRect& bounds) const
{
return m_overlapStack.last().overlapsLayers(bounds);
}
void beginNewOverlapTestingContext()
{
// This effectively creates a new "clean slate" for overlap state.
// This is used when we know that a subtree or remaining set of
// siblings does not need to check overlap with things behind it.
m_overlapStack.append(OverlapMapContainer());
}
void finishCurrentOverlapTestingContext()
{
// The overlap information on the top of the stack is still necessary
// for checking overlap of any layers outside this context that may
// overlap things from inside this context. Therefore, we must merge
// the information from the top of the stack before popping the stack.
//
// FIXME: we may be able to avoid this deep copy by rearranging how
// overlapMap state is managed.
m_overlapStack[m_overlapStack.size() - 2].unite(m_overlapStack.last());
m_overlapStack.removeLast();
}
private:
Vector<OverlapMapContainer> m_overlapStack;
};
主要有两个类,OverlapMap和OverlapMapContainer,OverlapMapContainer保存当前的layer以及其大小,OverlapMap是保存了当前CompositedLayer上一系列其他非CompositedLayer的layers以及其大小,当有新的layer需要被composited时,就会beginNewOverlapTestingContext,进行新的重叠测试。
版权声明:本文为博主原创文章,未经博主允许不得转载。