OLD | NEW |
1 # Platform paint code | 1 # Platform paint code |
2 | 2 |
3 This directory contains the implementation of display lists and display | 3 This directory contains the implementation of display lists and display |
4 list-based painting, except for code which requires knowledge of `core/` | 4 list-based painting, except for code which requires knowledge of `core/` |
5 concepts, such as DOM elements and layout objects. | 5 concepts, such as DOM elements and layout objects. |
6 | 6 |
7 This code is owned by the [paint team][paint-team-site]. | 7 This code is owned by the [paint team][paint-team-site]. |
8 | 8 |
9 Slimming Paint v2 is currently being implemented. Unlike Slimming Paint v1, SPv2 | 9 Slimming Paint v2 is currently being implemented. Unlike Slimming Paint v1, SPv2 |
10 represents its paint artifact not as a flat display list, but as a list of | 10 represents its paint artifact not as a flat display list, but as a list of |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 It is illegal for there to be two drawings with the same ID in a display item | 127 It is illegal for there to be two drawings with the same ID in a display item |
128 list, except for drawings that are marked uncacheable | 128 list, except for drawings that are marked uncacheable |
129 (see [DisplayItemCacheSkipper](DisplayItemCacheSkipper.h)). | 129 (see [DisplayItemCacheSkipper](DisplayItemCacheSkipper.h)). |
130 *** | 130 *** |
131 | 131 |
132 Generally, clients of this code should use stack-allocated recorder classes to | 132 Generally, clients of this code should use stack-allocated recorder classes to |
133 emit display items to a `PaintController` (using `GraphicsContext`). | 133 emit display items to a `PaintController` (using `GraphicsContext`). |
134 | 134 |
135 ### Standalone display items | 135 ### Standalone display items |
136 | 136 |
137 #### [CachedDisplayItem](CachedDisplayItem.h) | |
138 | |
139 See [Display item caching](../../../core/paint/README.md#paint-result-caching). | |
140 | |
141 #### [DrawingDisplayItem](DrawingDisplayItem.h) | 137 #### [DrawingDisplayItem](DrawingDisplayItem.h) |
142 | 138 |
143 Holds an `SkPicture` which contains the Skia commands required to draw some atom | 139 Holds an `SkPicture` which contains the Skia commands required to draw some atom |
144 of content. | 140 of content. |
145 | 141 |
146 #### [ForeignLayerDisplayItem](ForeignLayerDisplayItem.h) | 142 #### [ForeignLayerDisplayItem](ForeignLayerDisplayItem.h) |
147 | 143 |
148 Draws an atom of content, but using a `cc::Layer` produced by some agent outside | 144 Draws an atom of content, but using a `cc::Layer` produced by some agent outside |
149 of the normal Blink paint system (for example, a plugin). Since they always map | 145 of the normal Blink paint system (for example, a plugin). Since they always map |
150 to a `cc::Layer`, they are always the only display item in their paint chunk, | 146 to a `cc::Layer`, they are always the only display item in their paint chunk, |
151 and are ineligible for squashing with other layers. | 147 and are ineligible for squashing with other layers. |
152 | 148 |
153 ### Paired begin/end display items | 149 ### Paired begin/end display items |
154 | 150 |
155 *** aside | 151 *** aside |
156 TODO(jbroman): Describe how these work, once we've worked out what happens to | 152 TODO(jbroman): Describe how these work, once we've worked out what happens to |
157 them in SPv2. | 153 them in SPv2. |
158 *** | 154 *** |
159 | 155 |
160 ## Paint controller | 156 ## Paint controller |
161 | 157 |
162 Callers use `GraphicsContext` (via its drawing methods, and its | 158 Callers use `GraphicsContext` (via its drawing methods, and its |
163 `paintController()` accessor) and scoped recorder classes, which emit items into | 159 `paintController()` accessor) and scoped recorder classes, which emit items into |
164 a `PaintController`. | 160 a `PaintController`. |
165 | 161 |
166 `PaintController` is responsible for producing the paint artifact. It contains | 162 `PaintController` is responsible for producing the paint artifact. It contains |
167 the *current* paint artifact, which is always complete (i.e. it has no | 163 the *current* paint artifact, and *new* display items and paint chunks, which |
168 `CachedDisplayItem` objects), and *new* display items and paint chunks, which | |
169 are added as content is painted. | 164 are added as content is painted. |
170 | 165 |
| 166 Painters should call `PaintController::useCachedDrawingIfPossible()` or |
| 167 `PaintController::useCachedSubsequenceIfPossible()` and if the function returns |
| 168 `true`, existing display items that are still valid in the *current* paint artif
act |
| 169 will be reused and the painter should skip real painting of the drawing or subse
quence. |
| 170 |
171 When the new display items have been populated, clients call | 171 When the new display items have been populated, clients call |
172 `commitNewDisplayItems`, which merges the previous artifact with the new data, | 172 `commitNewDisplayItems`, which replaces the previous artifact with the new data, |
173 producing a new paint artifact, where `CachedDisplayItem` objects have been | 173 producing a new paint artifact. |
174 replaced with the cached content from the previous artifact. | |
175 | 174 |
176 At this point, the paint artifact is ready to be drawn or composited. | 175 At this point, the paint artifact is ready to be drawn or composited. |
177 | 176 |
178 ### Paint result caching and invalidation | 177 ### Paint result caching and invalidation |
179 | 178 |
180 See [Display item caching](../../../core/paint/README.md#paint-result-caching) | 179 See [Display item caching](../../../core/paint/README.md#paint-result-caching) |
181 and [Paint invalidation](../../../core/paint/README.md#paint-invalidation) for | 180 and [Paint invalidation](../../../core/paint/README.md#paint-invalidation) for |
182 more details about how caching and invalidation are handled in blink core | 181 more details about how caching and invalidation are handled in blink core |
183 module using `PaintController` API. | 182 module using `PaintController` API. |
184 | 183 |
185 We use 'cache generation' which is a unique id of cache status in each | 184 We use 'cache generation' which is a unique id of cache status in each |
186 `DisplayItemClient` and `PaintController` to determine if the client is validly | 185 `DisplayItemClient` and `PaintController` to determine if the client is validly |
187 cached by a `PaintController`. | 186 cached by a `PaintController`. |
188 | 187 |
189 A paint controller sets its cache generation to | 188 A paint controller sets its cache generation to |
190 `DisplayItemCacheGeneration::next()` at the end of each | 189 `DisplayItemCacheGeneration::next()` at the end of each |
191 `commitNewDisplayItems()`, and updates the cache generation of each client with | 190 `commitNewDisplayItems()`, and updates the cache generation of each client with |
192 cached drawings by calling `DisplayItemClient::setDisplayItemsCached()`. | 191 cached drawings by calling `DisplayItemClient::setDisplayItemsCached()`. |
193 A display item is treated as validly cached in a paint controller if its cache | 192 A display item is treated as validly cached in a paint controller if its cache |
194 generation matches the paint controller's cache generation. | 193 generation matches the paint controller's cache generation. |
195 | 194 |
196 `kInvalidCacheGeneration` is a special cache generation value which matches no | 195 A cache generation value smaller than `kFirstValidGeneration` matches no |
197 other cache generations. When a `DisplayItemClient` is invalidated, we set its | 196 other cache generations thus is always treated as invalid. When a |
198 cache generation to `kInvalidCacheGeneration`. When a `PaintController` is | 197 `DisplayItemClient` is invalidated, we set its cache generation to one of |
199 cleared (e.g. when the corresponding `GraphicsLayer` is fully invalidated), we | 198 `PaintInvalidationReason` values which are smaller than `kFirstValidGeneration`. |
200 also set its cache generation to `kInvalidCacheGeneration`. | 199 When a `PaintController` is cleared (e.g. when the corresponding `GraphicsLayer` |
| 200 is fully invalidated), we also invalidate its cache generation. |
201 | 201 |
202 For now we use a uint32_t variable to store cache generation. Assuming there is | 202 For now we use a uint32_t variable to store cache generation. Assuming there is |
203 an animation in 60fps needing main-thread repaint, the cache generation will | 203 an animation in 60fps needing main-thread repaint, the cache generation will |
204 overflow after 2^32/86400/60 = 828 days. The time may be shorter if there are | 204 overflow after 2^32/86400/60 = 828 days. The time may be shorter if there are |
205 multiple animating `PaintController`s in the same process. When it overflows, | 205 multiple animating `PaintController`s in the same process. When it overflows, |
206 we may treat some object that is not cached as cached if the following | 206 we may treat some object that is not cached as cached if the following |
207 conditions are all met: | 207 conditions are all met: |
208 * the object was painted when the cache generation was *n*; | 208 * the object was painted when the cache generation was *n*; |
209 * the object has been neither painted nor invalidated since cache generation | 209 * the object has been neither painted nor invalidated since cache generation |
210 *n*; | 210 *n*; |
(...skipping 30 matching lines...) Expand all Loading... |
241 visual and transformed rects of display items in the coordinate space of ancesto
r | 241 visual and transformed rects of display items in the coordinate space of ancesto
r |
242 [`PropertyTreeState`](PropertyTreeState.h)s. | 242 [`PropertyTreeState`](PropertyTreeState.h)s. |
243 | 243 |
244 The transformed rect of a display item in an ancestor `PropertyTreeState` is tha
t | 244 The transformed rect of a display item in an ancestor `PropertyTreeState` is tha
t |
245 rect, multiplied by the transforms between the display item's `PropertyTreeState
` | 245 rect, multiplied by the transforms between the display item's `PropertyTreeState
` |
246 and the ancestors, then flattened into 2D. | 246 and the ancestors, then flattened into 2D. |
247 | 247 |
248 The visual rect of a display item in an ancestor `PropertyTreeState` is the inte
rsection | 248 The visual rect of a display item in an ancestor `PropertyTreeState` is the inte
rsection |
249 of all of the intermediate clips (transformed in to the ancestor state), with | 249 of all of the intermediate clips (transformed in to the ancestor state), with |
250 the display item's transformed rect. | 250 the display item's transformed rect. |
OLD | NEW |