Bug 222101 - HTMLCanvasElement::copiedImage() contains old image with GPU Process on
Summary: HTMLCanvasElement::copiedImage() contains old image with GPU Process on
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Canvas (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Kimmo Kinnunen
URL:
Keywords: InRadar
: 220553 (view as bug list)
Depends on:
Blocks: webglgpup
  Show dependency treegraph
 
Reported: 2021-02-18 05:39 PST by Kimmo Kinnunen
Modified: 2021-03-01 22:46 PST (History)
6 users (show)

See Also:


Attachments
Patch (24.21 KB, patch)
2021-02-22 04:34 PST, Kimmo Kinnunen
no flags Details | Formatted Diff | Diff
Patch (32.30 KB, patch)
2021-02-22 06:44 PST, Kimmo Kinnunen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kimmo Kinnunen 2021-02-18 05:39:07 PST
HTMLCanvasElement::copiedImage() contains old image with GPU Process on

LayoutTests/fast/canvas/webgl/canvas-2d-webgl-texture.html appears to fail because HTMLCanvasElement::copiedImage() returns a new Image that contains old data.

The test is roughly as follows:
  ctx.fillStyle = "rgb(200, 0, 0)";
  ctx.fillRect(0, 0, 256, 256);
  gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d); // Calls HTMLCanvasElement::copiedImage() 

  ctx.fillStyle = "rgb(0, 0, 200)";
  ctx.fillRect(0, 0, 256, 256);
  gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d); // Calls HTMLCanvasElement::copiedImage()

It appears that while the second copiedImage should contain the blue contents, it still contains the red contents.

The copy is done with:

RefPtr<NativeImage> ImageBufferCGBitmapBackend::copyNativeImage(BackingStoreCopy copyBehavior) const
{
    switch (copyBehavior) {
    case CopyBackingStore:
        return NativeImage::create(adoptCF(CGBitmapContextCreateImage(context().platformContext())));
Comment 1 Kimmo Kinnunen 2021-02-18 05:41:32 PST
Said, do you have idea is the ConcreteImageBuffer::copyImage supposed to work?

Why RemoteImageBufferProxy::getImageData() has to ask the data from GPU Process
while RemoteImageBufferProxy::copyImage() can access the shared memory region in Web Process?
Comment 2 Kimmo Kinnunen 2021-02-22 04:34:10 PST
Created attachment 421180 [details]
Patch
Comment 3 Kimmo Kinnunen 2021-02-22 06:44:23 PST
Created attachment 421185 [details]
Patch
Comment 4 Simon Fraser (smfr) 2021-02-22 11:27:03 PST
Comment on attachment 421185 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=421185&action=review

> Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp:350
> +void RemoteRenderingBackend::getShareableBitmapForImageBuffer(WebCore::RenderingResourceIdentifier identifier, WebCore::PreserveResolution preserveResolution, CompletionHandler<void(ShareableBitmap::Handle&&)>&& completionHandler)

Does this need to use a CompletionHandler, since it's synchronous?
Comment 5 Kimmo Kinnunen 2021-02-23 00:36:32 PST
(In reply to Simon Fraser (smfr) from comment #4)
> Comment on attachment 421185 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=421185&action=review
> 
> > Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp:350
> > +void RemoteRenderingBackend::getShareableBitmapForImageBuffer(WebCore::RenderingResourceIdentifier identifier, WebCore::PreserveResolution preserveResolution, CompletionHandler<void(ShareableBitmap::Handle&&)>&& completionHandler)
> 
> Does this need to use a CompletionHandler, since it's synchronous?

I think it needs the CompletionHandler since it is processing a message that has a result. E.g. both async and sync messages post replies with CompletionHandler.
 
Yeah, all get*ForImageBuffer are synchronous, including this getShareableBitmapForImageBuffer().
Comment 6 EWS 2021-02-23 00:58:37 PST
Committed r273301: <https://commits.webkit.org/r273301>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 421185 [details].
Comment 7 Radar WebKit Bug Importer 2021-02-23 00:59:15 PST
<rdar://problem/74633005>
Comment 8 Said Abou-Hallawa 2021-03-01 22:46:03 PST
*** Bug 220553 has been marked as a duplicate of this bug. ***