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_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/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
9 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
10 #include "build/build_config.h" | 11 #include "build/build_config.h" |
11 #include "gpu/command_buffer/service/gpu_switches.h" | 12 #include "gpu/command_buffer/service/gpu_switches.h" |
12 #include "gpu/command_buffer/service/sync_point_manager.h" | 13 #include "gpu/command_buffer/service/sync_point_manager.h" |
13 #include "gpu/config/gpu_info_collector.h" | 14 #include "gpu/config/gpu_info_collector.h" |
14 #include "gpu/config/gpu_switches.h" | 15 #include "gpu/config/gpu_switches.h" |
15 #include "gpu/config/gpu_util.h" | 16 #include "gpu/config/gpu_util.h" |
16 #include "gpu/ipc/common/gpu_memory_buffer_support.h" | 17 #include "gpu/ipc/common/gpu_memory_buffer_support.h" |
17 #include "gpu/ipc/common/memory_stats.h" | 18 #include "gpu/ipc/common/memory_stats.h" |
(...skipping 19 matching lines...) Expand all Loading... |
37 namespace { | 38 namespace { |
38 | 39 |
39 void EstablishGpuChannelDone( | 40 void EstablishGpuChannelDone( |
40 mojo::ScopedMessagePipeHandle* channel_handle, | 41 mojo::ScopedMessagePipeHandle* channel_handle, |
41 const GpuServiceInternal::EstablishGpuChannelCallback& callback) { | 42 const GpuServiceInternal::EstablishGpuChannelCallback& callback) { |
42 callback.Run(std::move(*channel_handle)); | 43 callback.Run(std::move(*channel_handle)); |
43 } | 44 } |
44 | 45 |
45 } // namespace | 46 } // namespace |
46 | 47 |
47 GpuServiceInternal::GpuServiceInternal( | 48 GpuServiceInternal::GpuServiceInternal() |
48 const gpu::GPUInfo& gpu_info, | |
49 gpu::GpuWatchdogThread* watchdog_thread, | |
50 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) | |
51 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 49 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
52 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, | 50 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
53 base::WaitableEvent::InitialState::NOT_SIGNALED), | 51 base::WaitableEvent::InitialState::NOT_SIGNALED), |
54 gpu_thread_("GpuThread"), | 52 gpu_thread_("GpuThread"), |
55 io_thread_("GpuIOThread"), | 53 io_thread_("GpuIOThread"), |
56 watchdog_thread_(watchdog_thread), | |
57 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), | |
58 gpu_info_(gpu_info), | |
59 binding_(this) {} | 54 binding_(this) {} |
60 | 55 |
61 GpuServiceInternal::~GpuServiceInternal() { | 56 GpuServiceInternal::~GpuServiceInternal() { |
62 // Signal this event before destroying the child process. That way all | 57 // Signal this event before destroying the child process. That way all |
63 // background threads can cleanup. | 58 // background threads can cleanup. |
64 // For example, in the renderer the RenderThread instances will be able to | 59 // 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. | 60 // notice shutdown before the render process begins waiting for them to exit. |
66 shutdown_event_.Signal(); | 61 shutdown_event_.Signal(); |
67 io_thread_.Stop(); | 62 io_thread_.Stop(); |
68 } | 63 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 } | 152 } |
158 | 153 |
159 void GpuServiceInternal::InitializeOnGpuThread(base::WaitableEvent* event) { | 154 void GpuServiceInternal::InitializeOnGpuThread(base::WaitableEvent* event) { |
160 gpu_info_.video_decode_accelerator_capabilities = | 155 gpu_info_.video_decode_accelerator_capabilities = |
161 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); | 156 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); |
162 gpu_info_.video_encode_accelerator_supported_profiles = | 157 gpu_info_.video_encode_accelerator_supported_profiles = |
163 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); | 158 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); |
164 gpu_info_.jpeg_decode_accelerator_supported = | 159 gpu_info_.jpeg_decode_accelerator_supported = |
165 media::GpuJpegDecodeAccelerator::IsSupported(); | 160 media::GpuJpegDecodeAccelerator::IsSupported(); |
166 | 161 |
| 162 #if defined(USE_OZONE) |
| 163 // TODO(rjkroege): Must plumb the shell::Connector* to here and pass into |
| 164 // ozone. |
| 165 ui::OzonePlatform::InitializeForGPU(); |
| 166 #endif |
| 167 |
| 168 if (gpu::GetNativeGpuMemoryBufferType() != gfx::EMPTY_BUFFER) { |
| 169 gpu_memory_buffer_factory_ = |
| 170 gpu::GpuMemoryBufferFactory::CreateNativeType(); |
| 171 } |
| 172 |
| 173 if (!gl::init::InitializeGLOneOff()) |
| 174 VLOG(1) << "gl::init::InitializeGLOneOff failed"; |
| 175 |
167 DCHECK(!owned_sync_point_manager_); | 176 DCHECK(!owned_sync_point_manager_); |
168 const bool allow_threaded_wait = false; | 177 const bool allow_threaded_wait = false; |
169 owned_sync_point_manager_.reset( | 178 owned_sync_point_manager_.reset( |
170 new gpu::SyncPointManager(allow_threaded_wait)); | 179 new gpu::SyncPointManager(allow_threaded_wait)); |
171 | 180 |
172 // Defer creation of the render thread. This is to prevent it from handling | 181 // Defer creation of the render thread. This is to prevent it from handling |
173 // IPC messages before the sandbox has been enabled and all other necessary | 182 // IPC messages before the sandbox has been enabled and all other necessary |
174 // initialization has succeeded. | 183 // initialization has succeeded. |
| 184 watchdog_thread_ = gpu::GpuWatchdogThread::Create(); |
175 gpu_channel_manager_.reset(new gpu::GpuChannelManager( | 185 gpu_channel_manager_.reset(new gpu::GpuChannelManager( |
176 gpu_preferences_, this, watchdog_thread_, | 186 gpu_preferences_, this, watchdog_thread_.get(), |
177 base::ThreadTaskRunnerHandle::Get().get(), io_thread_.task_runner().get(), | 187 base::ThreadTaskRunnerHandle::Get().get(), io_thread_.task_runner().get(), |
178 &shutdown_event_, owned_sync_point_manager_.get(), | 188 &shutdown_event_, owned_sync_point_manager_.get(), |
179 gpu_memory_buffer_factory_)); | 189 gpu_memory_buffer_factory_.get())); |
180 | 190 |
181 media_service_.reset(new media::MediaService(gpu_channel_manager_.get())); | 191 media_service_.reset(new media::MediaService(gpu_channel_manager_.get())); |
182 event->Signal(); | 192 event->Signal(); |
183 } | 193 } |
184 | 194 |
185 void GpuServiceInternal::EstablishGpuChannelOnGpuThread( | 195 void GpuServiceInternal::EstablishGpuChannelOnGpuThread( |
186 int client_id, | 196 int client_id, |
187 uint64_t client_tracing_id, | 197 uint64_t client_tracing_id, |
188 bool preempts, | 198 bool preempts, |
189 bool allow_view_command_buffers, | 199 bool allow_view_command_buffers, |
(...skipping 23 matching lines...) Expand all Loading... |
213 #endif | 223 #endif |
214 CHECK(io_thread_.StartWithOptions(thread_options)); | 224 CHECK(io_thread_.StartWithOptions(thread_options)); |
215 | 225 |
216 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, | 226 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, |
217 base::WaitableEvent::InitialState::NOT_SIGNALED); | 227 base::WaitableEvent::InitialState::NOT_SIGNALED); |
218 gpu_thread_.task_runner()->PostTask( | 228 gpu_thread_.task_runner()->PostTask( |
219 FROM_HERE, base::Bind(&GpuServiceInternal::InitializeOnGpuThread, | 229 FROM_HERE, base::Bind(&GpuServiceInternal::InitializeOnGpuThread, |
220 base::Unretained(this), &event)); | 230 base::Unretained(this), &event)); |
221 event.Wait(); | 231 event.Wait(); |
222 | 232 |
| 233 // TODO(sad): Get the real GPUInfo. |
223 callback.Run(gpu_info_); | 234 callback.Run(gpu_info_); |
224 } | 235 } |
225 | 236 |
226 void GpuServiceInternal::EstablishGpuChannel( | 237 void GpuServiceInternal::EstablishGpuChannel( |
227 int32_t client_id, | 238 int32_t client_id, |
228 uint64_t client_tracing_id, | 239 uint64_t client_tracing_id, |
229 bool is_gpu_host, | 240 bool is_gpu_host, |
230 const EstablishGpuChannelCallback& callback) { | 241 const EstablishGpuChannelCallback& callback) { |
231 const bool preempts = is_gpu_host; | 242 const bool preempts = is_gpu_host; |
232 const bool allow_view_command_buffers = is_gpu_host; | 243 const bool allow_view_command_buffers = is_gpu_host; |
233 const bool allow_real_time_streams = is_gpu_host; | 244 const bool allow_real_time_streams = is_gpu_host; |
234 EstablishGpuChannelInternal(client_id, client_tracing_id, preempts, | 245 EstablishGpuChannelInternal(client_id, client_tracing_id, preempts, |
235 allow_view_command_buffers, | 246 allow_view_command_buffers, |
236 allow_real_time_streams, callback); | 247 allow_real_time_streams, callback); |
237 } | 248 } |
238 | 249 |
| 250 // static |
| 251 GpuServiceInternal* GpuServiceInternal::GetInstance() { |
| 252 return base::Singleton<GpuServiceInternal, |
| 253 base::LeakySingletonTraits<GpuServiceInternal>>::get(); |
| 254 } |
| 255 |
239 } // namespace ui | 256 } // namespace ui |
OLD | NEW |