@@ -84,10 +84,9 @@ Paint Invalidation {#paint-invalidation}
84
84
Each <<paint()>> function for a box has an associated <dfn>paint valid flag</dfn> . It may be either
85
85
<dfn>paint-valid</dfn> or <dfn>paint-invalid</dfn> . It is initially set to <a>paint-invalid</a> .
86
86
87
- When the size (as determined by layout) of a |box| changes, each <<paint()>> function's <a>paint
88
- valid flag</a> should be set to <a>paint-invalid</a> .
89
-
90
- When the computed style for a |box| changes, the user agent <em> must</em> run the following steps:
87
+ <div algorithm>
88
+ When the user agent wants to <dfn>invalidate paint functions</dfn> given |box|, the user agent
89
+ <em> must</em> run the following steps:
91
90
1. For each <<paint()>> function on the |box|, perform the following steps:
92
91
1. Let |paintFunction| be the current <<paint()>> function on the |box|.
93
92
@@ -104,10 +103,14 @@ When the computed style for a |box| changes, the user agent <em>must</em> run th
104
103
105
104
6. For each |property| in |inputProperties|, if the |property|'s <a>computed value</a> has
106
105
changed, set the <a>paint valid flag</a> on the |paintFunction| to <a>paint-invalid</a> .
106
+ </div>
107
107
108
108
Performing <a>draw a paint image</a> results in the <a>paint valid flag</a> for a <<paint()>>
109
109
function on a box to be set to <a>paint-valid</a> .
110
110
111
+ <a>Invalidate paint functions</a> is expected to be run when the user agent recalculates computed
112
+ style for a box.
113
+
111
114
Note: In a future version of the spec, support could be added for partial invalidation. The user
112
115
agent will be able to specify a region of the rendering context which needs to be re-painted by
113
116
the paint class.
@@ -614,12 +617,54 @@ When the user agent wants to <dfn>invoke a paint callback</dfn> given |name|, |i
614
617
9. Let |paintSize| be a new {{PaintSize}} initialized to the width and height defined by
615
618
|concreteObjectSize|.
616
619
617
- 10. Let |paintFunctionCallback| be |definition|'s <a>paint function</a> .
620
+ 10. At this stage the user agent may re-use an image from a previous invocation if |paintSize|,
621
+ |styleMap|, |inputArguments| are equivalent to that previous invocation. If so let the image
622
+ output be that cached image and abort all these steps.
623
+
624
+ <div class=note>
625
+ In the example below, both <code> div-1</code> and <code> div-2</code> have paint
626
+ functions which have equivalent javascript arguments. A user-agent can cache the result
627
+ of one invocation and use it for both elements.
628
+
629
+ <pre class=lang-javascript>
630
+ // paint.js
631
+ registerPaint('simple' , class {
632
+ paint(ctx, size) {
633
+ ctx.fillStyle = 'green' ;
634
+ ctx.fillRect(0, 0, size.width, size.height);
635
+ }
636
+ });
637
+ </pre>
638
+
639
+ <pre class=lang-markup>
640
+ <style>
641
+ .div-1 {
642
+ width: 50px;
643
+ height: 50px;
644
+ background-image: paint(simple);
645
+ }
646
+ .div-2 {
647
+ width: 100px;
648
+ height: 100px;
649
+
650
+ background-size: 50% 50%;
651
+ background-image: paint(simple);
652
+ }
653
+ </style>
654
+ <div class=div-1></div>
655
+ <div class=div-2></div>
656
+ <script>
657
+ CSS.paintWorklet.import('paint.js' );
658
+ </script>
659
+ </pre>
660
+ </div>
661
+
662
+ 11. Let |paintFunctionCallback| be |definition|'s <a>paint function</a> .
618
663
619
- 11 . <a>Invoke</a> |paintFunctionCallback| with arguments «|renderingContext|, |paintSize|,
664
+ 12 . <a>Invoke</a> |paintFunctionCallback| with arguments «|renderingContext|, |paintSize|,
620
665
|styleMap|, |inputArguments|», and with |paintInstance| as the <a>callback this value</a> .
621
666
622
- 12 . The image output is to be produced from the |renderingContext| given to the method.
667
+ 13 . The image output is to be produced from the |renderingContext| given to the method.
623
668
624
669
If an exception is <a>thrown</a> the let the image output be an <a>invalid image</a> .
625
670
0 commit comments