<?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>27513</bug_id>
          
          <creation_ts>2014-12-04 10:44:52 +0000</creation_ts>
          <short_desc>Clarify the behavior of Window.createImageBitmap(HTMLCanvasElement) for WebGL</short_desc>
          <delta_ts>2014-12-11 07:30:34 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>HTML WG</product>
          <component>HTML5 spec</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Dongseong Hwang">dongseong.hwang</reporter>
          <assigned_to name="This bug has no owner yet - up for the taking">dave.null</assigned_to>
          <cc>junov</cc>
    
    <cc>kbr</cc>
    
    <cc>mike</cc>
    
    <cc>public-html-admin</cc>
    
    <cc>public-html-wg-issue-tracking</cc>
          
          <qa_contact name="HTML WG Bugzilla archive list">public-html-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>115914</commentid>
    <comment_count>0</comment_count>
    <who name="Dongseong Hwang">dongseong.hwang</who>
    <bug_when>2014-12-04 10:44:52 +0000</bug_when>
    <thetext>http://www.w3.org/html/wg/drafts/html/master/webappapis.html#cropped-to-the-source-rectangle

&quot;Let the ImageBitmap object&apos;s bitmap data be a copy of the canvas element&apos;s bitmap data, cropped to the source rectangle.
&quot;

Above description is ambiguous for WebGL. WebGL has two kind of buffers; drawing buffer (i.e. back buffer) and presented buffer (i.e. front buffer)
The spec should specifies which buffer should be copied to ImageBitmap.

In my opinion, it should be presented buffer, because
1. the spec intends to copy the screenshot of webgl currently displayed.
2. drawing buffer is discarded in the next frame, so it&apos;s difficult to use this API to get RIGHT image.

WDYT?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115963</commentid>
    <comment_count>1</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2014-12-05 03:00:51 +0000</bug_when>
    <thetext>Thanks for pointing this out. I think this behavior probably needs to be defined in the WebGL spec, because otherwise the canvas spec will have to be modified to incorporate WebGL-specific concepts.

I think the behavior should be:

 - If any rendering commands have been issued to the WebGL context since the last time its results were presented to the page compositor, the ImageBitmap should read the context&apos;s current contents (the &quot;back buffer&quot;).

 - Otherwise, the ImageBitmap should read the canvas&apos;s current contents (the &quot;front buffer&quot;).

This will have less surprising behavior to developers that do the following:

 1. Draw some WebGL to a canvas
 2. Turn that canvas into an ImageBitmap
 3. When the ImageBitmap is resolved, draw it to a different canvas&apos;s 2D
context

The intent here would be to have the ImageBitmap contain the rendering results from (1), but if the ImageBitmap always reads the canvas&apos;s &quot;front buffer&quot; then it&apos;ll contain whatever the canvas was displaying before step (1).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115974</commentid>
    <comment_count>2</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2014-12-05 20:24:48 +0000</bug_when>
    <thetext>Sorry, I didn&apos;t think this through clearly. Per Dongseong&apos;s comments on https://codereview.chromium.org/776293002/ , the &apos;preserveDrawingBuffer=false&apos; context creation attribute already defines this behavior when drawing a WebGL-rendered canvas to a 2D canvas context via drawImage, and ImageBitmap shouldn&apos;t behave any differently.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116003</commentid>
    <comment_count>3</comment_count>
    <who name="Dongseong Hwang">dongseong.hwang</who>
    <bug_when>2014-12-08 07:47:20 +0000</bug_when>
    <thetext>@kbr, thank you for explaining.

WebGL spec defines how readPixels, toDataURL, texImage2D and drawImage work. We made consensus that ImageBitmap should behave like them. It means ImageBitmap should copy the drawing buffer (i.e. back buffer). It might be good for WebGL spec to mention ImageBitmap in below sentence.

https://www.khronos.org/registry/webgl/specs/latest/1.0/
&quot;&quot;&quot;
This default behavior can be changed by setting the preserveDrawingBuffer attribute of the WebGLContextAttributes object. If this flag is true, the contents of the drawing buffer shall be preserved until the author either clears or overwrites them. If this flag is false, attempting to perform operations using this context as a source image after the rendering function has returned can lead to undefined behavior. This includes readPixels or toDataURL calls, or using this context as the source image of another context&apos;s texImage2D or drawImage call.
&quot;&quot;&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116136</commentid>
    <comment_count>4</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2014-12-11 07:30:34 +0000</bug_when>
    <thetext>Thanks for the suggestion. The WebGL spec has been revised in https://github.com/KhronosGroup/WebGL/pull/805 . Closing this bug.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>