1 of 81

Chromium OS - Compositor Pipeline

malaykeshav@chromium.org | April 2019

go/cros-compositor-pipeline

2 of 81

Layer (ui & cc)

Property Tree

Compositor Frame

Surface Aggregator

Display Compositor

Contents

3 of 81

UI

Paint UI Framework

Raster Chrome Compositor

List of Draw Commands

COMPOSITOR FRAME

Textures

Draw Display Compositor

4 of 81

Layers

Base entity which holds information on what needs to be displayed in the region marked by its bounds. A layer does not own its child layer however certain properties may affect the child layer.

5 of 81

UI Layer Types

  • Not Drawn
  • Solid color layer
  • Painted texture layer
  • Transferable resource layer
  • Surface layer
  • Nine patch layer

6 of 81

Views

A toolkit to paint onto the ui layer in a hierarchical structure. Each view can only paint within its own bound which is a sub region of the ui layer it belongs to.

7 of 81

Layer

View 1

View 2

View 3

Layer

8 of 81

What do I mean when I say paint

Layer

1

2

3

9 of 81

What do I mean when I say paint

Layer

1

2

Display Item List

3

A DisplayItemList is associated with each layer at the time of paint. This list is passed to the layer’s delegate to paint on.

10 of 81

What do I mean when I say paint

Layer

1

2

Display Item List

- Clip to View 1 bounds

- Paint rect

- Paint image

- etc

- Clip to View 2 bounds

- Draw command

- Draw command

- etc

- Clip to View 3 bounds

- Draw command

- Draw command

- etc

3

When a view paints, it appends its list of draw commands onto the layer’s display item list.

11 of 81

What do I mean when I say paint

Layer

1

2

Display Item List

- Clip to View 1 bounds

- Paint rect

- Paint image

- etc

- Clip to View 2 bounds

- Draw command

- Draw command

- etc

- Clip to View 3 bounds

- Draw command

- Draw command

- etc

Deferred Raster on worker thread

TEXTURE

3

The display item list then undergoes a deferred rasterization to generate the final texture for that layer.

Fractional scaling and snapping to pixels is handled by the views framework.

12 of 81

Textures generated this way are tiles

,

,

,

,

,

13 of 81

Why the need for multiple layers?

  • Layers are expensive.
  • They hold textures that take up memory.
  • Have a larger overhead than views.

But

  • In terms of performance, layers are faster to manipulate than views in terms of transform, effects and clipping.
  • For a view to update and perform the same operation, it needs to repaint and regenerate the texture (repaint and re raster).

14 of 81

?

We now have textures from each of the layers that draw. The next step is to draw them onto the display buffer and apply any effects along the way. But how do we compute their final position, clip or effects like opacity and blur? Sometimes, these effects interact and depend on textures and properties from other layers.

15 of 81

Different Properties of a layer

CLIP

TRANSFORM

EFFECTS

MASKS

16 of 81

Clip

Parent

Child

SCREEN

17 of 81

Clip

Parent

Child

SCREEN

18 of 81

Clip

Parent

Child

To achieve this, we add an intermediate layer with the bounds of the clip and its clip to bounds property set. This layer will now clip its subtree to its own bounds. This layer also does not have to draw any content.

SCREEN

Clip layer

19 of 81

Clip

Parent

Child

SCREEN

Clip layer

20 of 81

Transform

Parent

Child

SCREEN

21 of 81

Transform

Parent

Child

SCREEN

22 of 81

Transform

Parent

Child

SCREEN

Apply the transform (translate and scale) on the parent layer and the child layer is also affected by it.

TRANSFORM

23 of 81

Effects

Parent

Child

SCREEN

24 of 81

Effects

Parent

Child

SCREEN

OPACITY

25 of 81

Layer Tree

EFFECT

TRANSFORM

CLIP

ROOT

DRAWS

E

DRAWS

D

T

C

DRAWS

TRANSFORM

