tree: 2a254951b0c5fc1fe11ecfcc05d18f479427a768 [path history] [tgz]
  1. CSSPaintDefinition.cpp
  2. CSSPaintDefinition.h
  3. CSSPaintImageGeneratorImpl.cpp
  4. CSSPaintImageGeneratorImpl.h
  5. DEPS
  6. OWNERS
  7. PaintRenderingContext2D.cpp
  8. PaintRenderingContext2D.h
  9. PaintRenderingContext2D.idl
  10. PaintRenderingContext2DTest.cpp
  11. PaintSize.h
  12. PaintSize.idl
  13. PaintWorklet.cpp
  14. PaintWorklet.h
  15. PaintWorkletGlobalScope.cpp
  16. PaintWorkletGlobalScope.h
  17. PaintWorkletGlobalScope.idl
  18. PaintWorkletTest.cpp
  19. README.md
  20. WindowPaintWorklet.cpp
  21. WindowPaintWorklet.h
  22. WindowPaintWorklet.idl
third_party/WebKit/Source/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 va 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 SkPicture.

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.

The SkPicture is produced from a RecordingImageBufferSurface.

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.