Index: Source/modules/webgl/WebGLRenderingContextBase.cpp |
diff --git a/Source/modules/webgl/WebGLRenderingContextBase.cpp b/Source/modules/webgl/WebGLRenderingContextBase.cpp |
index 53aaea0151620316a369e2c80916623f0b6df6ab..61b7c2951e93769667bd8608611b1b2c52312ec1 100644 |
--- a/Source/modules/webgl/WebGLRenderingContextBase.cpp |
+++ b/Source/modules/webgl/WebGLRenderingContextBase.cpp |
@@ -222,33 +222,6 @@ void WebGLRenderingContextBase::willDestroyContext(WebGLRenderingContextBase* co |
namespace { |
-// ScopedDrawingBufferBinder is used for ReadPixels/CopyTexImage2D/CopySubImage2D to read from |
-// a multisampled DrawingBuffer. In this situation, we need to blit to a single sampled buffer |
-// for reading, during which the bindings could be changed and need to be recovered. |
-class ScopedDrawingBufferBinder { |
- STACK_ALLOCATED(); |
-public: |
- ScopedDrawingBufferBinder(DrawingBuffer* drawingBuffer, WebGLFramebuffer* framebufferBinding) |
- : m_drawingBuffer(drawingBuffer) |
- , m_readFramebufferBinding(framebufferBinding) |
- { |
- // Commit DrawingBuffer if needed (e.g., for multisampling) |
- if (!m_readFramebufferBinding && m_drawingBuffer) |
- m_drawingBuffer->commit(); |
- } |
- |
- ~ScopedDrawingBufferBinder() |
- { |
- // Restore DrawingBuffer if needed |
- if (!m_readFramebufferBinding && m_drawingBuffer) |
- m_drawingBuffer->restoreFramebufferBindings(); |
- } |
- |
-private: |
- DrawingBuffer* m_drawingBuffer; |
- Member<WebGLFramebuffer> m_readFramebufferBinding; |
-}; |
- |
GLint clamp(GLint value, GLint min, GLint max) |
{ |
if (value < min) |
@@ -3729,33 +3702,15 @@ DOMArrayBufferView::ViewType WebGLRenderingContextBase::readPixelsExpectedArrayB |
} |
} |
-void WebGLRenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, DOMArrayBufferView* pixels) |
+bool WebGLRenderingContextBase::validateReadPixelsFuncParameters(GLsizei width, GLsizei height, GLenum format, GLenum type, unsigned domArrayBufferLength, WebGLFramebuffer*& readFramebufferBinding) |
Zhenyao Mo
2015/08/18 21:48:39
I prefer not to return the readFramebufferBinding
yunchao
2015/08/19 09:33:39
Make sense. Done.
|
{ |
- if (isContextLost()) |
- return; |
- // Due to WebGL's same-origin restrictions, it is not possible to |
- // taint the origin using the WebGL API. |
- ASSERT(canvas()->originClean()); |
- // Validate input parameters. |
- if (!pixels) { |
- synthesizeGLError(GL_INVALID_VALUE, "readPixels", "no destination ArrayBufferView"); |
- return; |
- } |
if (!validateReadPixelsFormatAndType(format, type)) |
- return; |
+ return false; |
GLenum readBufferInternalFormat = 0, readBufferType = 0; |
- WebGLFramebuffer* readFramebufferBinding = nullptr; |
if (!validateReadBufferAndGetInfo("readPixels", readFramebufferBinding, &readBufferInternalFormat, &readBufferType)) |
- return; |
+ return false; |
if (!validateReadPixelsFormatTypeCombination(format, type, readBufferInternalFormat, readBufferType)) |
- return; |
- |
- DOMArrayBufferView::ViewType expectedViewType = readPixelsExpectedArrayBufferViewType(type); |
- // Validate array type against pixel type. |
- if (pixels->type() != expectedViewType) { |
- synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView was the wrong type for the pixel format"); |
- return; |
- } |
+ return false; |
// Calculate array size, taking into consideration of PACK_ALIGNMENT. |
unsigned totalBytesRequired = 0; |
@@ -3763,15 +3718,26 @@ void WebGLRenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLsi |
GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, width, height, m_packAlignment, &totalBytesRequired, &padding); |
if (error != GL_NO_ERROR) { |
synthesizeGLError(error, "readPixels", "invalid dimensions"); |
- return; |
+ return false; |
} |
- if (pixels->byteLength() < totalBytesRequired) { |
+ if (domArrayBufferLength && domArrayBufferLength < totalBytesRequired) { |
synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView not large enough for dimensions"); |
- return; |
+ return false; |
} |
+ return true; |
+} |
+ |
+void WebGLRenderingContextBase::readPixelsImpl(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* data, unsigned domArrayBufferLength) |
+{ |
+ // Due to WebGL's same-origin restrictions, it is not possible to |
+ // taint the origin using the WebGL API. |
+ ASSERT(canvas()->originClean()); |
+ |
+ WebGLFramebuffer* readFramebufferBinding = nullptr; |
+ if (!validateReadPixelsFuncParameters(format, type, width, height, domArrayBufferLength, readFramebufferBinding)) |
+ return; |
clearIfComposited(); |
- void* data = pixels->baseAddress(); |
{ |
ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding); |
@@ -3779,6 +3745,26 @@ void WebGLRenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLsi |
} |
} |
+void WebGLRenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, DOMArrayBufferView* pixels) |
+{ |
+ if (isContextLost()) |
+ return; |
+ // Validate input parameters. |
+ if (!pixels) { |
+ synthesizeGLError(GL_INVALID_VALUE, "readPixels", "no destination ArrayBufferView"); |
+ return; |
+ } |
+ |
+ DOMArrayBufferView::ViewType expectedViewType = readPixelsExpectedArrayBufferViewType(type); |
+ // Validate array type against pixel type. |
+ if (pixels->type() != expectedViewType) { |
+ synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView was the wrong type for the pixel format"); |
+ return; |
+ } |
+ |
+ readPixelsImpl(x, y, width, height, format, type, pixels->baseAddress(), pixels->byteLength()); |
+} |
+ |
void WebGLRenderingContextBase::renderbufferStorageImpl( |
GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, |
const char* functionName) |