DRAWS

It could be some layers have multiple properties at once

26 of 81

Property Trees + Draw Layer List

EFFECT

TRANSFORM

CLIP

ROOT

DRAWS

E

DRAWS

D

T

C

DRAWS

TRANSFORM

DRAWS

TRANSFORM TREE

TRANSFORM

TRANSFORM

TRANSFORM

CLIP TREE

VIEWPORT

CLIP

CLIP

EFFECT TREE

EFFECT

EFFECT

DRAWS

DRAWS

DRAWS

DRAWS

DRAWS

27 of 81

Property Trees

TRANSFORM TREE

TRANSFORM

TRANSFORM

TRANSFORM

CLIP TREE

VIEWPORT

CLIP

CLIP

EFFECT TREE

EFFECT

EFFECT

DRAWS

DRAWS

DRAWS

DRAWS

DRAWS

Trees are sparse -- not every layer has an interesting transform, clip, effect, or scroll.

But cross-tree dependencies do exist

  • e.g. clips and effects happen in a particular transform space

Layer list still has non-drawing layers (for now). For this talk lets only considers the layer that draw.

28 of 81

Effect Tree

EFFECT TREE

F. BLUR

DRAWS

DRAWS

DRAWS

MASK

ROOT

SCREEN BUFFER

29 of 81

Effect Tree

EFFECT TREE

F. BLUR

DRAWS

DRAWS

DRAWS

MASK

ROOT

SCREEN BUFFER

30 of 81

Effect Tree

EFFECT TREE

F. BLUR

DRAWS

DRAWS

DRAWS

MASK

ROOT

SCREEN BUFFER

31 of 81

Effect Tree

EFFECT TREE

F. BLUR

DRAWS

DRAWS

DRAWS

MASK

ROOT

SCREEN BUFFER

32 of 81

Effect Tree

EFFECT TREE

F. BLUR

DRAWS

DRAWS

DRAWS

MASK

ROOT

SCREEN BUFFER

33 of 81

Effect Tree

EFFECT TREE

F. BLUR

DRAWS

DRAWS

DRAWS

MASK

ROOT

SCREEN BUFFER

A

34 of 81

Effect Tree

EFFECT TREE

F. BLUR

DRAWS

DRAWS

DRAWS

MASK

ROOT

SCREEN BUFFER

35 of 81

Effect Tree

SCREEN BUFFER

LAYER

36 of 81

Effect Tree

SCREEN BUFFER

LAYER

EFFECT TREE

OPACITY 0.5

ROOT

37 of 81

Effect Tree

LAYER

SCREEN BUFFER

EFFECT TREE

OPACITY 0.5

ROOT

LAYER

38 of 81

Effect Tree

LAYER

SCREEN BUFFER

EFFECT TREE

OPACITY 0.5

ROOT

LAYER

39 of 81

Effect Tree

SCREEN BUFFER

Drawing layer textures one by one will result in the two layer textures blending with each other.

40 of 81

Effect Tree

SCREEN BUFFER

SCREEN BUFFER

Drawing layer textures one by one will result in the two layer textures blending with each other.

Desired result where the two layers don’t blend with each other and only blend with the background.

41 of 81

Render Surfaces

  • Certain effects on a layer apply to the entire subtree rooted at that layer.
  • Temporary buffers, called render surfaces, hold the draw output of the subtree and then applies an effect on the render surface buffer.
  • Size of the render surface is the union of sizes of all the drawable layers in its subtree.
  • Any property affecting the original layer now effects the render surface.
  • Some operations that require this are:
    • opacity
    • filter (blur, contrast, saturation, etc.)
    • mask
    • non-axis-aligned clipping

RENDER SURFACE

42 of 81

Going back to the previous example

LAYER

SCREEN BUFFER

EFFECT TREE

OPACITY 0.5

ROOT

LAYER

43 of 81

Render Surfaces

