博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Render树、RenderObject与RenderLayer
阅读量:7122 次
发布时间:2019-06-28

本文共 2689 字,大约阅读时间需要 8 分钟。

  1. Chapter: 呈现树的构建
    1. 1. 
    2. 2. 
    3. 3. 
    4. 4. 
    5. 5. 
    6. 6. 
    7. 7. 
    8. 8. 
    9. 9. 
    10. 10. 
    11. 11. 
    12. 12. 
    13. 13. 

前面介绍了 Render 树,RenderLayer,还有RenderObject,可能对这些概念还是有点模糊,这里再补充下。

当浏览器通过网络或者本地文件系统加载一个 HTML 文件,并对它进行解析完毕后,内核就会生成它最重要的数据结构 - DOM 树。

DOM 树上每一个节点都对应着网页里面的每一个元素,并且网页也可以通过 JavaScript 操作这棵 DOM 树,动态改变它的结构。但是 DOM 树本身并不能直接用于排版和渲染,内核还会生成另外一棵树 - Render 树,Render 树上的每一个节点 - ,跟 DOM 树上的节点几乎是一一对应的,当一个可见的 DOM 节点被添加到 DOM 树上时,内核就会为它生成对应的 RenderOject 添加到 Render 树上。

Render 树是浏览器排版引擎的主要作业对象,排版引擎根据 DOM 树和 CSS 样式表的样式定义,按照预定的排版规则确定了 Render 树最后的结构,包括其中每一个 RenderObject 的大小和位置,而一棵经过排版的 Render 树,则是浏览器渲染引擎的主要输入,读者可以认为,Render 树是衔接浏览器排版引擎和渲染引擎之间的桥梁,它是排版引擎的输出,渲染引擎的输入。

不过浏览器渲染引擎并不是直接使用 Render 树进行绘制,为了方便处理 Positioning(定位),Clipping(裁剪),Overflow-scroll(页內滚动),CSS Transform/Opacity/Animation/Filter,Mask or Reflection,Z-indexing(Z排序)等,浏览器需要生成另外一棵树 – Layer 树。

渲染引擎会为一些特定的 RenderObject 生成对应的 ,而这些特定的 RenderObject 跟对应的 RenderLayer 就是直属的关系,相应的,它们的子节点如果没有对应的 RenderLayer,就从属于父节点的 RenderLayer。最终,每一个 RenderObject 都会直接或者间接地从属于一个 RenderLayer。

RenderObject 生成 RenderLayer 的条件,来自 

  • It’s the root object for the page
  • It has explicit CSS position properties (relative, absolute or a transform)
  • It is transparent
  • Has overflow, an alpha mask or reflection
  • Has a CSS filter
  • Corresponds to canvas element that has a 3D (WebGL) context or an accelerated 2D context
  • Corresponds to a video element

浏览器渲染引擎遍历 Layer 树,访问每一个 RenderLayer,再遍历从属于这个 RenderLayer 的 RenderObject,将每一个 RenderObject 绘制出来。读者可以认为,Layer 树决定了网页绘制的层次顺序,而从属于 RenderLayer 的 RenderObject 决定了这个 Layer 的内容,所有的 RenderLayer 和 RenderObject 一起就决定了网页在屏幕上最终呈现出来的内容。

软件渲染模式下,浏览器绘制 RenderLayer 和 RenderObject 的顺序,来自 

In the software path, the page is rendered by sequentially painting all the RenderLayers, from back to front. The RenderLayer hierarchy is traversed recursively starting from the root and the bulk of the work is done in RenderLayer::paintLayer() which performs the following basic steps (the list of steps is simplified here for clarity):

  1. Determines whether the layer intersects the damage rect for an early out.
  2. Recursively paints the layers below this one by calling paintLayer() for the layers in the negZOrderList.
  3. Asks RenderObjects associated with this RenderLayer to paint themselves.
  4. This is done by recursing down the RenderObject tree starting with the RenderObject which created the layer. Traversal stops whenever a RenderObject associated with a different RenderLayer is found.
  5. Recursively paints the layers above this one by calling paintLayer() for the layers in the posZOrderList.

In this mode RenderObjects paint themselves into the destination bitmap by issuing draw calls into a single shared GraphicsContext (implemented in Chrome via Skia).

转载于:https://www.cnblogs.com/huenchao/p/7341164.html

你可能感兴趣的文章
NPM中混入了包含恶意后门的包
查看>>
IBM开源API微网关
查看>>
企业金融云存储建设之路
查看>>
SQL Server新一轮更新
查看>>
未来的C#之只读引用与结构体
查看>>
TypeScript发布3.2版本,改进元编程支持、新增BigInt
查看>>
服务部署如何做到高可用?这份“三级跳”秘籍送给你\n
查看>>
独家解读 | 滴滴机器学习平台架构演进之路
查看>>
KubeEdge向左,K3S向右
查看>>
微软正式发布 Azure IoT Central
查看>>
Build 2018大会:.NET概述和路线图
查看>>
七牛李倩:⼯程效率如何为研发赋能
查看>>
从“被动挖光缆”到“主动剪网线”,蚂蚁金服异地多活的微服务体系
查看>>
PhpStorm2016.3激活
查看>>
Docker4Dev #7 新瓶装老酒 – 使用 Windows Container运行ASP.NET MVC 2 + SQLExpress 应用
查看>>
使用vue.js构建一个知乎日报
查看>>
Microsoft Flow发布GA版本
查看>>
Python 赋值的一般含义是引用
查看>>
magento2 在香港用paypal
查看>>
Yii系列(1)打造虚拟开发环境及Yii的安装配置
查看>>