OLD | NEW |
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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 "cc/output/gl_renderer.h" | 5 #include "cc/output/gl_renderer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 2282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2293 } | 2293 } |
2294 | 2294 |
2295 unsigned buffer = context_->createBuffer(); | 2295 unsigned buffer = context_->createBuffer(); |
2296 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 2296 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
2297 buffer)); | 2297 buffer)); |
2298 GLC(context_, context_->bufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 2298 GLC(context_, context_->bufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
2299 4 * window_rect.size().GetArea(), | 2299 4 * window_rect.size().GetArea(), |
2300 NULL, | 2300 NULL, |
2301 GL_STREAM_READ)); | 2301 GL_STREAM_READ)); |
2302 | 2302 |
| 2303 WebKit::WebGLId query = 0; |
| 2304 if (is_async) { |
| 2305 query = context_->createQueryEXT(); |
| 2306 GLC(context_, context_->beginQueryEXT( |
| 2307 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM, |
| 2308 query)); |
| 2309 } |
| 2310 |
2303 GLC(context_, | 2311 GLC(context_, |
2304 context_->readPixels(window_rect.x(), | 2312 context_->readPixels(window_rect.x(), |
2305 window_rect.y(), | 2313 window_rect.y(), |
2306 window_rect.width(), | 2314 window_rect.width(), |
2307 window_rect.height(), | 2315 window_rect.height(), |
2308 GL_RGBA, | 2316 GL_RGBA, |
2309 GL_UNSIGNED_BYTE, | 2317 GL_UNSIGNED_BYTE, |
2310 NULL)); | 2318 NULL)); |
2311 | 2319 |
2312 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 2320 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
2313 0)); | 2321 0)); |
2314 | 2322 |
2315 if (do_workaround) { | 2323 if (do_workaround) { |
2316 // Clean up. | 2324 // Clean up. |
2317 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, 0)); | 2325 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, 0)); |
2318 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0)); | 2326 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0)); |
2319 GLC(context_, context_->deleteFramebuffer(temporary_fbo)); | 2327 GLC(context_, context_->deleteFramebuffer(temporary_fbo)); |
2320 GLC(context_, context_->deleteTexture(temporary_texture)); | 2328 GLC(context_, context_->deleteTexture(temporary_texture)); |
2321 } | 2329 } |
2322 | 2330 |
2323 base::Closure finished_callback = | 2331 base::Closure finished_callback = |
2324 base::Bind(&GLRenderer::FinishedReadback, | 2332 base::Bind(&GLRenderer::FinishedReadback, |
2325 base::Unretained(this), | 2333 base::Unretained(this), |
2326 cleanup_callback, | 2334 cleanup_callback, |
2327 buffer, | 2335 buffer, |
| 2336 query, |
2328 dest_pixels, | 2337 dest_pixels, |
2329 window_rect.size()); | 2338 window_rect.size()); |
2330 // Save the finished_callback so it can be cancelled. | 2339 // Save the finished_callback so it can be cancelled. |
2331 pending_async_read_pixels_.front()->finished_read_pixels_callback.Reset( | 2340 pending_async_read_pixels_.front()->finished_read_pixels_callback.Reset( |
2332 finished_callback); | 2341 finished_callback); |
2333 | 2342 |
2334 // Save the buffer to verify the callbacks happen in the expected order. | 2343 // Save the buffer to verify the callbacks happen in the expected order. |
2335 pending_async_read_pixels_.front()->buffer = buffer; | 2344 pending_async_read_pixels_.front()->buffer = buffer; |
2336 | 2345 |
2337 if (is_async) { | 2346 if (is_async) { |
2338 unsigned sync_point = context_->insertSyncPoint(); | 2347 GLC(context_, context_->endQueryEXT( |
2339 SyncPointHelper::SignalSyncPoint( | 2348 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM)); |
| 2349 SyncPointHelper::SignalQuery( |
2340 context_, | 2350 context_, |
2341 sync_point, | 2351 query, |
2342 finished_callback); | 2352 finished_callback); |
2343 } else { | 2353 } else { |
2344 resource_provider_->Finish(); | 2354 resource_provider_->Finish(); |
2345 finished_callback.Run(); | 2355 finished_callback.Run(); |
2346 } | 2356 } |
2347 | 2357 |
2348 EnforceMemoryPolicy(); | 2358 EnforceMemoryPolicy(); |
2349 } | 2359 } |
2350 | 2360 |
2351 void GLRenderer::FinishedReadback( | 2361 void GLRenderer::FinishedReadback( |
2352 const AsyncGetFramebufferPixelsCleanupCallback& cleanup_callback, | 2362 const AsyncGetFramebufferPixelsCleanupCallback& cleanup_callback, |
2353 unsigned source_buffer, | 2363 unsigned source_buffer, |
| 2364 unsigned query, |
2354 uint8* dest_pixels, | 2365 uint8* dest_pixels, |
2355 gfx::Size size) { | 2366 gfx::Size size) { |
2356 DCHECK(!pending_async_read_pixels_.empty()); | 2367 DCHECK(!pending_async_read_pixels_.empty()); |
2357 | 2368 |
| 2369 if (query != 0) { |
| 2370 GLC(context_, context_->deleteQueryEXT(query)); |
| 2371 } |
| 2372 |
2358 PendingAsyncReadPixels* current_read = pending_async_read_pixels_.back(); | 2373 PendingAsyncReadPixels* current_read = pending_async_read_pixels_.back(); |
2359 // Make sure we service the readbacks in order. | 2374 // Make sure we service the readbacks in order. |
2360 DCHECK_EQ(source_buffer, current_read->buffer); | 2375 DCHECK_EQ(source_buffer, current_read->buffer); |
2361 | 2376 |
2362 uint8* src_pixels = NULL; | 2377 uint8* src_pixels = NULL; |
2363 | 2378 |
2364 if (source_buffer != 0) { | 2379 if (source_buffer != 0) { |
2365 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 2380 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
2366 source_buffer)); | 2381 source_buffer)); |
2367 src_pixels = static_cast<uint8*>( | 2382 src_pixels = static_cast<uint8*>( |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3088 std::string unique_context_name = base::StringPrintf( | 3103 std::string unique_context_name = base::StringPrintf( |
3089 "%s-Offscreen-%p", | 3104 "%s-Offscreen-%p", |
3090 Settings().compositor_name.c_str(), | 3105 Settings().compositor_name.c_str(), |
3091 context_); | 3106 context_); |
3092 resource_provider()->offscreen_context_provider()->Context3d()-> | 3107 resource_provider()->offscreen_context_provider()->Context3d()-> |
3093 pushGroupMarkerEXT(unique_context_name.c_str()); | 3108 pushGroupMarkerEXT(unique_context_name.c_str()); |
3094 } | 3109 } |
3095 | 3110 |
3096 | 3111 |
3097 } // namespace cc | 3112 } // namespace cc |
OLD | NEW |