Skip to content

Commit cdd6fed

Browse files
authored
[css-paint-api] Removes invalidation based on size, and allows user-a… (w3c#390)
* [css-paint-api] Removes invalidation based on size, and allows user-agents to cache. Fixes w3c#326. I realized that explicitly placing an invalidation based on size here was wrong, e.g. if a box changes size it has to run the "object size negotiation" algorithm, which makes invalidating the paint() function off size redundant. Additionally allows user-agents to cache results from previous invocations, and re-use. This allows UAs to re-use images between instances if they have the same input style, concrete object size, and input arguments.
1 parent 8cdd7f5 commit cdd6fed

File tree

1 file changed

+52
-7
lines changed

1 file changed

+52
-7
lines changed

css-paint-api/Overview.bs

+52-7
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,9 @@ Paint Invalidation {#paint-invalidation}
8484
Each <<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

108108
Performing <a>draw a paint image</a> results in the <a>paint valid flag</a> for a <<paint()>>
109109
function 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+
111114
Note: 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+
&lt;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+
&lt;/style>
657+
&lt;div class=div-1>&lt;/div>
658+
&lt;div class=div-2>&lt;/div>
659+
&lt;script>
660+
CSS.paintWorklet.import('paint.js');
661+
&lt;/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

Comments
 (0)