Bug 32188

Summary: texImage2D pixel junk for transparency
Product: WebKit Reporter: Keith Bauer <OneSadCookie>
Component: WebGLAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Major CC: oliver
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Mac   
OS: OS X 10.6   
Attachments:
Description Flags
Patch mjs: review+

Description Keith Bauer 2009-12-05 20:57:36 PST
When using texImage2D with an Image or Canvas as the source of the data, WebKit draws the underlying CGImage to a CGBitmapContext to get access to the pixels.  The context is created with memory from fastMalloc(), and therefore undefined.  When the CGImage being drawn contains transparency, this undefined data shows through, causing pixel junk in the resulting WebGL texture image.

There is no workaround for this; there is no way to affect the pixels of that CGBitmapContext in such a way that the pixel junk is cleared without also making the resulting texture opaque.

The patch is trivial (using calloc, or adding a memset, or CGClearRect, or similar to zero the bitmap context's data before drawing the image in imageToTexture() in WebCore/platform/graphics/mac/GraphicsContext3DMac.cpp.  I'm having trouble building WebKit though so I can't offer a tested patch.
Comment 1 Oliver Hunt 2009-12-06 02:47:31 PST
This problem can be fixed by forcing the blend mode to kCGBlendCopy.  Have  a patch in my tree, but haven't yet worked out how to make a testcase.
Comment 2 Oliver Hunt 2009-12-06 03:30:19 PST
Created attachment 44359 [details]
Patch
Comment 3 Maciej Stachowiak 2009-12-06 03:33:37 PST
Comment on attachment 44359 [details]
Patch

r=me
Comment 4 Oliver Hunt 2009-12-06 03:38:11 PST
Committed r51740