OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "services/ui/surfaces/display_compositor.h" | 5 #include "services/ui/surfaces/display_compositor.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "cc/output/in_process_context_provider.h" | 9 #include "cc/output/in_process_context_provider.h" |
10 #include "cc/output/texture_mailbox_deleter.h" | 10 #include "cc/output/texture_mailbox_deleter.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 } | 85 } |
86 | 86 |
87 void DisplayCompositor::OnCompositorFrameSinkPrivateConnectionLost( | 87 void DisplayCompositor::OnCompositorFrameSinkPrivateConnectionLost( |
88 const cc::FrameSinkId& frame_sink_id, | 88 const cc::FrameSinkId& frame_sink_id, |
89 bool destroy_compositor_frame_sink) { | 89 bool destroy_compositor_frame_sink) { |
90 DCHECK(thread_checker_.CalledOnValidThread()); | 90 DCHECK(thread_checker_.CalledOnValidThread()); |
91 if (destroy_compositor_frame_sink) | 91 if (destroy_compositor_frame_sink) |
92 compositor_frame_sinks_.erase(frame_sink_id); | 92 compositor_frame_sinks_.erase(frame_sink_id); |
93 } | 93 } |
94 | 94 |
95 void DisplayCompositor::CreateCompositorFrameSink( | 95 void DisplayCompositor::CreateDisplayCompositorFrameSink( |
96 const cc::FrameSinkId& frame_sink_id, | 96 const cc::FrameSinkId& frame_sink_id, |
97 gpu::SurfaceHandle surface_handle, | 97 gpu::SurfaceHandle surface_handle, |
98 cc::mojom::MojoCompositorFrameSinkRequest request, | 98 cc::mojom::MojoCompositorFrameSinkRequest request, |
99 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, | 99 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, |
100 cc::mojom::MojoCompositorFrameSinkClientPtr client) { | 100 cc::mojom::MojoCompositorFrameSinkClientPtr client) { |
101 DCHECK(thread_checker_.CalledOnValidThread()); | 101 DCHECK(thread_checker_.CalledOnValidThread()); |
102 // We cannot create more than one CompositorFrameSink with a given | 102 DCHECK_NE(surface_handle, gpu::kNullSurfaceHandle); |
103 // |frame_sink_id|. | 103 std::unique_ptr<cc::SyntheticBeginFrameSource> begin_frame_source( |
104 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); | 104 new cc::DelayBasedBeginFrameSource( |
105 base::MakeUnique<cc::DelayBasedTimeSource>(task_runner_.get()))); | |
106 CreateCompositorFrameSinkInternal( | |
107 frame_sink_id, surface_handle, | |
108 CreateDisplay(frame_sink_id, surface_handle, begin_frame_source.get()), | |
Fady Samuel
2016/12/15 14:43:44
store this in a local variable above to make sure
Alex Z.
2016/12/15 15:17:51
Done.
| |
109 std::move(begin_frame_source), std::move(request), | |
110 std::move(private_request), std::move(client)); | |
111 } | |
105 | 112 |
106 std::unique_ptr<cc::Display> display; | 113 void DisplayCompositor::CreateOffscreenCompositorFrameSink( |
107 std::unique_ptr<cc::SyntheticBeginFrameSource> begin_frame_source; | 114 const cc::FrameSinkId& frame_sink_id, |
108 if (surface_handle != gpu::kNullSurfaceHandle) { | 115 cc::mojom::MojoCompositorFrameSinkRequest request, |
109 begin_frame_source.reset(new cc::DelayBasedBeginFrameSource( | 116 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, |
110 base::MakeUnique<cc::DelayBasedTimeSource>(task_runner_.get()))); | 117 cc::mojom::MojoCompositorFrameSinkClientPtr client) { |
111 display = | 118 CreateCompositorFrameSinkInternal( |
112 CreateDisplay(frame_sink_id, surface_handle, begin_frame_source.get()); | 119 frame_sink_id, gpu::kNullSurfaceHandle, nullptr, nullptr, |
113 } | 120 std::move(request), std::move(private_request), std::move(client)); |
114 | |
115 compositor_frame_sinks_[frame_sink_id] = | |
116 base::MakeUnique<GpuCompositorFrameSink>( | |
117 this, frame_sink_id, std::move(display), | |
118 std::move(begin_frame_source), std::move(request), | |
119 std::move(private_request), std::move(client)); | |
120 } | 121 } |
121 | 122 |
122 void DisplayCompositor::AddSurfaceReference(const cc::SurfaceReference& ref) { | 123 void DisplayCompositor::AddSurfaceReference(const cc::SurfaceReference& ref) { |
123 const cc::SurfaceId& parent_id = ref.parent_id(); | 124 const cc::SurfaceId& parent_id = ref.parent_id(); |
124 const cc::SurfaceId& child_id = ref.child_id(); | 125 const cc::SurfaceId& child_id = ref.child_id(); |
125 | 126 |
126 auto vector_iter = temp_references_.find(child_id.frame_sink_id()); | 127 auto vector_iter = temp_references_.find(child_id.frame_sink_id()); |
127 | 128 |
128 // If there are no temporary references for the FrameSinkId then we can just | 129 // If there are no temporary references for the FrameSinkId then we can just |
129 // add reference and return. | 130 // add reference and return. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 std::unique_ptr<cc::DisplayScheduler> scheduler( | 212 std::unique_ptr<cc::DisplayScheduler> scheduler( |
212 new cc::DisplayScheduler(task_runner_.get(), max_frames_pending)); | 213 new cc::DisplayScheduler(task_runner_.get(), max_frames_pending)); |
213 | 214 |
214 return base::MakeUnique<cc::Display>( | 215 return base::MakeUnique<cc::Display>( |
215 nullptr /* bitmap_manager */, gpu_memory_buffer_manager_.get(), | 216 nullptr /* bitmap_manager */, gpu_memory_buffer_manager_.get(), |
216 cc::RendererSettings(), frame_sink_id, begin_frame_source, | 217 cc::RendererSettings(), frame_sink_id, begin_frame_source, |
217 std::move(display_output_surface), std::move(scheduler), | 218 std::move(display_output_surface), std::move(scheduler), |
218 base::MakeUnique<cc::TextureMailboxDeleter>(task_runner_.get())); | 219 base::MakeUnique<cc::TextureMailboxDeleter>(task_runner_.get())); |
219 } | 220 } |
220 | 221 |
222 void DisplayCompositor::CreateCompositorFrameSinkInternal( | |
223 const cc::FrameSinkId& frame_sink_id, | |
224 gpu::SurfaceHandle surface_handle, | |
225 std::unique_ptr<cc::Display> display, | |
226 std::unique_ptr<cc::SyntheticBeginFrameSource> begin_frame_source, | |
227 cc::mojom::MojoCompositorFrameSinkRequest request, | |
228 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, | |
229 cc::mojom::MojoCompositorFrameSinkClientPtr client) { | |
230 DCHECK(thread_checker_.CalledOnValidThread()); | |
231 // We cannot create more than one CompositorFrameSink with a given | |
232 // |frame_sink_id|. | |
233 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); | |
234 | |
235 compositor_frame_sinks_[frame_sink_id] = | |
236 base::MakeUnique<GpuCompositorFrameSink>( | |
237 this, frame_sink_id, std::move(display), | |
238 std::move(begin_frame_source), std::move(request), | |
239 std::move(private_request), std::move(client)); | |
240 } | |
241 | |
221 const cc::SurfaceId& DisplayCompositor::GetRootSurfaceId() const { | 242 const cc::SurfaceId& DisplayCompositor::GetRootSurfaceId() const { |
222 return reference_manager_->GetRootSurfaceId(); | 243 return reference_manager_->GetRootSurfaceId(); |
223 } | 244 } |
224 | 245 |
225 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id, | 246 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id, |
226 const gfx::Size& frame_size, | 247 const gfx::Size& frame_size, |
227 float device_scale_factor) { | 248 float device_scale_factor) { |
228 DCHECK(thread_checker_.CalledOnValidThread()); | 249 DCHECK(thread_checker_.CalledOnValidThread()); |
229 // We can get into a situation where multiple CompositorFrames arrive for a | 250 // We can get into a situation where multiple CompositorFrames arrive for a |
230 // CompositorFrameSink before the DisplayCompositorClient can add any | 251 // CompositorFrameSink before the DisplayCompositorClient can add any |
231 // references for the frame. When the second frame with a new size arrives, | 252 // references for the frame. When the second frame with a new size arrives, |
232 // the first will be destroyed and then if there are no references it will be | 253 // the first will be destroyed and then if there are no references it will be |
233 // deleted during surface GC. A temporary reference, removed when a real | 254 // deleted during surface GC. A temporary reference, removed when a real |
234 // reference is received, is added to prevent this from happening. | 255 // reference is received, is added to prevent this from happening. |
235 reference_manager_->AddSurfaceReference(GetRootSurfaceId(), surface_id); | 256 reference_manager_->AddSurfaceReference(GetRootSurfaceId(), surface_id); |
236 temp_references_[surface_id.frame_sink_id()].push_back( | 257 temp_references_[surface_id.frame_sink_id()].push_back( |
237 surface_id.local_frame_id()); | 258 surface_id.local_frame_id()); |
238 | 259 |
239 if (client_) | 260 if (client_) |
240 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); | 261 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); |
241 } | 262 } |
242 | 263 |
243 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, | 264 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, |
244 bool* changed) {} | 265 bool* changed) {} |
245 | 266 |
246 } // namespace ui | 267 } // namespace ui |
OLD | NEW |