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

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

Powered by Google App Engine
This is Rietveld 408576698