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

Side by Side Diff: components/mus/gpu/gpu_service_mus.cc

Issue 1976703003: Impl mus::mojom::GpuService to enable using Chrome IPC version gpu CmdBuf in mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 4 years, 6 months 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 "components/mus/gpu/gpu_service_mus.h" 5 #include "components/mus/gpu/gpu_service_mus.h"
6 6
7 #include "base/memory/shared_memory.h"
8 #include "base/memory/singleton.h"
9 #include "base/synchronization/waitable_event.h"
10 #include "base/threading/thread_task_runner_handle.h"
11 #include "components/mus/gpu/gpu_memory_buffer_manager_mus_local.h"
12 #include "gpu/command_buffer/service/gpu_switches.h"
13 #include "gpu/command_buffer/service/sync_point_manager.h"
14 #include "gpu/config/gpu_info_collector.h"
15 #include "gpu/config/gpu_switches.h"
16 #include "gpu/config/gpu_util.h"
17 #include "gpu/ipc/common/gpu_memory_buffer_support.h"
18 #include "gpu/ipc/common/memory_stats.h"
7 #include "gpu/ipc/common/surface_handle.h" 19 #include "gpu/ipc/common/surface_handle.h"
20 #include "gpu/ipc/service/gpu_memory_buffer_factory.h"
21 #include "ipc/ipc_channel_handle.h"
22 #include "ipc/ipc_sync_message_filter.h"
23 #include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h"
24 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h"
25 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h"
26 #include "media/gpu/ipc/service/media_service.h"
27 #include "ui/gl/gl_implementation.h"
28 #include "ui/gl/gl_switches.h"
29 #include "ui/gl/gpu_switching_manager.h"
30 #include "url/gurl.h"
8 31
9 namespace mus { 32 namespace mus {
33 namespace {
10 34
11 GpuServiceMus::GpuServiceMus() {} 35 const int kLocalGpuChannelClientId = 1;
36 const uint64_t kLocalGpuChannelClientTracingId = 1;
12 37
13 GpuServiceMus::~GpuServiceMus() {} 38 void EstablishGpuChannelDone(
39 std::unique_ptr<IPC::ChannelHandle> channel_handle,
40 const GpuServiceMus::EstablishGpuChannelCallback& callback) {
41 callback.Run(*channel_handle);
42 }
43 }
44
45 GpuServiceMus::GpuServiceMus()
46 : main_message_loop_(base::MessageLoop::current()),
47 shutdown_event_(true, false),
48 gpu_thread_("GpuThread"),
49 io_thread_("GpuIOThread") {
50 Initialize();
51 }
52
53 GpuServiceMus::~GpuServiceMus() {
54 // Signal this event before destroying the child process. That way all
55 // background threads can cleanup.
56 // For example, in the renderer the RenderThread instances will be able to
57 // notice shutdown before the render process begins waiting for them to exit.
58 shutdown_event_.Signal();
59 io_thread_.Stop();
60 }
14 61
15 void GpuServiceMus::EstablishGpuChannel( 62 void GpuServiceMus::EstablishGpuChannel(
16 bool prempts, 63 int client_id,
64 uint64_t client_tracing_id,
65 bool preempts,
17 bool allow_view_command_buffers, 66 bool allow_view_command_buffers,
18 bool allow_real_time_streams, 67 bool allow_real_time_streams,
19 const mojom::GpuService::EstablishGpuChannelCallback& callback) { 68 const EstablishGpuChannelCallback& callback) {
20 NOTIMPLEMENTED(); 69 DCHECK_GT(client_id, kLocalGpuChannelClientId);
70
71 if (!gpu_channel_manager_) {
72 callback.Run(IPC::ChannelHandle());
73 return;
74 }
75
76 std::unique_ptr<IPC::ChannelHandle> channel_handle(new IPC::ChannelHandle);
77 gpu_thread_.task_runner()->PostTaskAndReply(
78 FROM_HERE,
79 base::Bind(&GpuServiceMus::EstablishGpuChannelOnGpuThread,
80 base::Unretained(this), client_id, client_tracing_id, preempts,
81 allow_view_command_buffers, allow_real_time_streams,
82 base::Unretained(channel_handle.get())),
83 base::Bind(&EstablishGpuChannelDone, base::Passed(&channel_handle),
84 callback));
21 } 85 }
22 86
23 void GpuServiceMus::CreateGpuMemoryBuffer( 87 gfx::GpuMemoryBufferHandle GpuServiceMus::CreateGpuMemoryBuffer(
24 mojom::GpuMemoryBufferIdPtr id, 88 gfx::GpuMemoryBufferId id,
25 const gfx::Size& size, 89 const gfx::Size& size,
26 mojom::BufferFormat format, 90 gfx::BufferFormat format,
27 mojom::BufferUsage usage, 91 gfx::BufferUsage usage,
28 uint64_t surface_id, 92 int client_id,
29 const mojom::GpuService::CreateGpuMemoryBufferCallback& callback) { 93 int32_t surface_handle) {
30 NOTIMPLEMENTED(); 94 return gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(
95 id, size, format, usage, client_id,
96 static_cast<gpu::SurfaceHandle>(surface_handle));
31 } 97 }
32 98
33 void GpuServiceMus::CreateGpuMemoryBufferFromHandle( 99 gfx::GpuMemoryBufferHandle GpuServiceMus::CreateGpuMemoryBufferFromeHandle(
34 mojom::GpuMemoryBufferHandlePtr buffer_handle, 100 gfx::GpuMemoryBufferHandle buffer_handle,
35 mojom::GpuMemoryBufferIdPtr id, 101 gfx::GpuMemoryBufferId id,
36 const gfx::Size& size, 102 const gfx::Size& size,
37 mojom::BufferFormat format, 103 gfx::BufferFormat format,
38 const mojom::GpuService::CreateGpuMemoryBufferFromHandleCallback& 104 int client_id) {
39 callback) { 105 return gpu_memory_buffer_factory_->CreateGpuMemoryBufferFromHandle(
40 NOTIMPLEMENTED(); 106 buffer_handle, id, size, format, client_id);
41 } 107 }
42 108
43 void GpuServiceMus::DestroyGpuMemoryBuffer(mojom::GpuMemoryBufferIdPtr id, 109 void GpuServiceMus::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
110 int client_id,
44 const gpu::SyncToken& sync_token) { 111 const gpu::SyncToken& sync_token) {
45 NOTIMPLEMENTED(); 112 if (gpu_channel_manager_)
113 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token);
46 } 114 }
47 115
48 void GpuServiceMus::DidCreateOffscreenContext(const GURL& active_url) { 116 void GpuServiceMus::DidCreateOffscreenContext(const GURL& active_url) {
49 NOTIMPLEMENTED(); 117 NOTIMPLEMENTED();
50 } 118 }
51 119
52 void GpuServiceMus::DidDestroyChannel(int client_id) { 120 void GpuServiceMus::DidDestroyChannel(int client_id) {
121 media_service_->RemoveChannel(client_id);
53 NOTIMPLEMENTED(); 122 NOTIMPLEMENTED();
54 } 123 }
55 124
56 void GpuServiceMus::DidDestroyOffscreenContext(const GURL& active_url) { 125 void GpuServiceMus::DidDestroyOffscreenContext(const GURL& active_url) {
57 NOTIMPLEMENTED(); 126 NOTIMPLEMENTED();
58 } 127 }
59 128
60 void GpuServiceMus::DidLoseContext(bool offscreen, 129 void GpuServiceMus::DidLoseContext(bool offscreen,
61 gpu::error::ContextLostReason reason, 130 gpu::error::ContextLostReason reason,
62 const GURL& active_url) { 131 const GURL& active_url) {
63 NOTIMPLEMENTED(); 132 NOTIMPLEMENTED();
64 } 133 }
65 134
66 void GpuServiceMus::GpuMemoryUmaStats(const gpu::GPUMemoryUmaStats& params) { 135 void GpuServiceMus::GpuMemoryUmaStats(const gpu::GPUMemoryUmaStats& params) {
67 NOTIMPLEMENTED(); 136 NOTIMPLEMENTED();
68 } 137 }
69 138
70 void GpuServiceMus::StoreShaderToDisk(int32_t client_id, 139 void GpuServiceMus::StoreShaderToDisk(int client_id,
71 const std::string& key, 140 const std::string& key,
72 const std::string& shader) { 141 const std::string& shader) {
73 NOTIMPLEMENTED(); 142 NOTIMPLEMENTED();
74 } 143 }
75 144
76 #if defined(OS_WIN) 145 #if defined(OS_WIN)
77 void GpuServiceMus::SendAcceleratedSurfaceCreatedChildWindow( 146 void GpuServiceMus::SendAcceleratedSurfaceCreatedChildWindow(
78 gpu::SurfaceHandle parent_window, 147 gpu::SurfaceHandle parent_window,
79 gpu::SurfaceHandle child_window) { 148 gpu::SurfaceHandle child_window) {
80 NOTIMPLEMENTED(); 149 NOTIMPLEMENTED();
81 } 150 }
82 #endif 151 #endif
83 152
84 void GpuServiceMus::SetActiveURL(const GURL& url) { 153 void GpuServiceMus::SetActiveURL(const GURL& url) {
85 NOTIMPLEMENTED(); 154 NOTIMPLEMENTED();
86 } 155 }
87 156
157 void GpuServiceMus::Initialize() {
158 base::Thread::Options thread_options(base::MessageLoop::TYPE_DEFAULT, 0);
159 thread_options.priority = base::ThreadPriority::NORMAL;
160 CHECK(gpu_thread_.StartWithOptions(thread_options));
161
162 thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0);
163 thread_options.priority = base::ThreadPriority::NORMAL;
164 #if defined(OS_ANDROID)
165 // TODO(reveman): Remove this in favor of setting it explicitly for each type
166 // of process.
167 thread_options.priority = base::ThreadPriority::DISPLAY;
168 #endif
169 CHECK(io_thread_.StartWithOptions(thread_options));
170
171 IPC::ChannelHandle channel_handle;
172 bool manual_reset = true;
173 bool initially_signaled = false;
174 base::WaitableEvent event(manual_reset, initially_signaled);
175 gpu_thread_.task_runner()->PostTask(
176 FROM_HERE, base::Bind(&GpuServiceMus::InitializeOnGpuThread,
177 base::Unretained(this), &channel_handle, &event));
178 event.Wait();
179
180 gpu_memory_buffer_manager_mus_local_.reset(new GpuMemoryBufferManagerMusLocal(
181 kLocalGpuChannelClientId, kLocalGpuChannelClientTracingId));
182 gpu_channel_local_ = gpu::GpuChannelHost::Create(
183 this, kLocalGpuChannelClientId, gpu_info_, channel_handle,
184 &shutdown_event_, gpu_memory_buffer_manager_mus_local_.get());
185 }
186
187 void GpuServiceMus::InitializeOnGpuThread(IPC::ChannelHandle* channel_handle,
188 base::WaitableEvent* event) {
189 gpu_info_.video_decode_accelerator_capabilities =
190 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_);
191 gpu_info_.video_encode_accelerator_supported_profiles =
192 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_);
193 gpu_info_.jpeg_decode_accelerator_supported =
194 media::GpuJpegDecodeAccelerator::IsSupported();
195
196 if (gpu::GetNativeGpuMemoryBufferType() != gfx::EMPTY_BUFFER) {
197 gpu_memory_buffer_factory_ =
198 gpu::GpuMemoryBufferFactory::CreateNativeType();
199 }
200
201 if (!gl::GLSurface::InitializeOneOff())
202 VLOG(1) << "gfx::GLSurface::InitializeOneOff failed";
203
204 DCHECK(!owned_sync_point_manager_);
205 const bool allow_threaded_wait = false;
206 owned_sync_point_manager_.reset(
207 new gpu::SyncPointManager(allow_threaded_wait));
208
209 // Defer creation of the render thread. This is to prevent it from handling
210 // IPC messages before the sandbox has been enabled and all other necessary
211 // initialization has succeeded.
212 // TODO(penghuang): implement a watchdog.
213 gpu::GpuWatchdog* watchdog = nullptr;
214 gpu_channel_manager_.reset(new gpu::GpuChannelManager(
215 gpu_preferences_, this, watchdog,
216 base::ThreadTaskRunnerHandle::Get().get(), io_thread_.task_runner().get(),
217 &shutdown_event_, owned_sync_point_manager_.get(),
218 gpu_memory_buffer_factory_.get()));
219
220 media_service_.reset(new media::MediaService(gpu_channel_manager_.get()));
221
222 #if defined(USE_OZONE)
223 ui::OzonePlatform::GetInstance()
224 ->GetGpuPlatformSupport()
225 ->OnChannelEstablished(this);
226 #endif
227 const bool preempts = true;
228 const bool allow_view_command_buffers = true;
229 const bool allow_real_time_streams = true;
230 EstablishGpuChannelOnGpuThread(
231 kLocalGpuChannelClientId, kLocalGpuChannelClientTracingId, preempts,
232 allow_view_command_buffers, allow_real_time_streams, channel_handle);
233 event->Signal();
234 }
235
236 void GpuServiceMus::EstablishGpuChannelOnGpuThread(
237 int client_id,
238 uint64_t client_tracing_id,
239 bool preempts,
240 bool allow_view_command_buffers,
241 bool allow_real_time_streams,
242 IPC::ChannelHandle* channel_handle) {
243 if (gpu_channel_manager_) {
244 *channel_handle = gpu_channel_manager_->EstablishChannel(
245 client_id, client_tracing_id, preempts, allow_view_command_buffers,
246 allow_real_time_streams);
247 media_service_->AddChannel(client_id);
248 }
249 }
250
251 bool GpuServiceMus::IsMainThread() {
252 return main_message_loop_ == base::MessageLoop::current();
253 }
254
255 scoped_refptr<base::SingleThreadTaskRunner>
256 GpuServiceMus::GetIOThreadTaskRunner() {
257 return io_thread_.task_runner();
258 }
259
260 std::unique_ptr<base::SharedMemory> GpuServiceMus::AllocateSharedMemory(
261 size_t size) {
262 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory());
263 if (!shm->CreateAnonymous(size))
264 return std::unique_ptr<base::SharedMemory>();
265 return shm;
266 }
267
268 // static
269 GpuServiceMus* GpuServiceMus::GetInstance() {
270 return base::Singleton<GpuServiceMus,
271 base::LeakySingletonTraits<GpuServiceMus>>::get();
272 }
273
88 } // namespace mus 274 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698