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

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, 3 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 | « services/ui/gpu/gpu_service_internal.h ('k') | services/ui/gpu/interfaces/BUILD.gn » ('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 "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 23 matching lines...) Expand all
34 #include "ui/ozone/public/ozone_platform.h" 34 #include "ui/ozone/public/ozone_platform.h"
35 #endif 35 #endif
36 36
37 namespace ui { 37 namespace ui {
38 namespace { 38 namespace {
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,
45 mojo::ScopedMessagePipeHandle* channel_handle, 44 mojo::ScopedMessagePipeHandle* channel_handle,
46 const GpuServiceInternal::EstablishGpuChannelCallback& callback) { 45 const GpuServiceInternal::EstablishGpuChannelCallback& callback) {
47 callback.Run(client_id, std::move(*channel_handle)); 46 callback.Run(std::move(*channel_handle));
48 }
49 } 47 }
50 48
49 } // namespace
50
51 GpuServiceInternal::GpuServiceInternal() 51 GpuServiceInternal::GpuServiceInternal()
52 : next_client_id_(kLocalGpuChannelClientId), 52 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()),
53 main_task_runner_(base::ThreadTaskRunnerHandle::Get()),
54 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, 53 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL,
55 base::WaitableEvent::InitialState::NOT_SIGNALED), 54 base::WaitableEvent::InitialState::NOT_SIGNALED),
56 gpu_thread_("GpuThread"), 55 gpu_thread_("GpuThread"),
57 io_thread_("GpuIOThread") { 56 io_thread_("GpuIOThread"),
58 Initialize(); 57 binding_(this) {}
59 }
60 58
61 GpuServiceInternal::~GpuServiceInternal() { 59 GpuServiceInternal::~GpuServiceInternal() {
62 // Signal this event before destroying the child process. That way all 60 // Signal this event before destroying the child process. That way all
63 // background threads can cleanup. 61 // background threads can cleanup.
64 // For example, in the renderer the RenderThread instances will be able to 62 // 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. 63 // notice shutdown before the render process begins waiting for them to exit.
66 shutdown_event_.Signal(); 64 shutdown_event_.Signal();
67 io_thread_.Stop(); 65 io_thread_.Stop();
68 } 66 }
69 67
70 void GpuServiceInternal::EstablishGpuChannel( 68 void GpuServiceInternal::Add(mojom::GpuServiceInternalRequest request) {
69 binding_.Bind(std::move(request));
70 }
71
72 void GpuServiceInternal::EstablishGpuChannelInternal(
73 int32_t client_id,
71 uint64_t client_tracing_id, 74 uint64_t client_tracing_id,
72 bool preempts, 75 bool preempts,
73 bool allow_view_command_buffers, 76 bool allow_view_command_buffers,
74 bool allow_real_time_streams, 77 bool allow_real_time_streams,
75 const EstablishGpuChannelCallback& callback) { 78 const EstablishGpuChannelCallback& callback) {
76 DCHECK(CalledOnValidThread()); 79 DCHECK(CalledOnValidThread());
77 80
78 if (!gpu_channel_manager_) { 81 if (!gpu_channel_manager_) {
79 callback.Run(-1, mojo::ScopedMessagePipeHandle()); 82 callback.Run(mojo::ScopedMessagePipeHandle());
80 return; 83 return;
81 } 84 }
82 85
83 const int client_id = ++next_client_id_;
84 auto* channel_handle = new mojo::ScopedMessagePipeHandle; 86 auto* channel_handle = new mojo::ScopedMessagePipeHandle;
85 gpu_thread_.task_runner()->PostTaskAndReply( 87 gpu_thread_.task_runner()->PostTaskAndReply(
86 FROM_HERE, 88 FROM_HERE,
87 base::Bind(&GpuServiceInternal::EstablishGpuChannelOnGpuThread, 89 base::Bind(&GpuServiceInternal::EstablishGpuChannelOnGpuThread,
88 base::Unretained(this), client_id, client_tracing_id, preempts, 90 base::Unretained(this), client_id, client_tracing_id, preempts,
89 allow_view_command_buffers, allow_real_time_streams, 91 allow_view_command_buffers, allow_real_time_streams,
90 base::Unretained(channel_handle)), 92 base::Unretained(channel_handle)),
91 base::Bind(&EstablishGpuChannelDone, client_id, 93 base::Bind(&EstablishGpuChannelDone, base::Owned(channel_handle),
92 base::Owned(channel_handle), callback)); 94 callback));
93 } 95 }
94 96
95 gfx::GpuMemoryBufferHandle GpuServiceInternal::CreateGpuMemoryBuffer( 97 gfx::GpuMemoryBufferHandle GpuServiceInternal::CreateGpuMemoryBuffer(
96 gfx::GpuMemoryBufferId id, 98 gfx::GpuMemoryBufferId id,
97 const gfx::Size& size, 99 const gfx::Size& size,
98 gfx::BufferFormat format, 100 gfx::BufferFormat format,
99 gfx::BufferUsage usage, 101 gfx::BufferUsage usage,
100 int client_id, 102 int client_id,
101 gpu::SurfaceHandle surface_handle) { 103 gpu::SurfaceHandle surface_handle) {
102 DCHECK(CalledOnValidThread()); 104 DCHECK(CalledOnValidThread());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 gpu::SurfaceHandle parent_window, 151 gpu::SurfaceHandle parent_window,
150 gpu::SurfaceHandle child_window) { 152 gpu::SurfaceHandle child_window) {
151 ::SetParent(child_window, parent_window); 153 ::SetParent(child_window, parent_window);
152 } 154 }
153 #endif 155 #endif
154 156
155 void GpuServiceInternal::SetActiveURL(const GURL& url) { 157 void GpuServiceInternal::SetActiveURL(const GURL& url) {
156 // TODO(penghuang): implement this function. 158 // TODO(penghuang): implement this function.
157 } 159 }
158 160
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( 161 void GpuServiceInternal::InitializeOnGpuThread(
191 mojo::ScopedMessagePipeHandle* channel_handle, 162 mojo::ScopedMessagePipeHandle* channel_handle,
192 base::WaitableEvent* event) { 163 base::WaitableEvent* event) {
193 gpu_info_.video_decode_accelerator_capabilities = 164 gpu_info_.video_decode_accelerator_capabilities =
194 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); 165 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_);
195 gpu_info_.video_encode_accelerator_supported_profiles = 166 gpu_info_.video_encode_accelerator_supported_profiles =
196 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); 167 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_);
197 gpu_info_.jpeg_decode_accelerator_supported = 168 gpu_info_.jpeg_decode_accelerator_supported =
198 media::GpuJpegDecodeAccelerator::IsSupported(); 169 media::GpuJpegDecodeAccelerator::IsSupported();
199 170
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 235 }
265 236
266 std::unique_ptr<base::SharedMemory> GpuServiceInternal::AllocateSharedMemory( 237 std::unique_ptr<base::SharedMemory> GpuServiceInternal::AllocateSharedMemory(
267 size_t size) { 238 size_t size) {
268 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); 239 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory());
269 if (!shm->CreateAnonymous(size)) 240 if (!shm->CreateAnonymous(size))
270 return std::unique_ptr<base::SharedMemory>(); 241 return std::unique_ptr<base::SharedMemory>();
271 return shm; 242 return shm;
272 } 243 }
273 244
245 void GpuServiceInternal::Initialize(const InitializeCallback& callback) {
246 DCHECK(CalledOnValidThread());
247 base::Thread::Options thread_options(base::MessageLoop::TYPE_DEFAULT, 0);
248 thread_options.priority = base::ThreadPriority::NORMAL;
249 CHECK(gpu_thread_.StartWithOptions(thread_options));
250
251 thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0);
252 thread_options.priority = base::ThreadPriority::NORMAL;
253 #if defined(OS_ANDROID)
254 // TODO(reveman): Remove this in favor of setting it explicitly for each type
255 // of process.
256 thread_options.priority = base::ThreadPriority::DISPLAY;
257 #endif
258 CHECK(io_thread_.StartWithOptions(thread_options));
259
260 mojo::ScopedMessagePipeHandle channel_handle;
261 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL,
262 base::WaitableEvent::InitialState::NOT_SIGNALED);
263 gpu_thread_.task_runner()->PostTask(
264 FROM_HERE, base::Bind(&GpuServiceInternal::InitializeOnGpuThread,
265 base::Unretained(this), &channel_handle, &event));
266 event.Wait();
267
268 gpu_memory_buffer_manager_local_.reset(
269 new MusGpuMemoryBufferManager(this, kLocalGpuChannelClientId));
270 gpu_channel_local_ = gpu::GpuChannelHost::Create(
271 this, kLocalGpuChannelClientId, gpu_info_,
272 IPC::ChannelHandle(channel_handle.release()), &shutdown_event_,
273 gpu_memory_buffer_manager_local_.get());
274
275 // TODO(sad): Get the real GPUInfo.
276 callback.Run(gpu_info_);
277 }
278
279 void GpuServiceInternal::EstablishGpuChannel(
280 int32_t client_id,
281 uint64_t client_tracing_id,
282 const EstablishGpuChannelCallback& callback) {
283 // TODO(penghuang): windows server may want to control those flags.
284 // Add a private interface for windows server.
285 const bool preempts = false;
286 const bool allow_view_command_buffers = false;
287 const bool allow_real_time_streams = false;
288 EstablishGpuChannelInternal(client_id, client_tracing_id, preempts,
289 allow_view_command_buffers,
290 allow_real_time_streams, callback);
291 }
292
274 // static 293 // static
275 GpuServiceInternal* GpuServiceInternal::GetInstance() { 294 GpuServiceInternal* GpuServiceInternal::GetInstance() {
276 return base::Singleton<GpuServiceInternal, 295 return base::Singleton<GpuServiceInternal,
277 base::LeakySingletonTraits<GpuServiceInternal>>::get(); 296 base::LeakySingletonTraits<GpuServiceInternal>>::get();
278 } 297 }
279 298
280 } // namespace ui 299 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/gpu/gpu_service_internal.h ('k') | services/ui/gpu/interfaces/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698