Diff
Modified: trunk/LayoutTests/ChangeLog (157646 => 157647)
--- trunk/LayoutTests/ChangeLog 2013-10-18 20:28:06 UTC (rev 157646)
+++ trunk/LayoutTests/ChangeLog 2013-10-18 20:53:06 UTC (rev 157647)
@@ -1,3 +1,19 @@
+2013-10-18 Dean Jackson <d...@apple.com>
+
+ Unable to upload <img src="" as WebGL texture
+ https://bugs.webkit.org/show_bug.cgi?id=123035
+
+ Reviewed by Tim Horton.
+
+ Test that creates an HTMLImageElement, sets its source
+ to an SVG file, and then uploads as a WebGLTexture. Based
+ on the existing WebGL conformance tests.
+
+ * fast/canvas/webgl/resources/red-green.svg: Added.
+ * fast/canvas/webgl/resources/tex-image-and-sub-image-2d-with-svg-image.js: Added.
+ * fast/canvas/webgl/tex-image-and-sub-image-2d-with-svg-image-expected.txt: Added.
+ * fast/canvas/webgl/tex-image-and-sub-image-2d-with-svg-image.html: Added.
+
2013-10-18 Nadav Rotem <nro...@apple.com>
Fix a FlushLiveness problem.
Added: trunk/LayoutTests/fast/canvas/webgl/resources/red-green.svg (0 => 157647)
--- trunk/LayoutTests/fast/canvas/webgl/resources/red-green.svg (rev 0)
+++ trunk/LayoutTests/fast/canvas/webgl/resources/red-green.svg 2013-10-18 20:53:06 UTC (rev 157647)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
+ <rect fill="#ff0000" x="0" y="0" width="100" height="50"/>
+ <rect fill="#00ff00" x="0" y="50" width="100" height="50"/>
+</svg>
Property changes on: trunk/LayoutTests/fast/canvas/webgl/resources/red-green.svg
___________________________________________________________________
Added: svn:mime-type
Added: svn:keywords
Added: svn:eol-style
Added: trunk/LayoutTests/fast/canvas/webgl/resources/tex-image-and-sub-image-2d-with-svg-image.js (0 => 157647)
--- trunk/LayoutTests/fast/canvas/webgl/resources/tex-image-and-sub-image-2d-with-svg-image.js (rev 0)
+++ trunk/LayoutTests/fast/canvas/webgl/resources/tex-image-and-sub-image-2d-with-svg-image.js 2013-10-18 20:53:06 UTC (rev 157647)
@@ -0,0 +1,91 @@
+function generateTest(pixelFormat, pixelType, pathToTestRoot, prologue) {
+ var wtu = WebGLTestUtils;
+ var gl = null;
+ var textureLoc = null;
+ var successfullyParsed = false;
+ var imgCanvas;
+ var red = [255, 0, 0];
+ var green = [0, 255, 0];
+
+ var init = function()
+ {
+ if (window.initNonKhronosFramework) {
+ window.initNonKhronosFramework(true);
+ }
+
+ description('Verify texImage2D and texSubImage2D code paths taking SVG image elements');
+
+ gl = wtu.create3DContext("example");
+
+ if (!prologue(gl)) {
+ finishTest();
+ return;
+ }
+
+ var program = wtu.setupTexturedQuad(gl);
+
+ gl.clearColor(0,0,0,1);
+ gl.clearDepth(1);
+
+ textureLoc = gl.getUniformLocation(program, "tex");
+
+ var image = new Image();
+ image.width = 10;
+ image.height = 10;
+ image._onload_ = function () {
+ runTest(image);
+ }
+ image.src = "" + "/resources/red-green.svg";
+ }
+
+ function runOneIteration(image, useTexSubImage2D, flipY, topColor, bottomColor)
+ {
+ debug('Testing ' + (useTexSubImage2D ? 'texSubImage2D' : 'texImage2D') +
+ ' with flipY=' + flipY);
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+ var texture = gl.createTexture();
+ // Bind the texture to texture unit 0.
+ gl.bindTexture(gl.TEXTURE_2D, texture);
+ // Set up texture parameters.
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+ // Set up pixel store parameters.
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
+ gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
+ // Upload the image into the texture.
+ if (useTexSubImage2D) {
+ // Initialize the texture to black first.
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat], image.width, image.height, 0,
+ gl[pixelFormat], gl[pixelType], null);
+ gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl[pixelFormat], gl[pixelType], image);
+ } else
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat], gl[pixelFormat], gl[pixelType], image);
+
+ // Point the uniform sampler to texture unit 0.
+ gl.uniform1i(textureLoc, 0);
+ // Draw the triangles.
+ wtu.drawQuad(gl, [0, 255, 0, 255]);
+ // Check a few pixels near the top and bottom and make sure they have
+ // the right color.
+ debug("Checking lower left corner");
+ wtu.checkCanvasRect(gl, 4, 4, 2, 2, bottomColor,
+ "shouldBe " + bottomColor);
+ debug("Checking upper left corner");
+ wtu.checkCanvasRect(gl, 4, gl.canvas.height - 8, 2, 2, topColor,
+ "shouldBe " + topColor);
+ }
+
+ function runTest(image)
+ {
+ runOneIteration(image, false, true, red, green);
+ runOneIteration(image, false, false, green, red);
+ runOneIteration(image, true, true, red, green);
+ runOneIteration(image, true, false, green, red);
+ finishTest();
+ }
+
+ return init;
+}
Property changes on: trunk/LayoutTests/fast/canvas/webgl/resources/tex-image-and-sub-image-2d-with-svg-image.js
___________________________________________________________________
Added: svn:mime-type
Added: svn:keywords
Added: svn:eol-style
Added: trunk/LayoutTests/fast/canvas/webgl/tex-image-and-sub-image-2d-with-svg-image-expected.txt (0 => 157647)
--- trunk/LayoutTests/fast/canvas/webgl/tex-image-and-sub-image-2d-with-svg-image-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/canvas/webgl/tex-image-and-sub-image-2d-with-svg-image-expected.txt 2013-10-18 20:53:06 UTC (rev 157647)
@@ -0,0 +1,28 @@
+Verify texImage2D and texSubImage2D code paths taking SVG image elements
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Testing texImage2D with flipY=true
+Checking lower left corner
+PASS shouldBe 0,255,0
+Checking upper left corner
+PASS shouldBe 255,0,0
+Testing texImage2D with flipY=false
+Checking lower left corner
+PASS shouldBe 255,0,0
+Checking upper left corner
+PASS shouldBe 0,255,0
+Testing texSubImage2D with flipY=true
+Checking lower left corner
+PASS shouldBe 0,255,0
+Checking upper left corner
+PASS shouldBe 255,0,0
+Testing texSubImage2D with flipY=false
+Checking lower left corner
+PASS shouldBe 255,0,0
+Checking upper left corner
+PASS shouldBe 0,255,0
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Property changes on: trunk/LayoutTests/fast/canvas/webgl/tex-image-and-sub-image-2d-with-svg-image-expected.txt
___________________________________________________________________
Added: svn:mime-type
Added: svn:keywords
Added: svn:eol-style
Added: trunk/LayoutTests/fast/canvas/webgl/tex-image-and-sub-image-2d-with-svg-image.html (0 => 157647)
--- trunk/LayoutTests/fast/canvas/webgl/tex-image-and-sub-image-2d-with-svg-image.html (rev 0)
+++ trunk/LayoutTests/fast/canvas/webgl/tex-image-and-sub-image-2d-with-svg-image.html 2013-10-18 20:53:06 UTC (rev 157647)
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+<script>
+function testPrologue(gl) {
+ return true;
+}
+</script>
+</head>
+<body _onload_='generateTest("RGBA", "UNSIGNED_BYTE", ".", testPrologue)()'>
+<canvas id="example" width="32" height="32"></canvas>
+<div id="description"></div>
+<div id="console"></div>
+</body>
+</html>
Property changes on: trunk/LayoutTests/fast/canvas/webgl/tex-image-and-sub-image-2d-with-svg-image.html
___________________________________________________________________
Added: svn:mime-type
Added: svn:keywords
Added: svn:eol-style
Modified: trunk/Source/WebCore/ChangeLog (157646 => 157647)
--- trunk/Source/WebCore/ChangeLog 2013-10-18 20:28:06 UTC (rev 157646)
+++ trunk/Source/WebCore/ChangeLog 2013-10-18 20:53:06 UTC (rev 157647)
@@ -1,3 +1,30 @@
+2013-10-18 Dean Jackson <d...@apple.com>
+
+ Unable to upload <img src="" as WebGL texture
+ https://bugs.webkit.org/show_bug.cgi?id=123035
+
+ Reviewed by Tim Horton.
+
+ If the HTMLImageElement passed to texture2D is an SVG
+ image, paint it first into a bitmap buffer and upload that.
+ Note that the SVG image still needs to have an intrinsic
+ or explicit size - see how the test case must set width and
+ height.
+
+ I also renamed the cache of ImageBuffers since it is
+ no longer only being used for video frames.
+
+ Test: fast/canvas/webgl/tex-image-and-sub-image-2d-with-svg-image.html
+
+ * html/canvas/WebGLRenderingContext.cpp:
+ (WebCore::WebGLRenderingContext::WebGLRenderingContext): Rename m_videoCache to m_generatedImageCache.
+ (WebCore::WebGLRenderingContext::drawImageIntoBuffer): New method that creates an ImageBuffer
+ of the appropriate size and renders into that.
+ (WebCore::WebGLRenderingContext::texImage2D): If we see an SVG image, render it first.
+ (WebCore::WebGLRenderingContext::videoFrameToImage): Renamed m_generatedImageCache.
+ (WebCore::WebGLRenderingContext::texSubImage2D): If we see an SVG image, render it first.
+ * html/canvas/WebGLRenderingContext.h: Renaming.
+
2013-10-18 Brady Eidson <beid...@apple.com>
Move IDBTransactionBackend operations to the IDBTransactionBackend itself..
Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp (157646 => 157647)
--- trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp 2013-10-18 20:28:06 UTC (rev 157646)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp 2013-10-18 20:53:06 UTC (rev 157647)
@@ -455,7 +455,7 @@
, m_dispatchContextLostEventTimer(this, &WebGLRenderingContext::dispatchContextLostEvent)
, m_restoreAllowed(false)
, m_restoreTimer(this, &WebGLRenderingContext::maybeRestoreContext)
- , m_videoCache(4)
+ , m_generatedImageCache(4)
, m_contextLost(false)
, m_contextLostMode(SyntheticLostContext)
, m_attributes(attributes)
@@ -3815,17 +3815,37 @@
m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlignment);
}
+PassRefPtr<Image> WebGLRenderingContext::drawImageIntoBuffer(Image* image, int width, int height, int deviceScaleFactor)
+{
+ IntSize size(width, height);
+ size.scale(deviceScaleFactor);
+ ImageBuffer* buf = m_generatedImageCache.imageBuffer(size);
+ if (!buf) {
+ synthesizeGLError(GraphicsContext3D::OUT_OF_MEMORY, "texImage2D", "out of memory");
+ return 0;
+ }
+
+ IntRect srcRect(IntPoint(), image->size());
+ IntRect destRect(IntPoint(), size);
+ buf->context()->drawImage(image, ColorSpaceDeviceRGB, destRect, srcRect);
+ return buf->copyImage(ImageBuffer::fastCopyImageMode());
+}
+
void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat,
GC3Denum format, GC3Denum type, HTMLImageElement* image, ExceptionCode& ec)
{
ec = 0;
if (isContextLost() || !validateHTMLImageElement("texImage2D", image, ec))
return;
- Image* imageForRender = image->cachedImage()->imageForRenderer(image->renderer());
+
+ RefPtr<Image> imageForRender = image->cachedImage()->imageForRenderer(image->renderer());
+ if (imageForRender->isSVGImage())
+ imageForRender = drawImageIntoBuffer(imageForRender.get(), image->width(), image->height(), canvas()->deviceScaleFactor());
+
if (!imageForRender || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLImageElement, target, level, internalformat, imageForRender->width(), imageForRender->height(), 0, format, type, 0, 0))
return;
- texImage2DImpl(target, level, internalformat, format, type, imageForRender, GraphicsContext3D::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha, ec);
+ texImage2DImpl(target, level, internalformat, format, type, imageForRender.get(), GraphicsContext3D::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha, ec);
}
void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat,
@@ -3862,7 +3882,7 @@
PassRefPtr<Image> WebGLRenderingContext::videoFrameToImage(HTMLVideoElement* video, BackingStoreCopy backingStoreCopy, ExceptionCode&)
{
IntSize size(video->videoWidth(), video->videoHeight());
- ImageBuffer* buf = m_videoCache.imageBuffer(size);
+ ImageBuffer* buf = m_generatedImageCache.imageBuffer(size);
if (!buf) {
synthesizeGLError(GraphicsContext3D::OUT_OF_MEMORY, "texImage2D", "out of memory");
return 0;
@@ -4067,11 +4087,15 @@
ec = 0;
if (isContextLost() || !validateHTMLImageElement("texSubImage2D", image, ec))
return;
- Image* imageForRender = image->cachedImage()->imageForRenderer(image->renderer());
+
+ RefPtr<Image> imageForRender = image->cachedImage()->imageForRenderer(image->renderer());
+ if (imageForRender->isSVGImage())
+ imageForRender = drawImageIntoBuffer(imageForRender.get(), image->width(), image->height(), canvas()->deviceScaleFactor());
+
if (!imageForRender || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLImageElement, target, level, format, imageForRender->width(), imageForRender->height(), 0, format, type, xoffset, yoffset))
return;
- texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRender, GraphicsContext3D::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha, ec);
+ texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRender.get(), GraphicsContext3D::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha, ec);
}
void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset,
Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContext.h (157646 => 157647)
--- trunk/Source/WebCore/html/canvas/WebGLRenderingContext.h 2013-10-18 20:28:06 UTC (rev 157646)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContext.h 2013-10-18 20:53:06 UTC (rev 157647)
@@ -384,6 +384,8 @@
// Adds a compressed texture format.
void addCompressedTextureFormat(GC3Denum);
+ PassRefPtr<Image> drawImageIntoBuffer(Image*, int width, int height, int deviceScaleFactor);
+
#if ENABLE(VIDEO)
PassRefPtr<Image> videoFrameToImage(HTMLVideoElement*, BackingStoreCopy, ExceptionCode&);
#endif
@@ -472,7 +474,7 @@
std::unique_ptr<OwnPtr<ImageBuffer>[]> m_buffers;
int m_capacity;
};
- LRUImageBufferCache m_videoCache;
+ LRUImageBufferCache m_generatedImageCache;
GC3Dint m_maxTextureSize;
GC3Dint m_maxCubeMapTextureSize;