Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Side by Side Diff: services/ui/surfaces/gpu_compositor_frame_sink.cc

Issue 2481263002: Introduce Display Compositor mojo interface. Use InProcessContextProvider. (Closed)
Patch Set: Improved comment Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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,
35 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request,
36 cc::mojom::MojoCompositorFrameSinkClientPtr client) 36 cc::mojom::MojoCompositorFrameSinkClientPtr client)
37 : frame_sink_id_(frame_sink_id), 37 : frame_sink_id_(frame_sink_id),
38 task_runner_(base::ThreadTaskRunnerHandle::Get()), 38 task_runner_(base::ThreadTaskRunnerHandle::Get()),
39 display_compositor_(display_compositor), 39 display_compositor_(display_compositor),
40 surface_factory_(frame_sink_id_, display_compositor_->manager(), this), 40 surface_factory_(frame_sink_id_, display_compositor_->manager(), this),
41 client_(std::move(client)), 41 client_(std::move(client)),
42 binding_(this, std::move(request)) { 42 binding_(this, std::move(request)),
43 private_binding_(this, std::move(private_request)) {
43 display_compositor_->manager()->RegisterFrameSinkId(frame_sink_id_); 44 display_compositor_->manager()->RegisterFrameSinkId(frame_sink_id_);
44 display_compositor_->manager()->RegisterSurfaceFactoryClient(frame_sink_id_, 45 display_compositor_->manager()->RegisterSurfaceFactoryClient(frame_sink_id_,
45 this); 46 this);
46 47
47 if (widget != gfx::kNullAcceleratedWidget) 48 if (surface_handle != gpu::kNullSurfaceHandle) {
48 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)));
49 } 59 }
50 60
51 GpuCompositorFrameSink::~GpuCompositorFrameSink() { 61 GpuCompositorFrameSink::~GpuCompositorFrameSink() {
52 // SurfaceFactory's destructor will attempt to return resources which will 62 // SurfaceFactory's destructor will attempt to return resources which will
53 // call back into here and access |client_| so we should destroy 63 // call back into here and access |client_| so we should destroy
54 // |surface_factory_|'s resources early on. 64 // |surface_factory_|'s resources early on.
55 surface_factory_.DestroyAll(); 65 surface_factory_.DestroyAll();
56 display_compositor_->manager()->UnregisterSurfaceFactoryClient( 66 display_compositor_->manager()->UnregisterSurfaceFactoryClient(
57 frame_sink_id_); 67 frame_sink_id_);
58 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
107 } 117 }
108 118
109 void GpuCompositorFrameSink::RemoveChildFrameSink( 119 void GpuCompositorFrameSink::RemoveChildFrameSink(
110 const cc::FrameSinkId& child_frame_sink_id) { 120 const cc::FrameSinkId& child_frame_sink_id) {
111 cc::SurfaceManager* surface_manager = display_compositor_->manager(); 121 cc::SurfaceManager* surface_manager = display_compositor_->manager();
112 surface_manager->UnregisterFrameSinkHierarchy(frame_sink_id_, 122 surface_manager->UnregisterFrameSinkHierarchy(frame_sink_id_,
113 child_frame_sink_id); 123 child_frame_sink_id);
114 } 124 }
115 125
116 void GpuCompositorFrameSink::InitDisplay( 126 void GpuCompositorFrameSink::InitDisplay(
117 gfx::AcceleratedWidget widget, 127 gpu::SurfaceHandle surface_handle,
118 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, 128 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
119 scoped_refptr<SurfacesContextProvider> context_provider) { 129 scoped_refptr<cc::InProcessContextProvider> context_provider) {
120 // 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.
121 CHECK(context_provider->BindToCurrentThread()); 131 CHECK(context_provider->BindToCurrentThread());
122 132
123 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source( 133 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source(
124 new cc::DelayBasedBeginFrameSource( 134 new cc::DelayBasedBeginFrameSource(
125 base::MakeUnique<cc::DelayBasedTimeSource>(task_runner_.get()))); 135 base::MakeUnique<cc::DelayBasedTimeSource>(task_runner_.get())));
126 136
127 std::unique_ptr<cc::OutputSurface> display_output_surface; 137 std::unique_ptr<cc::OutputSurface> display_output_surface;
128 if (context_provider->ContextCapabilities().surfaceless) { 138 if (context_provider->ContextCapabilities().surfaceless) {
129 #if defined(USE_OZONE) 139 #if defined(USE_OZONE)
130 display_output_surface = base::MakeUnique<DirectOutputSurfaceOzone>( 140 display_output_surface = base::MakeUnique<DirectOutputSurfaceOzone>(
131 context_provider, widget, synthetic_begin_frame_source.get(), 141 std::move(context_provider), surface_handle,
132 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);
133 #else 144 #else
134 NOTREACHED(); 145 NOTREACHED();
135 #endif 146 #endif
136 } else { 147 } else {
137 display_output_surface = base::MakeUnique<DirectOutputSurface>( 148 display_output_surface = base::MakeUnique<DirectOutputSurface>(
138 context_provider, synthetic_begin_frame_source.get()); 149 std::move(context_provider), synthetic_begin_frame_source.get());
139 } 150 }
140 151
141 int max_frames_pending = 152 int max_frames_pending =
142 display_output_surface->capabilities().max_frames_pending; 153 display_output_surface->capabilities().max_frames_pending;
143 DCHECK_GT(max_frames_pending, 0); 154 DCHECK_GT(max_frames_pending, 0);
144 155
145 std::unique_ptr<cc::DisplayScheduler> scheduler( 156 std::unique_ptr<cc::DisplayScheduler> scheduler(
146 new cc::DisplayScheduler(synthetic_begin_frame_source.get(), 157 new cc::DisplayScheduler(synthetic_begin_frame_source.get(),
147 task_runner_.get(), max_frames_pending)); 158 task_runner_.get(), max_frames_pending));
148 159
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 if (needs_begin_frame_ == added_frame_observer_) 221 if (needs_begin_frame_ == added_frame_observer_)
211 return; 222 return;
212 223
213 added_frame_observer_ = needs_begin_frame_; 224 added_frame_observer_ = needs_begin_frame_;
214 if (needs_begin_frame_) 225 if (needs_begin_frame_)
215 begin_frame_source_->AddObserver(this); 226 begin_frame_source_->AddObserver(this);
216 else 227 else
217 begin_frame_source_->RemoveObserver(this); 228 begin_frame_source_->RemoveObserver(this);
218 } 229 }
219 230
220 } // 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
221 } // namespace ui 245 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698