This article provides the background and details of chrome hardware acceleration-based combination implementation.
Note: Why hardware synthesis?
Traditionally, Web browsers rely entirely on CPUs to render webpage content. But with the current GPUs capabilities and the ability to embed devices in smaller sizes, people gradually turn their focus to finding
More effective use of basic hardware to achieve better performance and reduce power consumption, the use of GPU to synthesize web content can significantly speed up
The advantages of hardware merging can be attributed to three factors:
1. In terms of drawing and combining pages containing a large number of pixels, The compositing page layer on the GPU can achieve better and more efficient performance than the CPU (in terms of speed and drawing capabilities. Especially for these types of hardware
Design for work
2. For the page content that has been placed on the GPU (the content bitmap generated by the browser), expensive read-back is usually unnecessary, such as accelerated video, canvas2d, webgl
3. The parallel Working Mechanism of CPU and GPU enables operations to create more efficient drawing pipelines at the same time
Note: CPU rendering (software rendering) usually draws all rendering objects into a bitmap and sends them from Ram to the GPU. Common rendering methods are drawn by software (CPU) three types of GPU combination
Use Cases
Next, we have a major statement before the official start: Chrome's drawing Stack has been evolving and improved over the past few years. This article will focus on the latest browser architecture,
But it's not about the configuration and functional breakdown of each platform, see http://dev.chromium.org/developers/design-documents/gpu-accelerated-compositing-in-chrome/gpu-architecture-roadmap
The code path will only involve a small amount
Part 1:BlinkRendering Basics
The source code of the Blink rendering engine is very large and complex, and there are few records at the same time. To understand how the GPU Accelerator works in chrome, first understand how blink renders
Basic page construction block knowledge is very important
1, Nodes, and DomTree
For blink, the page content is usually stored internally as a tree containing node objects and becomes a DOM tree. Each HTML element and text on the page are associated with a node, DOM tree
Usually the document Node
2, From node to rendering object
The visual output generated by each node with a DOM tree corresponds to renderobject, which is stored in a tree structure parallel to the DOM tree and becomes a render tree,
A rendering object knows how to draw a node content to the display device. To solve this problem, it must be drawn by calling graphicscontext. graphicscontext writes the pixel
The bitmap is displayed on the screen. For chrome, graphicscontext uses skia, our 2D drawing library
Traditionally, most graphicscontext calls the software bitmap by calling skcanvas or skplatformcanvas. For example, to draw a software bitmap immediately, in addition to drawing out of the main thread, these commands are currently
It is recorded as a skpicture, a command that serializes data structures that can be captured and subsequently replayed, similar to http://en.wikipedia.org/wiki/Display_list
There is no one-to-one correspondence between the two. For example, the document node, invisible node, and anonymous block are common parts of anonymous block,
If an adjacent node of the renderblock contains an embedded node, an anonymous renderblock is usually used by default to include these elements and use them as sub-elements of the anonymous block.
3, From the rendering object to the rendering layer (from renderobjects to renderlayers)
Each rendering object is directly or indirectly associated with the rendering layer renderlayer through ancestore renderobject
Renderobjects that share the same coordinate space belong to the same renderlayer. It is precisely because of the existence of the renderlayer that the elements of the page can be merged and correctly displayed in the correct order.
Stacked content, translucent elements, etc. Under some conditions, a new rendering layer is created for a special render object renderobject, which is defined in renderboxmodelobject ::
Requireslayer () is overwritten by some subclasses. The following renderobject ensures that the renderlayer is created.
1. Page root object
2. Explicit CSS position attribute definition (relative, absolute, or transform)
3. Transparent Elements
4. Specify overflow, Alpha mask, or reflection.
5. Specify CSS Filter
6. Corresponding Canvas elements include 3dcontext or accelerated 2D contxt
7. Video Elements
Note that renderobjects and renderlayers do not necessarily correspond to each other. A specific renderobject may be associated with a renderlayer created for it, or if the first parent level
Node-related renderlayout
The renderlayer is also a tree structure. The renderlayer of the root node corresponds to the root node element of the page and the layer corresponding to the child element of the visual descendant is included in the layer of the parent element. The child layer is retained in two
The sorting list contains the ascending order. The negzorderlist contains sub-layers that specify Negative Z-indices and poszorderlist. Only positive Z-indices can be specified for the sub-layers.
4From the rendering layer to the drawing layer from renderlayers to graphicslayers
To use synthesizer, some renderlayers obtain their field backing surface (backrest) (layers with their own backing surfaces are broadly referred to as compositing layers)
Each renderlayer has its own graphicslayer (if it is a compositing layer) or uses the parent node with graphicslayer at the first level. The relationship is similar to that between renderobject and renderlayer.
Each graphicslayer has a graphicscontext for drawing associated with renderlayers. In the subsequent merging steps, the synthesizer is responsible for merging the bitmap output by graphicscontexts to display the image on the screen at the most overall level.
However, in theory, each single renderlayer can be drawn into a separate backing surface. In terms of memory, this is very likely to cause waste. The following conditions must be met for the current blink implementation:
To own its own compositing Layer
1. Specify the layer of the 3D or transform CSS style attribute.
2. layer used by video to accelerate video decoding
3. layer used by the Canvas Element that contains 3dcontext or accelerated 2D context (accelerated 2D context)
4. layer Used for merging plug-ins is used for composited plugin
Original
Layer has 3D or perspective transform CSS Properties
Layer is used by <video> element using accelerated video decoding
Layer is used by a <canvas> element with a 3D context or accelerated 2D Context
Layer is used for a composited plugin
Layer uses a CSS animation for its opacity or uses an animated WebKit Transform
Layer uses accelerated CSS Filters
Layer has a descendant that is a compositing Layer
Layer has a sibling with a lower Z-index which has a compositing layer (in other words the layer overlaps a composited layer and shoshould be rendered on top of it)
5Layer Extrusion
No exception. As mentioned above, graphicslayer may consume a lot of memory and other resources (for example, some key operations of graphicslayer tree may take a lot of CPU time) to create some additional layers that consume, these layers may overlap with their backing surface, which may be very resource-consuming.
We call intrinsic compositing reasons (e.g. A layer that has a 3D transform on it) "direct" compositing reasons. to prevent a "layer explosion" when your elements are on top of a layer with a direct compositing reason, blink takes multiple renderlayers overlapping a direct-compositing-reason renderlayer and "squashes" them into a single backing store. this prevents the layer explosion caused by overlap. more detail motivating layer squashing can be found in this presentation, and more detail on the code in between renderlayers and compositing layers can be found in this presentation; both are current as of approximately Jan 2014 although this code is undergoing significant change in 2014.
6, From the drawing layerWeblayersToChrome compositor(From graphicslayers to weblayers to CC Layers)
Only a couple more layers of role action to go before we get to Chrome's compositor implementation! Graphicslayers can represent their content via one or more web * layers. these are interfaces that WebKit ports needed to implement; see blink's public/platform directory for interfaces such as webcontentslayer. h or webscrollbarlayer. h. chrome's implementations are in src/WebKit/Renderer/compositor_bindings which implement the abstract web * layer interfaces using chrome compositor layer types.
Putting it Together: The compositing Forest
In summary, there are conceptually four parallel tree structures in place that serve slightly different purposes for rendering:
- TheDOM tree,Which is our fundamental retained Model
- TheRenderobject tree,Which has a 1:1 mapping to the DOM tree's visible nodes. renderobjects know how to paint their corresponding DOM nodes.
- TheRenderlayer tree,Made up of renderlayersthat map to a renderobject on the renderobject tree. the mapping is mandatory-to-one, as each renderobject is either associated with its own renderlayer or the renderlayer of its first ancestor that has one. the renderlayer tree preserves Z-ordering amongst layers.
- TheGraphicslayer tree, Mapping graphicslayers one-to-least renderlayers.
Each graphicslayer has Web * layers implemented in Chrome with chrome compositor layers. It is these final "CC layers" (Cc = chrome compositor) that the compositor knows how to operate on.
From here on in this document "layer" is going to refer to a generic CC layer, since for hardware compositing these are the most interesting -- but don't be fooled, elsewhere when someone says "layer" they might be referring to any of the above constructs!
The compositing Forest
Now that we're 've (briefly) covered the data structures in blink that link the Dom to the compositor, We're re ready to release e the compositor itself in earnest.
Http://www.chromium.org/developers/design-documents/gpu-accelerated-compositing-in-chrome
Chrome blink render engine and the render mechanic