wiki:Accelerated rendering and compositing

Version 4 (modified by, 11 years ago) (diff)



  • Tree mania:
    • RenderObject
    • RenderLayer
    • z-order tree
    • Graphicslayer tree
    • PlatformLayer tree
  • Special considerations:
    • overlap
    • clipping
    • reflections
    • video/webgl/plugins/etc.
    • intersection
  • Accelerated drawing and compositing


Compositing: identify elements in the web page that benefit from rendering to bitmap and using gpu to composite it with other elements in the page.

This is done through RenderLayer tree. RenderLayer started as convenience for rendering certain objects. Create a RenderLayer for elements with their own coordinate system: overflow:scroll, transforms, and now video.

Render tree with hierarchy of RenderObjects. Certain RenderObjects have a RenderLayer off of them. There is a RenderLayer tree that mirrors RenderObject tree.

Painting: walk through RenderLayer tree, starting with the root, then go through child RenderLayer. Use RenderLayer for clipping and overflow.

Hit testing: reverse walk through child RenderLayers.

There is another hierarchy of RenderLayers which is important, and that is the z-order tree. This tree provides back-to-front ordering, and is used to support the z-index CSS property. Before painting, compute z-order tree by going through RenderLayer tree. Find stacking contexts. Painting and hit testing use this z-order tree, not the RenderLayer tree.

Compositing: We can identify RenderLayers that want to be composited, and create a backing store for them. We render to the backing store, then give it to the GPU. Probably rendered using OpenGL, on top of the regular content on page.

We have to ensure that any elements in front of composited layers are also composited.

A RenderLayerCompositor, per RenderView. manages hierarchy of layers and decides what needs to be a RenderLayer.

RenderLayer backing for each composited layer. RenderLayer backing creates at least 1 GraphicsLayer, which is the glue between rendering and platform-compositing code.

Each RenderLayer backing can create another GraphicsLayer; see clipping/masks/negative z indices. In these cases, you slice the GraphicsLayer into multiple planes and create an order for clipping.

GraphicsLayers are in their own tree. Used by platform code (like CoreAnimation) to create PlatformLayers. GraphicsLayers can have more than one platform layer; see masks and reflections. GraphicsLayers have a way of dumping its tree, can get it from gdb.

test for overlap. RLCompositor list of rects of things that have been composited. Makes other layers composited if they intersect that list of rects.

clipping: div with overflow:hidden, child with transform or video. impl clipping via platform layer. on mac: calayer add masks to apply. if a layer is composited through clipping, it doesn't have its own backing store, paints into something behind it.

reflections: cloning layers, tracking clones. tricky.

special layers, because of content that benefits from composites. video, rendervideo gets renderlayer, becomes composited. communication between mac media player and comp code so that media player hand pl to comp code, and pl into compositing layer tree.

layer intersections: allows 3d transforms, to paint into a gl texture. If layers intersect (child through parent), break into subtextures along intersections.

hit test is done in software in RL code. hit testing should be same for all paltforms.

overlap map is updated when there is a layotu or style change that changes compositing layer tree.

special casing css animations. which transform animation is running, we don't updating clipping during animations. update at start and end, not during. don't change layout during. don't update scrollbars, for example. it's a cheat, but gives performance. opacity animation also.

overlap test is used if real 3d xforms are not present in page.

platforms have their own accel drawing impls. on mac, but compositing still has value when there is accel drawing, but depends on content. feedback from paltform code to tell RLCompositor when its valuable to do compositing or not.

  • plugins like flash force compositing.

text: on mac there is a limitation on gfx sys where rendering text on transparent background, can't do subpixel antialiasing. no good soln to this problem right now. if something is composited, but with opaque bg-color, then it's fine.

limitations on compositing: not smart when applying scale trasnforms. on mac, (scale:2) just blow up bitmap, looks fuzzy.

ms support: ie10 has transforms and animations. doing stuff with direct2d when dealing with scaling.

if we redid wk, would it based on compositing primitives instead of bitmap primitives? this lives under the platform layer. only ms has done this by throwing everything out and rebuilding with direct2d.

webcore lacks logic where knowing if elements up front obscure stuff behind it. right now it just repaints everything behind it from back-to-front.

svg compositing? doesn't use rl at all. split up rl, piece related to compositing needs to be something svg could use.


  1. In Safari, "show compositing borders".
    • Every composited layer gets a border.
    • The number represents the number of times the layer has been repainted.
    • Yellow, now green, boxes have no css properties, so the layer is used just for geometry, and doesn't need a backing store.
    • Red represents layers that need a backing store.
    • Blue outline: composited because it has overflow:hidden/scroll on it.
  2. Do you see popping? Something popping in front is probably composited.
  3. In gdb, debug only "call showLayerTree" any RenderLayer tree. This shows it as a z-order tree. Also prints whether RenderLayer is composited, and why. Also shows which GraphicsLayers are associated with which RenderLayers.
  4. In inspector, turn on/off css properties that affect compositing; see overflow, z-order, transforms.
  5. Gmail bug anecdote: copy the DOM into a fresh document, to give you a snapshot. Although there was no CSS styling, the bug still repro'd.
  6. Via inspector, start deleting nodes.