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

Side by Side Diff: content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc

Issue 7566046: Add WebGraphicsContext support for readbacks from any framebuffer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #if defined(ENABLE_GPU) 5 #if defined(ENABLE_GPU)
6 6
7 #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h" 7 #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h"
8 8
9 #include <GLES2/gl2.h> 9 #include <GLES2/gl2.h>
10 #ifndef GL_GLEXT_PROTOTYPES 10 #ifndef GL_GLEXT_PROTOTYPES
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // creation attributes. 246 // creation attributes.
247 memcpy(scanline, row_b, row_bytes); 247 memcpy(scanline, row_b, row_bytes);
248 memcpy(row_b, row_a, row_bytes); 248 memcpy(row_b, row_a, row_bytes);
249 memcpy(row_a, scanline, row_bytes); 249 memcpy(row_a, scanline, row_bytes);
250 } 250 }
251 } 251 }
252 #endif 252 #endif
253 253
254 bool WebGraphicsContext3DCommandBufferImpl::readBackFramebuffer( 254 bool WebGraphicsContext3DCommandBufferImpl::readBackFramebuffer(
255 unsigned char* pixels, 255 unsigned char* pixels,
256 size_t buffer_size) { 256 int width,
257 if (buffer_size != static_cast<size_t>(4 * width() * height())) { 257 int height,
258 size_t buffer_size,
259 WebGLId buffer) {
260 if (buffer_size != static_cast<size_t>(4 * width * height)) {
258 return false; 261 return false;
259 } 262 }
260 263
261 // Earlier versions of this code used the GPU to flip the 264 // Earlier versions of this code used the GPU to flip the
262 // framebuffer vertically before reading it back for compositing 265 // framebuffer vertically before reading it back for compositing
263 // via software. This code was quite complicated, used a lot of 266 // via software. This code was quite complicated, used a lot of
264 // GPU memory, and didn't provide an obvious speedup. Since this 267 // GPU memory, and didn't provide an obvious speedup. Since this
265 // vertical flip is only a temporary solution anyway until Chrome 268 // vertical flip is only a temporary solution anyway until Chrome
266 // is fully GPU composited, it wasn't worth the complexity. 269 // is fully GPU composited, it wasn't worth the complexity.
267 270
268 bool mustRestoreFBO = (bound_fbo_ != 0); 271 bool mustRestoreFBO = (bound_fbo_ != buffer);
269 if (mustRestoreFBO) { 272 if (mustRestoreFBO) {
270 gl_->BindFramebuffer(GL_FRAMEBUFFER, 0); 273 gl_->BindFramebuffer(GL_FRAMEBUFFER, buffer);
271 } 274 }
Ken Russell (switch to Gerrit) 2011/08/04 22:55:07 Do you think we might want or need checks about th
jbauman 2011/08/04 23:20:21 Those can be expensive, so I'd rather avoid them (
272 gl_->ReadPixels(0, 0, cached_width_, cached_height_, 275 gl_->ReadPixels(0, 0, width, height,
273 GL_RGBA, GL_UNSIGNED_BYTE, pixels); 276 GL_RGBA, GL_UNSIGNED_BYTE, pixels);
274 277
275 // Swizzle red and blue channels 278 // Swizzle red and blue channels
276 // TODO(kbr): expose GL_BGRA as extension 279 // TODO(kbr): expose GL_BGRA as extension
277 for (size_t i = 0; i < buffer_size; i += 4) { 280 for (size_t i = 0; i < buffer_size; i += 4) {
278 std::swap(pixels[i], pixels[i + 2]); 281 std::swap(pixels[i], pixels[i + 2]);
279 } 282 }
280 283
281 if (mustRestoreFBO) { 284 if (mustRestoreFBO) {
282 gl_->BindFramebuffer(GL_FRAMEBUFFER, bound_fbo_); 285 gl_->BindFramebuffer(GL_FRAMEBUFFER, bound_fbo_);
283 } 286 }
284 287
285 #ifdef FLIP_FRAMEBUFFER_VERTICALLY 288 #ifdef FLIP_FRAMEBUFFER_VERTICALLY
286 if (pixels) { 289 if (pixels) {
287 FlipVertically(pixels, cached_width_, cached_height_); 290 FlipVertically(pixels, width, height);
288 } 291 }
289 #endif 292 #endif
290 293
291 return true; 294 return true;
292 } 295 }
293 296
297 bool WebGraphicsContext3DCommandBufferImpl::readBackFramebuffer(
298 unsigned char* pixels,
299 size_t buffer_size) {
300 return readBackFramebuffer(pixels, width(), height(), buffer_size, 0);
301 }
302
294 void WebGraphicsContext3DCommandBufferImpl::synthesizeGLError( 303 void WebGraphicsContext3DCommandBufferImpl::synthesizeGLError(
295 WGC3Denum error) { 304 WGC3Denum error) {
296 if (find(synthetic_errors_.begin(), synthetic_errors_.end(), error) == 305 if (find(synthetic_errors_.begin(), synthetic_errors_.end(), error) ==
297 synthetic_errors_.end()) { 306 synthetic_errors_.end()) {
298 synthetic_errors_.push_back(error); 307 synthetic_errors_.push_back(error);
299 } 308 }
300 } 309 }
301 310
302 void* WebGraphicsContext3DCommandBufferImpl::mapBufferSubDataCHROMIUM( 311 void* WebGraphicsContext3DCommandBufferImpl::mapBufferSubDataCHROMIUM(
303 WGC3Denum target, 312 WGC3Denum target,
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 context_lost_callback_->onContextLost(); 1037 context_lost_callback_->onContextLost();
1029 } 1038 }
1030 1039
1031 RenderView* renderview = 1040 RenderView* renderview =
1032 web_view_ ? RenderView::FromWebView(web_view_) : NULL; 1041 web_view_ ? RenderView::FromWebView(web_view_) : NULL;
1033 if (renderview) 1042 if (renderview)
1034 renderview->OnViewContextSwapBuffersAborted(); 1043 renderview->OnViewContextSwapBuffersAborted();
1035 } 1044 }
1036 1045
1037 #endif // defined(ENABLE_GPU) 1046 #endif // defined(ENABLE_GPU)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698