Bug 56414 - texImage2D gets old contents of canvas
Summary: texImage2D gets old contents of canvas
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGL (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Linux
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-15 14:04 PDT by John Bauman
Modified: 2011-03-16 22:55 PDT (History)
8 users (show)

See Also:


Attachments
Patch (3.08 KB, patch)
2011-03-16 15:23 PDT, John Bauman
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John Bauman 2011-03-15 14:04:29 PDT
Currently we don't seem to be marking the copied image of a canvas as dirty when we're doing accelerated rendering, causing a texImage2D on the canvas to possibly get old data.
Comment 1 John Bauman 2011-03-15 16:13:01 PDT
Looks like we're checking paintsIntoCanvasBuffer to see if we should do paintRenderingResultsToCanvas to update the image. This is true on chromium with accelerated compositing disabled (like in this test), so the paint doesn't happen.

I'm not sure what exactly paintsIntoCanvasBuffer is supposed to mean, but removing the check for it in HTMLCanvasElement::copiedImage seems to work.
Comment 2 Kenneth Russell 2011-03-15 17:11:00 PDT
Do you happen to know whether it's broken when passing a 2D-rendered Canvas to WebGL via texImage2D, when passing a WebGL-rendered Canvas to WebGL via texImage2D, or both?

For the WebGL case, https://bugs.webkit.org/show_bug.cgi?id=56431 will affect the behavior here, though we can fix this bug independently.
Comment 3 John Bauman 2011-03-15 17:16:51 PDT
I haven't tested reading from 2D-rendered Canvas, but I think that may be broken when the canvas is GPU-accelerated. An unaccelerated canvas should work fine.
Comment 4 John Bauman 2011-03-16 15:23:37 PDT
Created attachment 85986 [details]
Patch
Comment 5 James Robinson 2011-03-16 15:30:50 PDT
Comment on attachment 85986 [details]
Patch

This seems correct to me.  Should we have a more direct test for this? fast/canvas/webgl/premultiplyalpha-test.html seems to test a bunch of other stuff as well.
Comment 6 James Robinson 2011-03-16 15:31:23 PDT
It looks like this will never change behavior for the Mac port since paintsIntoCanvasBuffer() always returns false on mac for WebGL content.
Comment 7 John Bauman 2011-03-16 15:37:28 PDT
Right, the test already passes on Macs. The patch might change something on Qt, but hopefully it will change it to do the right thing.
Comment 8 Stephen White 2011-03-16 16:48:09 PDT
Is it possible this fix would break (or slow down) accelerated canvas2D -> canvas2D draws?  (the amazon shelf demo used to be a good test of this, but unfortunately it's not available anymore).

This seems to end up here:

bool GraphicsContext3DInternal::paintsIntoCanvasBuffer() const
{
    // If the gpu compositor is on then skip the readback and software rendering path.
    return !m_webViewImpl->isAcceleratedCompositingActive();
}
Comment 9 John Bauman 2011-03-16 16:54:04 PDT
HTMLCanvasElement::paint still checks paintsIntoCanvasBuffer, so that won't be affected. canvas2D->canvas2D drawImages go down a different path (not using copiedImage, but instead manually doing makeRenderingResultsAvailable if the canvas isn't accelerated), so they shouldn't change.
Comment 10 James Robinson 2011-03-16 17:05:05 PDT
canvas2d->canvas2d on chromium/skia uses this:
http://trac.webkit.org/browser/trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp#L1267

which does the readback if needed and then does this:
http://trac.webkit.org/browser/trunk/Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp#L118

which should still do the right thing
Comment 11 Stephen White 2011-03-16 17:20:45 PDT
(In reply to comment #10)
> canvas2d->canvas2d on chromium/skia uses this:
> http://trac.webkit.org/browser/trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp#L1267
> 
> which does the readback if needed and then does this:
> http://trac.webkit.org/browser/trunk/Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp#L118
> 
> which should still do the right thing

Right, thanks.  This change makes more sense to me now.
Comment 12 WebKit Commit Bot 2011-03-16 20:56:28 PDT
Comment on attachment 85986 [details]
Patch

Clearing flags on attachment: 85986

Committed r81317: <http://trac.webkit.org/changeset/81317>
Comment 13 WebKit Commit Bot 2011-03-16 20:56:34 PDT
All reviewed patches have been landed.  Closing bug.
Comment 14 WebKit Commit Bot 2011-03-16 22:55:13 PDT
The commit-queue encountered the following flaky tests while processing attachment 85986 [details]:

fast/workers/storage/use-same-database-in-page-and-workers.html bug 50995 (author: dumi@chromium.org)
The commit-queue is continuing to process your patch.