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.h" | 5 #include "services/ui/gpu/gpu_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/crash_logging.h" | 8 #include "base/debug/crash_logging.h" |
9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 GpuService::GpuService(const gpu::GPUInfo& gpu_info, | 40 GpuService::GpuService(const gpu::GPUInfo& gpu_info, |
41 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, | 41 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, |
42 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, | 42 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, |
43 scoped_refptr<base::SingleThreadTaskRunner> io_runner) | 43 scoped_refptr<base::SingleThreadTaskRunner> io_runner) |
44 : io_runner_(std::move(io_runner)), | 44 : io_runner_(std::move(io_runner)), |
45 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, | 45 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
46 base::WaitableEvent::InitialState::NOT_SIGNALED), | 46 base::WaitableEvent::InitialState::NOT_SIGNALED), |
47 watchdog_thread_(std::move(watchdog_thread)), | 47 watchdog_thread_(std::move(watchdog_thread)), |
48 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), | 48 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), |
49 gpu_info_(gpu_info) {} | 49 gpu_info_(gpu_info), |
| 50 sync_point_manager_(nullptr) {} |
50 | 51 |
51 GpuService::~GpuService() { | 52 GpuService::~GpuService() { |
52 bindings_.CloseAllBindings(); | 53 bindings_.CloseAllBindings(); |
53 media_gpu_channel_manager_.reset(); | 54 media_gpu_channel_manager_.reset(); |
54 gpu_channel_manager_.reset(); | 55 gpu_channel_manager_.reset(); |
55 owned_sync_point_manager_.reset(); | 56 owned_sync_point_manager_.reset(); |
56 | 57 |
57 // Signal this event before destroying the child process. That way all | 58 // Signal this event before destroying the child process. That way all |
58 // background threads can cleanup. | 59 // background threads can cleanup. |
59 // For example, in the renderer the RenderThread instances will be able to | 60 // 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. | 61 // notice shutdown before the render process begins waiting for them to exit. |
61 shutdown_event_.Signal(); | 62 shutdown_event_.Signal(); |
62 } | 63 } |
63 | 64 |
64 void GpuService::InitializeWithHost(mojom::GpuHostPtr gpu_host, | 65 void GpuService::InitializeWithHost(mojom::GpuHostPtr gpu_host, |
65 const gpu::GpuPreferences& preferences) { | 66 const gpu::GpuPreferences& preferences, |
| 67 gpu::SyncPointManager* sync_point_manager, |
| 68 base::WaitableEvent* shutdown_event) { |
66 DCHECK(CalledOnValidThread()); | 69 DCHECK(CalledOnValidThread()); |
67 DCHECK(!gpu_host_); | 70 DCHECK(!gpu_host_); |
68 gpu_host_ = std::move(gpu_host); | 71 gpu_host_ = std::move(gpu_host); |
69 gpu_preferences_ = preferences; | 72 gpu_preferences_ = preferences; |
70 gpu_info_.video_decode_accelerator_capabilities = | 73 gpu_info_.video_decode_accelerator_capabilities = |
71 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); | 74 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); |
72 gpu_info_.video_encode_accelerator_supported_profiles = | 75 gpu_info_.video_encode_accelerator_supported_profiles = |
73 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); | 76 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); |
74 gpu_info_.jpeg_decode_accelerator_supported = | 77 gpu_info_.jpeg_decode_accelerator_supported = |
75 media::GpuJpegDecodeAccelerator::IsSupported(); | 78 media::GpuJpegDecodeAccelerator::IsSupported(); |
76 gpu_host_->DidInitialize(gpu_info_); | 79 gpu_host_->DidInitialize(gpu_info_); |
77 | 80 |
78 DCHECK(!owned_sync_point_manager_); | 81 sync_point_manager_ = sync_point_manager; |
79 const bool allow_threaded_wait = false; | 82 if (!sync_point_manager_) { |
80 owned_sync_point_manager_.reset( | 83 const bool allow_threaded_wait = false; |
81 new gpu::SyncPointManager(allow_threaded_wait)); | 84 owned_sync_point_manager_ = |
| 85 base::MakeUnique<gpu::SyncPointManager>(allow_threaded_wait); |
| 86 sync_point_manager_ = owned_sync_point_manager_.get(); |
| 87 } |
82 | 88 |
83 // Defer creation of the render thread. This is to prevent it from handling | 89 // Defer creation of the render thread. This is to prevent it from handling |
84 // IPC messages before the sandbox has been enabled and all other necessary | 90 // IPC messages before the sandbox has been enabled and all other necessary |
85 // initialization has succeeded. | 91 // initialization has succeeded. |
86 gpu_channel_manager_.reset(new gpu::GpuChannelManager( | 92 gpu_channel_manager_.reset(new gpu::GpuChannelManager( |
87 gpu_preferences_, this, watchdog_thread_.get(), | 93 gpu_preferences_, this, watchdog_thread_.get(), |
88 base::ThreadTaskRunnerHandle::Get().get(), io_runner_.get(), | 94 base::ThreadTaskRunnerHandle::Get().get(), io_runner_.get(), |
89 &shutdown_event_, owned_sync_point_manager_.get(), | 95 shutdown_event ? shutdown_event : &shutdown_event_, sync_point_manager_, |
90 gpu_memory_buffer_factory_)); | 96 gpu_memory_buffer_factory_)); |
91 | 97 |
92 media_gpu_channel_manager_.reset( | 98 media_gpu_channel_manager_.reset( |
93 new media::MediaGpuChannelManager(gpu_channel_manager_.get())); | 99 new media::MediaGpuChannelManager(gpu_channel_manager_.get())); |
94 } | 100 } |
95 | 101 |
96 void GpuService::Bind(mojom::GpuServiceRequest request) { | 102 void GpuService::Bind(mojom::GpuServiceRequest request) { |
97 bindings_.AddBinding(this, std::move(request)); | 103 bindings_.AddBinding(this, std::move(request)); |
98 } | 104 } |
99 | 105 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 mojo::ScopedMessagePipeHandle channel_handle; | 180 mojo::ScopedMessagePipeHandle channel_handle; |
175 IPC::ChannelHandle handle = gpu_channel_manager_->EstablishChannel( | 181 IPC::ChannelHandle handle = gpu_channel_manager_->EstablishChannel( |
176 client_id, client_tracing_id, preempts, allow_view_command_buffers, | 182 client_id, client_tracing_id, preempts, allow_view_command_buffers, |
177 allow_real_time_streams); | 183 allow_real_time_streams); |
178 channel_handle.reset(handle.mojo_handle); | 184 channel_handle.reset(handle.mojo_handle); |
179 media_gpu_channel_manager_->AddChannel(client_id); | 185 media_gpu_channel_manager_->AddChannel(client_id); |
180 callback.Run(std::move(channel_handle)); | 186 callback.Run(std::move(channel_handle)); |
181 } | 187 } |
182 | 188 |
183 } // namespace ui | 189 } // namespace ui |
OLD | NEW |