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

Side by Side Diff: cc/output/gl_renderer.cc

Issue 279013002: Remove CompositeAndReadback from LayerTreeHost(Impl) and the Proxys. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rm-cnr-lth-proxy-renderer: . Created 6 years, 7 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 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 1940 matching lines...) Expand 10 before | Expand all | Expand 10 after
1951 1951
1952 // Bind the correct texture sampler location. 1952 // Bind the correct texture sampler location.
1953 GLC(gl_, gl_->Uniform1i(draw_cache_.sampler_location, 0)); 1953 GLC(gl_, gl_->Uniform1i(draw_cache_.sampler_location, 0));
1954 1954
1955 // Assume the current active textures is 0. 1955 // Assume the current active textures is 0.
1956 ResourceProvider::ScopedReadLockGL locked_quad(resource_provider_, 1956 ResourceProvider::ScopedReadLockGL locked_quad(resource_provider_,
1957 draw_cache_.resource_id); 1957 draw_cache_.resource_id);
1958 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_)); 1958 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_));
1959 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, locked_quad.texture_id())); 1959 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, locked_quad.texture_id()));
1960 1960
1961 COMPILE_ASSERT(sizeof(Float4) == 4 * sizeof(float), // NOLINT(runtime/sizeof) 1961 COMPILE_ASSERT(sizeof(Float4) == 4 * sizeof(float), struct_is_densely_packed);
brianderson 2014/05/10 00:47:53 Unrelated changes?
danakj 2014/05/10 15:30:55 Yeh.. The linter complained that size of wasn't a
1962 COMPILE_ASSERT(sizeof(Float16) == 16 * sizeof(float),
1962 struct_is_densely_packed); 1963 struct_is_densely_packed);
1963 COMPILE_ASSERT(
1964 sizeof(Float16) == 16 * sizeof(float), // NOLINT(runtime/sizeof)
1965 struct_is_densely_packed);
1966 1964
1967 // Upload the tranforms for both points and uvs. 1965 // Upload the tranforms for both points and uvs.
1968 GLC(gl_, 1966 GLC(gl_,
1969 gl_->UniformMatrix4fv( 1967 gl_->UniformMatrix4fv(
1970 static_cast<int>(draw_cache_.matrix_location), 1968 static_cast<int>(draw_cache_.matrix_location),
1971 static_cast<int>(draw_cache_.matrix_data.size()), 1969 static_cast<int>(draw_cache_.matrix_data.size()),
1972 false, 1970 false,
1973 reinterpret_cast<float*>(&draw_cache_.matrix_data.front()))); 1971 reinterpret_cast<float*>(&draw_cache_.matrix_data.front())));
1974 GLC(gl_, 1972 GLC(gl_,
1975 gl_->Uniform4fv( 1973 gl_->Uniform4fv(
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
2332 } 2330 }
2333 2331
2334 void GLRenderer::EnsureBackbuffer() { 2332 void GLRenderer::EnsureBackbuffer() {
2335 if (!is_backbuffer_discarded_) 2333 if (!is_backbuffer_discarded_)
2336 return; 2334 return;
2337 2335
2338 output_surface_->EnsureBackbuffer(); 2336 output_surface_->EnsureBackbuffer();
2339 is_backbuffer_discarded_ = false; 2337 is_backbuffer_discarded_ = false;
2340 } 2338 }
2341 2339
2342 void GLRenderer::GetFramebufferPixels(void* pixels, const gfx::Rect& rect) {
2343 if (!pixels || rect.IsEmpty())
2344 return;
2345
2346 // This function assumes that it is reading the root frame buffer.
2347 DCHECK(!current_framebuffer_lock_);
2348
2349 scoped_ptr<PendingAsyncReadPixels> pending_read(new PendingAsyncReadPixels);
2350 pending_async_read_pixels_.insert(pending_async_read_pixels_.begin(),
2351 pending_read.Pass());
2352
2353 // This is a syncronous call since the callback is null.
2354 gfx::Rect window_rect = MoveFromDrawToWindowSpace(rect);
2355 DoGetFramebufferPixels(static_cast<uint8*>(pixels),
2356 window_rect,
2357 AsyncGetFramebufferPixelsCleanupCallback());
2358 }
2359
2360 void GLRenderer::GetFramebufferPixelsAsync( 2340 void GLRenderer::GetFramebufferPixelsAsync(
2361 const gfx::Rect& rect, 2341 const gfx::Rect& rect,
2362 scoped_ptr<CopyOutputRequest> request) { 2342 scoped_ptr<CopyOutputRequest> request) {
2363 DCHECK(!request->IsEmpty()); 2343 DCHECK(!request->IsEmpty());
2364 if (request->IsEmpty()) 2344 if (request->IsEmpty())
2365 return; 2345 return;
2366 if (rect.IsEmpty()) 2346 if (rect.IsEmpty())
2367 return; 2347 return;
2368 2348
2369 gfx::Rect window_rect = MoveFromDrawToWindowSpace(rect); 2349 gfx::Rect window_rect = MoveFromDrawToWindowSpace(rect);
2350 DCHECK_GE(window_rect.x(), 0);
2351 DCHECK_GE(window_rect.y(), 0);
2352 DCHECK_LE(window_rect.right(), current_surface_size_.width());
2353 DCHECK_LE(window_rect.bottom(), current_surface_size_.height());
2370 2354
2371 if (!request->force_bitmap_result()) { 2355 if (!request->force_bitmap_result()) {
2372 bool own_mailbox = !request->has_texture_mailbox(); 2356 bool own_mailbox = !request->has_texture_mailbox();
2373 2357
2374 GLuint texture_id = 0; 2358 GLuint texture_id = 0;
2375 gl_->GenTextures(1, &texture_id); 2359 gl_->GenTextures(1, &texture_id);
2376 2360
2377 gpu::Mailbox mailbox; 2361 gpu::Mailbox mailbox;
2378 if (own_mailbox) { 2362 if (own_mailbox) {
2379 GLC(gl_, gl_->GenMailboxCHROMIUM(mailbox.name)); 2363 GLC(gl_, gl_->GenMailboxCHROMIUM(mailbox.name));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2417 gl_->DeleteTextures(1, &texture_id); 2401 gl_->DeleteTextures(1, &texture_id);
2418 } 2402 }
2419 2403
2420 request->SendTextureResult( 2404 request->SendTextureResult(
2421 window_rect.size(), texture_mailbox, release_callback.Pass()); 2405 window_rect.size(), texture_mailbox, release_callback.Pass());
2422 return; 2406 return;
2423 } 2407 }
2424 2408
2425 DCHECK(request->force_bitmap_result()); 2409 DCHECK(request->force_bitmap_result());
2426 2410
2427 scoped_ptr<SkBitmap> bitmap(new SkBitmap);
2428 bitmap->allocN32Pixels(window_rect.width(), window_rect.height());
2429
2430 scoped_ptr<SkAutoLockPixels> lock(new SkAutoLockPixels(*bitmap));
2431
2432 // Save a pointer to the pixels, the bitmap is owned by the cleanup_callback.
2433 uint8* pixels = static_cast<uint8*>(bitmap->getPixels());
2434
2435 AsyncGetFramebufferPixelsCleanupCallback cleanup_callback =
2436 base::Bind(&GLRenderer::PassOnSkBitmap,
2437 base::Unretained(this),
2438 base::Passed(&bitmap),
2439 base::Passed(&lock));
2440
2441 scoped_ptr<PendingAsyncReadPixels> pending_read(new PendingAsyncReadPixels); 2411 scoped_ptr<PendingAsyncReadPixels> pending_read(new PendingAsyncReadPixels);
2442 pending_read->copy_request = request.Pass(); 2412 pending_read->copy_request = request.Pass();
2443 pending_async_read_pixels_.insert(pending_async_read_pixels_.begin(), 2413 pending_async_read_pixels_.insert(pending_async_read_pixels_.begin(),
2444 pending_read.Pass()); 2414 pending_read.Pass());
2445 2415
2446 // This is an asyncronous call since the callback is not null.
2447 DoGetFramebufferPixels(pixels, window_rect, cleanup_callback);
2448 }
2449
2450 void GLRenderer::DoGetFramebufferPixels(
2451 uint8* dest_pixels,
2452 const gfx::Rect& window_rect,
2453 const AsyncGetFramebufferPixelsCleanupCallback& cleanup_callback) {
2454 DCHECK_GE(window_rect.x(), 0);
2455 DCHECK_GE(window_rect.y(), 0);
2456 DCHECK_LE(window_rect.right(), current_surface_size_.width());
2457 DCHECK_LE(window_rect.bottom(), current_surface_size_.height());
2458
2459 bool is_async = !cleanup_callback.is_null();
2460
2461 bool do_workaround = NeedsIOSurfaceReadbackWorkaround(); 2416 bool do_workaround = NeedsIOSurfaceReadbackWorkaround();
2462 2417
2463 unsigned temporary_texture = 0; 2418 unsigned temporary_texture = 0;
2464 unsigned temporary_fbo = 0; 2419 unsigned temporary_fbo = 0;
2465 2420
2466 if (do_workaround) { 2421 if (do_workaround) {
2467 // On Mac OS X, calling glReadPixels() against an FBO whose color attachment 2422 // On Mac OS X, calling glReadPixels() against an FBO whose color attachment
2468 // is an IOSurface-backed texture causes corruption of future glReadPixels() 2423 // is an IOSurface-backed texture causes corruption of future glReadPixels()
2469 // calls, even those on different OpenGL contexts. It is believed that this 2424 // calls, even those on different OpenGL contexts. It is believed that this
2470 // is the root cause of top crasher 2425 // is the root cause of top crasher
(...skipping 30 matching lines...) Expand all
2501 GLuint buffer = 0; 2456 GLuint buffer = 0;
2502 gl_->GenBuffers(1, &buffer); 2457 gl_->GenBuffers(1, &buffer);
2503 GLC(gl_, gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, buffer)); 2458 GLC(gl_, gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, buffer));
2504 GLC(gl_, 2459 GLC(gl_,
2505 gl_->BufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 2460 gl_->BufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM,
2506 4 * window_rect.size().GetArea(), 2461 4 * window_rect.size().GetArea(),
2507 NULL, 2462 NULL,
2508 GL_STREAM_READ)); 2463 GL_STREAM_READ));
2509 2464
2510 GLuint query = 0; 2465 GLuint query = 0;
2511 if (is_async) { 2466 gl_->GenQueriesEXT(1, &query);
2512 gl_->GenQueriesEXT(1, &query); 2467 GLC(gl_, gl_->BeginQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM, query));
2513 GLC(gl_, gl_->BeginQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM, query));
2514 }
2515 2468
2516 GLC(gl_, 2469 GLC(gl_,
2517 gl_->ReadPixels(window_rect.x(), 2470 gl_->ReadPixels(window_rect.x(),
2518 window_rect.y(), 2471 window_rect.y(),
2519 window_rect.width(), 2472 window_rect.width(),
2520 window_rect.height(), 2473 window_rect.height(),
2521 GL_RGBA, 2474 GL_RGBA,
2522 GL_UNSIGNED_BYTE, 2475 GL_UNSIGNED_BYTE,
2523 NULL)); 2476 NULL));
2524 2477
2525 GLC(gl_, gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0)); 2478 GLC(gl_, gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0));
2526 2479
2527 if (do_workaround) { 2480 if (do_workaround) {
2528 // Clean up. 2481 // Clean up.
2529 GLC(gl_, gl_->BindFramebuffer(GL_FRAMEBUFFER, 0)); 2482 GLC(gl_, gl_->BindFramebuffer(GL_FRAMEBUFFER, 0));
2530 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, 0)); 2483 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, 0));
2531 GLC(gl_, gl_->DeleteFramebuffers(1, &temporary_fbo)); 2484 GLC(gl_, gl_->DeleteFramebuffers(1, &temporary_fbo));
2532 GLC(gl_, gl_->DeleteTextures(1, &temporary_texture)); 2485 GLC(gl_, gl_->DeleteTextures(1, &temporary_texture));
2533 } 2486 }
2534 2487
2535 base::Closure finished_callback = base::Bind(&GLRenderer::FinishedReadback, 2488 base::Closure finished_callback = base::Bind(&GLRenderer::FinishedReadback,
2536 base::Unretained(this), 2489 base::Unretained(this),
2537 cleanup_callback,
2538 buffer, 2490 buffer,
2539 query, 2491 query,
2540 dest_pixels,
2541 window_rect.size()); 2492 window_rect.size());
2542 // Save the finished_callback so it can be cancelled. 2493 // Save the finished_callback so it can be cancelled.
2543 pending_async_read_pixels_.front()->finished_read_pixels_callback.Reset( 2494 pending_async_read_pixels_.front()->finished_read_pixels_callback.Reset(
2544 finished_callback); 2495 finished_callback);
2545 base::Closure cancelable_callback = 2496 base::Closure cancelable_callback =
2546 pending_async_read_pixels_.front()-> 2497 pending_async_read_pixels_.front()->
2547 finished_read_pixels_callback.callback(); 2498 finished_read_pixels_callback.callback();
2548 2499
2549 // Save the buffer to verify the callbacks happen in the expected order. 2500 // Save the buffer to verify the callbacks happen in the expected order.
2550 pending_async_read_pixels_.front()->buffer = buffer; 2501 pending_async_read_pixels_.front()->buffer = buffer;
2551 2502
2552 if (is_async) { 2503 GLC(gl_, gl_->EndQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM));
2553 GLC(gl_, gl_->EndQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM)); 2504 context_support_->SignalQuery(query, cancelable_callback);
2554 context_support_->SignalQuery(query, cancelable_callback);
2555 } else {
2556 resource_provider_->Finish();
2557 finished_callback.Run();
2558 }
2559 2505
2560 EnforceMemoryPolicy(); 2506 EnforceMemoryPolicy();
2561 } 2507 }
2562 2508
2563 void GLRenderer::FinishedReadback( 2509 void GLRenderer::FinishedReadback(unsigned source_buffer,
2564 const AsyncGetFramebufferPixelsCleanupCallback& cleanup_callback, 2510 unsigned query,
2565 unsigned source_buffer, 2511 const gfx::Size& size) {
2566 unsigned query,
2567 uint8* dest_pixels,
2568 const gfx::Size& size) {
2569 DCHECK(!pending_async_read_pixels_.empty()); 2512 DCHECK(!pending_async_read_pixels_.empty());
2570 2513
2571 if (query != 0) { 2514 if (query != 0) {
2572 GLC(gl_, gl_->DeleteQueriesEXT(1, &query)); 2515 GLC(gl_, gl_->DeleteQueriesEXT(1, &query));
2573 } 2516 }
2574 2517
2575 PendingAsyncReadPixels* current_read = pending_async_read_pixels_.back(); 2518 PendingAsyncReadPixels* current_read = pending_async_read_pixels_.back();
2576 // Make sure we service the readbacks in order. 2519 // Make sure we service the readbacks in order.
2577 DCHECK_EQ(source_buffer, current_read->buffer); 2520 DCHECK_EQ(source_buffer, current_read->buffer);
2578 2521
2579 uint8* src_pixels = NULL; 2522 uint8* src_pixels = NULL;
2523 scoped_ptr<SkBitmap> bitmap;
2580 2524
2581 if (source_buffer != 0) { 2525 if (source_buffer != 0) {
2582 GLC(gl_, 2526 GLC(gl_,
2583 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, source_buffer)); 2527 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, source_buffer));
2584 src_pixels = static_cast<uint8*>(gl_->MapBufferCHROMIUM( 2528 src_pixels = static_cast<uint8*>(gl_->MapBufferCHROMIUM(
2585 GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, GL_READ_ONLY)); 2529 GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, GL_READ_ONLY));
2586 2530
2587 if (src_pixels) { 2531 if (src_pixels) {
2532 bitmap.reset(new SkBitmap);
2533 bitmap->allocN32Pixels(size.width(), size.height());
2534 scoped_ptr<SkAutoLockPixels> lock(new SkAutoLockPixels(*bitmap));
2535 uint8* dest_pixels = static_cast<uint8*>(bitmap->getPixels());
2536
2588 size_t row_bytes = size.width() * 4; 2537 size_t row_bytes = size.width() * 4;
2589 int num_rows = size.height(); 2538 int num_rows = size.height();
2590 size_t total_bytes = num_rows * row_bytes; 2539 size_t total_bytes = num_rows * row_bytes;
2591 for (size_t dest_y = 0; dest_y < total_bytes; dest_y += row_bytes) { 2540 for (size_t dest_y = 0; dest_y < total_bytes; dest_y += row_bytes) {
2592 // Flip Y axis. 2541 // Flip Y axis.
2593 size_t src_y = total_bytes - dest_y - row_bytes; 2542 size_t src_y = total_bytes - dest_y - row_bytes;
2594 // Swizzle OpenGL -> Skia byte order. 2543 // Swizzle OpenGL -> Skia byte order.
2595 for (size_t x = 0; x < row_bytes; x += 4) { 2544 for (size_t x = 0; x < row_bytes; x += 4) {
2596 dest_pixels[dest_y + x + SK_R32_SHIFT / 8] = 2545 dest_pixels[dest_y + x + SK_R32_SHIFT / 8] =
2597 src_pixels[src_y + x + 0]; 2546 src_pixels[src_y + x + 0];
2598 dest_pixels[dest_y + x + SK_G32_SHIFT / 8] = 2547 dest_pixels[dest_y + x + SK_G32_SHIFT / 8] =
2599 src_pixels[src_y + x + 1]; 2548 src_pixels[src_y + x + 1];
2600 dest_pixels[dest_y + x + SK_B32_SHIFT / 8] = 2549 dest_pixels[dest_y + x + SK_B32_SHIFT / 8] =
2601 src_pixels[src_y + x + 2]; 2550 src_pixels[src_y + x + 2];
2602 dest_pixels[dest_y + x + SK_A32_SHIFT / 8] = 2551 dest_pixels[dest_y + x + SK_A32_SHIFT / 8] =
2603 src_pixels[src_y + x + 3]; 2552 src_pixels[src_y + x + 3];
2604 } 2553 }
2605 } 2554 }
2606 2555
2607 GLC(gl_, 2556 GLC(gl_,
2608 gl_->UnmapBufferCHROMIUM(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM)); 2557 gl_->UnmapBufferCHROMIUM(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM));
2609 } 2558 }
2610 GLC(gl_, gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0)); 2559 GLC(gl_, gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0));
2611 GLC(gl_, gl_->DeleteBuffers(1, &source_buffer)); 2560 GLC(gl_, gl_->DeleteBuffers(1, &source_buffer));
2612 } 2561 }
2613 2562
2614 // TODO(danakj): This can go away when synchronous readback is no more and its 2563 if (bitmap)
2615 // contents can just move here. 2564 current_read->copy_request->SendBitmapResult(bitmap.Pass());
2616 if (!cleanup_callback.is_null())
2617 cleanup_callback.Run(current_read->copy_request.Pass(), src_pixels != NULL);
2618
2619 pending_async_read_pixels_.pop_back(); 2565 pending_async_read_pixels_.pop_back();
2620 } 2566 }
2621 2567
2622 void GLRenderer::PassOnSkBitmap(scoped_ptr<SkBitmap> bitmap,
2623 scoped_ptr<SkAutoLockPixels> lock,
2624 scoped_ptr<CopyOutputRequest> request,
2625 bool success) {
2626 DCHECK(request->force_bitmap_result());
2627
2628 lock.reset();
2629 if (success)
2630 request->SendBitmapResult(bitmap.Pass());
2631 }
2632
2633 void GLRenderer::GetFramebufferTexture(unsigned texture_id, 2568 void GLRenderer::GetFramebufferTexture(unsigned texture_id,
2634 ResourceFormat texture_format, 2569 ResourceFormat texture_format,
2635 const gfx::Rect& window_rect) { 2570 const gfx::Rect& window_rect) {
2636 DCHECK(texture_id); 2571 DCHECK(texture_id);
2637 DCHECK_GE(window_rect.x(), 0); 2572 DCHECK_GE(window_rect.x(), 0);
2638 DCHECK_GE(window_rect.y(), 0); 2573 DCHECK_GE(window_rect.y(), 0);
2639 DCHECK_LE(window_rect.right(), current_surface_size_.width()); 2574 DCHECK_LE(window_rect.right(), current_surface_size_.width());
2640 DCHECK_LE(window_rect.bottom(), current_surface_size_.height()); 2575 DCHECK_LE(window_rect.bottom(), current_surface_size_.height());
2641 2576
2642 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, texture_id)); 2577 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, texture_id));
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
3221 context_support_->ScheduleOverlayPlane( 3156 context_support_->ScheduleOverlayPlane(
3222 overlay.plane_z_order, 3157 overlay.plane_z_order,
3223 overlay.transform, 3158 overlay.transform,
3224 pending_overlay_resources_.back()->texture_id(), 3159 pending_overlay_resources_.back()->texture_id(),
3225 overlay.display_rect, 3160 overlay.display_rect,
3226 overlay.uv_rect); 3161 overlay.uv_rect);
3227 } 3162 }
3228 } 3163 }
3229 3164
3230 } // namespace cc 3165 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698