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/ws/gpu_compositor_frame_sink.h" | 5 #include "services/ui/surfaces/gpu_compositor_frame_sink.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
11 #include "cc/output/compositor_frame.h" | 11 #include "cc/output/compositor_frame.h" |
12 #include "cc/output/output_surface.h" | 12 #include "cc/output/output_surface.h" |
13 #include "cc/output/texture_mailbox_deleter.h" | 13 #include "cc/output/texture_mailbox_deleter.h" |
14 #include "cc/quads/shared_quad_state.h" | 14 #include "cc/quads/shared_quad_state.h" |
15 #include "cc/quads/surface_draw_quad.h" | 15 #include "cc/quads/surface_draw_quad.h" |
16 #include "cc/scheduler/begin_frame_source.h" | 16 #include "cc/scheduler/begin_frame_source.h" |
17 #include "cc/surfaces/display_scheduler.h" | 17 #include "cc/surfaces/display_scheduler.h" |
18 #include "services/ui/surfaces/direct_output_surface.h" | 18 #include "services/ui/surfaces/direct_output_surface.h" |
19 #include "services/ui/surfaces/display_compositor.h" | 19 #include "services/ui/surfaces/display_compositor.h" |
20 | 20 |
21 #if defined(USE_OZONE) | 21 #if defined(USE_OZONE) |
22 #include "gpu/command_buffer/client/gles2_interface.h" | 22 #include "gpu/command_buffer/client/gles2_interface.h" |
23 #include "services/ui/surfaces/direct_output_surface_ozone.h" | 23 #include "services/ui/surfaces/direct_output_surface_ozone.h" |
24 #endif | 24 #endif |
25 | 25 |
26 namespace ui { | 26 namespace ui { |
27 namespace ws { | |
28 | 27 |
29 GpuCompositorFrameSink::GpuCompositorFrameSink( | 28 GpuCompositorFrameSink::GpuCompositorFrameSink( |
30 scoped_refptr<DisplayCompositor> display_compositor, | 29 DisplayCompositor* display_compositor, |
31 const cc::FrameSinkId& frame_sink_id, | 30 const cc::FrameSinkId& frame_sink_id, |
32 gfx::AcceleratedWidget widget, | 31 gpu::SurfaceHandle surface_handle, |
33 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 32 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
34 scoped_refptr<SurfacesContextProvider> context_provider, | 33 scoped_refptr<cc::InProcessContextProvider> context_provider, |
35 cc::mojom::MojoCompositorFrameSinkRequest request, | 34 cc::mojom::MojoCompositorFrameSinkRequest request, |
36 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, | 35 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, |
37 cc::mojom::MojoCompositorFrameSinkClientPtr client) | 36 cc::mojom::MojoCompositorFrameSinkClientPtr client) |
38 : frame_sink_id_(frame_sink_id), | 37 : frame_sink_id_(frame_sink_id), |
39 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 38 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
40 display_compositor_(display_compositor), | 39 display_compositor_(display_compositor), |
41 surface_factory_(frame_sink_id_, display_compositor_->manager(), this), | 40 surface_factory_(frame_sink_id_, display_compositor_->manager(), this), |
42 client_(std::move(client)), | 41 client_(std::move(client)), |
43 binding_(this, std::move(request)), | 42 binding_(this, std::move(request)), |
44 private_binding_(this, std::move(private_request)) { | 43 private_binding_(this, std::move(private_request)) { |
45 display_compositor_->manager()->RegisterFrameSinkId(frame_sink_id_); | 44 display_compositor_->manager()->RegisterFrameSinkId(frame_sink_id_); |
46 display_compositor_->manager()->RegisterSurfaceFactoryClient(frame_sink_id_, | 45 display_compositor_->manager()->RegisterSurfaceFactoryClient(frame_sink_id_, |
47 this); | 46 this); |
48 | 47 |
49 if (widget != gfx::kNullAcceleratedWidget) | 48 if (surface_handle != gpu::kNullSurfaceHandle) { |
50 InitDisplay(widget, gpu_memory_buffer_manager, std::move(context_provider)); | 49 InitDisplay(surface_handle, gpu_memory_buffer_manager, |
| 50 std::move(context_provider)); |
| 51 } |
| 52 |
| 53 binding_.set_connection_error_handler(base::Bind( |
| 54 &GpuCompositorFrameSink::OnClientConnectionLost, base::Unretained(this))); |
| 55 |
| 56 private_binding_.set_connection_error_handler( |
| 57 base::Bind(&GpuCompositorFrameSink::OnPrivateConnectionLost, |
| 58 base::Unretained(this))); |
51 } | 59 } |
52 | 60 |
53 GpuCompositorFrameSink::~GpuCompositorFrameSink() { | 61 GpuCompositorFrameSink::~GpuCompositorFrameSink() { |
54 // SurfaceFactory's destructor will attempt to return resources which will | 62 // SurfaceFactory's destructor will attempt to return resources which will |
55 // call back into here and access |client_| so we should destroy | 63 // call back into here and access |client_| so we should destroy |
56 // |surface_factory_|'s resources early on. | 64 // |surface_factory_|'s resources early on. |
57 surface_factory_.DestroyAll(); | 65 surface_factory_.DestroyAll(); |
58 display_compositor_->manager()->UnregisterSurfaceFactoryClient( | 66 display_compositor_->manager()->UnregisterSurfaceFactoryClient( |
59 frame_sink_id_); | 67 frame_sink_id_); |
60 display_compositor_->manager()->InvalidateFrameSinkId(frame_sink_id_); | 68 display_compositor_->manager()->InvalidateFrameSinkId(frame_sink_id_); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 } | 117 } |
110 | 118 |
111 void GpuCompositorFrameSink::RemoveChildFrameSink( | 119 void GpuCompositorFrameSink::RemoveChildFrameSink( |
112 const cc::FrameSinkId& child_frame_sink_id) { | 120 const cc::FrameSinkId& child_frame_sink_id) { |
113 cc::SurfaceManager* surface_manager = display_compositor_->manager(); | 121 cc::SurfaceManager* surface_manager = display_compositor_->manager(); |
114 surface_manager->UnregisterFrameSinkHierarchy(frame_sink_id_, | 122 surface_manager->UnregisterFrameSinkHierarchy(frame_sink_id_, |
115 child_frame_sink_id); | 123 child_frame_sink_id); |
116 } | 124 } |
117 | 125 |
118 void GpuCompositorFrameSink::InitDisplay( | 126 void GpuCompositorFrameSink::InitDisplay( |
119 gfx::AcceleratedWidget widget, | 127 gpu::SurfaceHandle surface_handle, |
120 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 128 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
121 scoped_refptr<SurfacesContextProvider> context_provider) { | 129 scoped_refptr<cc::InProcessContextProvider> context_provider) { |
122 // TODO(rjkroege): If there is something better to do than CHECK, add it. | 130 // TODO(rjkroege): If there is something better to do than CHECK, add it. |
123 CHECK(context_provider->BindToCurrentThread()); | 131 CHECK(context_provider->BindToCurrentThread()); |
124 | 132 |
125 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source( | 133 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source( |
126 new cc::DelayBasedBeginFrameSource( | 134 new cc::DelayBasedBeginFrameSource( |
127 base::MakeUnique<cc::DelayBasedTimeSource>(task_runner_.get()))); | 135 base::MakeUnique<cc::DelayBasedTimeSource>(task_runner_.get()))); |
128 | 136 |
129 std::unique_ptr<cc::OutputSurface> display_output_surface; | 137 std::unique_ptr<cc::OutputSurface> display_output_surface; |
130 if (context_provider->ContextCapabilities().surfaceless) { | 138 if (context_provider->ContextCapabilities().surfaceless) { |
131 #if defined(USE_OZONE) | 139 #if defined(USE_OZONE) |
132 display_output_surface = base::MakeUnique<DirectOutputSurfaceOzone>( | 140 display_output_surface = base::MakeUnique<DirectOutputSurfaceOzone>( |
133 context_provider, widget, synthetic_begin_frame_source.get(), | 141 std::move(context_provider), surface_handle, |
134 gpu_memory_buffer_manager, GL_TEXTURE_2D, GL_RGB); | 142 synthetic_begin_frame_source.get(), gpu_memory_buffer_manager, |
| 143 GL_TEXTURE_2D, GL_RGB); |
135 #else | 144 #else |
136 NOTREACHED(); | 145 NOTREACHED(); |
137 #endif | 146 #endif |
138 } else { | 147 } else { |
139 display_output_surface = base::MakeUnique<DirectOutputSurface>( | 148 display_output_surface = base::MakeUnique<DirectOutputSurface>( |
140 context_provider, synthetic_begin_frame_source.get()); | 149 std::move(context_provider), synthetic_begin_frame_source.get()); |
141 } | 150 } |
142 | 151 |
143 int max_frames_pending = | 152 int max_frames_pending = |
144 display_output_surface->capabilities().max_frames_pending; | 153 display_output_surface->capabilities().max_frames_pending; |
145 DCHECK_GT(max_frames_pending, 0); | 154 DCHECK_GT(max_frames_pending, 0); |
146 | 155 |
147 std::unique_ptr<cc::DisplayScheduler> scheduler( | 156 std::unique_ptr<cc::DisplayScheduler> scheduler( |
148 new cc::DisplayScheduler(synthetic_begin_frame_source.get(), | 157 new cc::DisplayScheduler(synthetic_begin_frame_source.get(), |
149 task_runner_.get(), max_frames_pending)); | 158 task_runner_.get(), max_frames_pending)); |
150 | 159 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 if (needs_begin_frame_ == added_frame_observer_) | 221 if (needs_begin_frame_ == added_frame_observer_) |
213 return; | 222 return; |
214 | 223 |
215 added_frame_observer_ = needs_begin_frame_; | 224 added_frame_observer_ = needs_begin_frame_; |
216 if (needs_begin_frame_) | 225 if (needs_begin_frame_) |
217 begin_frame_source_->AddObserver(this); | 226 begin_frame_source_->AddObserver(this); |
218 else | 227 else |
219 begin_frame_source_->RemoveObserver(this); | 228 begin_frame_source_->RemoveObserver(this); |
220 } | 229 } |
221 | 230 |
222 } // namespace ws | 231 void GpuCompositorFrameSink::OnClientConnectionLost() { |
| 232 client_connection_lost_ = true; |
| 233 // Request destruction of |this| only if both connections are lost. |
| 234 display_compositor_->OnCompositorFrameSinkClientConnectionLost( |
| 235 frame_sink_id_, private_connection_lost_); |
| 236 } |
| 237 |
| 238 void GpuCompositorFrameSink::OnPrivateConnectionLost() { |
| 239 private_connection_lost_ = true; |
| 240 // Request destruction of |this| only if both connections are lost. |
| 241 display_compositor_->OnCompositorFrameSinkPrivateConnectionLost( |
| 242 frame_sink_id_, client_connection_lost_); |
| 243 } |
| 244 |
223 } // namespace ui | 245 } // namespace ui |
OLD | NEW |