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" |
(...skipping 11 matching lines...) Expand all Loading... |
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 frame_sink_id_(frame_sink_id), |
31 surface_manager_(surface_manager), | 31 surface_manager_(surface_manager), |
32 display_(display) { | 32 display_(display), |
| 33 factory_(frame_sink_id, surface_manager, this) { |
33 DCHECK(thread_checker_.CalledOnValidThread()); | 34 DCHECK(thread_checker_.CalledOnValidThread()); |
34 capabilities_.can_force_reclaim_resources = true; | 35 capabilities_.can_force_reclaim_resources = true; |
35 // Display and DirectCompositorFrameSink share a GL context, so sync | 36 // Display and DirectCompositorFrameSink share a GL context, so sync |
36 // points aren't needed when passing resources between them. | 37 // points aren't needed when passing resources between them. |
37 capabilities_.delegated_sync_points_required = false; | 38 capabilities_.delegated_sync_points_required = false; |
| 39 factory_.set_needs_sync_points(false); |
38 } | 40 } |
39 | 41 |
40 DirectCompositorFrameSink::DirectCompositorFrameSink( | 42 DirectCompositorFrameSink::DirectCompositorFrameSink( |
41 const FrameSinkId& frame_sink_id, | 43 const FrameSinkId& frame_sink_id, |
42 SurfaceManager* surface_manager, | 44 SurfaceManager* surface_manager, |
43 Display* display, | 45 Display* display, |
44 scoped_refptr<VulkanContextProvider> vulkan_context_provider) | 46 scoped_refptr<VulkanContextProvider> vulkan_context_provider) |
45 : CompositorFrameSink(std::move(vulkan_context_provider)), | 47 : CompositorFrameSink(std::move(vulkan_context_provider)), |
46 frame_sink_id_(frame_sink_id), | 48 frame_sink_id_(frame_sink_id), |
47 surface_manager_(surface_manager), | 49 surface_manager_(surface_manager), |
48 display_(display) { | 50 display_(display), |
| 51 factory_(frame_sink_id_, surface_manager, this) { |
49 DCHECK(thread_checker_.CalledOnValidThread()); | 52 DCHECK(thread_checker_.CalledOnValidThread()); |
50 capabilities_.can_force_reclaim_resources = true; | 53 capabilities_.can_force_reclaim_resources = true; |
51 } | 54 } |
52 | 55 |
53 DirectCompositorFrameSink::~DirectCompositorFrameSink() { | 56 DirectCompositorFrameSink::~DirectCompositorFrameSink() { |
54 DCHECK(thread_checker_.CalledOnValidThread()); | 57 DCHECK(thread_checker_.CalledOnValidThread()); |
55 } | 58 } |
56 | 59 |
57 bool DirectCompositorFrameSink::BindToClient( | 60 bool DirectCompositorFrameSink::BindToClient( |
58 CompositorFrameSinkClient* client) { | 61 CompositorFrameSinkClient* client) { |
59 DCHECK(thread_checker_.CalledOnValidThread()); | 62 DCHECK(thread_checker_.CalledOnValidThread()); |
60 | 63 |
61 if (!CompositorFrameSink::BindToClient(client)) | 64 if (!CompositorFrameSink::BindToClient(client)) |
62 return false; | 65 return false; |
63 | 66 |
| 67 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); |
| 68 |
64 // We want the Display's output surface to hear about lost context, and since | 69 // We want the Display's output surface to hear about lost context, and since |
65 // this shares a context with it, we should not be listening for lost context | 70 // this shares a context with it, we should not be listening for lost context |
66 // callbacks on the context here. | 71 // callbacks on the context here. |
67 if (auto* cp = context_provider()) | 72 if (auto* cp = context_provider()) |
68 cp->SetLostContextCallback(base::Closure()); | 73 cp->SetLostContextCallback(base::Closure()); |
69 | 74 |
70 constexpr bool is_root = true; | |
71 constexpr bool handles_frame_sink_id_invalidation = false; | |
72 support_ = base::MakeUnique<CompositorFrameSinkSupport>( | |
73 this, surface_manager_, frame_sink_id_, is_root, | |
74 handles_frame_sink_id_invalidation, | |
75 capabilities_.delegated_sync_points_required); | |
76 begin_frame_source_ = base::MakeUnique<ExternalBeginFrameSource>(this); | |
77 client_->SetBeginFrameSource(begin_frame_source_.get()); | |
78 | |
79 // Avoid initializing GL context here, as this should be sharing the | 75 // Avoid initializing GL context here, as this should be sharing the |
80 // Display's context. | 76 // Display's context. |
81 display_->Initialize(this, surface_manager_); | 77 display_->Initialize(this, surface_manager_); |
82 return true; | 78 return true; |
83 } | 79 } |
84 | 80 |
85 void DirectCompositorFrameSink::DetachFromClient() { | 81 void DirectCompositorFrameSink::DetachFromClient() { |
86 client_->SetBeginFrameSource(nullptr); | |
87 begin_frame_source_.reset(); | |
88 | |
89 // Unregister the SurfaceFactoryClient here instead of the dtor so that only | 82 // Unregister the SurfaceFactoryClient here instead of the dtor so that only |
90 // one client is alive for this namespace at any given time. | 83 // one client is alive for this namespace at any given time. |
91 support_.reset(); | 84 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); |
| 85 factory_.EvictSurface(); |
92 | 86 |
93 CompositorFrameSink::DetachFromClient(); | 87 CompositorFrameSink::DetachFromClient(); |
94 } | 88 } |
95 | 89 |
96 void DirectCompositorFrameSink::SubmitCompositorFrame(CompositorFrame frame) { | 90 void DirectCompositorFrameSink::SubmitCompositorFrame(CompositorFrame frame) { |
97 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); | 91 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); |
98 if (frame_size.IsEmpty() || frame_size != last_swap_frame_size_) { | 92 if (frame_size.IsEmpty() || frame_size != last_swap_frame_size_) { |
99 delegated_local_surface_id_ = surface_id_allocator_.GenerateId(); | 93 delegated_local_surface_id_ = surface_id_allocator_.GenerateId(); |
100 last_swap_frame_size_ = frame_size; | 94 last_swap_frame_size_ = frame_size; |
101 } | 95 } |
102 display_->SetLocalSurfaceId(delegated_local_surface_id_, | 96 display_->SetLocalSurfaceId(delegated_local_surface_id_, |
103 frame.metadata.device_scale_factor); | 97 frame.metadata.device_scale_factor); |
104 | 98 |
105 support_->SubmitCompositorFrame(delegated_local_surface_id_, | 99 factory_.SubmitCompositorFrame( |
106 std::move(frame)); | 100 delegated_local_surface_id_, std::move(frame), |
| 101 base::Bind(&DirectCompositorFrameSink::DidDrawCallback, |
| 102 base::Unretained(this))); |
107 } | 103 } |
108 | 104 |
109 void DirectCompositorFrameSink::ForceReclaimResources() { | 105 void DirectCompositorFrameSink::ForceReclaimResources() { |
110 support_->ForceReclaimResources(); | 106 if (delegated_local_surface_id_.is_valid()) |
| 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); |
111 } | 120 } |
112 | 121 |
113 void DirectCompositorFrameSink::DisplayOutputSurfaceLost() { | 122 void DirectCompositorFrameSink::DisplayOutputSurfaceLost() { |
114 is_lost_ = true; | 123 is_lost_ = true; |
115 client_->DidLoseCompositorFrameSink(); | 124 client_->DidLoseCompositorFrameSink(); |
116 } | 125 } |
117 | 126 |
118 void DirectCompositorFrameSink::DisplayWillDrawAndSwap( | 127 void DirectCompositorFrameSink::DisplayWillDrawAndSwap( |
119 bool will_draw_and_swap, | 128 bool will_draw_and_swap, |
120 const RenderPassList& render_passes) { | 129 const RenderPassList& render_passes) { |
121 // This notification is not relevant to our client outside of tests. | 130 // This notification is not relevant to our client outside of tests. |
122 } | 131 } |
123 | 132 |
124 void DirectCompositorFrameSink::DisplayDidDrawAndSwap() { | 133 void DirectCompositorFrameSink::DisplayDidDrawAndSwap() { |
125 // This notification is not relevant to our client outside of tests. We | 134 // This notification is not relevant to our client outside of tests. We |
126 // unblock the client from DidDrawCallback() when the surface is going to | 135 // unblock the client from DidDrawCallback() when the surface is going to |
127 // be drawn. | 136 // be drawn. |
128 } | 137 } |
129 | 138 |
130 void DirectCompositorFrameSink::DidReceiveCompositorFrameAck() { | 139 void DirectCompositorFrameSink::DidDrawCallback() { |
131 client_->DidReceiveCompositorFrameAck(); | 140 client_->DidReceiveCompositorFrameAck(); |
132 } | 141 } |
133 | 142 |
134 void DirectCompositorFrameSink::OnBeginFrame(const BeginFrameArgs& args) { | |
135 begin_frame_source_->OnBeginFrame(args); | |
136 } | |
137 | |
138 void DirectCompositorFrameSink::ReclaimResources( | |
139 const ReturnedResourceArray& resources) { | |
140 client_->ReclaimResources(resources); | |
141 } | |
142 | |
143 void DirectCompositorFrameSink::WillDrawSurface( | |
144 const LocalSurfaceId& local_surface_id, | |
145 const gfx::Rect& damage_rect) { | |
146 // TODO(staraz): Implement this. | |
147 } | |
148 | |
149 void DirectCompositorFrameSink::OnNeedsBeginFrames(bool needs_begin_frame) { | |
150 support_->SetNeedsBeginFrame(needs_begin_frame); | |
151 } | |
152 | |
153 } // namespace cc | 143 } // namespace cc |
OLD | NEW |