OLD | NEW |
(Empty) | |
| 1 # CSS Paint API |
| 2 |
| 3 This directory contains the implementation of the CSS Paint API. |
| 4 |
| 5 See [CSS Paint API](https://drafts.css-houdini.org/css-paint-api/) for the web e
xposed APIs this |
| 6 implements. |
| 7 |
| 8 ## Implementation |
| 9 |
| 10 ### [CSSPaintDefinition](CSSPaintDefinition.h) |
| 11 |
| 12 Represents a class registered by the author through `PaintWorkletGlobalScope#reg
isterPaint`. |
| 13 Specifically this class holds onto the javascript constructor and paint function
s of the class via |
| 14 persistent handles. This class keeps these functions alive so they don't get gar
bage collected. |
| 15 |
| 16 The `CSSPaintDefinition` also holds onto an instance of the paint class va a per
sistent handle. This |
| 17 instance is lazily created upon first use. If the constructor throws for some re
ason the constructor |
| 18 is marked as invalid and will always produce invalid images. |
| 19 |
| 20 The `PaintWorkletGlobalScope` has a map of paint `name` to `CSSPaintDefinition`. |
| 21 |
| 22 ### [CSSPaintImageGenerator][generator] and [CSSPaintImageGeneratorImpl][generat
or-impl] |
| 23 |
| 24 `CSSPaintImageGenerator` represents the interface from which the `CSSPaintValue`
can generate |
| 25 `Image`s. This is done via the `CSSPaintImageGenerator#paint` method. Each `CSSP
aintValue` owns a |
| 26 separate instance of `CSSPaintImageGenerator`. |
| 27 |
| 28 `CSSPaintImageGeneratorImpl` is the implementation which lives in `modules/csspa
int`. (We have this |
| 29 interface / implementation split as `core/` cannot depend on `modules/`). |
| 30 |
| 31 When created the generator will access its paint worklet and lookup it's corresp
onding |
| 32 `CSSPaintDefinition` via `PaintWorkletGlobalScope#findDefinition`. |
| 33 |
| 34 If the paint worklet does not have a `CSSPaintDefinition` matching the paint `na
me` the |
| 35 `CSSPaintImageGeneratorImpl` is placed in a "pending" map. Once a paint class wi
th `name` is |
| 36 registered the generator is notified so it can invalidate an display the correct
image. |
| 37 |
| 38 [generator]: ../../core/css/CSSPaintImageGenerator.h |
| 39 [generator-impl]: CSSPaintImageGeneratorImpl.h |
| 40 [paint-value]: ../../core/css/CSSPaintValue.h |
| 41 |
| 42 ### Generating a [PaintGeneratedImage](../../platform/graphics/PaintGeneratedIma
ge.h) |
| 43 |
| 44 `PaintGeneratedImage` is a `Image` which just paints a single `SkPicture`. |
| 45 |
| 46 A `CSSPaintValue` can generate an image from the method `CSSPaintImageGenerator#
paint`. This method |
| 47 calls through to `CSSPaintDefinition#paint` which actually invokes the javascrip
t paint method. |
| 48 This method returns the `PaintGeneratedImage`. |
| 49 |
| 50 The `SkPicture` is produced from a `RecordingImageBufferSurface`. |
| 51 |
| 52 ## Testing |
| 53 |
| 54 Tests live [here](../../../LayoutTests/csspaint/). |
| 55 |
OLD | NEW |