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

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

Issue 2281583003: services/ui: Split GpuServiceInternal into gpu vs. ws pieces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@DONE_2016.08.24_mus-ws-gpu-refactor
Patch Set: tot merge 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
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"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "gpu/command_buffer/service/gpu_switches.h" 12 #include "gpu/command_buffer/service/gpu_switches.h"
13 #include "gpu/command_buffer/service/sync_point_manager.h" 13 #include "gpu/command_buffer/service/sync_point_manager.h"
14 #include "gpu/config/gpu_info_collector.h" 14 #include "gpu/config/gpu_info_collector.h"
15 #include "gpu/config/gpu_switches.h" 15 #include "gpu/config/gpu_switches.h"
16 #include "gpu/config/gpu_util.h" 16 #include "gpu/config/gpu_util.h"
17 #include "gpu/ipc/common/gpu_memory_buffer_support.h" 17 #include "gpu/ipc/common/gpu_memory_buffer_support.h"
18 #include "gpu/ipc/common/memory_stats.h" 18 #include "gpu/ipc/common/memory_stats.h"
19 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" 19 #include "gpu/ipc/service/gpu_memory_buffer_factory.h"
20 #include "ipc/ipc_channel_handle.h" 20 #include "ipc/ipc_channel_handle.h"
21 #include "ipc/ipc_sync_message_filter.h" 21 #include "ipc/ipc_sync_message_filter.h"
22 #include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h" 22 #include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h"
23 #include "media/gpu/ipc/service/gpu_video_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" 24 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h"
25 #include "media/gpu/ipc/service/media_service.h" 25 #include "media/gpu/ipc/service/media_service.h"
26 #include "services/ui/gpu/mus_gpu_memory_buffer_manager.h"
27 #include "ui/gl/gl_implementation.h" 26 #include "ui/gl/gl_implementation.h"
28 #include "ui/gl/gl_switches.h" 27 #include "ui/gl/gl_switches.h"
29 #include "ui/gl/gpu_switching_manager.h" 28 #include "ui/gl/gpu_switching_manager.h"
30 #include "ui/gl/init/gl_factory.h" 29 #include "ui/gl/init/gl_factory.h"
31 #include "url/gurl.h" 30 #include "url/gurl.h"
32 31
33 #if defined(USE_OZONE) 32 #if defined(USE_OZONE)
34 #include "ui/ozone/public/ozone_platform.h" 33 #include "ui/ozone/public/ozone_platform.h"
35 #endif 34 #endif
36 35
37 namespace ui { 36 namespace ui {
38 namespace { 37 namespace {
39 38
40 const int kLocalGpuChannelClientId = 1;
41 const uint64_t kLocalGpuChannelClientTracingId = 1;
42
43 void EstablishGpuChannelDone( 39 void EstablishGpuChannelDone(
44 mojo::ScopedMessagePipeHandle* channel_handle, 40 mojo::ScopedMessagePipeHandle* channel_handle,
45 const GpuServiceInternal::EstablishGpuChannelCallback& callback) { 41 const GpuServiceInternal::EstablishGpuChannelCallback& callback) {
46 callback.Run(std::move(*channel_handle)); 42 callback.Run(std::move(*channel_handle));
47 } 43 }
48 44
49 } // namespace 45 } // namespace
50 46
51 GpuServiceInternal::GpuServiceInternal() 47 GpuServiceInternal::GpuServiceInternal()
52 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), 48 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()),
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 gpu::SurfaceHandle parent_window, 147 gpu::SurfaceHandle parent_window,
152 gpu::SurfaceHandle child_window) { 148 gpu::SurfaceHandle child_window) {
153 ::SetParent(child_window, parent_window); 149 ::SetParent(child_window, parent_window);
154 } 150 }
155 #endif 151 #endif
156 152
157 void GpuServiceInternal::SetActiveURL(const GURL& url) { 153 void GpuServiceInternal::SetActiveURL(const GURL& url) {
158 // TODO(penghuang): implement this function. 154 // TODO(penghuang): implement this function.
159 } 155 }
160 156
161 void GpuServiceInternal::InitializeOnGpuThread( 157 void GpuServiceInternal::InitializeOnGpuThread(base::WaitableEvent* event) {
162 mojo::ScopedMessagePipeHandle* channel_handle,
163 base::WaitableEvent* event) {
164 gpu_info_.video_decode_accelerator_capabilities = 158 gpu_info_.video_decode_accelerator_capabilities =
165 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); 159 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_);
166 gpu_info_.video_encode_accelerator_supported_profiles = 160 gpu_info_.video_encode_accelerator_supported_profiles =
167 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); 161 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_);
168 gpu_info_.jpeg_decode_accelerator_supported = 162 gpu_info_.jpeg_decode_accelerator_supported =
169 media::GpuJpegDecodeAccelerator::IsSupported(); 163 media::GpuJpegDecodeAccelerator::IsSupported();
170 164
171 #if defined(USE_OZONE) 165 #if defined(USE_OZONE)
172 // TODO(rjkroege): Must plumb the shell::Connector* to here and pass into 166 // TODO(rjkroege): Must plumb the shell::Connector* to here and pass into
173 // ozone. 167 // ozone.
(...skipping 18 matching lines...) Expand all
192 // initialization has succeeded. 186 // initialization has succeeded.
193 // TODO(penghuang): implement a watchdog. 187 // TODO(penghuang): implement a watchdog.
194 gpu::GpuWatchdog* watchdog = nullptr; 188 gpu::GpuWatchdog* watchdog = nullptr;
195 gpu_channel_manager_.reset(new gpu::GpuChannelManager( 189 gpu_channel_manager_.reset(new gpu::GpuChannelManager(
196 gpu_preferences_, this, watchdog, 190 gpu_preferences_, this, watchdog,
197 base::ThreadTaskRunnerHandle::Get().get(), io_thread_.task_runner().get(), 191 base::ThreadTaskRunnerHandle::Get().get(), io_thread_.task_runner().get(),
198 &shutdown_event_, owned_sync_point_manager_.get(), 192 &shutdown_event_, owned_sync_point_manager_.get(),
199 gpu_memory_buffer_factory_.get())); 193 gpu_memory_buffer_factory_.get()));
200 194
201 media_service_.reset(new media::MediaService(gpu_channel_manager_.get())); 195 media_service_.reset(new media::MediaService(gpu_channel_manager_.get()));
202
203 const bool preempts = true;
204 const bool allow_view_command_buffers = true;
205 const bool allow_real_time_streams = true;
206 EstablishGpuChannelOnGpuThread(
207 kLocalGpuChannelClientId, kLocalGpuChannelClientTracingId, preempts,
208 allow_view_command_buffers, allow_real_time_streams, channel_handle);
209 event->Signal(); 196 event->Signal();
210 } 197 }
211 198
212 void GpuServiceInternal::EstablishGpuChannelOnGpuThread( 199 void GpuServiceInternal::EstablishGpuChannelOnGpuThread(
213 int client_id, 200 int client_id,
214 uint64_t client_tracing_id, 201 uint64_t client_tracing_id,
215 bool preempts, 202 bool preempts,
216 bool allow_view_command_buffers, 203 bool allow_view_command_buffers,
217 bool allow_real_time_streams, 204 bool allow_real_time_streams,
218 mojo::ScopedMessagePipeHandle* channel_handle) { 205 mojo::ScopedMessagePipeHandle* channel_handle) {
219 if (gpu_channel_manager_) { 206 if (gpu_channel_manager_) {
220 auto handle = gpu_channel_manager_->EstablishChannel( 207 auto handle = gpu_channel_manager_->EstablishChannel(
221 client_id, client_tracing_id, preempts, allow_view_command_buffers, 208 client_id, client_tracing_id, preempts, allow_view_command_buffers,
222 allow_real_time_streams); 209 allow_real_time_streams);
223 channel_handle->reset(handle.mojo_handle); 210 channel_handle->reset(handle.mojo_handle);
224 media_service_->AddChannel(client_id); 211 media_service_->AddChannel(client_id);
225 } 212 }
226 } 213 }
227 214
228 bool GpuServiceInternal::IsMainThread() {
229 return main_task_runner_->BelongsToCurrentThread();
230 }
231
232 scoped_refptr<base::SingleThreadTaskRunner>
233 GpuServiceInternal::GetIOThreadTaskRunner() {
234 return io_thread_.task_runner();
235 }
236
237 std::unique_ptr<base::SharedMemory> GpuServiceInternal::AllocateSharedMemory(
238 size_t size) {
239 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory());
240 if (!shm->CreateAnonymous(size))
241 return std::unique_ptr<base::SharedMemory>();
242 return shm;
243 }
244
245 void GpuServiceInternal::Initialize(const InitializeCallback& callback) { 215 void GpuServiceInternal::Initialize(const InitializeCallback& callback) {
246 DCHECK(CalledOnValidThread()); 216 DCHECK(CalledOnValidThread());
247 base::Thread::Options thread_options(base::MessageLoop::TYPE_DEFAULT, 0); 217 base::Thread::Options thread_options(base::MessageLoop::TYPE_DEFAULT, 0);
248 thread_options.priority = base::ThreadPriority::NORMAL; 218 thread_options.priority = base::ThreadPriority::NORMAL;
249 CHECK(gpu_thread_.StartWithOptions(thread_options)); 219 CHECK(gpu_thread_.StartWithOptions(thread_options));
250 220
251 thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0); 221 thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0);
252 thread_options.priority = base::ThreadPriority::NORMAL; 222 thread_options.priority = base::ThreadPriority::NORMAL;
253 #if defined(OS_ANDROID) 223 #if defined(OS_ANDROID)
254 // TODO(reveman): Remove this in favor of setting it explicitly for each type 224 // TODO(reveman): Remove this in favor of setting it explicitly for each type
255 // of process. 225 // of process.
256 thread_options.priority = base::ThreadPriority::DISPLAY; 226 thread_options.priority = base::ThreadPriority::DISPLAY;
257 #endif 227 #endif
258 CHECK(io_thread_.StartWithOptions(thread_options)); 228 CHECK(io_thread_.StartWithOptions(thread_options));
259 229
260 mojo::ScopedMessagePipeHandle channel_handle;
261 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, 230 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL,
262 base::WaitableEvent::InitialState::NOT_SIGNALED); 231 base::WaitableEvent::InitialState::NOT_SIGNALED);
263 gpu_thread_.task_runner()->PostTask( 232 gpu_thread_.task_runner()->PostTask(
264 FROM_HERE, base::Bind(&GpuServiceInternal::InitializeOnGpuThread, 233 FROM_HERE, base::Bind(&GpuServiceInternal::InitializeOnGpuThread,
265 base::Unretained(this), &channel_handle, &event)); 234 base::Unretained(this), &event));
266 event.Wait(); 235 event.Wait();
267 236
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. 237 // TODO(sad): Get the real GPUInfo.
276 callback.Run(gpu_info_); 238 callback.Run(gpu_info_);
277 } 239 }
278 240
279 void GpuServiceInternal::EstablishGpuChannel( 241 void GpuServiceInternal::EstablishGpuChannel(
280 int32_t client_id, 242 int32_t client_id,
281 uint64_t client_tracing_id, 243 uint64_t client_tracing_id,
244 bool privileged,
Fady Samuel 2016/08/26 16:27:59 Maybe be more explicit on what this means? is_gpu_
sadrul 2016/08/26 17:23:50 Done.
282 const EstablishGpuChannelCallback& callback) { 245 const EstablishGpuChannelCallback& callback) {
283 // TODO(penghuang): windows server may want to control those flags. 246 const bool preempts = privileged;
284 // Add a private interface for windows server. 247 const bool allow_view_command_buffers = privileged;
285 const bool preempts = false; 248 const bool allow_real_time_streams = privileged;
286 const bool allow_view_command_buffers = false;
287 const bool allow_real_time_streams = false;
288 EstablishGpuChannelInternal(client_id, client_tracing_id, preempts, 249 EstablishGpuChannelInternal(client_id, client_tracing_id, preempts,
289 allow_view_command_buffers, 250 allow_view_command_buffers,
290 allow_real_time_streams, callback); 251 allow_real_time_streams, callback);
291 } 252 }
292 253
293 // static 254 // static
294 GpuServiceInternal* GpuServiceInternal::GetInstance() { 255 GpuServiceInternal* GpuServiceInternal::GetInstance() {
295 return base::Singleton<GpuServiceInternal, 256 return base::Singleton<GpuServiceInternal,
296 base::LeakySingletonTraits<GpuServiceInternal>>::get(); 257 base::LeakySingletonTraits<GpuServiceInternal>>::get();
297 } 258 }
298 259
299 } // namespace ui 260 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698