<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>23515</bug_id>
          
          <creation_ts>2013-10-14 22:11:07 +0000</creation_ts>
          <short_desc>&lt;canvas&gt;: opaque backing stores</short_desc>
          <delta_ts>2014-09-08 22:53:21 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>HTML</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>other</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ian &apos;Hixie&apos; Hickson">ian</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>ed</cc>
    
    <cc>ian</cc>
    
    <cc>junov</cc>
    
    <cc>mike</cc>
    
    <cc>roc</cc>
    
    <cc>senorblanco</cc>
          
          <qa_contact>contributor</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>94724</commentid>
    <comment_count>0</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-10-14 22:11:07 +0000</bug_when>
    <thetext>http://wiki.whatwg.org/wiki/CanvasOpaque

On Tue, 23 Jul 2013, Stephen White wrote:
&gt; On Tue, Jul 16, 2013 at 6:41 PM, Ian Hickson &lt;ian@hixie.ch&gt; wrote:
&gt; &gt;
&gt; &gt; This thread was gigantic and involved many proposals. I&apos;ve only included
&gt; &gt; the last one below, since it seemed to take into account the most of the
&gt; &gt; feedback mentioned on the thread; I haven&apos;t responded to all the
&gt; &gt; intermediate e-mails which were mainly just a discussion amongst
&gt; &gt; contributors, and not direct feedback on the spec itself.
&gt; &gt;
&gt; &gt; I haven&apos;t yet changed the spec. The main thrust of the feedback below ends
&gt; &gt; with the proposal to use WebGL&apos;s &apos;alpha&apos; feature for the 2D context; is
&gt; &gt; this what implementors want to do?
&gt;
&gt; We&apos;re implementing this in Chromium (currently behind the &quot;experimental
&gt; canvas features&quot; flag).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94760</commentid>
    <comment_count>1</comment_count>
    <who name="Erik Dahlström">ed</who>
    <bug_when>2013-10-15 13:07:50 +0000</bug_when>
    <thetext>moz-opaque: https://bugzilla.mozilla.org/show_bug.cgi?id=430906

Blink intent-to-ship thread: https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/4KMwyiaOxHg/0OOogCofycYJ
implementation: https://code.google.com/p/chromium/issues/detail?id=234297</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94771</commentid>
    <comment_count>2</comment_count>
    <who name="Justin Novosad">junov</who>
    <bug_when>2013-10-15 15:04:23 +0000</bug_when>
    <thetext>Update: the WebGL-style &apos;alpha&apos; feature is now fully exposed in the Blink/Chromium trunk, and on course to ship in Chrome 32.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102247</commentid>
    <comment_count>3</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-03-12 18:07:35 +0000</bug_when>
    <thetext>https://groups.google.com/forum/#!topic/mozilla.dev.platform/5i8H-xKGtEg</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102830</commentid>
    <comment_count>4</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-03-24 16:10:10 +0000</bug_when>
    <thetext>Ok, my plan is to reverse engineer Chrome and Firefox implementations of what is described here: http://wiki.whatwg.org/wiki/CanvasOpaque

I&apos;ll then try to spec the interoperable subset.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105244</commentid>
    <comment_count>5</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-05-06 21:43:23 +0000</bug_when>
    <thetext>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 &apos;alpha:undefined&apos; like &apos;alpha:false&apos;:

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/3009</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105253</commentid>
    <comment_count>6</comment_count>
    <who name="Justin Novosad">junov</who>
    <bug_when>2014-05-06 22:40:59 +0000</bug_when>
    <thetext>(In reply to Ian &apos;Hixie&apos; Hickson from comment #5)

&gt; One difference between Chrome and Firefox is that Chrome blanks the canvas
&gt; when you call getContent(), whereas Firefox waits until the first time you
&gt; 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&amp;revision=171408

&gt; Another is that Chrome treats &apos;alpha:undefined&apos; like &apos;alpha:false&apos;

Isn&apos;t that the right thing to do? ECMAScript spec says conversion of undefined to bool gives false.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105326</commentid>
    <comment_count>7</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-05-07 18:15:30 +0000</bug_when>
    <thetext>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!).


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

It depends. If it&apos;s a dictionary, then it&apos;s wrong, because &apos;undefined&apos; is treated as absent and triggers the default value (presumably, in this case, true) according to WebIDL.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105342</commentid>
    <comment_count>8</comment_count>
    <who name="Justin Novosad">junov</who>
    <bug_when>2014-05-07 20:38:25 +0000</bug_when>
    <thetext>(In reply to Ian &apos;Hixie&apos; Hickson from comment #7)
&gt; It depends. If it&apos;s a dictionary, then it&apos;s wrong, because &apos;undefined&apos; is
&gt; treated as absent and triggers the default value (presumably, in this case,
&gt; true) according to WebIDL.

Oh, thanks. I will fix it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105353</commentid>
    <comment_count>9</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-05-07 21:32:30 +0000</bug_when>
    <thetext>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 &apos;alpha&apos; of type &apos;boolean&apos; defaulting to &apos;true&apos;, and then check if that dictionary had an &apos;alpha&apos; 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?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105356</commentid>
    <comment_count>10</comment_count>
    <who name="Robert O&apos;Callahan (Mozilla)">roc</who>
    <bug_when>2014-05-07 21:45:30 +0000</bug_when>
    <thetext>I agree that the Chrome behavior is correct and the Firefox behavior is a bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>109706</commentid>
    <comment_count>11</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-07-31 20:56:32 +0000</bug_when>
    <thetext>So what is it that this actually requires at the canvas level? (See paragraph 2 of comment 9 above.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>109716</commentid>
    <comment_count>12</comment_count>
    <who name="Robert O&apos;Callahan (Mozilla)">roc</who>
    <bug_when>2014-07-31 22:34:25 +0000</bug_when>
    <thetext>(In reply to Ian &apos;Hixie&apos; Hickson from comment #9)
&gt; Then... yikes, what exactly do I have to change? Is it sufficient to put a
&gt; single requirement somewhere that says to clamp the opacity when painting,
&gt; plus driving the fourth byte to 255 in getImageData() and ignoring every
&gt; fourth byte in putImageData()?

That sounds right to me. There might be some extra things that need to be patched but I can&apos;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&apos;s a bug in the spec, and not just some very subtle intended behavior.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>109718</commentid>
    <comment_count>13</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-07-31 22:45:20 +0000</bug_when>
    <thetext>Thanks.

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

You&apos;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&apos;s no conflict, even if it means interpreting both parts in wildly crazy ways.

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

    </bug>

</bugzilla>