Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1777)

Unified Diff: Source/modules/webgl/WebGLRenderingContextBase.cpp

Issue 1300573002: WebGL 2: add readPixels API to read pixels into pixel pack buffer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: code refactoring to fix bugs in conformance test Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/webgl/WebGLRenderingContextBase.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/webgl/WebGLRenderingContextBase.cpp
diff --git a/Source/modules/webgl/WebGLRenderingContextBase.cpp b/Source/modules/webgl/WebGLRenderingContextBase.cpp
index 4e53c20f450f360fc3c6306714410d5e20994055..ca419d66592160103dc8cdd92f313b4a331ae582 100644
--- a/Source/modules/webgl/WebGLRenderingContextBase.cpp
+++ b/Source/modules/webgl/WebGLRenderingContextBase.cpp
@@ -1582,6 +1582,8 @@ void WebGLRenderingContextBase::bufferDataImpl(GLenum target, long long size, co
if (!validateValueFitNonNegInt32("bufferData", "size", size))
return;
+ buffer->setSize(size);
+
webContext()->bufferData(target, static_cast<GLsizeiptr>(size), data, usage);
}
@@ -3678,6 +3680,32 @@ DOMArrayBufferView::ViewType WebGLRenderingContextBase::readPixelsExpectedArrayB
}
}
+bool WebGLRenderingContextBase::validateReadPixelsFuncParameters(GLsizei width, GLsizei height, GLenum format, GLenum type, long long bufferSize)
+{
+ if (!validateReadPixelsFormatAndType(format, type))
+ return false;
+ WebGLFramebuffer* readFramebufferBinding = nullptr;
+ GLenum readBufferInternalFormat = 0, readBufferType = 0;
+ if (!validateReadBufferAndGetInfo("readPixels", readFramebufferBinding, &readBufferInternalFormat, &readBufferType))
+ return false;
+ if (!validateReadPixelsFormatTypeCombination(format, type, readBufferInternalFormat, readBufferType))
+ return false;
+
+ // Calculate array size, taking into consideration of PACK_ALIGNMENT.
+ unsigned totalBytesRequired = 0;
+ unsigned padding = 0;
+ GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, width, height, m_packAlignment, &totalBytesRequired, &padding);
+ if (error != GL_NO_ERROR) {
+ synthesizeGLError(error, "readPixels", "invalid dimensions");
+ return false;
+ }
+ if (bufferSize < static_cast<long long>(totalBytesRequired)) {
+ synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "buffer is not large enough for dimensions");
+ return false;
+ }
+ return true;
+}
+
void WebGLRenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, DOMArrayBufferView* pixels)
{
if (isContextLost())
@@ -3690,13 +3718,8 @@ void WebGLRenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLsi
synthesizeGLError(GL_INVALID_VALUE, "readPixels", "no destination ArrayBufferView");
return;
}
- if (!validateReadPixelsFormatAndType(format, type))
- return;
- GLenum readBufferInternalFormat = 0, readBufferType = 0;
- WebGLFramebuffer* readFramebufferBinding = nullptr;
- if (!validateReadBufferAndGetInfo("readPixels", readFramebufferBinding, &readBufferInternalFormat, &readBufferType))
- return;
- if (!validateReadPixelsFormatTypeCombination(format, type, readBufferInternalFormat, readBufferType))
+
+ if (!validateReadPixelsFuncParameters(width, height, format, type, static_cast<long long>(pixels->byteLength())))
return;
DOMArrayBufferView::ViewType expectedViewType = readPixelsExpectedArrayBufferViewType(type);
@@ -3706,22 +3729,11 @@ void WebGLRenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLsi
return;
}
- // Calculate array size, taking into consideration of PACK_ALIGNMENT.
- unsigned totalBytesRequired = 0;
- unsigned padding = 0;
- GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, width, height, m_packAlignment, &totalBytesRequired, &padding);
- if (error != GL_NO_ERROR) {
- synthesizeGLError(error, "readPixels", "invalid dimensions");
- return;
- }
- if (pixels->byteLength() < totalBytesRequired) {
- synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView not large enough for dimensions");
- return;
- }
-
clearIfComposited();
void* data = pixels->baseAddress();
+ GLenum target = isWebGL2OrHigher() ? GL_READ_FRAMEBUFFER : GL_FRAMEBUFFER;
+ WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(target);
{
ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding);
webContext()->readPixels(x, y, width, height, format, type, data);
« no previous file with comments | « Source/modules/webgl/WebGLRenderingContextBase.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698