chromium:LoadUrl之后会发生那些事情之CompositedLayer 创建

一 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;

};

主要有两个类,OverlapMapOverlapMapContainerOverlapMapContainer保存当前的layer以及其大小,OverlapMap是保存了当前CompositedLayer上一系列其他非CompositedLayerlayers以及其大小,当有新的layer需要被composited时,就会beginNewOverlapTestingContext,进行新的重叠测试。


版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值