Chromium Code Reviews| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 // notice shutdown before the render process begins waiting for them to exit. | 68 // notice shutdown before the render process begins waiting for them to exit. |
| 69 shutdown_event_.Signal(); | 69 shutdown_event_.Signal(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void GpuService::InitializeWithHost(mojom::GpuHostPtr gpu_host, | 72 void GpuService::InitializeWithHost(mojom::GpuHostPtr gpu_host, |
| 73 const gpu::GpuPreferences& preferences, | 73 const gpu::GpuPreferences& preferences, |
| 74 gpu::GpuProcessActivityFlags activity_flags, | 74 gpu::GpuProcessActivityFlags activity_flags, |
| 75 gpu::SyncPointManager* sync_point_manager, | 75 gpu::SyncPointManager* sync_point_manager, |
| 76 base::WaitableEvent* shutdown_event) { | 76 base::WaitableEvent* shutdown_event) { |
| 77 DCHECK(CalledOnValidThread()); | 77 DCHECK(CalledOnValidThread()); |
| 78 DCHECK(!gpu_host_); | |
| 79 gpu_host_ = std::move(gpu_host); | |
| 80 gpu_preferences_ = preferences; | 78 gpu_preferences_ = preferences; |
| 81 gpu_info_.video_decode_accelerator_capabilities = | 79 gpu_info_.video_decode_accelerator_capabilities = |
| 82 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); | 80 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); |
| 83 gpu_info_.video_encode_accelerator_supported_profiles = | 81 gpu_info_.video_encode_accelerator_supported_profiles = |
| 84 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); | 82 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); |
| 85 gpu_info_.jpeg_decode_accelerator_supported = | 83 gpu_info_.jpeg_decode_accelerator_supported = |
| 86 media::GpuJpegDecodeAcceleratorFactoryProvider:: | 84 media::GpuJpegDecodeAcceleratorFactoryProvider:: |
| 87 IsAcceleratedJpegDecodeSupported(); | 85 IsAcceleratedJpegDecodeSupported(); |
| 88 gpu_host_->DidInitialize(gpu_info_); | 86 gpu_host->DidInitialize(gpu_info_); |
| 87 | |
| 88 task_tracker_.PostTask( | |
| 89 io_runner_.get(), FROM_HERE, | |
| 90 base::Bind(&GpuService::BindGpuHostOnIO, base::Unretained(this), | |
| 91 base::Passed(gpu_host.PassInterface()))); | |
| 89 | 92 |
| 90 sync_point_manager_ = sync_point_manager; | 93 sync_point_manager_ = sync_point_manager; |
| 91 if (!sync_point_manager_) { | 94 if (!sync_point_manager_) { |
| 92 owned_sync_point_manager_ = base::MakeUnique<gpu::SyncPointManager>(); | 95 owned_sync_point_manager_ = base::MakeUnique<gpu::SyncPointManager>(); |
| 93 sync_point_manager_ = owned_sync_point_manager_.get(); | 96 sync_point_manager_ = owned_sync_point_manager_.get(); |
| 94 } | 97 } |
| 95 | 98 |
| 96 // Defer creation of the render thread. This is to prevent it from handling | 99 // Defer creation of the render thread. This is to prevent it from handling |
| 97 // IPC messages before the sandbox has been enabled and all other necessary | 100 // IPC messages before the sandbox has been enabled and all other necessary |
| 98 // initialization has succeeded. | 101 // initialization has succeeded. |
| 99 gpu_channel_manager_.reset(new gpu::GpuChannelManager( | 102 gpu_channel_manager_.reset(new gpu::GpuChannelManager( |
| 100 gpu_preferences_, this, watchdog_thread_.get(), | 103 gpu_preferences_, this, watchdog_thread_.get(), |
| 101 base::ThreadTaskRunnerHandle::Get().get(), io_runner_.get(), | 104 base::ThreadTaskRunnerHandle::Get().get(), io_runner_.get(), |
| 102 shutdown_event ? shutdown_event : &shutdown_event_, sync_point_manager_, | 105 shutdown_event ? shutdown_event : &shutdown_event_, sync_point_manager_, |
| 103 gpu_memory_buffer_factory_, gpu_feature_info_, | 106 gpu_memory_buffer_factory_, gpu_feature_info_, |
| 104 std::move(activity_flags))); | 107 std::move(activity_flags))); |
| 105 | 108 |
| 106 media_gpu_channel_manager_.reset( | 109 media_gpu_channel_manager_.reset( |
| 107 new media::MediaGpuChannelManager(gpu_channel_manager_.get())); | 110 new media::MediaGpuChannelManager(gpu_channel_manager_.get())); |
| 108 } | 111 } |
| 109 | 112 |
| 110 void GpuService::Bind(mojom::GpuServiceRequest request) { | 113 void GpuService::Bind(mojom::GpuServiceRequest request) { |
| 111 bindings_.AddBinding(this, std::move(request)); | 114 bindings_.AddBinding(this, std::move(request)); |
| 112 } | 115 } |
| 113 | 116 |
| 117 void GpuService::BindGpuHostOnIO(mojom::GpuHostPtrInfo ptr_info) { | |
| 118 DCHECK(io_runner_->RunsTasksOnCurrentThread()); | |
| 119 mojom::GpuHostPtr gpu_host; | |
| 120 gpu_host.Bind(std::move(ptr_info)); | |
| 121 gpu_host_ = mojom::ThreadSafeGpuHostPtr::Create(std::move(gpu_host)); | |
|
Ken Rockot(use gerrit already)
2017/03/21 22:40:35
The ThreadSafeInterfacePtr itself is thread-safe,
sadrul
2017/03/21 22:43:10
Ooh, so ThreadSafe* can be take a task-runner of a
sadrul
2017/03/21 23:14:17
Done.
| |
| 122 } | |
| 123 | |
| 114 void GpuService::CreateGpuMemoryBuffer( | 124 void GpuService::CreateGpuMemoryBuffer( |
| 115 gfx::GpuMemoryBufferId id, | 125 gfx::GpuMemoryBufferId id, |
| 116 const gfx::Size& size, | 126 const gfx::Size& size, |
| 117 gfx::BufferFormat format, | 127 gfx::BufferFormat format, |
| 118 gfx::BufferUsage usage, | 128 gfx::BufferUsage usage, |
| 119 int client_id, | 129 int client_id, |
| 120 gpu::SurfaceHandle surface_handle, | 130 gpu::SurfaceHandle surface_handle, |
| 121 const CreateGpuMemoryBufferCallback& callback) { | 131 const CreateGpuMemoryBufferCallback& callback) { |
| 122 DCHECK(CalledOnValidThread()); | 132 DCHECK(CalledOnValidThread()); |
| 123 callback.Run(gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( | 133 callback.Run(gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 136 const GetVideoMemoryUsageStatsCallback& callback) { | 146 const GetVideoMemoryUsageStatsCallback& callback) { |
| 137 gpu::VideoMemoryUsageStats video_memory_usage_stats; | 147 gpu::VideoMemoryUsageStats video_memory_usage_stats; |
| 138 if (gpu_channel_manager_) { | 148 if (gpu_channel_manager_) { |
| 139 gpu_channel_manager_->gpu_memory_manager()->GetVideoMemoryUsageStats( | 149 gpu_channel_manager_->gpu_memory_manager()->GetVideoMemoryUsageStats( |
| 140 &video_memory_usage_stats); | 150 &video_memory_usage_stats); |
| 141 } | 151 } |
| 142 callback.Run(video_memory_usage_stats); | 152 callback.Run(video_memory_usage_stats); |
| 143 } | 153 } |
| 144 | 154 |
| 145 void GpuService::DidCreateOffscreenContext(const GURL& active_url) { | 155 void GpuService::DidCreateOffscreenContext(const GURL& active_url) { |
| 146 gpu_host_->DidCreateOffscreenContext(active_url); | 156 (*gpu_host_)->DidCreateOffscreenContext(active_url); |
| 147 } | 157 } |
| 148 | 158 |
| 149 void GpuService::DidDestroyChannel(int client_id) { | 159 void GpuService::DidDestroyChannel(int client_id) { |
| 150 media_gpu_channel_manager_->RemoveChannel(client_id); | 160 media_gpu_channel_manager_->RemoveChannel(client_id); |
| 151 gpu_host_->DidDestroyChannel(client_id); | 161 (*gpu_host_)->DidDestroyChannel(client_id); |
| 152 } | 162 } |
| 153 | 163 |
| 154 void GpuService::DidDestroyOffscreenContext(const GURL& active_url) { | 164 void GpuService::DidDestroyOffscreenContext(const GURL& active_url) { |
| 155 gpu_host_->DidDestroyOffscreenContext(active_url); | 165 (*gpu_host_)->DidDestroyOffscreenContext(active_url); |
| 156 } | 166 } |
| 157 | 167 |
| 158 void GpuService::DidLoseContext(bool offscreen, | 168 void GpuService::DidLoseContext(bool offscreen, |
| 159 gpu::error::ContextLostReason reason, | 169 gpu::error::ContextLostReason reason, |
| 160 const GURL& active_url) { | 170 const GURL& active_url) { |
| 161 gpu_host_->DidLoseContext(offscreen, reason, active_url); | 171 (*gpu_host_)->DidLoseContext(offscreen, reason, active_url); |
| 162 } | 172 } |
| 163 | 173 |
| 164 void GpuService::StoreShaderToDisk(int client_id, | 174 void GpuService::StoreShaderToDisk(int client_id, |
| 165 const std::string& key, | 175 const std::string& key, |
| 166 const std::string& shader) { | 176 const std::string& shader) { |
| 167 gpu_host_->StoreShaderToDisk(client_id, key, shader); | 177 (*gpu_host_)->StoreShaderToDisk(client_id, key, shader); |
| 168 } | 178 } |
| 169 | 179 |
| 170 #if defined(OS_WIN) | 180 #if defined(OS_WIN) |
| 171 void GpuService::SendAcceleratedSurfaceCreatedChildWindow( | 181 void GpuService::SendAcceleratedSurfaceCreatedChildWindow( |
| 172 gpu::SurfaceHandle parent_window, | 182 gpu::SurfaceHandle parent_window, |
| 173 gpu::SurfaceHandle child_window) { | 183 gpu::SurfaceHandle child_window) { |
| 174 gpu_host_->SetChildSurface(parent_window, child_window); | 184 (*gpu_host_)->SetChildSurface(parent_window, child_window); |
| 175 } | 185 } |
| 176 #endif | 186 #endif |
| 177 | 187 |
| 178 void GpuService::SetActiveURL(const GURL& url) { | 188 void GpuService::SetActiveURL(const GURL& url) { |
| 179 constexpr char kActiveURL[] = "url-chunk"; | 189 constexpr char kActiveURL[] = "url-chunk"; |
| 180 base::debug::SetCrashKeyValue(kActiveURL, url.possibly_invalid_spec()); | 190 base::debug::SetCrashKeyValue(kActiveURL, url.possibly_invalid_spec()); |
| 181 } | 191 } |
| 182 | 192 |
| 183 void GpuService::EstablishGpuChannel( | 193 void GpuService::EstablishGpuChannel( |
| 184 int32_t client_id, | 194 int32_t client_id, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 NOTREACHED() << "Java exception not supported on this platform."; | 276 NOTREACHED() << "Java exception not supported on this platform."; |
| 267 #endif | 277 #endif |
| 268 } | 278 } |
| 269 | 279 |
| 270 void GpuService::Stop(const StopCallback& callback) { | 280 void GpuService::Stop(const StopCallback& callback) { |
| 271 base::MessageLoop::current()->QuitWhenIdle(); | 281 base::MessageLoop::current()->QuitWhenIdle(); |
| 272 callback.Run(); | 282 callback.Run(); |
| 273 } | 283 } |
| 274 | 284 |
| 275 } // namespace ui | 285 } // namespace ui |
| OLD | NEW |