Skip to content

Commit 4504469

Browse files
committed
[css-paint-api] Adds "alpha" option to paint class.
Fixes #220.
1 parent b41aa79 commit 4504469

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

css-paint-api/Overview.bs

+29-13
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ interface PaintWorkletGlobalScope : WorkletGlobalScope {
114114
<pre class='lang-javascript'>
115115
class MyPaint {
116116
static get inputProperties() { return ['--foo']; }
117+
static get alpha() { return true; }
117118
paint(ctx, size, styleMap) {
118119
// Paint code goes here.
119120
}
@@ -135,6 +136,8 @@ the <<paint()>> function. It consists of:
135136

136137
- A <dfn>paint constructor valid flag</dfn>.
137138

139+
- A <dfn>paint context alpha flag</dfn>.
140+
138141
Registering Custom Paint {#registering-custom-paint}
139142
====================================================
140143

@@ -177,20 +180,32 @@ called, the user agent <em>must</em> run the following steps:
177180
can also contains currently invalid properties for the user agent. For example
178181
<code>margin-bikeshed-property</code>.
179182

180-
5. If the result of <a>IsConstructor</a>(|paintCtor|) is false, <a>throw</a> a <a>TypeError</a>
183+
5. Let |alphaValue| be the result of <a>Get</a>(|paintCtor|, "alpha").
184+
185+
6. If |alphaValue| is not undefined and the result of <a>Type</a>(|alpha|) is not Boolean,
186+
<a>throw</a> a <a>TypeError</a> and abort all these steps.
187+
188+
7. Let |alpha| be <code>true</code> if |alphaValue| is undefined, otherwise let it be the value
189+
of |alphaValue|.
190+
191+
Note: Setting <code>alpha</code> is <code>false</code> allows user agents to anti-alias text
192+
an addition to performing "visibility" optimizations, e.g. not painting an image behind
193+
the paint image as the paint image is opaque.
194+
195+
8. If the result of <a>IsConstructor</a>(|paintCtor|) is false, <a>throw</a> a <a>TypeError</a>
181196
and abort all these steps.
182197

183-
6. Let |prototype| be the result of <a>Get</a>(|paintCtor|, "prototype").
198+
9. Let |prototype| be the result of <a>Get</a>(|paintCtor|, "prototype").
184199

185-
7. If the result of <a>Type</a>(|prototype|) is not Object, <a>throw</a> a <a>TypeError</a> and
200+
10. If the result of <a>Type</a>(|prototype|) is not Object, <a>throw</a> a <a>TypeError</a> and
186201
abort all these steps.
187202

188-
8. Let |paint| be the result of <a>Get</a>(|prototype|, "paint").
203+
11. Let |paint| be the result of <a>Get</a>(|prototype|, "paint").
189204

190-
9. If the result of <a>IsCallable</a>(|paint|) is false, <a>throw</a> a <a>TypeError</a> and
205+
12. If the result of <a>IsCallable</a>(|paint|) is false, <a>throw</a> a <a>TypeError</a> and
191206
abort all these steps.
192207

193-
10. Let |definition| be a new <a>paint image definition</a> with:
208+
13. Let |definition| be a new <a>paint image definition</a> with:
194209

195210
- <a>paint image name</a> being |name|
196211

@@ -199,11 +214,13 @@ called, the user agent <em>must</em> run the following steps:
199214
- <a>paint function</a> being |paint|
200215

201216
- <a>paint constructor valid flag</a> being true
217+
218+
- <a>paint context alpha flag</a> being |alpha|.
202219

203-
11. Add the key-value pair (|name| - |inputProperties|) to the <a>paint name to input properties
220+
14. Add the key-value pair (|name| - |inputProperties|) to the <a>paint name to input properties
204221
map</a> of the associated <a>document</a>.
205222

206-
12. Add the key-value pair (|name| - |definition|) to the <a>paint name to paint image
223+
15. Add the key-value pair (|name| - |definition|) to the <a>paint name to paint image
207224
definition map</a> of the associated <a>document</a>.
208225

209226

@@ -269,19 +286,17 @@ that the user agent will use internally or during rendering. For example, if the
269286
zoomed the user agent may internally use bitmaps which correspond to the number of device pixels in
270287
the coordinate space, so that the resulting rendering is of high quality.
271288

272-
The {{PaintRenderingContext2D}} object should have its <a>alpha</a> flag set to true. That is the
273-
rendering context is initially fully transparent.
274-
275289
Additionally the user agent may record the sequence of drawing operations which have been applied to
276290
the <a>output bitmap</a> such that the user agent can subsequently draw onto a device bitmap at the
277291
correct resolution. This also allows user agents to re-use the same output of the <a>output
278292
bitmap</a> repeatably while the visual viewport is being zoomed for example.
279293

280294
When the user agent is to <dfn>create a PaintRenderingContext2D object</dfn> for a given |width|,
281-
|height| it <em>must</em> run the following steps:
295+
|height| and |alpha| it <em>must</em> run the following steps:
282296
1. Create a new {{PaintRenderingContext2D}}.
283297
2. <a>Set bitmap dimensions</a> for the context's <a>output bitmap</a> to |width| and |height|.
284-
3. Return the new {{PaintRenderingContext2D}}.
298+
3. Set the {{PaintRenderingContext2D}}'s <a>alpha</a> flag to |alpha|.
299+
4. Return the new {{PaintRenderingContext2D}}.
285300

286301
Note: The initial state of the rendering context is set inside the <a>set bitmap dimensions</a>
287302
algorithm, as it invokes <a>reset the rendering context to its default state</a> and clears the
@@ -387,6 +402,7 @@ following steps:
387402
9. Let |renderingContext| be the result of <a>create a PaintRenderingContext2D object</a> given:
388403
- "width" - The width given by |concreteObjectSize|.
389404
- "height" - The height given by |concreteObjectSize|.
405+
- "alpha" - The <a>paint context alpha flag</a> given by |definition|.
390406

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

0 commit comments

Comments
 (0)