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 via a we
ak persistent |
| 17 handle. The actual instance of the paint class is kept alive by `CSSPaintImageGe
neratorImpl`. This |
| 18 is so the instance can be garbage collected when not in use anymore. |
| 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 from. This is done via the `CSSPaintImageGenerator#paint` method. Each
`CSSPaintValue` |
| 26 owns a 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 paint worklet and lookup it's correspondi
ng |
| 32 `CSSPaintDefinition` via `PaintWorkletGlobalScope#findDefinition`. It will also
keep a persistent |
| 33 handle to the javascript paint class instance to keep this alive. |
| 34 |
| 35 If the paint worklet does not have a `CSSPaintDefinition` matching the paint `na
me` the |
| 36 `CSSPaintImageGeneratorImpl` is placed in a "pending" map. Once a paint class wi
th `name` is |
| 37 registered the generator is notified so it can invalidate an display the correct
image. |
| 38 |
| 39 [generator]: ../../core/css/CSSPaintImageGenerator.h |
| 40 [generator-impl]: CSSPaintImageGeneratorImpl.h |
| 41 [paint-value]: ../../core/css/CSSPaintValue.h |
| 42 |
| 43 ### Generating a [PaintGeneratedImage](../../platform/graphics/PaintGeneratedIma
ge.h) |
| 44 |
| 45 `PaintGeneratedImage` is a `Image` which just paints a single `SkPicture`. |
| 46 |
| 47 A `CSSPaintValue` can generate an image from the method `CSSPaintImageGenerator#
paint`. This method |
| 48 calls through to `CSSPaintDefinition#paint` which actually invokes the javascrip
t paint method. |
| 49 This method returns the `PaintGeneratedImage`. |
| 50 |
| 51 The `SkPicture` is produced from a `RecordingImageBufferSurface`. |
| 52 |
| 53 ## Testing |
| 54 |
| 55 Tests live [here](../../../LayoutTests/csspaint/). |
| 56 |
OLD | NEW |