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 const gpu::GPUInfo& gpu_info, |
| 49 gpu::GpuWatchdogThread* watchdog_thread, |
| 50 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) |
49 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 51 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
50 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, | 52 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
51 base::WaitableEvent::InitialState::NOT_SIGNALED), | 53 base::WaitableEvent::InitialState::NOT_SIGNALED), |
52 gpu_thread_("GpuThread"), | 54 gpu_thread_("GpuThread"), |
53 io_thread_("GpuIOThread"), | 55 io_thread_("GpuIOThread"), |
| 56 watchdog_thread_(watchdog_thread), |
| 57 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), |
| 58 gpu_info_(gpu_info), |
54 binding_(this) {} | 59 binding_(this) {} |
55 | 60 |
56 GpuServiceInternal::~GpuServiceInternal() { | 61 GpuServiceInternal::~GpuServiceInternal() { |
57 // Signal this event before destroying the child process. That way all | 62 // Signal this event before destroying the child process. That way all |
58 // background threads can cleanup. | 63 // background threads can cleanup. |
59 // For example, in the renderer the RenderThread instances will be able to | 64 // 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. | 65 // notice shutdown before the render process begins waiting for them to exit. |
61 shutdown_event_.Signal(); | 66 shutdown_event_.Signal(); |
62 io_thread_.Stop(); | 67 io_thread_.Stop(); |
63 } | 68 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 } | 157 } |
153 | 158 |
154 void GpuServiceInternal::InitializeOnGpuThread(base::WaitableEvent* event) { | 159 void GpuServiceInternal::InitializeOnGpuThread(base::WaitableEvent* event) { |
155 gpu_info_.video_decode_accelerator_capabilities = | 160 gpu_info_.video_decode_accelerator_capabilities = |
156 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); | 161 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); |
157 gpu_info_.video_encode_accelerator_supported_profiles = | 162 gpu_info_.video_encode_accelerator_supported_profiles = |
158 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); | 163 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); |
159 gpu_info_.jpeg_decode_accelerator_supported = | 164 gpu_info_.jpeg_decode_accelerator_supported = |
160 media::GpuJpegDecodeAccelerator::IsSupported(); | 165 media::GpuJpegDecodeAccelerator::IsSupported(); |
161 | 166 |
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 | |
176 DCHECK(!owned_sync_point_manager_); | 167 DCHECK(!owned_sync_point_manager_); |
177 const bool allow_threaded_wait = false; | 168 const bool allow_threaded_wait = false; |
178 owned_sync_point_manager_.reset( | 169 owned_sync_point_manager_.reset( |
179 new gpu::SyncPointManager(allow_threaded_wait)); | 170 new gpu::SyncPointManager(allow_threaded_wait)); |
180 | 171 |
181 // Defer creation of the render thread. This is to prevent it from handling | 172 // Defer creation of the render thread. This is to prevent it from handling |
182 // IPC messages before the sandbox has been enabled and all other necessary | 173 // IPC messages before the sandbox has been enabled and all other necessary |
183 // initialization has succeeded. | 174 // initialization has succeeded. |
184 watchdog_thread_ = gpu::GpuWatchdogThread::Create(); | |
185 gpu_channel_manager_.reset(new gpu::GpuChannelManager( | 175 gpu_channel_manager_.reset(new gpu::GpuChannelManager( |
186 gpu_preferences_, this, watchdog_thread_.get(), | 176 gpu_preferences_, this, watchdog_thread_, |
187 base::ThreadTaskRunnerHandle::Get().get(), io_thread_.task_runner().get(), | 177 base::ThreadTaskRunnerHandle::Get().get(), io_thread_.task_runner().get(), |
188 &shutdown_event_, owned_sync_point_manager_.get(), | 178 &shutdown_event_, owned_sync_point_manager_.get(), |
189 gpu_memory_buffer_factory_.get())); | 179 gpu_memory_buffer_factory_)); |
190 | 180 |
191 media_service_.reset(new media::MediaService(gpu_channel_manager_.get())); | 181 media_service_.reset(new media::MediaService(gpu_channel_manager_.get())); |
192 event->Signal(); | 182 event->Signal(); |
193 } | 183 } |
194 | 184 |
195 void GpuServiceInternal::EstablishGpuChannelOnGpuThread( | 185 void GpuServiceInternal::EstablishGpuChannelOnGpuThread( |
196 int client_id, | 186 int client_id, |
197 uint64_t client_tracing_id, | 187 uint64_t client_tracing_id, |
198 bool preempts, | 188 bool preempts, |
199 bool allow_view_command_buffers, | 189 bool allow_view_command_buffers, |
(...skipping 23 matching lines...) Expand all Loading... |
223 #endif | 213 #endif |
224 CHECK(io_thread_.StartWithOptions(thread_options)); | 214 CHECK(io_thread_.StartWithOptions(thread_options)); |
225 | 215 |
226 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, | 216 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, |
227 base::WaitableEvent::InitialState::NOT_SIGNALED); | 217 base::WaitableEvent::InitialState::NOT_SIGNALED); |
228 gpu_thread_.task_runner()->PostTask( | 218 gpu_thread_.task_runner()->PostTask( |
229 FROM_HERE, base::Bind(&GpuServiceInternal::InitializeOnGpuThread, | 219 FROM_HERE, base::Bind(&GpuServiceInternal::InitializeOnGpuThread, |
230 base::Unretained(this), &event)); | 220 base::Unretained(this), &event)); |
231 event.Wait(); | 221 event.Wait(); |
232 | 222 |
233 // TODO(sad): Get the real GPUInfo. | |
234 callback.Run(gpu_info_); | 223 callback.Run(gpu_info_); |
235 } | 224 } |
236 | 225 |
237 void GpuServiceInternal::EstablishGpuChannel( | 226 void GpuServiceInternal::EstablishGpuChannel( |
238 int32_t client_id, | 227 int32_t client_id, |
239 uint64_t client_tracing_id, | 228 uint64_t client_tracing_id, |
240 bool is_gpu_host, | 229 bool is_gpu_host, |
241 const EstablishGpuChannelCallback& callback) { | 230 const EstablishGpuChannelCallback& callback) { |
242 const bool preempts = is_gpu_host; | 231 const bool preempts = is_gpu_host; |
243 const bool allow_view_command_buffers = is_gpu_host; | 232 const bool allow_view_command_buffers = is_gpu_host; |
244 const bool allow_real_time_streams = is_gpu_host; | 233 const bool allow_real_time_streams = is_gpu_host; |
245 EstablishGpuChannelInternal(client_id, client_tracing_id, preempts, | 234 EstablishGpuChannelInternal(client_id, client_tracing_id, preempts, |
246 allow_view_command_buffers, | 235 allow_view_command_buffers, |
247 allow_real_time_streams, callback); | 236 allow_real_time_streams, callback); |
248 } | 237 } |
249 | 238 |
250 // static | |
251 GpuServiceInternal* GpuServiceInternal::GetInstance() { | |
252 return base::Singleton<GpuServiceInternal, | |
253 base::LeakySingletonTraits<GpuServiceInternal>>::get(); | |
254 } | |
255 | |
256 } // namespace ui | 239 } // namespace ui |
OLD | NEW |