tree: 1be979d61ae3d37139ed1600665f9fed256f02e2 [path history] [tgz]
  1. BUILD.gn
  2. DEPS
  3. OWNERS
  4. README.md
  5. css_paint_definition.cc
  6. css_paint_definition.h
  7. css_paint_image_generator_impl.cc
  8. css_paint_image_generator_impl.h
  9. css_paint_worklet.cc
  10. css_paint_worklet.h
  11. css_paint_worklet.idl
  12. document_paint_definition.cc
  13. document_paint_definition.h
  14. paint_rendering_context_2d.cc
  15. paint_rendering_context_2d.h
  16. paint_rendering_context_2d.idl
  17. paint_rendering_context_2d_settings.idl
  18. paint_rendering_context_2d_test.cc
  19. paint_size.h
  20. paint_size.idl
  21. paint_worklet.cc
  22. paint_worklet.h
  23. paint_worklet_global_scope.cc
  24. paint_worklet_global_scope.h
  25. paint_worklet_global_scope.idl
  26. paint_worklet_global_scope_proxy.cc
  27. paint_worklet_global_scope_proxy.h
  28. paint_worklet_global_scope_test.cc
  29. paint_worklet_messaging_proxy.cc
  30. paint_worklet_messaging_proxy.h
  31. paint_worklet_pending_generator_registry.cc
  32. paint_worklet_pending_generator_registry.h
  33. paint_worklet_proxy_client.cc
  34. paint_worklet_proxy_client.h
  35. paint_worklet_test.cc
third_party/blink/renderer/modules/csspaint/README.md

CSS Paint API

This directory contains the implementation of the CSS Paint API.

See CSS Paint API for the web exposed APIs this implements.

Implementation

CSSPaintDefinition

Represents a class registered by the author through PaintWorkletGlobalScope#registerPaint. Specifically this class holds onto the javascript constructor and paint functions of the class via persistent handles. This class keeps these functions alive so they don't get garbage collected.

The CSSPaintDefinition also holds onto an instance of the paint class via a persistent handle. This instance is lazily created upon first use. If the constructor throws for some reason the constructor is marked as invalid and will always produce invalid images.

The PaintWorkletGlobalScope has a map of paint name to CSSPaintDefinition.

CSSPaintImageGenerator and CSSPaintImageGeneratorImpl

CSSPaintImageGenerator represents the interface from which the CSSPaintValue can generate Images. This is done via the CSSPaintImageGenerator#paint method. Each CSSPaintValue owns a separate instance of CSSPaintImageGenerator.

CSSPaintImageGeneratorImpl is the implementation which lives in modules/csspaint. (We have this interface / implementation split as core/ cannot depend on modules/).

When created the generator will access its paint worklet and lookup it's corresponding CSSPaintDefinition via PaintWorkletGlobalScope#findDefinition.

If the paint worklet does not have a CSSPaintDefinition matching the paint name the CSSPaintImageGeneratorImpl is placed in a “pending” map. Once a paint class with name is registered the generator is notified so it can invalidate an display the correct image.

Generating a PaintGeneratedImage

PaintGeneratedImage is a Image which just paints a single PaintRecord.

A CSSPaintValue can generate an image from the method CSSPaintImageGenerator#paint. This method calls through to CSSPaintDefinition#paint which actually invokes the javascript paint method. This method returns the PaintGeneratedImage.

Style Invalidation

The CSSPaintDefinition keeps a list of both native and custom properties it will invalidate on. During style invalidation ComputedStyle checks if it has any CSSPaintValues, and if any of their properties have changed; if so it will invalidate paint for that ComputedStyle.

If the CSSPaintValue doesn‘t have a corresponding CSSPaintDefinition yet, it doesn’t invalidate paint.

Testing

Tests live here.