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

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

Powered by Google App Engine
This is Rietveld 408576698