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