@@ -84,10 +84,9 @@ Paint Invalidation {#paint-invalidation}
8484Each <<paint()>> function for a box has an associated <dfn>paint valid flag</dfn> . It may be either
8585<dfn>paint-valid</dfn> or <dfn>paint-invalid</dfn> . It is initially set to <a>paint-invalid</a> .
8686
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:
9190 1. For each <<paint()>> function on the |box|, perform the following steps:
9291 1. Let |paintFunction| be the current <<paint()>> function on the |box|.
9392
@@ -104,10 +103,14 @@ When the computed style for a |box| changes, the user agent <em>must</em> run th
104103
105104 6. For each |property| in |inputProperties|, if the |property|'s <a>computed value</a> has
106105 changed, set the <a>paint valid flag</a> on the |paintFunction| to <a>paint-invalid</a> .
106+ </div>
107107
108108Performing <a>draw a paint image</a> results in the <a>paint valid flag</a> for a <<paint()>>
109109function on a box to be set to <a>paint-valid</a> .
110110
111+ <a>Invalidate paint functions</a> <em> must</em> be run when the user agent recalculates the computed
112+ style for a box.
113+
111114Note: In a future version of the spec, support could be added for partial invalidation. The user
112115 agent will be able to specify a region of the rendering context which needs to be re-painted by
113116 the paint class.
@@ -617,9 +620,51 @@ When the user agent wants to <dfn>invoke a paint callback</dfn> given |name|, |i
617620 9. Let |paintSize| be a new {{PaintSize}} initialized to the width and height defined by
618621 |concreteObjectSize|.
619622
620- 10. Let |paintFunctionCallback| be |definition|'s <a>paint function</a> .
623+ 10. At this stage the user agent may re-use an image from a previous invocation if |paintSize|,
624+ |styleMap|, |inputArguments| are equivalent to that previous invocation. If so let the image
625+ output be that cached image and abort all these steps.
626+
627+ <div class=note>
628+ In the example below, both <code> div-1</code> and <code> div-2</code> have paint
629+ functions which have equivalent javascript arguments. A user-agent can cache the result
630+ of one invocation and use it for both elements.
631+
632+ <pre class=lang-javascript>
633+ // paint.js
634+ registerPaint('simple' , class {
635+ paint(ctx, size) {
636+ ctx.fillStyle = 'green' ;
637+ ctx.fillRect(0, 0, size.width, size.height);
638+ }
639+ });
640+ </pre>
641+
642+ <pre class=lang-markup>
643+ <style>
644+ .div-1 {
645+ width: 50px;
646+ height: 50px;
647+ background-image: paint(simple);
648+ }
649+ .div-2 {
650+ width: 100px;
651+ height: 100px;
652+
653+ background-size: 50% 50%;
654+ background-image: paint(simple);
655+ }
656+ </style>
657+ <div class=div-1></div>
658+ <div class=div-2></div>
659+ <script>
660+ CSS.paintWorklet.import('paint.js' );
661+ </script>
662+ </pre>
663+ </div>
664+
665+ 11. Let |paintFunctionCallback| be |definition|'s <a>paint function</a> .
621666
622- 11 . <a>Invoke</a> |paintFunctionCallback| with arguments «|renderingContext|, |paintSize|,
667+ 12 . <a>Invoke</a> |paintFunctionCallback| with arguments «|renderingContext|, |paintSize|,
623668 |styleMap|, |inputArguments|», and with |paintInstance| as the <a>callback this value</a> .
624669
625670 If |paintFunctionCallback| does not complete within an acceptable time (as determined by the
@@ -630,7 +675,7 @@ When the user agent wants to <dfn>invoke a paint callback</dfn> given |name|, |i
630675 expensive their paint classes are. User agents could also how an "unresponsive script"
631676 dialog in this case if appropriate.
632677
633- 12 . The image output is to be produced from the |renderingContext| given to the method.
678+ 13 . The image output is to be produced from the |renderingContext| given to the method.
634679
635680 If an exception is <a>thrown</a> the let the image output be an <a>invalid image</a> .
636681
0 commit comments