Skip to content

[CSS Paint API] Pass snapped concrete size to paint function #518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 5, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions css-paint-api/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,9 @@ Note: The user agent can optionally defer drawing images which are <a>paint-inva
</div>

The <a>draw a paint image</a> function is invoked by the user agent during the <a>object size
negotiation</a> algorithm which is responsible for rendering an <<image>>, with |concreteObjectSize|
set to the <a>concrete object size</a> of the <a>box</a>.
negotiation</a> algorithm which is responsible for rendering an <<image>>, with |snappedConcreteObjectSize|
set to the rounded <a>concrete object size</a> of the <a>box</a>, divided by the
Copy link
Contributor

@flackr flackr Nov 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this phrasing captures pixel snapping correctly. Also, AFAICT, concrete object size is in CSS pixels. Rounding the concrete object size would suggests that

  • this only affects objects whose size is non-integral - this is not true as it affects integral sizes when they are rastered into a non-integral transformed space (i.e. non-integer devicePixelRatio).
  • we always snap an object of a particular size in the same direction, but it actually depends on the object's location.
  • all browsers snap the same way. This seems to be the case but should probably not be required.

Instead, I think we should specify this in a way that allows the browser to use its own subpixel snapping determination.

{{PaintWorkletGlobalScope/devicePixelRatio}}.

For the purposes of the <a>object size negotiation</a> algorithm, the paint image has no
<a>intrinsic dimensions</a>.
Expand All @@ -463,15 +464,15 @@ Note: In a future version of the spec, the author could have the ability to spec
dimensions</a> based on computed style and size changes.

The {{PaintSize}} object represents the size of the image that the author should draw. This is
the <a>concrete object size</a> given by the user agent.
the |snappedConcreteObjectSize| given by the user agent.

Note: See [[css-images-3#object-sizing-examples]] for examples on how the <a>concrete object
size</a> is calculated.

The <a>draw a paint image</a> function may be speculatively invoked by the user agent at any point,
with any |concreteObjectSize|. The resulting image is not displayed.
with any |snappedConcreteObjectSize|. The resulting image is not displayed.

Note: User agents may use any heuristic to speculate a possible future value for |concretObjectSize|,
Note: User agents may use any heuristic to speculate a possible future value for |snappedConcretObjectSize|,
for example speculating that the size remains unchanged.

Note: Although the image is not displayed, it may still be cached, and subsequent invocations of
Expand All @@ -488,12 +489,12 @@ interface PaintSize {
<div algorithm>
When the user agent wants to <dfn>draw a paint image</dfn> of a <<paint()>> function for a |box|
into its appropriate stacking level (as defined by the property the CSS property its associated
with), given |concreteObjectSize| it <em>must</em> run the following steps:
with), given |snappedConcreteObjectSize| it <em>must</em> run the following steps:
1. Let |paintFunction| be the <<paint()>> function on the |box| which the user agent wants to
draw.

2. If the <a>paint valid flag</a> for the |paintFunction| is <a>paint-valid</a>, and the
previous invocation had the same |concreteObjectSize|, the user agent <em>may</em> use the
previous invocation had the same |snappedConcreteObjectSize|, the user agent <em>may</em> use the
drawn image from the previous invocation. If so it <em>may</em> abort all these steps and
use the previously drawn image.

Expand Down Expand Up @@ -572,7 +573,7 @@ with), given |concreteObjectSize| it <em>must</em> run the following steps:
The user agent <em>may</em> also <a>create a WorkletGlobalScope</a> at this time, given the
paint {{Worklet}}.

13. Run <a>invoke a paint callback</a> given |name|, |inputArguments|, |concreteObjectSize|,
13. Run <a>invoke a paint callback</a> given |name|, |inputArguments|, |snappedConcreteObjectSize|,
|workletGlobalScope| optionally <a>in parallel</a>.

Note: If the user agent runs <a>invoke a paint callback</a> on a thread <a>in parallel</a>,
Expand All @@ -581,7 +582,7 @@ with), given |concreteObjectSize| it <em>must</em> run the following steps:

<div algorithm>
When the user agent wants to <dfn>invoke a paint callback</dfn> given |name|, |inputArguments|,
|concreteObjectSize|, and |workletGlobalScope|, it <em>must</em> run the following steps:
|snappedConcreteObjectSize|, and |workletGlobalScope|, it <em>must</em> run the following steps:

1. Let |paintDefinitionMap| be |workletGlobalScope|'s <a>paint definitions</a> map.

Expand Down Expand Up @@ -630,7 +631,7 @@ When the user agent wants to <dfn>invoke a paint callback</dfn> given |name|, |i
<a>computed value</a>'s for properties listed in |inputProperties|.

8. Let |renderingContext| be the result of <a>create a PaintRenderingContext2D object</a> given:
- "width" - The width given by |concreteObjectSize|.
- "width" - The width given by |concreteObjectSize|.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new space?

- "height" - The height given by |concreteObjectSize|.
- "paintRenderingContext2DSettings" - The
<a for="paint definition">PaintRenderingContext2DSettings object</a> given by |definition|.
Expand All @@ -646,7 +647,7 @@ When the user agent wants to <dfn>invoke a paint callback</dfn> given |name|, |i
images.

9. Let |paintSize| be a new {{PaintSize}} initialized to the width and height defined by
|concreteObjectSize|.
|snappedConcreteObjectSize|.

10. At this stage the user agent may re-use an image from a previous invocation if |paintSize|,
|styleMap|, |inputArguments| are equivalent to that previous invocation. If so let the image
Expand Down