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

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>217377</bug_id>
          
          <creation_ts>2020-10-06 04:47:43 -0700</creation_ts>
          <short_desc>Implement ANGLE version of WebGL layer snapshot copyImageSnapshotWithColorSpace</short_desc>
          <delta_ts>2021-09-01 22:47:31 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebGL</component>
          <version>WebKit Local Build</version>
          <rep_platform>Mac</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>198948</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Kimmo Kinnunen">kkinnunen</reporter>
          <assigned_to name="Kimmo Kinnunen">kkinnunen</assigned_to>
          <cc>dino</cc>
    
    <cc>jdarpinian</cc>
    
    <cc>kbr</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>thorton</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1695096</commentid>
    <comment_count>0</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2020-10-06 04:47:43 -0700</bug_when>
    <thetext>To understand: Should the function snapshot the back buffer or the front buffer?


Old CGL implementation (not sure if this is correct implementation)


#if USE(OPENGL)
    CGLContextObj cglContext = static_cast&lt;CGLContextObj&gt;(_context-&gt;platformGraphicsContextGL());
    CGLSetCurrentContext(cglContext);

    RetainPtr&lt;CGColorSpaceRef&gt; imageColorSpace = colorSpace;
    if (!imageColorSpace)
        imageColorSpace = WebCore::sRGBColorSpaceRef();

    CGRect layerBounds = CGRectIntegral([self bounds]);

    size_t width = layerBounds.size.width * _devicePixelRatio;
    size_t height = layerBounds.size.height * _devicePixelRatio;

    size_t rowBytes = (width * 4 + 15) &amp; ~15;
    size_t dataSize = rowBytes * height;
    void* data = fastMalloc(dataSize);
    if (!data)
        return nullptr;

    glPixelStorei(GL_PACK_ROW_LENGTH, rowBytes / 4);
    glReadPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);

    WebCore::verifyImageBufferIsBigEnough((uint8_t*)data, dataSize);
    CGDataProviderRef provider = CGDataProviderCreateWithData(0, data, dataSize, freeData);
    CGImageRef image = CGImageCreate(width, height, 8, 32, rowBytes, imageColorSpace.get(),
        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, provider, 0, true, kCGRenderingIntentDefault);
    CGDataProviderRelease(provider);
    return image;
#else</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1697224</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2020-10-13 04:48:16 -0700</bug_when>
    <thetext>&lt;rdar://problem/70248151&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1701612</commentid>
    <comment_count>2</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2020-10-26 14:05:09 -0700</bug_when>
    <thetext>Which code calls this method? The old implementation used the front buffer and perhaps that&apos;s the correct semantic, but it&apos;s not clear because there doesn&apos;t seem to be any documentation for it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1701778</commentid>
    <comment_count>3</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2020-10-26 23:33:02 -0700</bug_when>
    <thetext>As per my understanding, the old implementation used the back buffer, not the front buffer. This is on the grounds that there&apos;s no bind of any kind, so it expects to read what is bound. The front buffer is not bound ever. In fact, the old code did not have any concept of front buffer conceptually &quot;inside OpenGL&quot;, so it can not be read by that read pixels. Front buffer it a CA layer holding a IOSurface. The only way it can be reading front buffer if it was, back in the day before prepareForDisplay, called during CA commit but before buffer swap. E.g. it would read the back buffer just before it became front buffer. However, even in this case it will either have read wrong frame buffers if client had bound something or alternatively left gl state wrong (by a bind that is not seen in the code). 

I couldn&apos;t find the call site, so I&apos;d assume it is either dead code or CALayer Obj-C vfunc override which I&apos;m not that familiar with at the moment.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1702460</commentid>
    <comment_count>4</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2020-10-28 12:56:46 -0700</bug_when>
    <thetext>Sorry - I must have been tired - you&apos;re right, and I meant that it looked like it was snapshotting the back buffer.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1702461</commentid>
    <comment_count>5</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2020-10-28 12:57:21 -0700</bug_when>
    <thetext>If it looks like this function&apos;s unused then perhaps the best thing to do is to remove it along with the old implementations.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1788856</commentid>
    <comment_count>6</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2021-08-31 03:44:16 -0700</bug_when>
    <thetext>Function introduced in trunk@50067
    2009-10-26  Simon Fraser  &lt;simon.fraser@apple.com&gt;
    
            Reviewed by Sam Weinig.
    
            &lt;rdar://problem/6988966&gt; Hardware layers do not show up in page snapshots
    
            * WebView/WebHTMLViewPrivate.h:
            * WebView/WebHTMLView.mm:
            (-[WebHTMLView _compositingLayersHostingView]):
            Add a private method that returns the NSView used to host compositing layers.
    
            * platform/graphics/mac/Canvas3DLayer.h:
            * platform/graphics/mac/Canvas3DLayer.mm:
            (-[Canvas3DLayer copyImageSnapshotWithColorSpace:]):
            Add a method that gets called when snapshotting Canvas3DLayers for page snapshots,
            that allows the layer to return a CGImageRef of its contents. 

Unclear if it&apos;s still used.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1788871</commentid>
    <comment_count>7</comment_count>
      <attachid>436876</attachid>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2021-08-31 05:01:29 -0700</bug_when>
    <thetext>Created attachment 436876
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1789602</commentid>
    <comment_count>8</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2021-09-01 22:47:29 -0700</bug_when>
    <thetext>Committed r281909 (241221@main): &lt;https://commits.webkit.org/241221@main&gt;

All reviewed patches have been landed. Closing bug and clearing flags on attachment 436876.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>436876</attachid>
            <date>2021-08-31 05:01:29 -0700</date>
            <delta_ts>2021-09-01 22:47:30 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-217377-20210831150127.patch</filename>
            <type>text/plain</type>
            <size>2290</size>
            <attacher name="Kimmo Kinnunen">kkinnunen</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMjgxNzUzCmRpZmYgLS1naXQgYS9Tb3VyY2UvV2ViQ29yZS9D
aGFuZ2VMb2cgYi9Tb3VyY2UvV2ViQ29yZS9DaGFuZ2VMb2cKaW5kZXggMjM5MDU1ZGE1ZjU1Yzhh
Y2M0MTVkMDVkNzdmNjE5Y2E1MWNkNTJiNi4uZWY2Y2NjMjdmYTFlZjY2OWQxYTFiZTllYzg1NTc2
MDdkMTgzNTE0NiAxMDA2NDQKLS0tIGEvU291cmNlL1dlYkNvcmUvQ2hhbmdlTG9nCisrKyBiL1Nv
dXJjZS9XZWJDb3JlL0NoYW5nZUxvZwpAQCAtMSwzICsxLDE2IEBACisyMDIxLTA4LTMxICBLaW1t
byBLaW5udW5lbiAgPGtraW5udW5lbkBhcHBsZS5jb20+Cis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