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

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

Issue 2162193002: Add logic to GLRenderer to support RenderPassDrawQuad copying. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up. Created 4 years, 5 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
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/output/output_surface.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <limits> 11 #include <limits>
12 #include <memory> 12 #include <memory>
13 #include <set> 13 #include <set>
14 #include <string> 14 #include <string>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/ptr_util.h" 19 #include "base/memory/ptr_util.h"
20 #include "base/strings/string_split.h" 20 #include "base/strings/string_split.h"
21 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
22 #include "base/strings/stringprintf.h" 22 #include "base/strings/stringprintf.h"
23 #include "base/threading/thread_task_runner_handle.h"
23 #include "base/trace_event/trace_event.h" 24 #include "base/trace_event/trace_event.h"
24 #include "build/build_config.h" 25 #include "build/build_config.h"
25 #include "cc/base/container_util.h" 26 #include "cc/base/container_util.h"
26 #include "cc/base/math_util.h" 27 #include "cc/base/math_util.h"
27 #include "cc/output/compositor_frame.h" 28 #include "cc/output/compositor_frame.h"
28 #include "cc/output/compositor_frame_metadata.h" 29 #include "cc/output/compositor_frame_metadata.h"
29 #include "cc/output/context_provider.h" 30 #include "cc/output/context_provider.h"
30 #include "cc/output/copy_output_request.h" 31 #include "cc/output/copy_output_request.h"
31 #include "cc/output/dynamic_geometry_binding.h" 32 #include "cc/output/dynamic_geometry_binding.h"
32 #include "cc/output/gl_frame_data.h" 33 #include "cc/output/gl_frame_data.h"
33 #include "cc/output/layer_quad.h" 34 #include "cc/output/layer_quad.h"
34 #include "cc/output/output_surface.h" 35 #include "cc/output/output_surface.h"
35 #include "cc/output/render_surface_filters.h" 36 #include "cc/output/render_surface_filters.h"
36 #include "cc/output/static_geometry_binding.h" 37 #include "cc/output/static_geometry_binding.h"
37 #include "cc/output/texture_mailbox_deleter.h" 38 #include "cc/output/texture_mailbox_deleter.h"
38 #include "cc/quads/draw_polygon.h" 39 #include "cc/quads/draw_polygon.h"
39 #include "cc/quads/picture_draw_quad.h" 40 #include "cc/quads/picture_draw_quad.h"
40 #include "cc/quads/render_pass.h" 41 #include "cc/quads/render_pass.h"
41 #include "cc/quads/stream_video_draw_quad.h" 42 #include "cc/quads/stream_video_draw_quad.h"
42 #include "cc/quads/texture_draw_quad.h" 43 #include "cc/quads/texture_draw_quad.h"
43 #include "cc/raster/scoped_gpu_raster.h" 44 #include "cc/raster/scoped_gpu_raster.h"
45 #include "cc/resources/resource_pool.h"
44 #include "cc/resources/scoped_resource.h" 46 #include "cc/resources/scoped_resource.h"
45 #include "gpu/GLES2/gl2extchromium.h" 47 #include "gpu/GLES2/gl2extchromium.h"
46 #include "gpu/command_buffer/client/context_support.h" 48 #include "gpu/command_buffer/client/context_support.h"
47 #include "gpu/command_buffer/client/gles2_interface.h" 49 #include "gpu/command_buffer/client/gles2_interface.h"
48 #include "gpu/command_buffer/common/gpu_memory_allocation.h" 50 #include "gpu/command_buffer/common/gpu_memory_allocation.h"
49 #include "skia/ext/texture_handle.h" 51 #include "skia/ext/texture_handle.h"
50 #include "third_party/skia/include/core/SkBitmap.h" 52 #include "third_party/skia/include/core/SkBitmap.h"
51 #include "third_party/skia/include/core/SkColor.h" 53 #include "third_party/skia/include/core/SkColor.h"
52 #include "third_party/skia/include/core/SkColorFilter.h" 54 #include "third_party/skia/include/core/SkColorFilter.h"
53 #include "third_party/skia/include/core/SkImage.h" 55 #include "third_party/skia/include/core/SkImage.h"
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 capabilities_.max_msaa_samples = 0; 366 capabilities_.max_msaa_samples = 0;
365 else 367 else
366 capabilities_.max_msaa_samples = context_caps.max_samples; 368 capabilities_.max_msaa_samples = context_caps.max_samples;
367 369
368 use_sync_query_ = context_caps.sync_query; 370 use_sync_query_ = context_caps.sync_query;
369 use_blend_equation_advanced_ = context_caps.blend_equation_advanced; 371 use_blend_equation_advanced_ = context_caps.blend_equation_advanced;
370 use_blend_equation_advanced_coherent_ = 372 use_blend_equation_advanced_coherent_ =
371 context_caps.blend_equation_advanced_coherent; 373 context_caps.blend_equation_advanced_coherent;
372 374
373 InitializeSharedObjects(); 375 InitializeSharedObjects();
376
377 overlay_resource_pool_ = ResourcePool::CreateForGpuMemoryBufferResources(
378 resource_provider_, base::ThreadTaskRunnerHandle::Get().get());
374 } 379 }
375 380
376 GLRenderer::~GLRenderer() { 381 GLRenderer::~GLRenderer() {
377 while (!pending_async_read_pixels_.empty()) { 382 while (!pending_async_read_pixels_.empty()) {
378 PendingAsyncReadPixels* pending_read = 383 PendingAsyncReadPixels* pending_read =
379 pending_async_read_pixels_.back().get(); 384 pending_async_read_pixels_.back().get();
380 pending_read->finished_read_pixels_callback.Cancel(); 385 pending_read->finished_read_pixels_callback.Cancel();
381 pending_async_read_pixels_.pop_back(); 386 pending_async_read_pixels_.pop_back();
382 } 387 }
383 388
(...skipping 3241 matching lines...) Expand 10 before | Expand all | Expand 10 after
3625 // restoring. 3630 // restoring.
3626 SetViewport(); 3631 SetViewport();
3627 } 3632 }
3628 3633
3629 bool GLRenderer::IsContextLost() { 3634 bool GLRenderer::IsContextLost() {
3630 return gl_->GetGraphicsResetStatusKHR() != GL_NO_ERROR; 3635 return gl_->GetGraphicsResetStatusKHR() != GL_NO_ERROR;
3631 } 3636 }
3632 3637
3633 void GLRenderer::ScheduleCALayers(DrawingFrame* frame) { 3638 void GLRenderer::ScheduleCALayers(DrawingFrame* frame) {
3634 scoped_refptr<CALayerOverlaySharedState> shared_state; 3639 scoped_refptr<CALayerOverlaySharedState> shared_state;
3640 size_t copied_render_pass_count = 0;
3635 for (const CALayerOverlay& ca_layer_overlay : frame->ca_layer_overlay_list) { 3641 for (const CALayerOverlay& ca_layer_overlay : frame->ca_layer_overlay_list) {
3642 ResourceId contents_resource_id = ca_layer_overlay.contents_resource_id;
3643 Resource* resource = nullptr;
3644 // Some CALayers require a final round of processing.
3645 if (ca_layer_overlay.render_pass_id.IsValid()) {
3646 CopyRenderPassToOverlayResource(ca_layer_overlay.render_pass_id,
3647 &resource);
3648 contents_resource_id = resource->id();
3649 ++copied_render_pass_count;
3650 }
3651
3636 unsigned texture_id = 0; 3652 unsigned texture_id = 0;
3637 if (ca_layer_overlay.contents_resource_id) { 3653 if (contents_resource_id) {
3638 pending_overlay_resources_.push_back( 3654 pending_overlay_resources_.push_back(
3639 base::WrapUnique(new ResourceProvider::ScopedReadLockGL( 3655 base::WrapUnique(new ResourceProvider::ScopedReadLockGL(
3640 resource_provider_, ca_layer_overlay.contents_resource_id))); 3656 resource_provider_, contents_resource_id)));
3641 texture_id = pending_overlay_resources_.back()->texture_id(); 3657 texture_id = pending_overlay_resources_.back()->texture_id();
3658
3659 if (resource) {
3660 // Once a resource is released, it is marked as "busy". It will be
3661 // available for reuse after the ScopedReadLockGL is destroyed.
3662 overlay_resource_pool_->ReleaseResource(resource);
3663 }
3642 } 3664 }
3643 GLfloat contents_rect[4] = { 3665 GLfloat contents_rect[4] = {
3644 ca_layer_overlay.contents_rect.x(), ca_layer_overlay.contents_rect.y(), 3666 ca_layer_overlay.contents_rect.x(), ca_layer_overlay.contents_rect.y(),
3645 ca_layer_overlay.contents_rect.width(), 3667 ca_layer_overlay.contents_rect.width(),
3646 ca_layer_overlay.contents_rect.height(), 3668 ca_layer_overlay.contents_rect.height(),
3647 }; 3669 };
3648 GLfloat bounds_rect[4] = { 3670 GLfloat bounds_rect[4] = {
3649 ca_layer_overlay.bounds_rect.x(), ca_layer_overlay.bounds_rect.y(), 3671 ca_layer_overlay.bounds_rect.x(), ca_layer_overlay.bounds_rect.y(),
3650 ca_layer_overlay.bounds_rect.width(), 3672 ca_layer_overlay.bounds_rect.width(),
3651 ca_layer_overlay.bounds_rect.height(), 3673 ca_layer_overlay.bounds_rect.height(),
(...skipping 12 matching lines...) Expand all
3664 if (ca_layer_overlay.shared_state != shared_state) { 3686 if (ca_layer_overlay.shared_state != shared_state) {
3665 shared_state = ca_layer_overlay.shared_state; 3687 shared_state = ca_layer_overlay.shared_state;
3666 gl_->ScheduleCALayerSharedStateCHROMIUM( 3688 gl_->ScheduleCALayerSharedStateCHROMIUM(
3667 ca_layer_overlay.shared_state->opacity, is_clipped, clip_rect, 3689 ca_layer_overlay.shared_state->opacity, is_clipped, clip_rect,
3668 sorting_context_id, transform); 3690 sorting_context_id, transform);
3669 } 3691 }
3670 gl_->ScheduleCALayerCHROMIUM( 3692 gl_->ScheduleCALayerCHROMIUM(
3671 texture_id, contents_rect, ca_layer_overlay.background_color, 3693 texture_id, contents_rect, ca_layer_overlay.background_color,
3672 ca_layer_overlay.edge_aa_mask, bounds_rect, filter); 3694 ca_layer_overlay.edge_aa_mask, bounds_rect, filter);
3673 } 3695 }
3696
3697 // Take the number of copied render passes in this frame, and use 3 times that
3698 // amount as the cache limit.
3699 overlay_resource_pool_->SetResourceUsageLimits(
3700 std::numeric_limits<std::size_t>::max(), copied_render_pass_count * 3);
3674 } 3701 }
3675 3702
3676 void GLRenderer::ScheduleOverlays(DrawingFrame* frame) { 3703 void GLRenderer::ScheduleOverlays(DrawingFrame* frame) {
3677 if (frame->overlay_list.empty()) 3704 if (frame->overlay_list.empty())
3678 return; 3705 return;
3679 3706
3680 OverlayCandidateList& overlays = frame->overlay_list; 3707 OverlayCandidateList& overlays = frame->overlay_list;
3681 for (const OverlayCandidate& overlay : overlays) { 3708 for (const OverlayCandidate& overlay : overlays) {
3682 unsigned texture_id = 0; 3709 unsigned texture_id = 0;
3683 if (overlay.use_output_surface_for_resource) { 3710 if (overlay.use_output_surface_for_resource) {
3684 texture_id = output_surface_->GetOverlayTextureId(); 3711 texture_id = output_surface_->GetOverlayTextureId();
3685 DCHECK(texture_id || IsContextLost()); 3712 DCHECK(texture_id || IsContextLost());
3686 } else { 3713 } else {
3687 pending_overlay_resources_.push_back( 3714 pending_overlay_resources_.push_back(
3688 base::WrapUnique(new ResourceProvider::ScopedReadLockGL( 3715 base::WrapUnique(new ResourceProvider::ScopedReadLockGL(
3689 resource_provider_, overlay.resource_id))); 3716 resource_provider_, overlay.resource_id)));
3690 texture_id = pending_overlay_resources_.back()->texture_id(); 3717 texture_id = pending_overlay_resources_.back()->texture_id();
3691 } 3718 }
3692 3719
3693 context_support_->ScheduleOverlayPlane( 3720 context_support_->ScheduleOverlayPlane(
3694 overlay.plane_z_order, overlay.transform, texture_id, 3721 overlay.plane_z_order, overlay.transform, texture_id,
3695 ToNearestRect(overlay.display_rect), overlay.uv_rect); 3722 ToNearestRect(overlay.display_rect), overlay.uv_rect);
3696 } 3723 }
3697 } 3724 }
3698 3725
3726 void GLRenderer::CopyRenderPassToOverlayResource(
3727 const RenderPassId& render_pass_id,
3728 Resource** resource) {
3729 ScopedResource* contents_texture =
3730 render_pass_textures_[render_pass_id].get();
3731 DCHECK(contents_texture);
3732 DCHECK(contents_texture->id());
3733 // TODO(erikchen): Fix this to allow the creation of IOSurfaces.
3734 // https://crbug.com/581526.
3735 *resource = overlay_resource_pool_->AcquireResource(
3736 contents_texture->size(), ResourceFormat::RGBA_8888);
3737 ResourceProvider::ScopedWriteLockGL destination(resource_provider_,
3738 (*resource)->id(), false);
3739
3740 GLuint source_texture = 0;
3741 std::unique_ptr<ResourceProvider::ScopedReadLockGL> source;
3742 if (current_framebuffer_lock_ &&
3743 current_framebuffer_lock_->texture_id() == contents_texture->id()) {
3744 source_texture = current_framebuffer_lock_->texture_id();
3745 } else {
3746 source.reset(new ResourceProvider::ScopedReadLockGL(
3747 resource_provider_, contents_texture->id()));
3748 source_texture = source->texture_id();
3749 }
3750 gl_->CopySubTextureCHROMIUM(source_texture, destination.texture_id(), 0, 0, 0,
ccameron 2016/07/21 20:47:18 nit: I guess we can just do CopyTextureCHROMIUM? S
erikchen 2016/07/21 20:55:14 I think CopyTextureCHROMIUM would work because of
3751 0, contents_texture->size().width(),
3752 contents_texture->size().height(), GL_TRUE,
3753 GL_FALSE, GL_FALSE);
3754 }
3755
3699 } // namespace cc 3756 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/output/output_surface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698