RENDER SURFACE

  • Allocate a temporary buffer of the size of the subtree which is the union of sizes of all the layer in the subtree.

44 of 81

Render Surfaces

RENDER SURFACE

Draw the layer textures onto the render surface buffer

45 of 81

Render Surfaces

SCREEN BUFFER

Composite the texture of the render surface onto its target buffer and apply the effect.

46 of 81

Render Surfaces

SCREEN BUFFER

47 of 81

Memory Impact of Render Surfaces

LAYER

SCREEN BUFFER

EFFECT TREE

OPACITY 0.5

ROOT

LAYER

LAYER

MASK

48 of 81

Textures already in memory

49 of 81

Additional Textures to allocate

The clipped render surface buffer allocated is smaller due to clip from its parent.

RENDER SURFACE

A

RENDER SURFACE

B

50 of 81

Window with rounded corner mask

This window could be maximized when not in overview mode. And would have a texture of the size of almost the entire screen. (In overview mode the textures are scaled down at draw step.)

On a pixel slate device with display resolution of 3000*2000, this means the texture is taking almost ~22mb. To apply the rounded corner, we have a mask texture of the same size (~22 mb). And finally a render surface of the same size which requires another (+22 mb along with allocation time for each frame). That is ~60-66 mb per window.

51 of 81

Window with new implementation of rounded corner

The new implementation of rounded corner does away with the use of render surface and mask layers. Instead it performs the rounding at the draw step of the pipeline by using OpenGL shaders.

The current memory usage for overview mode per window is ~22mb. At the same time, the fps increase measured is around 10-15 fps for pixel slate.

52 of 81

Draw

RENDER SURFACE A

53 of 81

Draw

RENDER SURFACE A

RENDER SURFACE B

OPACITY

54 of 81

Draw

MASK

RENDER SURFACE A

RENDER SURFACE B

ROOT RENDER SURFACE

55 of 81

Render Target

RENDER TARGET

A

ROOT RENDER TARGET

RENDER TARGET

B

  • Each layer draws to some target render surface (render target).
  • Usually the first render surface in that layer’s parent chain.
  • A layer that points to an property tree node (from any tree), respects all the nodes in its parent chain up to its render target.

56 of 81

Output of Property Trees

Layer draw properties

  • Draw transform
  • Draw opacity
  • Clip bounds
  • Visible bounds
  • Render Target

Render surface draw properties

  • Screen space transform
  • Draw transform
  • List of effects
  • Content bounds
  • Clip rect

And a list of render surfaces...

57 of 81

Output of cc - Draw Quads

  • Each quad holds a resource that will be is composited onto its target buffer.
  • A draw quad additionally holds a bag of data used for drawing a quad onto the buffer.
  • Depending on what kind of resource the quad holds, there are different kinds of draw quads including:
    • Solid Color
    • Texture
    • Tile
    • Surface
    • Video
    • Render Pass

58 of 81

We now have all the info needed to put textures and actual pixels on the screen.

59 of 81

Compositor Frame

Render Passes

(RENDER SURFACE)

RENDER PASS

A

ROOT RENDER PASS

RENDER PASS

B

,

,

60 of 81

Compositor Frame

Compositor Frame

Render Pass A Draw Quad List

,

,

,

,

,

,

,

,

,

,

,

RENDER SURFACE A

Render Passes

(RENDER SURFACE)

ROOT RENDER PASS

,

,

RENDER PASS

A

RENDER PASS

B

61 of 81

Compositor Frame

Render Passes

(RENDER SURFACE)

ROOT RENDER PASS

,

,

Render Pass A Draw Quad List

,

,

,

,

,

,

,

,

,

,

,

,

Render Pass B Draw Quad List

RENDER PASS

A

RENDER PASS

B

RPDQ A

62 of 81

Compositor Frame

Render Pass A Draw Quad List

,

,

,

,

,

,

,

,

,

,

,

Render Pass B Draw Quad List

