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 2283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2294 } | 2294 } |
2295 | 2295 |
2296 unsigned buffer = context_->createBuffer(); | 2296 unsigned buffer = context_->createBuffer(); |
2297 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 2297 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
2298 buffer)); | 2298 buffer)); |
2299 GLC(context_, context_->bufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 2299 GLC(context_, context_->bufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
2300 4 * window_rect.size().GetArea(), | 2300 4 * window_rect.size().GetArea(), |
2301 NULL, | 2301 NULL, |
2302 GL_STREAM_READ)); | 2302 GL_STREAM_READ)); |
2303 | 2303 |
| 2304 WebKit::WebGLId query = 0; |
| 2305 if (is_async) { |
| 2306 query = context_->createQueryEXT(); |
| 2307 GLC(context_, context_->beginQueryEXT( |
| 2308 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM, |
| 2309 query)); |
| 2310 } |
| 2311 |
2304 GLC(context_, | 2312 GLC(context_, |
2305 context_->readPixels(window_rect.x(), | 2313 context_->readPixels(window_rect.x(), |
2306 window_rect.y(), | 2314 window_rect.y(), |
2307 window_rect.width(), | 2315 window_rect.width(), |
2308 window_rect.height(), | 2316 window_rect.height(), |
2309 GL_RGBA, | 2317 GL_RGBA, |
2310 GL_UNSIGNED_BYTE, | 2318 GL_UNSIGNED_BYTE, |
2311 NULL)); | 2319 NULL)); |
2312 | 2320 |
2313 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 2321 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
2314 0)); | 2322 0)); |
2315 | 2323 |
2316 if (do_workaround) { | 2324 if (do_workaround) { |
2317 // Clean up. | 2325 // Clean up. |
2318 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, 0)); | 2326 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, 0)); |
2319 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0)); | 2327 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0)); |
2320 GLC(context_, context_->deleteFramebuffer(temporary_fbo)); | 2328 GLC(context_, context_->deleteFramebuffer(temporary_fbo)); |
2321 GLC(context_, context_->deleteTexture(temporary_texture)); | 2329 GLC(context_, context_->deleteTexture(temporary_texture)); |
2322 } | 2330 } |
2323 | 2331 |
2324 base::Closure finished_callback = | 2332 base::Closure finished_callback = |
2325 base::Bind(&GLRenderer::FinishedReadback, | 2333 base::Bind(&GLRenderer::FinishedReadback, |
2326 base::Unretained(this), | 2334 base::Unretained(this), |
2327 cleanup_callback, | 2335 cleanup_callback, |
2328 buffer, | 2336 buffer, |
| 2337 query, |
2329 dest_pixels, | 2338 dest_pixels, |
2330 window_rect.size()); | 2339 window_rect.size()); |
2331 // Save the finished_callback so it can be cancelled. | 2340 // Save the finished_callback so it can be cancelled. |
2332 pending_async_read_pixels_.front()->finished_read_pixels_callback.Reset( | 2341 pending_async_read_pixels_.front()->finished_read_pixels_callback.Reset( |
2333 finished_callback); | 2342 finished_callback); |
2334 | 2343 |
2335 // Save the buffer to verify the callbacks happen in the expected order. | 2344 // Save the buffer to verify the callbacks happen in the expected order. |
2336 pending_async_read_pixels_.front()->buffer = buffer; | 2345 pending_async_read_pixels_.front()->buffer = buffer; |
2337 | 2346 |
2338 if (is_async) { | 2347 if (is_async) { |
2339 unsigned sync_point = context_->insertSyncPoint(); | 2348 GLC(context_, context_->endQueryEXT( |
2340 SyncPointHelper::SignalSyncPoint( | 2349 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM)); |
| 2350 SyncPointHelper::SignalQuery( |
2341 context_, | 2351 context_, |
2342 sync_point, | 2352 query, |
2343 finished_callback); | 2353 finished_callback); |
2344 } else { | 2354 } else { |
2345 resource_provider_->Finish(); | 2355 resource_provider_->Finish(); |
2346 finished_callback.Run(); | 2356 finished_callback.Run(); |
2347 } | 2357 } |
2348 | 2358 |
2349 EnforceMemoryPolicy(); | 2359 EnforceMemoryPolicy(); |
2350 } | 2360 } |
2351 | 2361 |
2352 void GLRenderer::FinishedReadback( | 2362 void GLRenderer::FinishedReadback( |
2353 const AsyncGetFramebufferPixelsCleanupCallback& cleanup_callback, | 2363 const AsyncGetFramebufferPixelsCleanupCallback& cleanup_callback, |
2354 unsigned source_buffer, | 2364 unsigned source_buffer, |
| 2365 unsigned query, |
2355 uint8* dest_pixels, | 2366 uint8* dest_pixels, |
2356 gfx::Size size) { | 2367 gfx::Size size) { |
2357 DCHECK(!pending_async_read_pixels_.empty()); | 2368 DCHECK(!pending_async_read_pixels_.empty()); |
2358 | 2369 |
| 2370 if (query != 0) { |
| 2371 GLC(context_, context_->deleteQueryEXT(query)); |
| 2372 } |
| 2373 |
2359 PendingAsyncReadPixels* current_read = pending_async_read_pixels_.back(); | 2374 PendingAsyncReadPixels* current_read = pending_async_read_pixels_.back(); |
2360 // Make sure we service the readbacks in order. | 2375 // Make sure we service the readbacks in order. |
2361 DCHECK_EQ(source_buffer, current_read->buffer); | 2376 DCHECK_EQ(source_buffer, current_read->buffer); |
2362 | 2377 |
2363 uint8* src_pixels = NULL; | 2378 uint8* src_pixels = NULL; |
2364 | 2379 |
2365 if (source_buffer != 0) { | 2380 if (source_buffer != 0) { |
2366 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 2381 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
2367 source_buffer)); | 2382 source_buffer)); |
2368 src_pixels = static_cast<uint8*>( | 2383 src_pixels = static_cast<uint8*>( |
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3046 std::string unique_context_name = base::StringPrintf( | 3061 std::string unique_context_name = base::StringPrintf( |
3047 "%s-Offscreen-%p", | 3062 "%s-Offscreen-%p", |
3048 Settings().compositor_name.c_str(), | 3063 Settings().compositor_name.c_str(), |
3049 context_); | 3064 context_); |
3050 resource_provider()->offscreen_context_provider()->Context3d()-> | 3065 resource_provider()->offscreen_context_provider()->Context3d()-> |
3051 pushGroupMarkerEXT(unique_context_name.c_str()); | 3066 pushGroupMarkerEXT(unique_context_name.c_str()); |
3052 } | 3067 } |
3053 | 3068 |
3054 | 3069 |
3055 } // namespace cc | 3070 } // namespace cc |
OLD | NEW |