Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/surfaces/direct_compositor_frame_sink.h" | 5 #include "cc/surfaces/direct_compositor_frame_sink.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "cc/output/compositor_frame.h" | 8 #include "cc/output/compositor_frame.h" |
| 9 #include "cc/output/compositor_frame_sink_client.h" | 9 #include "cc/output/compositor_frame_sink_client.h" |
| 10 #include "cc/surfaces/display.h" | 10 #include "cc/surfaces/display.h" |
| 11 #include "cc/surfaces/frame_sink_id.h" | 11 #include "cc/surfaces/frame_sink_id.h" |
| 12 #include "cc/surfaces/surface.h" | 12 #include "cc/surfaces/surface.h" |
| 13 #include "cc/surfaces/surface_id_allocator.h" | 13 #include "cc/surfaces/surface_id_allocator.h" |
| 14 #include "cc/surfaces/surface_manager.h" | 14 #include "cc/surfaces/surface_manager.h" |
| 15 | 15 |
| 16 namespace cc { | 16 namespace cc { |
| 17 | 17 |
| 18 DirectCompositorFrameSink::DirectCompositorFrameSink( | 18 DirectCompositorFrameSink::DirectCompositorFrameSink( |
| 19 const FrameSinkId& frame_sink_id, | 19 const FrameSinkId& frame_sink_id, |
| 20 SurfaceManager* surface_manager, | 20 SurfaceManager* surface_manager, |
| 21 Display* display, | 21 Display* display, |
| 22 scoped_refptr<ContextProvider> context_provider, | 22 scoped_refptr<ContextProvider> context_provider, |
| 23 scoped_refptr<ContextProvider> worker_context_provider, | 23 scoped_refptr<ContextProvider> worker_context_provider, |
| 24 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 24 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 25 SharedBitmapManager* shared_bitmap_manager) | 25 SharedBitmapManager* shared_bitmap_manager) |
| 26 : CompositorFrameSink(std::move(context_provider), | 26 : CompositorFrameSink(std::move(context_provider), |
| 27 std::move(worker_context_provider), | 27 std::move(worker_context_provider), |
| 28 gpu_memory_buffer_manager, | 28 gpu_memory_buffer_manager, |
| 29 shared_bitmap_manager), | 29 shared_bitmap_manager), |
| 30 frame_sink_id_(frame_sink_id), | 30 support_(this, |
| 31 surface_manager_(surface_manager), | 31 surface_manager, |
| 32 display_(display), | 32 frame_sink_id, |
| 33 factory_(frame_sink_id, surface_manager, this) { | 33 std::move(display), |
| 34 nullptr) { | |
| 34 DCHECK(thread_checker_.CalledOnValidThread()); | 35 DCHECK(thread_checker_.CalledOnValidThread()); |
| 35 capabilities_.can_force_reclaim_resources = true; | 36 capabilities_.can_force_reclaim_resources = true; |
| 36 // Display and DirectCompositorFrameSink share a GL context, so sync | 37 // Display and DirectCompositorFrameSink share a GL context, so sync |
| 37 // points aren't needed when passing resources between them. | 38 // points aren't needed when passing resources between them. |
| 38 capabilities_.delegated_sync_points_required = false; | 39 capabilities_.delegated_sync_points_required = false; |
| 39 factory_.set_needs_sync_points(false); | 40 support_.SetFactoryNeedsSyncPoints(false); |
| 40 } | 41 } |
| 41 | 42 |
| 42 DirectCompositorFrameSink::DirectCompositorFrameSink( | 43 DirectCompositorFrameSink::DirectCompositorFrameSink( |
| 43 const FrameSinkId& frame_sink_id, | 44 const FrameSinkId& frame_sink_id, |
| 44 SurfaceManager* surface_manager, | 45 SurfaceManager* surface_manager, |
| 45 Display* display, | 46 Display* display, |
| 46 scoped_refptr<VulkanContextProvider> vulkan_context_provider) | 47 scoped_refptr<VulkanContextProvider> vulkan_context_provider) |
| 47 : CompositorFrameSink(std::move(vulkan_context_provider)), | 48 : CompositorFrameSink(std::move(vulkan_context_provider)), |
| 48 frame_sink_id_(frame_sink_id), | 49 support_(this, |
| 49 surface_manager_(surface_manager), | 50 surface_manager, |
| 50 display_(display), | 51 frame_sink_id, |
| 51 factory_(frame_sink_id_, surface_manager, this) { | 52 std::move(display), |
| 53 nullptr) { | |
| 52 DCHECK(thread_checker_.CalledOnValidThread()); | 54 DCHECK(thread_checker_.CalledOnValidThread()); |
| 53 capabilities_.can_force_reclaim_resources = true; | 55 capabilities_.can_force_reclaim_resources = true; |
| 54 } | 56 } |
| 55 | 57 |
| 56 DirectCompositorFrameSink::~DirectCompositorFrameSink() { | 58 DirectCompositorFrameSink::~DirectCompositorFrameSink() { |
| 57 DCHECK(thread_checker_.CalledOnValidThread()); | 59 DCHECK(thread_checker_.CalledOnValidThread()); |
| 58 } | 60 } |
| 59 | 61 |
| 60 bool DirectCompositorFrameSink::BindToClient( | 62 bool DirectCompositorFrameSink::BindToClient( |
| 61 CompositorFrameSinkClient* client) { | 63 CompositorFrameSinkClient* client) { |
| 62 DCHECK(thread_checker_.CalledOnValidThread()); | 64 DCHECK(thread_checker_.CalledOnValidThread()); |
| 63 | 65 |
| 64 if (!CompositorFrameSink::BindToClient(client)) | 66 if (!CompositorFrameSink::BindToClient(client)) |
| 65 return false; | 67 return false; |
| 66 | 68 |
| 67 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); | 69 support_.BindToClient(); |
|
Fady Samuel
2017/01/04 20:59:25
Create support_ here instead. Use a unique_ptr.
| |
| 68 | |
| 69 // We want the Display's output surface to hear about lost context, and since | 70 // We want the Display's output surface to hear about lost context, and since |
| 70 // this shares a context with it, we should not be listening for lost context | 71 // this shares a context with it, we should not be listening for lost context |
| 71 // callbacks on the context here. | 72 // callbacks on the context here. |
| 72 if (auto* cp = context_provider()) | 73 if (auto* cp = context_provider()) |
| 73 cp->SetLostContextCallback(base::Closure()); | 74 cp->SetLostContextCallback(base::Closure()); |
| 74 | 75 |
| 75 // Avoid initializing GL context here, as this should be sharing the | 76 // Avoid initializing GL context here, as this should be sharing the |
| 76 // Display's context. | 77 // Display's context. |
| 77 display_->Initialize(this, surface_manager_); | |
| 78 return true; | 78 return true; |
| 79 } | 79 } |
| 80 | 80 |
| 81 void DirectCompositorFrameSink::DetachFromClient() { | 81 void DirectCompositorFrameSink::DetachFromClient() { |
| 82 // Unregister the SurfaceFactoryClient here instead of the dtor so that only | 82 support_.DetachFromClient(); |
|
Fady Samuel
2017/01/04 20:59:25
support_.reset()
support_ is a unique_ptr.
| |
| 83 // one client is alive for this namespace at any given time. | |
| 84 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); | |
| 85 factory_.EvictSurface(); | |
| 86 | |
| 87 CompositorFrameSink::DetachFromClient(); | 83 CompositorFrameSink::DetachFromClient(); |
| 88 } | 84 } |
| 89 | 85 |
| 90 void DirectCompositorFrameSink::SubmitCompositorFrame(CompositorFrame frame) { | 86 void DirectCompositorFrameSink::SubmitCompositorFrame(CompositorFrame frame) { |
| 91 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); | 87 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); |
| 92 if (frame_size.IsEmpty() || frame_size != last_swap_frame_size_) { | 88 if (frame_size.IsEmpty() || frame_size != last_swap_frame_size_) { |
| 93 delegated_local_frame_id_ = surface_id_allocator_.GenerateId(); | 89 delegated_local_frame_id_ = surface_id_allocator_.GenerateId(); |
| 94 last_swap_frame_size_ = frame_size; | 90 last_swap_frame_size_ = frame_size; |
| 95 } | 91 } |
| 96 display_->SetLocalFrameId(delegated_local_frame_id_, | 92 support_.SubmitCompositorFrame(delegated_local_frame_id_, std::move(frame)); |
| 97 frame.metadata.device_scale_factor); | |
| 98 | |
| 99 factory_.SubmitCompositorFrame( | |
| 100 delegated_local_frame_id_, std::move(frame), | |
| 101 base::Bind(&DirectCompositorFrameSink::DidDrawCallback, | |
| 102 base::Unretained(this))); | |
| 103 } | 93 } |
| 104 | 94 |
| 105 void DirectCompositorFrameSink::ForceReclaimResources() { | 95 void DirectCompositorFrameSink::ForceReclaimResources() { |
| 106 if (delegated_local_frame_id_.is_valid()) | 96 support_.ForceReclaimResources(); |
| 107 factory_.ClearSurface(); | |
| 108 } | |
| 109 | |
| 110 void DirectCompositorFrameSink::ReturnResources( | |
| 111 const ReturnedResourceArray& resources) { | |
| 112 if (client_) | |
| 113 client_->ReclaimResources(resources); | |
| 114 } | |
| 115 | |
| 116 void DirectCompositorFrameSink::SetBeginFrameSource( | |
| 117 BeginFrameSource* begin_frame_source) { | |
| 118 DCHECK(client_); | |
| 119 client_->SetBeginFrameSource(begin_frame_source); | |
| 120 } | 97 } |
| 121 | 98 |
| 122 void DirectCompositorFrameSink::DisplayOutputSurfaceLost() { | 99 void DirectCompositorFrameSink::DisplayOutputSurfaceLost() { |
| 123 is_lost_ = true; | 100 is_lost_ = true; |
| 124 client_->DidLoseCompositorFrameSink(); | 101 client_->DidLoseCompositorFrameSink(); |
| 125 } | 102 } |
| 126 | 103 |
| 127 void DirectCompositorFrameSink::DisplayWillDrawAndSwap( | 104 void DirectCompositorFrameSink::DisplayWillDrawAndSwap( |
| 128 bool will_draw_and_swap, | 105 bool will_draw_and_swap, |
| 129 const RenderPassList& render_passes) { | 106 const RenderPassList& render_passes) { |
| 130 // This notification is not relevant to our client outside of tests. | 107 // This notification is not relevant to our client outside of tests. |
| 131 } | 108 } |
| 132 | 109 |
| 133 void DirectCompositorFrameSink::DisplayDidDrawAndSwap() { | 110 void DirectCompositorFrameSink::DisplayDidDrawAndSwap() { |
| 134 // This notification is not relevant to our client outside of tests. We | 111 // This notification is not relevant to our client outside of tests. We |
| 135 // unblock the client from DidDrawCallback() when the surface is going to | 112 // unblock the client from DidDrawCallback() when the surface is going to |
| 136 // be drawn. | 113 // be drawn. |
| 137 } | 114 } |
| 138 | 115 |
| 116 void DirectCompositorFrameSink::DidReceiveCompositorFrameAck() { | |
| 117 if (client_) | |
| 118 client_->DidReceiveCompositorFrameAck(); | |
| 119 } | |
| 120 | |
| 121 void DirectCompositorFrameSink::OnBeginFrame(const BeginFrameArgs& args) { | |
| 122 // TODO(staraz): Implement this. | |
| 123 NOTIMPLEMENTED(); | |
| 124 } | |
| 125 | |
| 126 void DirectCompositorFrameSink::ReclaimResources( | |
| 127 const ReturnedResourceArray& resources) { | |
| 128 if (client_) | |
| 129 client_->ReclaimResources(resources); | |
| 130 } | |
| 131 | |
| 132 void DirectCompositorFrameSink::WillDrawSurface() { | |
| 133 // TODO(staraz): Implement this. | |
| 134 } | |
| 135 | |
| 139 void DirectCompositorFrameSink::DidDrawCallback() { | 136 void DirectCompositorFrameSink::DidDrawCallback() { |
| 140 client_->DidReceiveCompositorFrameAck(); | 137 client_->DidReceiveCompositorFrameAck(); |
| 141 } | 138 } |
| 142 | 139 |
| 143 } // namespace cc | 140 } // namespace cc |
| OLD | NEW |