Root Render Pass Draw Quad List

,

Render Passes

(RENDER SURFACE)

ROOT RENDER PASS

,

,

RENDER PASS

A

RENDER PASS

B

RPDQ A

RPDQ B

63 of 81

COMPOSITOR FRAME

RENDER PASSES

DRAW QUADS

BROWSER PROCESS

ui::Compositor

GPU PROCESS

Display Compositor

64 of 81

65 of 81

Where is the web content?

66 of 81

SOLID

ROOT

TEXTURE

NO DRAWN

SURFACE

COMPOSITOR FRAME

RENDER PASSES

DRAW QUADS

Draw Quad a

Surface Draw Quad b

Draw Quad c

67 of 81

COMPOSITOR FRAME

RENDER PASSES

DRAW QUADS

BROWSER PROCESS

ui::Compositor

COMPOSITOR FRAME

RENDER PASSES

DRAW QUADS

RENDERER PROCESS

Blink

68 of 81

COMPOSITOR FRAME

RENDER PASSES

DRAW QUADS

BROWSER PROCESS

ui::Compositor

COMPOSITOR FRAME

RENDER PASSES

DRAW QUADS

RENDERER PROCESS

Blink

SURFACE AGGREGATOR

GPU PROCESS

COMPOSITOR FRAME

RENDER PASSES

DRAW QUADS

69 of 81

ui::Compositor

Blink

SURFACE AGGREGATOR

COMPOSITOR FRAME

GPU PROCESS

COMPOSITOR FRAME

RENDER PASSES

DRAW QUADS

COMPOSITOR FRAME

ARC++

COMPOSITOR FRAME

Crostini

COMPOSITOR FRAME

70 of 81

Ways for a Surface Aggregator to aggregate

COMPOSITOR FRAME A

RENDER PASSES

DRAW QUADS

Draw Quad a

Surface Draw Quad b

Draw Quad c

Root Render Pass Quad List

Draw Quad x

Draw Quad y

Draw Quad z

COMPOSITOR FRAME B

RENDER PASSES

DRAW QUADS

ROOT RENDER PASS

71 of 81

Ways for a Surface Aggregator to aggregate

COMPOSITOR FRAME A

RENDER PASSES

DRAW QUADS

Draw Quad a

RP Draw Quad b

Draw Quad c

ROOT RENDER PASS

Draw Quad x

Draw Quad y

Draw Quad z

RENDER PASSES

OPTION 1

72 of 81

Ways for a Surface Aggregator to aggregate

Draw Quad a

RP Draw Quad b

Draw Quad c

OPTION 1

COMPOSITOR FRAME A

RENDER PASSES

DRAW QUADS

73 of 81

Ways for a Surface Aggregator to aggregate

OPTION 2

COMPOSITOR FRAME A

RENDER PASSES

DRAW QUADS

Draw Quad a

Surface Draw Quad b

Draw Quad c

Root Render Pass Quad List

Draw Quad x

Draw Quad y

Draw Quad z

ROOT RENDER PASS

74 of 81

Ways for a Surface Aggregator to aggregate

Draw Quad a

Draw Quad x

Draw Quad y

Draw Quad z

Draw Quad c

OPTION 2

COMPOSITOR FRAME A

RENDER PASSES

DRAW QUADS

75 of 81

SURFACE AGGREGATOR

COMPOSITOR FRAME

GPU PROCESS

COMPOSITOR FRAME

RENDER PASSES

DRAW QUADS

COMPOSITOR FRAME

COMPOSITOR FRAME

COMPOSITOR FRAME

GPU PROCESS

Display Compositor

76 of 81

GPU PROCESS

Display Compositor

GPU PROCESS

Display

Renderer

77 of 81

78 of 81

79 of 81

80 of 81

Questions?

Thank you!

81 of 81

GPU Brownbag for Surface aggregation: Link

GPU Brownbag for OOP-Display Compositor: Link