Skip to content

Commit 08a4cf8

Browse files
committed
[css-paint-api] Initial overview of what is in PaintRenderingContext2D.
1 parent 30b3007 commit 08a4cf8

File tree

1 file changed

+61
-16
lines changed

1 file changed

+61
-16
lines changed

css-paint-api/Overview.bs

+61-16
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ urlPrefix: https://heycam.github.io/webidl/; type: dfn;
2424
url: throw; text: thrown
2525
urlPrefix: https://html.spec.whatwg.org/multipage/scripting.html; type: dfn;
2626
text: reset the rendering context to its default state
27+
text: scratch bitmap
28+
text: set bitmap dimensions
2729
urlPrefix: http://www.ecma-international.org/ecma-262/6.0/#sec-; type: dfn;
2830
text: Construct
2931
text: IsArray
@@ -81,7 +83,7 @@ A {{PaintWorkletGlobalScope}} has a map of <b>name to paint instance map</b>. In
8183
<pre class='idl'>
8284
callback interface PaintClass {
8385
readonly attribute sequence&lt;DOMString&gt; inputProperties;
84-
void paint(PaintRenderingContext2d ctx, Geometry geom, StylePropertyMap inputProperties);
86+
void paint(PaintRenderingContext2D ctx, Geometry geom, StylePropertyMap inputProperties);
8587
void overflow(StylePropertyMap inputProperties);
8688
};
8789
</pre>
@@ -131,22 +133,70 @@ Issue(w3c/css-houdini-drafts#33): What to do about cursor.
131133

132134
Issue: How do we do things like conic-gradient? I.e. paint functions which accept arguments as inputs?
133135

134-
Drawing an image {#drawing-an-image}
135-
====================================
136+
The 2D rendering context {#2d-rendering-context}
137+
================================================
136138

137139
<pre class='idl'>
138-
interface PaintRenderingContext2d {
139-
// TODO link to actual CanvasRenderingContext2d.
140+
[Exposed=Worklet]
141+
interface PaintRenderingContext2D {
140142
};
143+
PaintRenderingContext2D implements CanvasState;
144+
PaintRenderingContext2D implements CanvasTransform;
145+
PaintRenderingContext2D implements CanvasCompositing;
146+
PaintRenderingContext2D implements CanvasImageSmoothing;
147+
PaintRenderingContext2D implements CanvasFillStrokeStyles;
148+
PaintRenderingContext2D implements CanvasShadowStyles;
149+
PaintRenderingContext2D implements CanvasRect;
150+
PaintRenderingContext2D implements CanvasDrawPath;
151+
PaintRenderingContext2D implements CanvasText;
152+
PaintRenderingContext2D implements CanvasDrawImage;
153+
PaintRenderingContext2D implements CanvasPathDrawingStyles;
154+
PaintRenderingContext2D implements CanvasTextDrawingStyles;
155+
PaintRenderingContext2D implements CanvasPath;
156+
</pre>
157+
158+
Note: The {{PaintRenderingContext2D}} implements a subset of the {{CanvasRenderingContext2D}} API.
159+
Specifically it doesn't implement the {{CanvasHitRegion}}, {{CanvasImageData}} or
160+
{{CanvasUserInterface}} APIs.
161+
162+
A {{PaintRenderingContext2D}} object has a <a>scratch bitmap</a>. This is initialised when the
163+
object is created. The size of the <a>scratch bitmap</a> is the size of the fragment it is rendering
164+
plus the size specified by the overflow method.
165+
166+
The logical origin (0,0) is not necessarily placed at the origin of the <a>scratch bitmap</a>. If
167+
the fragment which is being painted has an associated overflow, the logical origin is placed at
168+
(overflow-left,overflow-top) of the <a>scratch bitmap</a>.
169+
170+
Issue: Add image explaining origin vs. logical origin.
171+
172+
The size of the <a>scratch bitmap</a> does not necessarily represent the size of the actual bitmap
173+
that the user agent will use internally or during rendering. For example, if the visual viewport is
174+
zoomed the user agent may internally use bitmaps which correspond to the number of device pixels in
175+
the coordinate space, so that the resulting rendering is of high quality.
176+
177+
Additionally the user agent may record the sequence of drawing operations which have been applied to
178+
the <a>scratch bitmap</a> such that the user agent can subsequently draw onto a device bitmap at the
179+
correct resolution. This also allows user agents to re-use the same output of the <a>scratch
180+
bitmap</a> repeatably while the visual viewport is being zoomed for example.
181+
182+
When the user agent is to <dfn>create a {{PaintRenderingContext2D}} object</dfn> for a given
183+
|width|, |height| and |overflowOffset| it <em>must</em> run the following steps:
184+
1. Create a new {{PaintRenderingContext2D}}.
185+
2. <a>Set bitmap dimensions</a> for the context's <a>scratch bitmap</a> to |width| and |height|.
186+
3. Set the logical origin of the <a>scratch bitmap</a> to |overflowOffset|.
187+
4. Return the new {{PaintRenderingContext2D}}.
141188

189+
Drawing an image {#drawing-an-image}
190+
====================================
191+
192+
<pre class='idl'>
193+
[Exposed=Worklet]
142194
interface Geometry {
143195
readonly attribute double width;
144196
readonly attribute double height;
145197
};
146198
</pre>
147199

148-
Issue: Create a new interface which uses IDL mixins to share methods with CanvasRenderingContext2d.
149-
150200
If a <<paint()>> function for a fragment is <a>paint-invalid</a> and the fragment is within the visual viewport,
151201
then user agent <em>must</em> <a>draw an image</a> for the current frame.
152202

@@ -177,15 +227,10 @@ When the user agent wants to <dfn>draw an image</dfn> of a <<paint()>> for a <va
177227
Note: User agents may have to compute overflow before entering their paint phase in order to determine which fragments to paint (overflow changes what could be seen on the output device).
178228
User agents may opt into running the steps up to this point, to determine overflow, then continuing later to determine the drawn image for the fragments which need painting.
179229

180-
7. Let <var>renderingContext</var> be a new {{PaintRenderingContext2d}}.
181-
182-
The backing size of the |renderingContext| must be the size of the |fragment| plus the size specified by |overflow|.
183-
184-
The user agent must ensure to <a>reset the rendering context to its default state</a>.
185-
186-
The origin of the |renderingContext| must be offset by the left, top size specified by |overflow|.
187-
188-
Note: (0,0) is the top-left of the |fragment|, (-offsetLeft,-offsetTop) is the top-left of the |overflow|.
230+
7. Let <var>renderingContext</var> be the result of <a>create a {{PaintRenderingContext2D}} object</a> given:
231+
- "overflowOffset" - The logical offset for the <a>scratch bitmap</a> specified by |overflow|.
232+
- "width" - The width of the |fragment| plus the additional width specified by |overflow|.
233+
- "height" - The height of the |fragment| plus the additional height specified by |overflow|.
189234

190235
Note: The |renderingContext| must not be re-used between invocations of paint. Implicitly this means that there is no stored data, or state on the |renderingContext| between invocations.
191236
For example you can't setup a clip on the context, and expect the same clip to be applied next time the paint method is called.

0 commit comments

Comments
 (0)