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

Side by Side Diff: Source/modules/webgl/WebGL2RenderingContextBase.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, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "modules/webgl/WebGL2RenderingContextBase.h" 6 #include "modules/webgl/WebGL2RenderingContextBase.h"
7 7
8 #include "bindings/modules/v8/WebGLAny.h" 8 #include "bindings/modules/v8/WebGLAny.h"
9 #include "core/html/HTMLCanvasElement.h" 9 #include "core/html/HTMLCanvasElement.h"
10 #include "core/html/HTMLImageElement.h" 10 #include "core/html/HTMLImageElement.h"
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } else { 237 } else {
238 if (mode == GL_BACK) { 238 if (mode == GL_BACK) {
239 synthesizeGLError(GL_INVALID_OPERATION, "readBuffer", "invalid read buffer"); 239 synthesizeGLError(GL_INVALID_OPERATION, "readBuffer", "invalid read buffer");
240 return; 240 return;
241 } 241 }
242 readFramebufferBinding->readBuffer(mode); 242 readFramebufferBinding->readBuffer(mode);
243 } 243 }
244 webContext()->readBuffer(mode); 244 webContext()->readBuffer(mode);
245 } 245 }
246 246
247 void WebGL2RenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLs izei height, GLenum format, GLenum type, DOMArrayBufferView* pixels)
248 {
249 if (isContextLost())
250 return;
251 if (m_boundPixelPackBuffer.get()) {
252 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "PIXEL_PACK buffer should not be bound");
253 return;
254 }
255
256 WebGLRenderingContextBase::readPixels(x, y, width, height, format, type, pix els);
257 }
258
259 void WebGL2RenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLs izei height, GLenum format, GLenum type, long long offset)
260 {
261 if (isContextLost())
262 return;
263
264 // Due to WebGL's same-origin restrictions, it is not possible to
265 // taint the origin using the WebGL API.
266 ASSERT(canvas()->originClean());
267
268 if (!validateValueFitNonNegInt32("readPixels", "offset", offset))
269 return;
270
271 WebGLBuffer* buffer = m_boundPixelPackBuffer.get();
272 if (!buffer) {
273 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "no PIXEL_PACK buf fer bound");
274 return;
275 }
276
277 // Need to validate whether the pixel pack buffer is mapped,
278 // if we decide to expose mapBufferRange() to web developers.
279
280 long long size = buffer->getSize() - offset;
281
282 // If size is negative, or size is not large enough to store pixels, those c ases
283 // are handled by validateReadPixelsFuncParameters to generate INVALID_OPERA TION.
284 if (!validateReadPixelsFuncParameters(width, height, format, type, size))
285 return;
286
287 clearIfComposited();
288
289 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(GL_READ_FRA MEBUFFER);
290 {
291 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding );
292 webContext()->readPixels(x, y, width, height, format, type, reinterpret_ cast<void*>(offset));
293 }
294 }
295
247 void WebGL2RenderingContextBase::renderbufferStorageImpl( 296 void WebGL2RenderingContextBase::renderbufferStorageImpl(
248 GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsize i height, 297 GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsize i height,
249 const char* functionName) 298 const char* functionName)
250 { 299 {
251 switch (internalformat) { 300 switch (internalformat) {
252 case GL_R8UI: 301 case GL_R8UI:
253 case GL_R8I: 302 case GL_R8I:
254 case GL_R16UI: 303 case GL_R16UI:
255 case GL_R16I: 304 case GL_R16I:
256 case GL_R32UI: 305 case GL_R32UI:
(...skipping 2220 matching lines...) Expand 10 before | Expand all | Expand 10 after
2477 GLenum WebGL2RenderingContextBase::boundFramebufferColorFormat() 2526 GLenum WebGL2RenderingContextBase::boundFramebufferColorFormat()
2478 { 2527 {
2479 if (m_readFramebufferBinding && m_readFramebufferBinding->object()) 2528 if (m_readFramebufferBinding && m_readFramebufferBinding->object())
2480 return m_readFramebufferBinding->colorBufferFormat(); 2529 return m_readFramebufferBinding->colorBufferFormat();
2481 if (m_requestedAttributes.alpha()) 2530 if (m_requestedAttributes.alpha())
2482 return GL_RGBA; 2531 return GL_RGBA;
2483 return GL_RGB; 2532 return GL_RGB;
2484 } 2533 }
2485 2534
2486 } // namespace blink 2535 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/webgl/WebGL2RenderingContextBase.h ('k') | Source/modules/webgl/WebGL2RenderingContextBase.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698