Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/renderer/android/synchronous_compositor_frame_sink.h" | 5 #include "content/renderer/android/synchronous_compositor_frame_sink.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "cc/output/compositor_frame.h" | 16 #include "cc/output/compositor_frame.h" |
| 17 #include "cc/output/compositor_frame_sink_client.h" | 17 #include "cc/output/compositor_frame_sink_client.h" |
| 18 #include "cc/output/context_provider.h" | 18 #include "cc/output/context_provider.h" |
| 19 #include "cc/output/output_surface.h" | 19 #include "cc/output/output_surface.h" |
| 20 #include "cc/output/output_surface_frame.h" | 20 #include "cc/output/output_surface_frame.h" |
| 21 #include "cc/output/renderer_settings.h" | 21 #include "cc/output/renderer_settings.h" |
| 22 #include "cc/output/software_output_device.h" | 22 #include "cc/output/software_output_device.h" |
| 23 #include "cc/output/texture_mailbox_deleter.h" | 23 #include "cc/output/texture_mailbox_deleter.h" |
| 24 #include "cc/quads/render_pass.h" | 24 #include "cc/quads/render_pass.h" |
| 25 #include "cc/quads/surface_draw_quad.h" | 25 #include "cc/quads/surface_draw_quad.h" |
| 26 #include "cc/surfaces/compositor_frame_sink_support.h" | |
| 26 #include "cc/surfaces/display.h" | 27 #include "cc/surfaces/display.h" |
| 27 #include "cc/surfaces/surface_factory.h" | |
| 28 #include "cc/surfaces/surface_id_allocator.h" | 28 #include "cc/surfaces/surface_id_allocator.h" |
| 29 #include "cc/surfaces/surface_manager.h" | 29 #include "cc/surfaces/surface_manager.h" |
| 30 #include "content/common/android/sync_compositor_messages.h" | 30 #include "content/common/android/sync_compositor_messages.h" |
| 31 #include "content/renderer/android/synchronous_compositor_filter.h" | 31 #include "content/renderer/android/synchronous_compositor_filter.h" |
| 32 #include "content/renderer/android/synchronous_compositor_registry.h" | 32 #include "content/renderer/android/synchronous_compositor_registry.h" |
| 33 #include "content/renderer/gpu/frame_swap_message_queue.h" | 33 #include "content/renderer/gpu/frame_swap_message_queue.h" |
| 34 #include "content/renderer/render_thread_impl.h" | 34 #include "content/renderer/render_thread_impl.h" |
| 35 #include "gpu/command_buffer/client/context_support.h" | 35 #include "gpu/command_buffer/client/context_support.h" |
| 36 #include "gpu/command_buffer/client/gles2_interface.h" | 36 #include "gpu/command_buffer/client/gles2_interface.h" |
| 37 #include "gpu/command_buffer/common/gpu_memory_allocation.h" | 37 #include "gpu/command_buffer/common/gpu_memory_allocation.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 gpu_memory_buffer_manager, | 117 gpu_memory_buffer_manager, |
| 118 nullptr), | 118 nullptr), |
| 119 routing_id_(routing_id), | 119 routing_id_(routing_id), |
| 120 compositor_frame_sink_id_(compositor_frame_sink_id), | 120 compositor_frame_sink_id_(compositor_frame_sink_id), |
| 121 registry_(registry), | 121 registry_(registry), |
| 122 sender_(RenderThreadImpl::current()->sync_compositor_message_filter()), | 122 sender_(RenderThreadImpl::current()->sync_compositor_message_filter()), |
| 123 memory_policy_(0u), | 123 memory_policy_(0u), |
| 124 frame_swap_message_queue_(frame_swap_message_queue), | 124 frame_swap_message_queue_(frame_swap_message_queue), |
| 125 surface_manager_(new cc::SurfaceManager), | 125 surface_manager_(new cc::SurfaceManager), |
| 126 surface_id_allocator_(new cc::SurfaceIdAllocator()), | 126 surface_id_allocator_(new cc::SurfaceIdAllocator()), |
| 127 root_factory_(new cc::SurfaceFactory(kRootFrameSinkId, | |
| 128 surface_manager_.get(), | |
| 129 this)), | |
| 130 child_factory_(new cc::SurfaceFactory(kChildFrameSinkId, | |
| 131 surface_manager_.get(), | |
| 132 this)), | |
| 133 begin_frame_source_(std::move(begin_frame_source)) { | 127 begin_frame_source_(std::move(begin_frame_source)) { |
| 134 DCHECK(registry_); | 128 DCHECK(registry_); |
| 135 DCHECK(sender_); | 129 DCHECK(sender_); |
| 136 DCHECK(begin_frame_source_); | 130 DCHECK(begin_frame_source_); |
| 137 thread_checker_.DetachFromThread(); | 131 thread_checker_.DetachFromThread(); |
| 138 memory_policy_.priority_cutoff_when_visible = | 132 memory_policy_.priority_cutoff_when_visible = |
| 139 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; | 133 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; |
| 140 } | 134 } |
| 141 | 135 |
| 142 SynchronousCompositorFrameSink::~SynchronousCompositorFrameSink() = default; | 136 SynchronousCompositorFrameSink::~SynchronousCompositorFrameSink() = default; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 167 return false; | 161 return false; |
| 168 | 162 |
| 169 DCHECK(begin_frame_source_); | 163 DCHECK(begin_frame_source_); |
| 170 client_->SetBeginFrameSource(begin_frame_source_.get()); | 164 client_->SetBeginFrameSource(begin_frame_source_.get()); |
| 171 client_->SetMemoryPolicy(memory_policy_); | 165 client_->SetMemoryPolicy(memory_policy_); |
| 172 client_->SetTreeActivationCallback( | 166 client_->SetTreeActivationCallback( |
| 173 base::Bind(&SynchronousCompositorFrameSink::DidActivatePendingTree, | 167 base::Bind(&SynchronousCompositorFrameSink::DidActivatePendingTree, |
| 174 base::Unretained(this))); | 168 base::Unretained(this))); |
| 175 registry_->RegisterCompositorFrameSink(routing_id_, this); | 169 registry_->RegisterCompositorFrameSink(routing_id_, this); |
| 176 | 170 |
| 177 surface_manager_->RegisterFrameSinkId(kRootFrameSinkId); | 171 root_support_.reset(new cc::CompositorFrameSinkSupport( |
| 178 surface_manager_->RegisterFrameSinkId(kChildFrameSinkId); | 172 this, surface_manager_.get(), kRootFrameSinkId, |
| 179 surface_manager_->RegisterSurfaceFactoryClient(kRootFrameSinkId, this); | 173 true /* submits_to_display_compositor */)); |
| 180 surface_manager_->RegisterSurfaceFactoryClient(kChildFrameSinkId, this); | 174 child_support_.reset(new cc::CompositorFrameSinkSupport( |
| 175 this, surface_manager_.get(), kChildFrameSinkId, | |
| 176 true /* submits_to_display_compositor */)); | |
|
Fady Samuel
2017/02/13 21:24:14
Ahh this doesn't hang off the root, so this is fal
Saman Sami
2017/02/13 21:29:35
Done.
| |
| 181 | 177 |
| 182 cc::RendererSettings software_renderer_settings; | 178 cc::RendererSettings software_renderer_settings; |
| 183 | 179 |
| 184 auto output_surface = base::MakeUnique<SoftwareOutputSurface>( | 180 auto output_surface = base::MakeUnique<SoftwareOutputSurface>( |
| 185 base::MakeUnique<SoftwareDevice>(¤t_sw_canvas_)); | 181 base::MakeUnique<SoftwareDevice>(¤t_sw_canvas_)); |
| 186 software_output_surface_ = output_surface.get(); | 182 software_output_surface_ = output_surface.get(); |
| 187 | 183 |
| 188 // The shared_bitmap_manager and gpu_memory_buffer_manager here are null as | 184 // The shared_bitmap_manager and gpu_memory_buffer_manager here are null as |
| 189 // this Display is only used for resourcesless software draws, where no | 185 // this Display is only used for resourcesless software draws, where no |
| 190 // resources are included in the frame swapped from the compositor. So there | 186 // resources are included in the frame swapped from the compositor. So there |
| 191 // is no need for these. | 187 // is no need for these. |
| 192 display_.reset(new cc::Display( | 188 display_.reset(new cc::Display( |
| 193 nullptr /* shared_bitmap_manager */, | 189 nullptr /* shared_bitmap_manager */, |
| 194 nullptr /* gpu_memory_buffer_manager */, software_renderer_settings, | 190 nullptr /* gpu_memory_buffer_manager */, software_renderer_settings, |
| 195 kRootFrameSinkId, nullptr /* begin_frame_source */, | 191 kRootFrameSinkId, nullptr /* begin_frame_source */, |
| 196 std::move(output_surface), nullptr /* scheduler */, | 192 std::move(output_surface), nullptr /* scheduler */, |
| 197 nullptr /* texture_mailbox_deleter */)); | 193 nullptr /* texture_mailbox_deleter */)); |
| 198 display_->Initialize(&display_client_, surface_manager_.get()); | 194 display_->Initialize(&display_client_, surface_manager_.get()); |
| 199 display_->SetVisible(true); | 195 display_->SetVisible(true); |
| 200 return true; | 196 return true; |
| 201 } | 197 } |
| 202 | 198 |
| 203 void SynchronousCompositorFrameSink::DetachFromClient() { | 199 void SynchronousCompositorFrameSink::DetachFromClient() { |
| 204 DCHECK(CalledOnValidThread()); | 200 DCHECK(CalledOnValidThread()); |
| 205 client_->SetBeginFrameSource(nullptr); | 201 client_->SetBeginFrameSource(nullptr); |
| 206 // Destroy the begin frame source on the same thread it was bound on. | 202 // Destroy the begin frame source on the same thread it was bound on. |
| 207 begin_frame_source_ = nullptr; | 203 begin_frame_source_ = nullptr; |
| 208 registry_->UnregisterCompositorFrameSink(routing_id_, this); | 204 registry_->UnregisterCompositorFrameSink(routing_id_, this); |
| 209 client_->SetTreeActivationCallback(base::Closure()); | 205 client_->SetTreeActivationCallback(base::Closure()); |
| 210 root_factory_->EvictSurface(); | 206 root_support_.reset(); |
| 211 child_factory_->EvictSurface(); | 207 child_support_.reset(); |
| 212 surface_manager_->UnregisterSurfaceFactoryClient(kRootFrameSinkId); | |
| 213 surface_manager_->UnregisterSurfaceFactoryClient(kChildFrameSinkId); | |
| 214 surface_manager_->InvalidateFrameSinkId(kRootFrameSinkId); | |
| 215 surface_manager_->InvalidateFrameSinkId(kChildFrameSinkId); | |
| 216 software_output_surface_ = nullptr; | 208 software_output_surface_ = nullptr; |
| 217 display_ = nullptr; | 209 display_ = nullptr; |
| 218 child_factory_ = nullptr; | |
| 219 root_factory_ = nullptr; | |
| 220 surface_id_allocator_ = nullptr; | 210 surface_id_allocator_ = nullptr; |
| 221 surface_manager_ = nullptr; | 211 surface_manager_ = nullptr; |
| 222 cc::CompositorFrameSink::DetachFromClient(); | 212 cc::CompositorFrameSink::DetachFromClient(); |
| 223 CancelFallbackTick(); | 213 CancelFallbackTick(); |
| 224 } | 214 } |
| 225 | 215 |
| 226 static void NoOpDrawCallback() {} | |
| 227 | |
| 228 void SynchronousCompositorFrameSink::SubmitCompositorFrame( | 216 void SynchronousCompositorFrameSink::SubmitCompositorFrame( |
| 229 cc::CompositorFrame frame) { | 217 cc::CompositorFrame frame) { |
| 230 DCHECK(CalledOnValidThread()); | 218 DCHECK(CalledOnValidThread()); |
| 231 DCHECK(sync_client_); | 219 DCHECK(sync_client_); |
| 232 | 220 |
| 233 if (fallback_tick_running_) { | 221 if (fallback_tick_running_) { |
| 234 DCHECK(frame.resource_list.empty()); | 222 DCHECK(frame.resource_list.empty()); |
| 235 cc::ReturnedResourceArray return_resources; | 223 cc::ReturnedResourceArray return_resources; |
| 236 ReturnResources(return_resources); | 224 ReclaimResources(return_resources); |
| 237 did_submit_frame_ = true; | 225 did_submit_frame_ = true; |
| 238 return; | 226 return; |
| 239 } | 227 } |
| 240 | 228 |
| 241 cc::CompositorFrame submit_frame; | 229 cc::CompositorFrame submit_frame; |
| 242 | 230 |
| 243 if (in_software_draw_) { | 231 if (in_software_draw_) { |
| 244 // The frame we send to the client is actually just the metadata. Preserve | 232 // The frame we send to the client is actually just the metadata. Preserve |
| 245 // the |frame| for the software path below. | 233 // the |frame| for the software path below. |
| 246 submit_frame.metadata = frame.metadata.Clone(); | 234 submit_frame.metadata = frame.metadata.Clone(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 auto* surface_quad = | 278 auto* surface_quad = |
| 291 embed_render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | 279 embed_render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); |
| 292 shared_quad_state->SetAll( | 280 shared_quad_state->SetAll( |
| 293 child_transform, child_size, gfx::Rect(child_size), | 281 child_transform, child_size, gfx::Rect(child_size), |
| 294 gfx::Rect() /* clip_rect */, false /* is_clipped */, 1.f /* opacity */, | 282 gfx::Rect() /* clip_rect */, false /* is_clipped */, 1.f /* opacity */, |
| 295 SkBlendMode::kSrcOver, 0 /* sorting_context_id */); | 283 SkBlendMode::kSrcOver, 0 /* sorting_context_id */); |
| 296 surface_quad->SetNew( | 284 surface_quad->SetNew( |
| 297 shared_quad_state, gfx::Rect(child_size), gfx::Rect(child_size), | 285 shared_quad_state, gfx::Rect(child_size), gfx::Rect(child_size), |
| 298 cc::SurfaceId(kChildFrameSinkId, child_local_surface_id_)); | 286 cc::SurfaceId(kChildFrameSinkId, child_local_surface_id_)); |
| 299 | 287 |
| 300 child_factory_->SubmitCompositorFrame(child_local_surface_id_, | 288 child_support_->SubmitCompositorFrame(child_local_surface_id_, |
| 301 std::move(frame), | 289 std::move(frame)); |
| 302 base::Bind(&NoOpDrawCallback)); | 290 root_support_->SubmitCompositorFrame(root_local_surface_id_, |
| 303 root_factory_->SubmitCompositorFrame(root_local_surface_id_, | 291 std::move(embed_frame)); |
| 304 std::move(embed_frame), | |
| 305 base::Bind(&NoOpDrawCallback)); | |
| 306 display_->DrawAndSwap(); | 292 display_->DrawAndSwap(); |
| 307 } else { | 293 } else { |
| 308 // For hardware draws we send the whole frame to the client so it can draw | 294 // For hardware draws we send the whole frame to the client so it can draw |
| 309 // the content in it. | 295 // the content in it. |
| 310 submit_frame = std::move(frame); | 296 submit_frame = std::move(frame); |
| 311 } | 297 } |
| 312 | 298 |
| 313 sync_client_->SubmitCompositorFrame(compositor_frame_sink_id_, | 299 sync_client_->SubmitCompositorFrame(compositor_frame_sink_id_, |
| 314 std::move(submit_frame)); | 300 std::move(submit_frame)); |
| 315 DeliverMessages(); | 301 DeliverMessages(); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 | 444 |
| 459 bool SynchronousCompositorFrameSink::Send(IPC::Message* message) { | 445 bool SynchronousCompositorFrameSink::Send(IPC::Message* message) { |
| 460 DCHECK(CalledOnValidThread()); | 446 DCHECK(CalledOnValidThread()); |
| 461 return sender_->Send(message); | 447 return sender_->Send(message); |
| 462 } | 448 } |
| 463 | 449 |
| 464 bool SynchronousCompositorFrameSink::CalledOnValidThread() const { | 450 bool SynchronousCompositorFrameSink::CalledOnValidThread() const { |
| 465 return thread_checker_.CalledOnValidThread(); | 451 return thread_checker_.CalledOnValidThread(); |
| 466 } | 452 } |
| 467 | 453 |
| 468 void SynchronousCompositorFrameSink::ReturnResources( | 454 void SynchronousCompositorFrameSink::DidReceiveCompositorFrameAck() {} |
| 455 | |
| 456 void SynchronousCompositorFrameSink::OnBeginFrame( | |
| 457 const cc::BeginFrameArgs& args) {} | |
| 458 | |
| 459 void SynchronousCompositorFrameSink::ReclaimResources( | |
| 469 const cc::ReturnedResourceArray& resources) { | 460 const cc::ReturnedResourceArray& resources) { |
| 470 DCHECK(resources.empty()); | 461 DCHECK(resources.empty()); |
| 471 client_->ReclaimResources(resources); | 462 client_->ReclaimResources(resources); |
| 472 } | 463 } |
| 473 | 464 |
| 474 void SynchronousCompositorFrameSink::SetBeginFrameSource( | 465 void SynchronousCompositorFrameSink::WillDrawSurface() {} |
| 475 cc::BeginFrameSource* begin_frame_source) { | |
| 476 // Software output is synchronous and doesn't use a BeginFrameSource. | |
| 477 NOTREACHED(); | |
| 478 } | |
| 479 | 466 |
| 480 } // namespace content | 467 } // namespace content |
| OLD | NEW |