Paint Layer Tree 创建

本文介绍了Paint Layer Tree的创建过程,从LayoutObject的CSS属性变化开始,详细阐述了何时需要创建Paint Layer,以及创建和插入Paint Layer Tree的具体步骤。涉及关键函数如StyleDidChange、LayerTypeRequired、InsertOnlyThisLayerAfterStyleChange等,解释了不同情况下的Layer处理逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

站在老罗的肩膀上:https://blog.youkuaiyun.com/luoshengyang/article/details/50648792

 目前Render Layer已经更新为Paint Layer, 其最终通过PaintLayer::InsertOnlyThisLayerAfterStyleChange创建,其函数调用关系如下,通过之前创建Layout Object Tree的LayoutTreeBuilderForElement::CreateLayoutObject调入:

LayoutTreeBuilderForElement::CreateLayoutObject实现如下:

DISABLE_CFI_PERF
void LayoutTreeBuilderForElement::CreateLayoutObject() {
  ...
  LayoutObject* new_layout_object = node_->CreateLayoutObject(style);
  ...
  new_layout_object->SetStyle(
      &style);  // SetStyle() can depend on LayoutObject() already being set
  ...
}
                                                                                

其调用SetStyle设置LayoutObject的CSS属性:

DISABLE_CFI_PERF
void LayoutObject::SetStyle(scoped_refptr<ComputedStyle> style) {
  DCHECK(style);
  if (style_ == style)
    return;
  StyleDifference diff;
  ...
  diff = AdjustStyleDifference(diff);
  StyleWillChange(diff, *style);
  scoped_refptr<ComputedStyle> old_style = std::move(style_);
  SetStyleInternal(std::move(style));
  ...
  StyleDidChange(diff, old_style.get());
  ...
}

其中style_ type is ComputedStyle, describe the CSS attribute of this layout object. And it calculte the CSS difference between current and previous one, and calling SetStyleInternal to store new CSS into style_.  Then calling LayoutBlockFlow::StyleDidChange. LayoutBlockFlow类是间接地从LayoutObject类继承下来的,并且重写了成员函数StyleDidChange。因此,接下来RenderBlockFlow类的成员函数StyleDidChange就会被调用。在调用的过程中,就会检查是否需要创建一个Paint Layer。LayoutBlockFlow类的成员函数StyleDidChange的实现如下所示:

void LayoutBlock::StyleDidChange(StyleDifference diff,
                                 const ComputedStyle* old_style) {
  LayoutBox::StyleDidChange(diff, old_style);
  ...
}

void LayoutBlock::StyleDidChange(StyleDifference diff,
                                 const ComputedStyle* old_style) {
  LayoutBox::StyleDidChange(diff, old_style);
  ...
}

void LayoutBox::StyleDidChange(StyleDifference diff,
                               const ComputedStyle* old_style) {
  ...
  LayoutBoxModelObject::StyleDidChange(diff, old_style);
  ...
}

并且一步步回调基类的StyleDidChange,直到LayoutBoxModelObject

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值