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

Side by Side Diff: services/ui/gpu/gpu_service_internal.cc

Issue 2481263002: Introduce Display Compositor mojo interface. Use InProcessContextProvider. (Closed)
Patch Set: Make ContextProvider NON_EXPORTED_BASE of InProcessContextProvider 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/gpu/gpu_service_internal.h" 5 #include "services/ui/gpu/gpu_service_internal.h"
6 6
7 #include "base/bind.h"
7 #include "base/memory/shared_memory.h" 8 #include "base/memory/shared_memory.h"
8 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
9 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "cc/output/in_process_context_provider.h"
10 #include "gpu/command_buffer/service/gpu_switches.h" 12 #include "gpu/command_buffer/service/gpu_switches.h"
11 #include "gpu/command_buffer/service/sync_point_manager.h" 13 #include "gpu/command_buffer/service/sync_point_manager.h"
12 #include "gpu/config/gpu_info_collector.h" 14 #include "gpu/config/gpu_info_collector.h"
13 #include "gpu/config/gpu_switches.h" 15 #include "gpu/config/gpu_switches.h"
14 #include "gpu/config/gpu_util.h" 16 #include "gpu/config/gpu_util.h"
15 #include "gpu/ipc/common/gpu_memory_buffer_support.h" 17 #include "gpu/ipc/common/gpu_memory_buffer_support.h"
16 #include "gpu/ipc/common/memory_stats.h" 18 #include "gpu/ipc/common/memory_stats.h"
19 #include "gpu/ipc/gpu_in_process_thread_service.h"
20 #include "gpu/ipc/service/gpu_channel_manager.h"
17 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" 21 #include "gpu/ipc/service/gpu_memory_buffer_factory.h"
18 #include "gpu/ipc/service/gpu_watchdog_thread.h" 22 #include "gpu/ipc/service/gpu_watchdog_thread.h"
19 #include "ipc/ipc_channel_handle.h" 23 #include "ipc/ipc_channel_handle.h"
20 #include "ipc/ipc_sync_message_filter.h" 24 #include "ipc/ipc_sync_message_filter.h"
21 #include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h" 25 #include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h"
22 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h" 26 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h"
23 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h" 27 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h"
24 #include "media/gpu/ipc/service/media_gpu_channel_manager.h" 28 #include "media/gpu/ipc/service/media_gpu_channel_manager.h"
29 #include "mojo/public/cpp/bindings/strong_binding.h"
30 #include "services/ui/surfaces/display_compositor.h"
31 #include "services/ui/surfaces/mus_gpu_memory_buffer_manager.h"
25 #include "ui/gl/gl_implementation.h" 32 #include "ui/gl/gl_implementation.h"
26 #include "ui/gl/gl_switches.h" 33 #include "ui/gl/gl_switches.h"
27 #include "ui/gl/gpu_switching_manager.h" 34 #include "ui/gl/gpu_switching_manager.h"
28 #include "ui/gl/init/gl_factory.h" 35 #include "ui/gl/init/gl_factory.h"
29 #include "url/gurl.h" 36 #include "url/gurl.h"
30 37
31 namespace ui { 38 namespace ui {
32 39
33 GpuServiceInternal::GpuServiceInternal( 40 GpuServiceInternal::GpuServiceInternal(
34 const gpu::GPUInfo& gpu_info, 41 const gpu::GPUInfo& gpu_info,
35 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, 42 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread,
36 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, 43 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory,
37 scoped_refptr<base::SingleThreadTaskRunner> io_runner) 44 scoped_refptr<base::SingleThreadTaskRunner> io_runner)
38 : io_runner_(std::move(io_runner)), 45 : io_runner_(std::move(io_runner)),
39 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, 46 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL,
40 base::WaitableEvent::InitialState::NOT_SIGNALED), 47 base::WaitableEvent::InitialState::NOT_SIGNALED),
41 watchdog_thread_(std::move(watchdog_thread)), 48 watchdog_thread_(std::move(watchdog_thread)),
42 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), 49 gpu_memory_buffer_factory_(gpu_memory_buffer_factory),
43 gpu_info_(gpu_info), 50 gpu_info_(gpu_info),
44 binding_(this) {} 51 compositor_thread_("GpuCompositorThread") {
sadrul 2016/11/21 17:23:49 DisplayCompositorThread?
Fady Samuel 2016/11/21 20:40:41 Done.
52 compositor_thread_.Start();
53 }
45 54
46 GpuServiceInternal::~GpuServiceInternal() { 55 GpuServiceInternal::~GpuServiceInternal() {
47 binding_.Close(); 56 bindings_.CloseAllBindings();
48 media_gpu_channel_manager_.reset(); 57 media_gpu_channel_manager_.reset();
49 gpu_channel_manager_.reset(); 58 gpu_channel_manager_.reset();
50 owned_sync_point_manager_.reset(); 59 owned_sync_point_manager_.reset();
51 60
52 // Signal this event before destroying the child process. That way all 61 // Signal this event before destroying the child process. That way all
53 // background threads can cleanup. 62 // background threads can cleanup.
54 // For example, in the renderer the RenderThread instances will be able to 63 // For example, in the renderer the RenderThread instances will be able to
55 // notice shutdown before the render process begins waiting for them to exit. 64 // notice shutdown before the render process begins waiting for them to exit.
56 shutdown_event_.Signal(); 65 shutdown_event_.Signal();
57 } 66 }
58 67
59 void GpuServiceInternal::Add(mojom::GpuServiceInternalRequest request) { 68 void GpuServiceInternal::Add(mojom::GpuServiceInternalRequest request) {
60 binding_.Close(); 69 bindings_.AddBinding(this, std::move(request));
61 binding_.Bind(std::move(request));
62 } 70 }
63 71
64 void GpuServiceInternal::CreateGpuMemoryBuffer( 72 void GpuServiceInternal::CreateGpuMemoryBuffer(
65 gfx::GpuMemoryBufferId id, 73 gfx::GpuMemoryBufferId id,
66 const gfx::Size& size, 74 const gfx::Size& size,
67 gfx::BufferFormat format, 75 gfx::BufferFormat format,
68 gfx::BufferUsage usage, 76 gfx::BufferUsage usage,
69 int client_id, 77 int client_id,
70 gpu::SurfaceHandle surface_handle, 78 gpu::SurfaceHandle surface_handle,
71 const CreateGpuMemoryBufferCallback& callback) { 79 const CreateGpuMemoryBufferCallback& callback) {
72 DCHECK(CalledOnValidThread()); 80 DCHECK(CalledOnValidThread());
73 callback.Run(gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( 81 callback.Run(gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(
74 id, size, format, usage, client_id, surface_handle)); 82 id, size, format, usage, client_id, surface_handle));
75 } 83 }
76 84
77 void GpuServiceInternal::DestroyGpuMemoryBuffer( 85 void GpuServiceInternal::DestroyGpuMemoryBuffer(
78 gfx::GpuMemoryBufferId id, 86 gfx::GpuMemoryBufferId id,
79 int client_id, 87 int client_id,
80 const gpu::SyncToken& sync_token) { 88 const gpu::SyncToken& sync_token) {
81 DCHECK(CalledOnValidThread()); 89 DCHECK(CalledOnValidThread());
82 if (gpu_channel_manager_) 90 if (gpu_channel_manager_)
83 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token); 91 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token);
84 } 92 }
85 93
94 void GpuServiceInternal::CreateDisplayCompositor(
95 cc::mojom::DisplayCompositorRequest request,
96 cc::mojom::DisplayCompositorClientPtr client) {
97 DCHECK(!gpu_command_service_);
sadrul 2016/11/21 17:23:49 DCHECK(CalledOnValidThread())
Fady Samuel 2016/11/21 20:40:41 Done.
98 gpu_command_service_ = new gpu::GpuInProcessThreadService(
99 base::ThreadTaskRunnerHandle::Get(), owned_sync_point_manager_.get(),
100 gpu_channel_manager_->mailbox_manager(),
101 gpu_channel_manager_->share_group());
102 mojom::GpuServiceInternalPtr gpu_service_ptr;
103 Add(mojo::GetProxy(&gpu_service_ptr));
104 compositor_thread_.task_runner()->PostTask(
sadrul 2016/11/21 17:23:49 Why does DC need to live in a separate thread? (I
Fady Samuel 2016/11/21 20:40:41 InProcessCommandBuffer can block on progress on th
105 FROM_HERE,
106 base::Bind(&GpuServiceInternal::CreateDisplayCompositorOnCompositorThread,
107 base::Unretained(this),
108 base::Passed(gpu_service_ptr.PassInterface()),
109 base::Passed(&request), base::Passed(client.PassInterface())));
110 }
111
112 void GpuServiceInternal::CreateDisplayCompositorOnCompositorThread(
113 mojom::GpuServiceInternalPtrInfo gpu_service_info,
114 cc::mojom::DisplayCompositorRequest request,
115 cc::mojom::DisplayCompositorClientPtrInfo client_info) {
116 mojom::GpuServiceInternalPtr gpu_service_ptr;
sadrul 2016/11/21 17:23:49 DCHECK(compositor_thread_.task_runner()->BelongsTo
Fady Samuel 2016/11/21 20:40:41 Done.
117 gpu_service_ptr.Bind(std::move(gpu_service_info));
118
119 cc::mojom::DisplayCompositorClientPtr client_ptr;
120 client_ptr.Bind(std::move(client_info));
121
122 std::unique_ptr<MusGpuMemoryBufferManager> gpu_memory_buffer_manager =
123 base::MakeUnique<MusGpuMemoryBufferManager>(std::move(gpu_service_ptr),
124 1 /* client_id */);
125 // |gpu_memory_buffer_factory_| is null in tests.
126 gpu::ImageFactory* image_factory =
127 gpu_memory_buffer_factory_ ? gpu_memory_buffer_factory_->AsImageFactory()
128 : nullptr;
129 mojo::MakeStrongBinding(
130 base::MakeUnique<DisplayCompositor>(gpu_command_service_,
131 std::move(gpu_memory_buffer_manager),
132 image_factory, std::move(client_ptr)),
133 std::move(request));
134 }
86 void GpuServiceInternal::DidCreateOffscreenContext(const GURL& active_url) { 135 void GpuServiceInternal::DidCreateOffscreenContext(const GURL& active_url) {
87 NOTIMPLEMENTED(); 136 NOTIMPLEMENTED();
88 } 137 }
89 138
90 void GpuServiceInternal::DidDestroyChannel(int client_id) { 139 void GpuServiceInternal::DidDestroyChannel(int client_id) {
91 media_gpu_channel_manager_->RemoveChannel(client_id); 140 media_gpu_channel_manager_->RemoveChannel(client_id);
92 NOTIMPLEMENTED(); 141 NOTIMPLEMENTED();
93 } 142 }
94 143
95 void GpuServiceInternal::DidDestroyOffscreenContext(const GURL& active_url) { 144 void GpuServiceInternal::DidDestroyOffscreenContext(const GURL& active_url) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // IPC messages before the sandbox has been enabled and all other necessary 187 // IPC messages before the sandbox has been enabled and all other necessary
139 // initialization has succeeded. 188 // initialization has succeeded.
140 gpu_channel_manager_.reset(new gpu::GpuChannelManager( 189 gpu_channel_manager_.reset(new gpu::GpuChannelManager(
141 gpu_preferences_, this, watchdog_thread_.get(), 190 gpu_preferences_, this, watchdog_thread_.get(),
142 base::ThreadTaskRunnerHandle::Get().get(), io_runner_.get(), 191 base::ThreadTaskRunnerHandle::Get().get(), io_runner_.get(),
143 &shutdown_event_, owned_sync_point_manager_.get(), 192 &shutdown_event_, owned_sync_point_manager_.get(),
144 gpu_memory_buffer_factory_)); 193 gpu_memory_buffer_factory_));
145 194
146 media_gpu_channel_manager_.reset( 195 media_gpu_channel_manager_.reset(
147 new media::MediaGpuChannelManager(gpu_channel_manager_.get())); 196 new media::MediaGpuChannelManager(gpu_channel_manager_.get()));
197
148 callback.Run(gpu_info_); 198 callback.Run(gpu_info_);
149 } 199 }
150 200
151 void GpuServiceInternal::EstablishGpuChannel( 201 void GpuServiceInternal::EstablishGpuChannel(
152 int32_t client_id, 202 int32_t client_id,
153 uint64_t client_tracing_id, 203 uint64_t client_tracing_id,
154 bool is_gpu_host, 204 bool is_gpu_host,
155 const EstablishGpuChannelCallback& callback) { 205 const EstablishGpuChannelCallback& callback) {
156 DCHECK(CalledOnValidThread()); 206 DCHECK(CalledOnValidThread());
157 207
158 if (!gpu_channel_manager_) { 208 if (!gpu_channel_manager_) {
159 callback.Run(mojo::ScopedMessagePipeHandle()); 209 callback.Run(mojo::ScopedMessagePipeHandle());
160 return; 210 return;
161 } 211 }
162 212
163 const bool preempts = is_gpu_host; 213 const bool preempts = is_gpu_host;
164 const bool allow_view_command_buffers = is_gpu_host; 214 const bool allow_view_command_buffers = is_gpu_host;
165 const bool allow_real_time_streams = is_gpu_host; 215 const bool allow_real_time_streams = is_gpu_host;
166 mojo::ScopedMessagePipeHandle channel_handle; 216 mojo::ScopedMessagePipeHandle channel_handle;
167 IPC::ChannelHandle handle = gpu_channel_manager_->EstablishChannel( 217 IPC::ChannelHandle handle = gpu_channel_manager_->EstablishChannel(
168 client_id, client_tracing_id, preempts, allow_view_command_buffers, 218 client_id, client_tracing_id, preempts, allow_view_command_buffers,
169 allow_real_time_streams); 219 allow_real_time_streams);
170 channel_handle.reset(handle.mojo_handle); 220 channel_handle.reset(handle.mojo_handle);
171 media_gpu_channel_manager_->AddChannel(client_id); 221 media_gpu_channel_manager_->AddChannel(client_id);
172 callback.Run(std::move(channel_handle)); 222 callback.Run(std::move(channel_handle));
173 } 223 }
174 224
175 } // namespace ui 225 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698