Skip to content

Commit 869c59a

Browse files
xidachenbfgeek
authored andcommitted
[css-paint-api] Replace alpha flag with a PaintRenderingContext2DSettings object (w3c#448)
This replaces the single "alpha" flag with a "contextOptions" dictionary. This just has alpha at the moment, but can be extended to other options in the future.
1 parent 70d944c commit 869c59a

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

css-paint-api/Overview.bs

+28-17
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,23 @@ interface PaintWorkletGlobalScope : WorkletGlobalScope {
142142
};
143143
</pre>
144144

145+
The {{PaintRenderingContext2DSettings}} contains the settings for the rendering context associated
146+
with the paint canvas. The {{PaintRenderingContext2DSettings}} provides a supported subset
147+
of canvas rendering context 2D settings. In the future, it may be extended to support color
148+
management in paint canvas.
149+
<pre class='idl'>
150+
dictionary PaintRenderingContext2DSettings {
151+
boolean alpha = true;
152+
};
153+
</pre>
154+
145155
<div class='note'>
146156
Note: The shape of the class should be:
147157
<pre class='lang-javascript'>
148158
class MyPaint {
149159
static get inputProperties() { return ['--foo']; }
150160
static get inputArguments() { return ['&lt;color>']; }
151-
static get alpha() { return true; }
161+
static get contextOptions() { return {alpha: true}; }
152162

153163
paint(ctx, size, styleMap) {
154164
// Paint code goes here.
@@ -173,7 +183,7 @@ A <dfn>paint definition</dfn> is a <a>struct</a> which describes the information
173183
- <dfn for="paint definition">input properties</dfn> which is a <a>list</a> of
174184
<code>DOMStrings</code>.
175185

176-
- A <dfn for="paint definition">context alpha flag</dfn>.
186+
- A <dfn for="paint definition">PaintRenderingContext2DSettings object</dfn>.
177187

178188
A <dfn>document paint definition</dfn> is a <a>struct</a> which describes the information
179189
needed by the <a>document</a> about the author defined <<image>> function (which can be referenced
@@ -185,7 +195,7 @@ by the paint function). It consists of:
185195
- A <dfn for="document paint definition">input argument syntaxes</dfn> which is a <a>list</a> of
186196
parsed [[css-properties-values-api-1#supported-syntax-strings]].
187197

188-
- A <dfn for="document paint definition">context alpha flag</dfn>.
198+
- A <dfn for="document paint definition">PaintRenderingContext2DSettings object</dfn>.
189199

190200
Registering Custom Paint {#registering-custom-paint}
191201
====================================================
@@ -248,15 +258,15 @@ called, the user agent <em>must</em> run the following steps:
248258

249259
2. <a for=list>Append</a> |parsedSyntax| to |inputArgumentSyntaxes|.
250260

251-
12. Let |alphaValue| be the result of <a>Get</a>(|paintCtor|, "alpha").
261+
12. Let |contextOptionsValue| be the result of <a>Get</a>(|paintCtor|, "contextOptions").
252262

253-
13. Let |alpha| be <code>true</code> if |alphaValue| is undefined, otherwise let it be the
254-
result of <a>converting</a> |alphaValue| to a <a>boolean</a>. If an exception is
255-
<a>thrown</a>, rethrow the exception and abort all these steps.
263+
13. Let |paintRenderingContext2DSettings| be the result of <a>converting</a>
264+
|contextOptionsValue| to a {{PaintRenderingContext2DSettings}}.
265+
If an exception is <a>thrown</a>, rethrow the exception and abort all these steps.
256266

257-
Note: Setting <code>alpha</code> is <code>false</code> allows user agents to anti-alias text
258-
an addition to performing "visibility" optimizations, e.g. not painting an image behind
259-
the paint image as the paint image is opaque.
267+
Note: Setting <code>paintRenderingContext2DSettings.alpha</code> is <code>false</code> allows user agents
268+
to anti-alias text in addition to performing "visibility" optimizations, e.g. not
269+
painting an image behind the paint image as the paint image is opaque.
260270

261271
14. If the result of <a>IsConstructor</a>(|paintCtor|) is false, <a>throw</a> a <a>TypeError</a>
262272
and abort all these steps.
@@ -281,7 +291,7 @@ called, the user agent <em>must</em> run the following steps:
281291

282292
- <a for="paint definition">input properties</a> being |inputProperties|.
283293

284-
- <a for="paint definition">context alpha flag</a> being |alpha|.
294+
- <a for="paint definition">PaintRenderingContext2DSettings object</a> being |paintRenderingContext2DSettings|.
285295

286296
20. <a for=map>Set</a> |paintDefinitionMap|[|name|] to |definition|.
287297

@@ -297,7 +307,7 @@ called, the user agent <em>must</em> run the following steps:
297307
- <a for="document paint definition">input argument syntaxes</a> being
298308
|inputArgumentSyntaxes|.
299309

300-
- <a for="document paint definition">context alpha flag</a> being |alpha|.
310+
- <a for="document paint definition">PaintRenderingContext2DSettings object</a> being |paintRenderingContext2DSettings|.
301311

302312
3. If |documentPaintDefinitionMap|[|name|] <a for=map>exists</a>, run the following steps:
303313

@@ -309,13 +319,13 @@ called, the user agent <em>must</em> run the following steps:
309319
3. If |existingDocumentDefinition| and |documentDefinition| are not equivalent, (that is
310320
<a for="document paint definition">input properties</a>, <a for="document paint
311321
definition">input argument syntaxes</a>, and <a for="document paint
312-
definition">context alpha flag</a> are different), then:
322+
definition">PaintRenderingContext2DSettings object</a> are different), then:
313323

314324
<a for=map>Set</a> |documentPaintDefinitionMap|[|name|] to <code>"invalid"</code>.
315325

316326
Log an error to the debugging console stating that the same class was registered
317327
with different <code>inputProperties</code>, <code>inputArguments</code>, or
318-
<code>alpha</code>.
328+
<code>paintRenderingContext2DSettings</code>.
319329

320330
4. Otherwise, <a for=map>set</a> |documentPaintDefinitionMap|[|name|] to
321331
|documentDefinition|.
@@ -409,10 +419,10 @@ is treated as opaque black.
409419

410420
<div algorithm>
411421
When the user agent is to <dfn>create a PaintRenderingContext2D object</dfn> for a given |width|,
412-
|height|, and |alpha|, it <em>must</em> run the following steps:
422+
|height|, and |paintRenderingContext2DSettings|, it <em>must</em> run the following steps:
413423
1. Create a new {{PaintRenderingContext2D}}.
414424
2. <a>Set bitmap dimensions</a> for the context's <a>output bitmap</a> to |width| and |height|.
415-
3. Set the {{PaintRenderingContext2D}}'s <a>alpha</a> flag to |alpha|.
425+
3. Set the {{PaintRenderingContext2D}}'s <a>alpha</a> flag to |paintRenderingContext2DSettings.alpha|.
416426
4. Return the new {{PaintRenderingContext2D}}.
417427

418428
Note: The initial state of the rendering context is set inside the <a>set bitmap dimensions</a>
@@ -609,7 +619,8 @@ When the user agent wants to <dfn>invoke a paint callback</dfn> given |name|, |i
609619
8. Let |renderingContext| be the result of <a>create a PaintRenderingContext2D object</a> given:
610620
- "width" - The width given by |concreteObjectSize|.
611621
- "height" - The height given by |concreteObjectSize|.
612-
- "alpha" - The <a for="paint definition">context alpha flag</a> given by |definition|.
622+
- "paintRenderingContext2DSettings" - The
623+
<a for="paint definition">PaintRenderingContext2DSettings object</a> given by |definition|.
613624

614625
Note: The |renderingContext| is not be re-used between invocations of paint. Implicitly this
615626
means that there is no stored data, or state on the |renderingContext| between

0 commit comments

Comments
 (0)