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

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

Issue 2276963002: services/ui: Introduce mojom.GpuServiceInternal. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mus-gpu-renames
Patch Set: . Created 4 years, 4 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 "services/ui/gpu/gpu_service_internal.h" 5 #include "services/ui/gpu/gpu_service_internal.h"
6 6
7 #include "base/memory/shared_memory.h" 7 #include "base/memory/shared_memory.h"
8 #include "base/memory/singleton.h" 8 #include "base/memory/singleton.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
(...skipping 28 matching lines...) Expand all
39 39
40 const int kLocalGpuChannelClientId = 1; 40 const int kLocalGpuChannelClientId = 1;
41 const uint64_t kLocalGpuChannelClientTracingId = 1; 41 const uint64_t kLocalGpuChannelClientTracingId = 1;
42 42
43 void EstablishGpuChannelDone( 43 void EstablishGpuChannelDone(
44 int client_id, 44 int client_id,
45 mojo::ScopedMessagePipeHandle* channel_handle, 45 mojo::ScopedMessagePipeHandle* channel_handle,
46 const GpuServiceInternal::EstablishGpuChannelCallback& callback) { 46 const GpuServiceInternal::EstablishGpuChannelCallback& callback) {
47 callback.Run(client_id, std::move(*channel_handle)); 47 callback.Run(client_id, std::move(*channel_handle));
48 } 48 }
49 } 49
50 } // namespace
50 51
51 GpuServiceInternal::GpuServiceInternal() 52 GpuServiceInternal::GpuServiceInternal()
52 : next_client_id_(kLocalGpuChannelClientId), 53 : next_client_id_(kLocalGpuChannelClientId),
53 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), 54 main_task_runner_(base::ThreadTaskRunnerHandle::Get()),
54 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, 55 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL,
55 base::WaitableEvent::InitialState::NOT_SIGNALED), 56 base::WaitableEvent::InitialState::NOT_SIGNALED),
56 gpu_thread_("GpuThread"), 57 gpu_thread_("GpuThread"),
57 io_thread_("GpuIOThread") { 58 io_thread_("GpuIOThread"),
58 Initialize(); 59 binding_(this) {
59 } 60 }
60 61
61 GpuServiceInternal::~GpuServiceInternal() { 62 GpuServiceInternal::~GpuServiceInternal() {
62 // Signal this event before destroying the child process. That way all 63 // Signal this event before destroying the child process. That way all
63 // background threads can cleanup. 64 // background threads can cleanup.
64 // For example, in the renderer the RenderThread instances will be able to 65 // For example, in the renderer the RenderThread instances will be able to
65 // notice shutdown before the render process begins waiting for them to exit. 66 // notice shutdown before the render process begins waiting for them to exit.
66 shutdown_event_.Signal(); 67 shutdown_event_.Signal();
67 io_thread_.Stop(); 68 io_thread_.Stop();
68 } 69 }
69 70
70 void GpuServiceInternal::EstablishGpuChannel( 71 void GpuServiceInternal::Add(mojom::GpuServiceInternalRequest request) {
72 binding_.Bind(std::move(request));
73 }
74
75 void GpuServiceInternal::EstablishGpuChannelInternal(
71 uint64_t client_tracing_id, 76 uint64_t client_tracing_id,
72 bool preempts, 77 bool preempts,
73 bool allow_view_command_buffers, 78 bool allow_view_command_buffers,
74 bool allow_real_time_streams, 79 bool allow_real_time_streams,
75 const EstablishGpuChannelCallback& callback) { 80 const EstablishGpuChannelCallback& callback) {
76 DCHECK(CalledOnValidThread()); 81 DCHECK(CalledOnValidThread());
77 82
78 if (!gpu_channel_manager_) { 83 if (!gpu_channel_manager_) {
79 callback.Run(-1, mojo::ScopedMessagePipeHandle()); 84 callback.Run(-1, mojo::ScopedMessagePipeHandle());
80 return; 85 return;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 gpu::SurfaceHandle parent_window, 154 gpu::SurfaceHandle parent_window,
150 gpu::SurfaceHandle child_window) { 155 gpu::SurfaceHandle child_window) {
151 ::SetParent(child_window, parent_window); 156 ::SetParent(child_window, parent_window);
152 } 157 }
153 #endif 158 #endif
154 159
155 void GpuServiceInternal::SetActiveURL(const GURL& url) { 160 void GpuServiceInternal::SetActiveURL(const GURL& url) {
156 // TODO(penghuang): implement this function. 161 // TODO(penghuang): implement this function.
157 } 162 }
158 163
159 void GpuServiceInternal::Initialize() {
160 DCHECK(CalledOnValidThread());
161 base::Thread::Options thread_options(base::MessageLoop::TYPE_DEFAULT, 0);
162 thread_options.priority = base::ThreadPriority::NORMAL;
163 CHECK(gpu_thread_.StartWithOptions(thread_options));
164
165 thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0);
166 thread_options.priority = base::ThreadPriority::NORMAL;
167 #if defined(OS_ANDROID)
168 // TODO(reveman): Remove this in favor of setting it explicitly for each type
169 // of process.
170 thread_options.priority = base::ThreadPriority::DISPLAY;
171 #endif
172 CHECK(io_thread_.StartWithOptions(thread_options));
173
174 mojo::ScopedMessagePipeHandle channel_handle;
175 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL,
176 base::WaitableEvent::InitialState::NOT_SIGNALED);
177 gpu_thread_.task_runner()->PostTask(
178 FROM_HERE, base::Bind(&GpuServiceInternal::InitializeOnGpuThread,
179 base::Unretained(this), &channel_handle, &event));
180 event.Wait();
181
182 gpu_memory_buffer_manager_local_.reset(
183 new MusGpuMemoryBufferManager(this, kLocalGpuChannelClientId));
184 gpu_channel_local_ = gpu::GpuChannelHost::Create(
185 this, kLocalGpuChannelClientId, gpu_info_,
186 IPC::ChannelHandle(channel_handle.release()), &shutdown_event_,
187 gpu_memory_buffer_manager_local_.get());
188 }
189
190 void GpuServiceInternal::InitializeOnGpuThread( 164 void GpuServiceInternal::InitializeOnGpuThread(
191 mojo::ScopedMessagePipeHandle* channel_handle, 165 mojo::ScopedMessagePipeHandle* channel_handle,
192 base::WaitableEvent* event) { 166 base::WaitableEvent* event) {
193 gpu_info_.video_decode_accelerator_capabilities = 167 gpu_info_.video_decode_accelerator_capabilities =
194 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); 168 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_);
195 gpu_info_.video_encode_accelerator_supported_profiles = 169 gpu_info_.video_encode_accelerator_supported_profiles =
196 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); 170 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_);
197 gpu_info_.jpeg_decode_accelerator_supported = 171 gpu_info_.jpeg_decode_accelerator_supported =
198 media::GpuJpegDecodeAccelerator::IsSupported(); 172 media::GpuJpegDecodeAccelerator::IsSupported();
199 173
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 238 }
265 239
266 std::unique_ptr<base::SharedMemory> GpuServiceInternal::AllocateSharedMemory( 240 std::unique_ptr<base::SharedMemory> GpuServiceInternal::AllocateSharedMemory(
267 size_t size) { 241 size_t size) {
268 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); 242 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory());
269 if (!shm->CreateAnonymous(size)) 243 if (!shm->CreateAnonymous(size))
270 return std::unique_ptr<base::SharedMemory>(); 244 return std::unique_ptr<base::SharedMemory>();
271 return shm; 245 return shm;
272 } 246 }
273 247
248 void GpuServiceInternal::Initialize(const InitializeCallback& callback) {
249 DCHECK(CalledOnValidThread());
250 base::Thread::Options thread_options(base::MessageLoop::TYPE_DEFAULT, 0);
251 thread_options.priority = base::ThreadPriority::NORMAL;
252 CHECK(gpu_thread_.StartWithOptions(thread_options));
253
254 thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0);
255 thread_options.priority = base::ThreadPriority::NORMAL;
256 #if defined(OS_ANDROID)
257 // TODO(reveman): Remove this in favor of setting it explicitly for each type
258 // of process.
259 thread_options.priority = base::ThreadPriority::DISPLAY;
260 #endif
261 CHECK(io_thread_.StartWithOptions(thread_options));
262
263 mojo::ScopedMessagePipeHandle channel_handle;
264 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL,
265 base::WaitableEvent::InitialState::NOT_SIGNALED);
266 gpu_thread_.task_runner()->PostTask(
267 FROM_HERE, base::Bind(&GpuServiceInternal::InitializeOnGpuThread,
268 base::Unretained(this), &channel_handle, &event));
269 event.Wait();
270
271 gpu_memory_buffer_manager_local_.reset(
272 new MusGpuMemoryBufferManager(this, kLocalGpuChannelClientId));
273 gpu_channel_local_ = gpu::GpuChannelHost::Create(
274 this, kLocalGpuChannelClientId, gpu_info_,
275 IPC::ChannelHandle(channel_handle.release()), &shutdown_event_,
276 gpu_memory_buffer_manager_local_.get());
277
278 // TODO(sad): Get the real GPUInfo.
279 callback.Run(gpu_info_);
280 }
281
282 void GpuServiceInternal::EstablishGpuChannel(
283 const EstablishGpuChannelCallback& callback) {
284 // TODO(penghuang): crbug.com/617415 figure out how to generate a meaningful
285 // tracing id.
286 const uint64_t client_tracing_id = 0;
287 // TODO(penghuang): windows server may want to control those flags.
288 // Add a private interface for windows server.
289 const bool preempts = false;
290 const bool allow_view_command_buffers = false;
291 const bool allow_real_time_streams = false;
292 EstablishGpuChannelInternal(client_tracing_id, preempts,
293 allow_view_command_buffers,
294 allow_real_time_streams, callback);
295 }
296
274 // static 297 // static
275 GpuServiceInternal* GpuServiceInternal::GetInstance() { 298 GpuServiceInternal* GpuServiceInternal::GetInstance() {
276 return base::Singleton<GpuServiceInternal, 299 return base::Singleton<GpuServiceInternal,
277 base::LeakySingletonTraits<GpuServiceInternal>>::get(); 300 base::LeakySingletonTraits<GpuServiceInternal>>::get();
278 } 301 }
279 302
280 } // namespace ui 303 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698