| OLD | NEW |
| 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_mus.h" | 5 #include "services/ui/gpu/gpu_service_mus.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 24 matching lines...) Expand all Loading... |
| 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, | 44 int client_id, |
| 45 const IPC::ChannelHandle* channel_handle, | 45 mojo::ScopedMessagePipeHandle* channel_handle, |
| 46 const GpuServiceMus::EstablishGpuChannelCallback& callback) { | 46 const GpuServiceMus::EstablishGpuChannelCallback& callback) { |
| 47 callback.Run(channel_handle ? client_id : -1, *channel_handle); | 47 callback.Run(client_id, std::move(*channel_handle)); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 GpuServiceMus::GpuServiceMus() | 51 GpuServiceMus::GpuServiceMus() |
| 52 : next_client_id_(kLocalGpuChannelClientId), | 52 : next_client_id_(kLocalGpuChannelClientId), |
| 53 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 53 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 54 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, | 54 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
| 55 base::WaitableEvent::InitialState::NOT_SIGNALED), | 55 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 56 gpu_thread_("GpuThread"), | 56 gpu_thread_("GpuThread"), |
| 57 io_thread_("GpuIOThread") { | 57 io_thread_("GpuIOThread") { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 69 | 69 |
| 70 void GpuServiceMus::EstablishGpuChannel( | 70 void GpuServiceMus::EstablishGpuChannel( |
| 71 uint64_t client_tracing_id, | 71 uint64_t client_tracing_id, |
| 72 bool preempts, | 72 bool preempts, |
| 73 bool allow_view_command_buffers, | 73 bool allow_view_command_buffers, |
| 74 bool allow_real_time_streams, | 74 bool allow_real_time_streams, |
| 75 const EstablishGpuChannelCallback& callback) { | 75 const EstablishGpuChannelCallback& callback) { |
| 76 DCHECK(CalledOnValidThread()); | 76 DCHECK(CalledOnValidThread()); |
| 77 | 77 |
| 78 if (!gpu_channel_manager_) { | 78 if (!gpu_channel_manager_) { |
| 79 callback.Run(-1, IPC::ChannelHandle()); | 79 callback.Run(-1, mojo::ScopedMessagePipeHandle()); |
| 80 return; | 80 return; |
| 81 } | 81 } |
| 82 | 82 |
| 83 const int client_id = ++next_client_id_; | 83 const int client_id = ++next_client_id_; |
| 84 IPC::ChannelHandle* channel_handle = new IPC::ChannelHandle; | 84 auto* channel_handle = new mojo::ScopedMessagePipeHandle; |
| 85 gpu_thread_.task_runner()->PostTaskAndReply( | 85 gpu_thread_.task_runner()->PostTaskAndReply( |
| 86 FROM_HERE, | 86 FROM_HERE, |
| 87 base::Bind(&GpuServiceMus::EstablishGpuChannelOnGpuThread, | 87 base::Bind(&GpuServiceMus::EstablishGpuChannelOnGpuThread, |
| 88 base::Unretained(this), client_id, client_tracing_id, preempts, | 88 base::Unretained(this), client_id, client_tracing_id, preempts, |
| 89 allow_view_command_buffers, allow_real_time_streams, | 89 allow_view_command_buffers, allow_real_time_streams, |
| 90 base::Unretained(channel_handle)), | 90 base::Unretained(channel_handle)), |
| 91 base::Bind(&EstablishGpuChannelDone, client_id, | 91 base::Bind(&EstablishGpuChannelDone, client_id, |
| 92 base::Owned(channel_handle), callback)); | 92 base::Owned(channel_handle), callback)); |
| 93 } | 93 } |
| 94 | 94 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 162 |
| 163 thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0); | 163 thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0); |
| 164 thread_options.priority = base::ThreadPriority::NORMAL; | 164 thread_options.priority = base::ThreadPriority::NORMAL; |
| 165 #if defined(OS_ANDROID) | 165 #if defined(OS_ANDROID) |
| 166 // TODO(reveman): Remove this in favor of setting it explicitly for each type | 166 // TODO(reveman): Remove this in favor of setting it explicitly for each type |
| 167 // of process. | 167 // of process. |
| 168 thread_options.priority = base::ThreadPriority::DISPLAY; | 168 thread_options.priority = base::ThreadPriority::DISPLAY; |
| 169 #endif | 169 #endif |
| 170 CHECK(io_thread_.StartWithOptions(thread_options)); | 170 CHECK(io_thread_.StartWithOptions(thread_options)); |
| 171 | 171 |
| 172 IPC::ChannelHandle channel_handle; | 172 mojo::ScopedMessagePipeHandle channel_handle; |
| 173 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, | 173 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, |
| 174 base::WaitableEvent::InitialState::NOT_SIGNALED); | 174 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 175 gpu_thread_.task_runner()->PostTask( | 175 gpu_thread_.task_runner()->PostTask( |
| 176 FROM_HERE, base::Bind(&GpuServiceMus::InitializeOnGpuThread, | 176 FROM_HERE, base::Bind(&GpuServiceMus::InitializeOnGpuThread, |
| 177 base::Unretained(this), &channel_handle, &event)); | 177 base::Unretained(this), &channel_handle, &event)); |
| 178 event.Wait(); | 178 event.Wait(); |
| 179 | 179 |
| 180 gpu_memory_buffer_manager_local_.reset( | 180 gpu_memory_buffer_manager_local_.reset( |
| 181 new MusGpuMemoryBufferManager(this, kLocalGpuChannelClientId)); | 181 new MusGpuMemoryBufferManager(this, kLocalGpuChannelClientId)); |
| 182 gpu_channel_local_ = gpu::GpuChannelHost::Create( | 182 gpu_channel_local_ = gpu::GpuChannelHost::Create( |
| 183 this, kLocalGpuChannelClientId, gpu_info_, channel_handle, | 183 this, kLocalGpuChannelClientId, gpu_info_, |
| 184 &shutdown_event_, gpu_memory_buffer_manager_local_.get()); | 184 IPC::ChannelHandle(channel_handle.release()), &shutdown_event_, |
| 185 gpu_memory_buffer_manager_local_.get()); |
| 185 } | 186 } |
| 186 | 187 |
| 187 void GpuServiceMus::InitializeOnGpuThread(IPC::ChannelHandle* channel_handle, | 188 void GpuServiceMus::InitializeOnGpuThread( |
| 188 base::WaitableEvent* event) { | 189 mojo::ScopedMessagePipeHandle* channel_handle, |
| 190 base::WaitableEvent* event) { |
| 189 gpu_info_.video_decode_accelerator_capabilities = | 191 gpu_info_.video_decode_accelerator_capabilities = |
| 190 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); | 192 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); |
| 191 gpu_info_.video_encode_accelerator_supported_profiles = | 193 gpu_info_.video_encode_accelerator_supported_profiles = |
| 192 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); | 194 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); |
| 193 gpu_info_.jpeg_decode_accelerator_supported = | 195 gpu_info_.jpeg_decode_accelerator_supported = |
| 194 media::GpuJpegDecodeAccelerator::IsSupported(); | 196 media::GpuJpegDecodeAccelerator::IsSupported(); |
| 195 | 197 |
| 196 #if defined(USE_OZONE) | 198 #if defined(USE_OZONE) |
| 197 // TODO(rjkroege): Must plumb the shell::Connector* to here and pass into | 199 // TODO(rjkroege): Must plumb the shell::Connector* to here and pass into |
| 198 // ozone. | 200 // ozone. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 allow_view_command_buffers, allow_real_time_streams, channel_handle); | 235 allow_view_command_buffers, allow_real_time_streams, channel_handle); |
| 234 event->Signal(); | 236 event->Signal(); |
| 235 } | 237 } |
| 236 | 238 |
| 237 void GpuServiceMus::EstablishGpuChannelOnGpuThread( | 239 void GpuServiceMus::EstablishGpuChannelOnGpuThread( |
| 238 int client_id, | 240 int client_id, |
| 239 uint64_t client_tracing_id, | 241 uint64_t client_tracing_id, |
| 240 bool preempts, | 242 bool preempts, |
| 241 bool allow_view_command_buffers, | 243 bool allow_view_command_buffers, |
| 242 bool allow_real_time_streams, | 244 bool allow_real_time_streams, |
| 243 IPC::ChannelHandle* channel_handle) { | 245 mojo::ScopedMessagePipeHandle* channel_handle) { |
| 244 if (gpu_channel_manager_) { | 246 if (gpu_channel_manager_) { |
| 245 *channel_handle = gpu_channel_manager_->EstablishChannel( | 247 auto handle = gpu_channel_manager_->EstablishChannel( |
| 246 client_id, client_tracing_id, preempts, allow_view_command_buffers, | 248 client_id, client_tracing_id, preempts, allow_view_command_buffers, |
| 247 allow_real_time_streams); | 249 allow_real_time_streams); |
| 250 channel_handle->reset(handle.mojo_handle); |
| 248 media_service_->AddChannel(client_id); | 251 media_service_->AddChannel(client_id); |
| 249 } | 252 } |
| 250 } | 253 } |
| 251 | 254 |
| 252 bool GpuServiceMus::IsMainThread() { | 255 bool GpuServiceMus::IsMainThread() { |
| 253 return main_task_runner_->BelongsToCurrentThread(); | 256 return main_task_runner_->BelongsToCurrentThread(); |
| 254 } | 257 } |
| 255 | 258 |
| 256 scoped_refptr<base::SingleThreadTaskRunner> | 259 scoped_refptr<base::SingleThreadTaskRunner> |
| 257 GpuServiceMus::GetIOThreadTaskRunner() { | 260 GpuServiceMus::GetIOThreadTaskRunner() { |
| 258 return io_thread_.task_runner(); | 261 return io_thread_.task_runner(); |
| 259 } | 262 } |
| 260 | 263 |
| 261 std::unique_ptr<base::SharedMemory> GpuServiceMus::AllocateSharedMemory( | 264 std::unique_ptr<base::SharedMemory> GpuServiceMus::AllocateSharedMemory( |
| 262 size_t size) { | 265 size_t size) { |
| 263 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); | 266 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); |
| 264 if (!shm->CreateAnonymous(size)) | 267 if (!shm->CreateAnonymous(size)) |
| 265 return std::unique_ptr<base::SharedMemory>(); | 268 return std::unique_ptr<base::SharedMemory>(); |
| 266 return shm; | 269 return shm; |
| 267 } | 270 } |
| 268 | 271 |
| 269 // static | 272 // static |
| 270 GpuServiceMus* GpuServiceMus::GetInstance() { | 273 GpuServiceMus* GpuServiceMus::GetInstance() { |
| 271 return base::Singleton<GpuServiceMus, | 274 return base::Singleton<GpuServiceMus, |
| 272 base::LeakySingletonTraits<GpuServiceMus>>::get(); | 275 base::LeakySingletonTraits<GpuServiceMus>>::get(); |
| 273 } | 276 } |
| 274 | 277 |
| 275 } // namespace ui | 278 } // namespace ui |
| OLD | NEW |