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" |
11 #include "cc/surfaces/display.h" | 11 #include "cc/surfaces/display.h" |
12 #include "cc/surfaces/display_scheduler.h" | 12 #include "cc/surfaces/display_scheduler.h" |
13 #include "cc/surfaces/surface.h" | 13 #include "cc/surfaces/surface.h" |
14 #include "gpu/command_buffer/client/shared_memory_limits.h" | 14 #include "gpu/command_buffer/client/shared_memory_limits.h" |
15 #include "gpu/ipc/gpu_in_process_thread_service.h" | 15 #include "gpu/ipc/gpu_in_process_thread_service.h" |
16 #include "mojo/public/cpp/bindings/strong_binding.h" | 16 #include "mojo/public/cpp/bindings/strong_binding.h" |
17 #include "services/ui/surfaces/display_output_surface.h" | 17 #include "services/ui/surfaces/display_output_surface.h" |
18 #include "services/ui/surfaces/gpu_compositor_frame_sink.h" | 18 #include "services/ui/surfaces/gpu_compositor_frame_sink.h" |
19 | 19 |
20 #if defined(USE_OZONE) | 20 #if defined(USE_OZONE) |
21 #include "gpu/command_buffer/client/gles2_interface.h" | 21 #include "gpu/command_buffer/client/gles2_interface.h" |
22 #include "services/ui/surfaces/display_output_surface_ozone.h" | 22 #include "services/ui/surfaces/display_output_surface_ozone.h" |
23 #endif | 23 #endif |
24 | 24 |
25 namespace ui { | 25 namespace ui { |
26 | 26 |
27 DisplayCompositor::DisplayCompositor( | 27 DisplayCompositor::DisplayCompositor( |
28 scoped_refptr<gpu::InProcessCommandBuffer::Service> gpu_service, | 28 scoped_refptr<gpu::InProcessCommandBuffer::Service> gpu_service, |
29 std::unique_ptr<gpu::GpuMemoryBufferManager> gpu_memory_buffer_manager, | 29 std::unique_ptr<gpu::GpuMemoryBufferManager> gpu_memory_buffer_manager, |
30 gpu::ImageFactory* image_factory, | 30 gpu::ImageFactory* image_factory, |
31 cc::mojom::DisplayCompositorRequest request, | 31 cc::mojom::DisplayCompositorRequest request, |
32 cc::mojom::DisplayCompositorClientPtr client) | 32 cc::mojom::DisplayCompositorClientPtr client) |
33 : manager_(cc::SurfaceManager::LifetimeType::REFERENCES), | 33 : manager_(cc::SurfaceManager::LifetimeType::REFERENCES), |
34 reference_manager_(&manager_), | 34 reference_manager_(&manager_), |
35 gpu_service_(std::move(gpu_service)), | 35 gpu_service_(std::move(gpu_service)), |
(...skipping 49 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, gpu::SurfaceHandle surface_handle, |
97 gpu::SurfaceHandle surface_handle, | |
98 cc::mojom::MojoCompositorFrameSinkRequest request, | 97 cc::mojom::MojoCompositorFrameSinkRequest request, |
99 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, | 98 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, |
100 cc::mojom::MojoCompositorFrameSinkClientPtr client) { | 99 cc::mojom::MojoCompositorFrameSinkClientPtr client) { |
101 DCHECK(thread_checker_.CalledOnValidThread()); | 100 DCHECK(thread_checker_.CalledOnValidThread()); |
102 // We cannot create more than one CompositorFrameSink with a given | 101 DCHECK_NE(surface_handle, gpu::kNullSurfaceHandle); |
103 // |frame_sink_id|. | 102 std::unique_ptr<cc::SyntheticBeginFrameSource> begin_frame_source( |
104 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); | 103 new cc::DelayBasedBeginFrameSource( |
| 104 base::MakeUnique<cc::DelayBasedTimeSource>(task_runner_.get()))); |
| 105 std::unique_ptr<cc::Display> display = |
| 106 CreateDisplay(frame_sink_id, surface_handle, begin_frame_source.get()); |
| 107 CreateCompositorFrameSinkInternal( |
| 108 frame_sink_id, surface_handle, std::move(display), |
| 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, gpu::SurfaceHandle surface_handle, |
| 224 std::unique_ptr<cc::Display> display, |
| 225 std::unique_ptr<cc::SyntheticBeginFrameSource> begin_frame_source, |
| 226 cc::mojom::MojoCompositorFrameSinkRequest request, |
| 227 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, |
| 228 cc::mojom::MojoCompositorFrameSinkClientPtr client) { |
| 229 DCHECK(thread_checker_.CalledOnValidThread()); |
| 230 // We cannot create more than one CompositorFrameSink with a given |
| 231 // |frame_sink_id|. |
| 232 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); |
| 233 |
| 234 compositor_frame_sinks_[frame_sink_id] = |
| 235 base::MakeUnique<GpuCompositorFrameSink>( |
| 236 this, frame_sink_id, std::move(display), |
| 237 std::move(begin_frame_source), std::move(request), |
| 238 std::move(private_request), std::move(client)); |
| 239 } |
| 240 |
221 const cc::SurfaceId& DisplayCompositor::GetRootSurfaceId() const { | 241 const cc::SurfaceId& DisplayCompositor::GetRootSurfaceId() const { |
222 return reference_manager_->GetRootSurfaceId(); | 242 return reference_manager_->GetRootSurfaceId(); |
223 } | 243 } |
224 | 244 |
225 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id, | 245 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id, |
226 const gfx::Size& frame_size, | 246 const gfx::Size& frame_size, |
227 float device_scale_factor) { | 247 float device_scale_factor) { |
228 DCHECK(thread_checker_.CalledOnValidThread()); | 248 DCHECK(thread_checker_.CalledOnValidThread()); |
229 // We can get into a situation where multiple CompositorFrames arrive for a | 249 // We can get into a situation where multiple CompositorFrames arrive for a |
230 // CompositorFrameSink before the DisplayCompositorClient can add any | 250 // CompositorFrameSink before the DisplayCompositorClient can add any |
231 // references for the frame. When the second frame with a new size arrives, | 251 // 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 | 252 // 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 | 253 // deleted during surface GC. A temporary reference, removed when a real |
234 // reference is received, is added to prevent this from happening. | 254 // reference is received, is added to prevent this from happening. |
235 reference_manager_->AddSurfaceReference(GetRootSurfaceId(), surface_id); | 255 reference_manager_->AddSurfaceReference(GetRootSurfaceId(), surface_id); |
236 temp_references_[surface_id.frame_sink_id()].push_back( | 256 temp_references_[surface_id.frame_sink_id()].push_back( |
237 surface_id.local_frame_id()); | 257 surface_id.local_frame_id()); |
238 | 258 |
239 if (client_) | 259 if (client_) |
240 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); | 260 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); |
241 } | 261 } |
242 | 262 |
243 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, | 263 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, |
244 bool* changed) {} | 264 bool* changed) {} |
245 | 265 |
246 } // namespace ui | 266 } // namespace ui |
OLD | NEW |