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 2289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2300 } | 2300 } |
2301 | 2301 |
2302 unsigned buffer = context_->createBuffer(); | 2302 unsigned buffer = context_->createBuffer(); |
2303 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 2303 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
2304 buffer)); | 2304 buffer)); |
2305 GLC(context_, context_->bufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 2305 GLC(context_, context_->bufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
2306 4 * window_rect.size().GetArea(), | 2306 4 * window_rect.size().GetArea(), |
2307 NULL, | 2307 NULL, |
2308 GL_STREAM_READ)); | 2308 GL_STREAM_READ)); |
2309 | 2309 |
| 2310 WebKit::WebGLId query = 0; |
| 2311 if (is_async) { |
| 2312 query = context_->createQueryEXT(); |
| 2313 GLC(context_, context_->beginQueryEXT( |
| 2314 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM, |
| 2315 query)); |
| 2316 } |
| 2317 |
2310 GLC(context_, | 2318 GLC(context_, |
2311 context_->readPixels(window_rect.x(), | 2319 context_->readPixels(window_rect.x(), |
2312 window_rect.y(), | 2320 window_rect.y(), |
2313 window_rect.width(), | 2321 window_rect.width(), |
2314 window_rect.height(), | 2322 window_rect.height(), |
2315 GL_RGBA, | 2323 GL_RGBA, |
2316 GL_UNSIGNED_BYTE, | 2324 GL_UNSIGNED_BYTE, |
2317 NULL)); | 2325 NULL)); |
2318 | 2326 |
2319 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 2327 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
2320 0)); | 2328 0)); |
2321 | 2329 |
2322 if (do_workaround) { | 2330 if (do_workaround) { |
2323 // Clean up. | 2331 // Clean up. |
2324 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, 0)); | 2332 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, 0)); |
2325 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0)); | 2333 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0)); |
2326 GLC(context_, context_->deleteFramebuffer(temporary_fbo)); | 2334 GLC(context_, context_->deleteFramebuffer(temporary_fbo)); |
2327 GLC(context_, context_->deleteTexture(temporary_texture)); | 2335 GLC(context_, context_->deleteTexture(temporary_texture)); |
2328 } | 2336 } |
2329 | 2337 |
2330 base::Closure finished_callback = | 2338 base::Closure finished_callback = |
2331 base::Bind(&GLRenderer::FinishedReadback, | 2339 base::Bind(&GLRenderer::FinishedReadback, |
2332 base::Unretained(this), | 2340 base::Unretained(this), |
2333 cleanup_callback, | 2341 cleanup_callback, |
2334 buffer, | 2342 buffer, |
| 2343 query, |
2335 dest_pixels, | 2344 dest_pixels, |
2336 window_rect.size()); | 2345 window_rect.size()); |
2337 // Save the finished_callback so it can be cancelled. | 2346 // Save the finished_callback so it can be cancelled. |
2338 pending_async_read_pixels_.front()->finished_read_pixels_callback.Reset( | 2347 pending_async_read_pixels_.front()->finished_read_pixels_callback.Reset( |
2339 finished_callback); | 2348 finished_callback); |
2340 | 2349 |
2341 // Save the buffer to verify the callbacks happen in the expected order. | 2350 // Save the buffer to verify the callbacks happen in the expected order. |
2342 pending_async_read_pixels_.front()->buffer = buffer; | 2351 pending_async_read_pixels_.front()->buffer = buffer; |
2343 | 2352 |
2344 if (is_async) { | 2353 if (is_async) { |
2345 unsigned sync_point = context_->insertSyncPoint(); | 2354 GLC(context_, context_->endQueryEXT( |
2346 SyncPointHelper::SignalSyncPoint( | 2355 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM)); |
| 2356 SyncPointHelper::SignalQuery( |
2347 context_, | 2357 context_, |
2348 sync_point, | 2358 query, |
2349 finished_callback); | 2359 finished_callback); |
2350 } else { | 2360 } else { |
2351 resource_provider_->Finish(); | 2361 resource_provider_->Finish(); |
2352 finished_callback.Run(); | 2362 finished_callback.Run(); |
2353 } | 2363 } |
2354 | 2364 |
2355 EnforceMemoryPolicy(); | 2365 EnforceMemoryPolicy(); |
2356 } | 2366 } |
2357 | 2367 |
2358 void GLRenderer::FinishedReadback( | 2368 void GLRenderer::FinishedReadback( |
2359 const AsyncGetFramebufferPixelsCleanupCallback& cleanup_callback, | 2369 const AsyncGetFramebufferPixelsCleanupCallback& cleanup_callback, |
2360 unsigned source_buffer, | 2370 unsigned source_buffer, |
| 2371 unsigned query, |
2361 uint8* dest_pixels, | 2372 uint8* dest_pixels, |
2362 gfx::Size size) { | 2373 gfx::Size size) { |
2363 DCHECK(!pending_async_read_pixels_.empty()); | 2374 DCHECK(!pending_async_read_pixels_.empty()); |
2364 | 2375 |
| 2376 if (query != 0) { |
| 2377 GLC(context_, context_->deleteQueryEXT(query)); |
| 2378 } |
| 2379 |
2365 PendingAsyncReadPixels* current_read = pending_async_read_pixels_.back(); | 2380 PendingAsyncReadPixels* current_read = pending_async_read_pixels_.back(); |
2366 // Make sure we service the readbacks in order. | 2381 // Make sure we service the readbacks in order. |
2367 DCHECK_EQ(source_buffer, current_read->buffer); | 2382 DCHECK_EQ(source_buffer, current_read->buffer); |
2368 | 2383 |
2369 uint8* src_pixels = NULL; | 2384 uint8* src_pixels = NULL; |
2370 | 2385 |
2371 if (source_buffer != 0) { | 2386 if (source_buffer != 0) { |
2372 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 2387 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
2373 source_buffer)); | 2388 source_buffer)); |
2374 src_pixels = static_cast<uint8*>( | 2389 src_pixels = static_cast<uint8*>( |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3034 // The Skia GPU backend requires a stencil buffer. See ReinitializeGrCanvas | 3049 // The Skia GPU backend requires a stencil buffer. See ReinitializeGrCanvas |
3035 // implementation. | 3050 // implementation. |
3036 return gr_context_ && context_->getContextAttributes().stencil; | 3051 return gr_context_ && context_->getContextAttributes().stencil; |
3037 } | 3052 } |
3038 | 3053 |
3039 bool GLRenderer::IsContextLost() { | 3054 bool GLRenderer::IsContextLost() { |
3040 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); | 3055 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); |
3041 } | 3056 } |
3042 | 3057 |
3043 } // namespace cc | 3058 } // namespace cc |
OLD | NEW |