This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 23515 - <canvas>: opaque backing stores
Summary: <canvas>: opaque backing stores
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other other
: P3 enhancement
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-14 22:11 UTC by Ian 'Hixie' Hickson
Modified: 2014-09-08 22:53 UTC (History)
6 users (show)

See Also:


Attachments

Description Ian 'Hixie' Hickson 2013-10-14 22:11:07 UTC
http://wiki.whatwg.org/wiki/CanvasOpaque

On Tue, 23 Jul 2013, Stephen White wrote:
> On Tue, Jul 16, 2013 at 6:41 PM, Ian Hickson <ian@hixie.ch> wrote:
> >
> > This thread was gigantic and involved many proposals. I've only included
> > the last one below, since it seemed to take into account the most of the
> > feedback mentioned on the thread; I haven't responded to all the
> > intermediate e-mails which were mainly just a discussion amongst
> > contributors, and not direct feedback on the spec itself.
> >
> > I haven't yet changed the spec. The main thrust of the feedback below ends
> > with the proposal to use WebGL's 'alpha' feature for the 2D context; is
> > this what implementors want to do?
>
> We're implementing this in Chromium (currently behind the "experimental
> canvas features" flag).
Comment 2 Justin Novosad 2013-10-15 15:04:23 UTC
Update: the WebGL-style 'alpha' feature is now fully exposed in the Blink/Chromium trunk, and on course to ship in Chrome 32.
Comment 4 Ian 'Hixie' Hickson 2014-03-24 16:10:10 UTC
Ok, my plan is to reverse engineer Chrome and Firefox implementations of what is described here: http://wiki.whatwg.org/wiki/CanvasOpaque

I'll then try to spec the interoperable subset.
Comment 5 Ian 'Hixie' Hickson 2014-05-06 21:43:23 UTC
http://software.hixie.ch/utilities/js/live-dom-viewer/saved/3006
http://software.hixie.ch/utilities/js/live-dom-viewer/saved/3007

One difference between Chrome and Firefox is that Chrome blanks the canvas when you call getContent(), whereas Firefox waits until the first time you draw to the canvas, or call getImageData():

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/3008

Another is that Chrome treats 'alpha:undefined' like 'alpha:false':

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/3009
Comment 6 Justin Novosad 2014-05-06 22:40:59 UTC
(In reply to Ian 'Hixie' Hickson from comment #5)

> One difference between Chrome and Firefox is that Chrome blanks the canvas
> when you call getContent(), whereas Firefox waits until the first time you
> draw to the canvas, or call getImageData():

Chrome used to behave as you describe for Firefox, but we considered it to be a bug. Firefox should probably make the same fix we made.

FWIW: Chrome, just like Firefox, defers the allocation of the canvas backing store until something is actually drawn, and if the canvas needs to be painted before then, and it has alpha:false, the then we just draw an opaque black rect (backing store creation continues to be deferred). See:
http://src.chromium.org/viewvc/blink?view=revision&revision=171408

> Another is that Chrome treats 'alpha:undefined' like 'alpha:false'

Isn't that the right thing to do? ECMAScript spec says conversion of undefined to bool gives false.
Comment 7 Ian 'Hixie' Hickson 2014-05-07 18:15:30 UTC
roc, any opinion on the effect of getContext(... alpha:false) before script does any painting? I tend to agree with Justin that it should immediately make the element opaque, especially given that getImageData() returns opaque data (and causes the canvas to change colour!).


> > Another is that Chrome treats 'alpha:undefined' like 'alpha:false'
> 
> Isn't that the right thing to do? ECMAScript spec says conversion of
> undefined to bool gives false.

It depends. If it's a dictionary, then it's wrong, because 'undefined' is treated as absent and triggers the default value (presumably, in this case, true) according to WebIDL.
Comment 8 Justin Novosad 2014-05-07 20:38:25 UTC
(In reply to Ian 'Hixie' Hickson from comment #7)
> It depends. If it's a dictionary, then it's wrong, because 'undefined' is
> treated as absent and triggers the default value (presumably, in this case,
> true) according to WebIDL.

Oh, thanks. I will fix it.
Comment 9 Ian 'Hixie' Hickson 2014-05-07 21:32:30 UTC
So, assuming roc is ok with the Chrome behaviour described above, I guess the way this would work is that the 2D context creation algorithm would see if there was a first argument, and if there was, convert it to a dictionary of a type that had one member 'alpha' of type 'boolean' defaulting to 'true', and then check if that dictionary had an 'alpha' member with value false, and if so, flag the context as being opaque.

Then... yikes, what exactly do I have to change? Is it sufficient to put a single requirement somewhere that says to clamp the opacity when painting, plus driving the fourth byte to 255 in getImageData() and ignoring every fourth byte in putImageData()? Or is it more subtle than that? Is it just equivalent to the canvas having a forced black bacground?
Comment 10 Robert O'Callahan (Mozilla) 2014-05-07 21:45:30 UTC
I agree that the Chrome behavior is correct and the Firefox behavior is a bug.
Comment 11 Ian 'Hixie' Hickson 2014-07-31 20:56:32 UTC
So what is it that this actually requires at the canvas level? (See paragraph 2 of comment 9 above.)
Comment 12 Robert O'Callahan (Mozilla) 2014-07-31 22:34:25 UTC
(In reply to Ian 'Hixie' Hickson from comment #9)
> Then... yikes, what exactly do I have to change? Is it sufficient to put a
> single requirement somewhere that says to clamp the opacity when painting,
> plus driving the fourth byte to 255 in getImageData() and ignoring every
> fourth byte in putImageData()?

That sounds right to me. There might be some extra things that need to be patched but I can't think of any right now.

BTW this is an example of a situation where stating some redundant invariants in the spec would be helpful. If the spec says (normatively) that the alpha value of every pixel in an opaque canvas is 255 (or 1.0), then if someone discovers another part of the spec which implies an alpha value in an opaque canvas can be something else, we know it's a bug in the spec, and not just some very subtle intended behavior.
Comment 13 Ian 'Hixie' Hickson 2014-07-31 22:45:20 UTC
Thanks.

(In reply to Robert O'Callahan (Mozilla) from comment #12)
> BTW this is an example of a situation where stating some redundant
> invariants in the spec would be helpful. If the spec says (normatively) that
> the alpha value of every pixel in an opaque canvas is 255 (or 1.0), then if
> someone discovers another part of the spec which implies an alpha value in
> an opaque canvas can be something else, we know it's a bug in the spec, and
> not just some very subtle intended behavior.

You'd think, but in practice (a) it turns out the invariants are wrong as often as the prose contradicting them, and (b) when there _is_ a conflict, implementors tend to try really hard to find ways to interpret the spec so that there's no conflict, even if it means interpreting both parts in wildly crazy ways.

But yeah. There's some asserts here or there (sometimes in <!--comments-->, sometimes in non-normative notes, sometimes just in the way that things are phrased, especially in the case of "otherwise" clauses, e.g. "if A, then X, otherwise not-A, Y").
Comment 14 Ian 'Hixie' Hickson 2014-09-08 22:51:31 UTC
Let me know if this is a bad way to spec it. Thanks.
Comment 15 contributor 2014-09-08 22:53:21 UTC
Checked in as WHATWG revision r8755.
Check-in comment: Define getContext('2d', {alpha:false}).
http://html5.org/tools/web-apps-tracker?from=8754&to=8755