| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/gpu/gpu_child_thread.h" | 5 #include "content/gpu/gpu_child_thread.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/threading/thread_local.h" |
| 13 #include "base/threading/worker_pool.h" | 14 #include "base/threading/worker_pool.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "content/child/child_process.h" | 16 #include "content/child/child_process.h" |
| 16 #include "content/child/thread_safe_sender.h" | 17 #include "content/child/thread_safe_sender.h" |
| 17 #include "content/common/establish_channel_params.h" | 18 #include "content/common/establish_channel_params.h" |
| 18 #include "content/common/gpu/gpu_memory_buffer_factory.h" | 19 #include "content/common/gpu/gpu_memory_buffer_factory.h" |
| 19 #include "content/common/gpu/media/gpu_jpeg_decode_accelerator.h" | 20 #include "content/common/gpu/media/gpu_jpeg_decode_accelerator.h" |
| 20 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" | 21 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" |
| 21 #include "content/common/gpu/media/gpu_video_encode_accelerator.h" | 22 #include "content/common/gpu/media/gpu_video_encode_accelerator.h" |
| 22 #include "content/common/gpu/media/media_service.h" | 23 #include "content/common/gpu/media/media_service.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 43 #include "ui/ozone/public/ozone_platform.h" | 44 #include "ui/ozone/public/ozone_platform.h" |
| 44 #endif | 45 #endif |
| 45 | 46 |
| 46 #if defined(ENABLE_VULKAN) | 47 #if defined(ENABLE_VULKAN) |
| 47 #include "gpu/vulkan/vulkan_surface.h" | 48 #include "gpu/vulkan/vulkan_surface.h" |
| 48 #endif | 49 #endif |
| 49 | 50 |
| 50 namespace content { | 51 namespace content { |
| 51 namespace { | 52 namespace { |
| 52 | 53 |
| 54 base::LazyInstance<base::ThreadLocalPointer<GpuChildThread>> g_lazy_tls = |
| 55 LAZY_INSTANCE_INITIALIZER; |
| 56 |
| 53 static base::LazyInstance<scoped_refptr<ThreadSafeSender> > | 57 static base::LazyInstance<scoped_refptr<ThreadSafeSender> > |
| 54 g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER; | 58 g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER; |
| 55 | 59 |
| 56 bool GpuProcessLogMessageHandler(int severity, | 60 bool GpuProcessLogMessageHandler(int severity, |
| 57 const char* file, int line, | 61 const char* file, int line, |
| 58 size_t message_start, | 62 size_t message_start, |
| 59 const std::string& str) { | 63 const std::string& str) { |
| 60 std::string header = str.substr(0, message_start); | 64 std::string header = str.substr(0, message_start); |
| 61 std::string message = str.substr(message_start); | 65 std::string message = str.substr(message_start); |
| 62 | 66 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 ->GetMessageFilter(); | 145 ->GetMessageFilter(); |
| 142 if (message_filter) | 146 if (message_filter) |
| 143 builder.AddStartupFilter(message_filter); | 147 builder.AddStartupFilter(message_filter); |
| 144 #endif | 148 #endif |
| 145 | 149 |
| 146 return builder.Build(); | 150 return builder.Build(); |
| 147 } | 151 } |
| 148 | 152 |
| 149 } // namespace | 153 } // namespace |
| 150 | 154 |
| 155 // static |
| 156 GpuChildThread* GpuChildThread::current() { |
| 157 return g_lazy_tls.Pointer()->Get(); |
| 158 } |
| 159 |
| 151 GpuChildThread::GpuChildThread( | 160 GpuChildThread::GpuChildThread( |
| 152 GpuWatchdogThread* watchdog_thread, | 161 GpuWatchdogThread* watchdog_thread, |
| 153 bool dead_on_arrival, | 162 bool dead_on_arrival, |
| 154 const gpu::GPUInfo& gpu_info, | 163 const gpu::GPUInfo& gpu_info, |
| 155 const DeferredMessages& deferred_messages, | 164 const DeferredMessages& deferred_messages, |
| 156 GpuMemoryBufferFactory* gpu_memory_buffer_factory, | 165 GpuMemoryBufferFactory* gpu_memory_buffer_factory, |
| 157 gpu::SyncPointManager* sync_point_manager) | 166 gpu::SyncPointManager* sync_point_manager) |
| 158 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), | 167 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), |
| 159 dead_on_arrival_(dead_on_arrival), | 168 dead_on_arrival_(dead_on_arrival), |
| 160 sync_point_manager_(sync_point_manager), | 169 sync_point_manager_(sync_point_manager), |
| 161 gpu_info_(gpu_info), | 170 gpu_info_(gpu_info), |
| 162 deferred_messages_(deferred_messages), | 171 deferred_messages_(deferred_messages), |
| 163 in_browser_process_(false), | 172 in_browser_process_(false), |
| 164 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) { | 173 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) { |
| 165 watchdog_thread_ = watchdog_thread; | 174 watchdog_thread_ = watchdog_thread; |
| 166 #if defined(OS_WIN) | 175 #if defined(OS_WIN) |
| 167 target_services_ = NULL; | 176 target_services_ = NULL; |
| 168 #endif | 177 #endif |
| 169 g_thread_safe_sender.Get() = thread_safe_sender(); | 178 g_thread_safe_sender.Get() = thread_safe_sender(); |
| 179 g_lazy_tls.Pointer()->Set(this); |
| 170 } | 180 } |
| 171 | 181 |
| 172 GpuChildThread::GpuChildThread( | 182 GpuChildThread::GpuChildThread( |
| 173 const gpu::GpuPreferences& gpu_preferences, | 183 const gpu::GpuPreferences& gpu_preferences, |
| 174 const InProcessChildThreadParams& params, | 184 const InProcessChildThreadParams& params, |
| 175 GpuMemoryBufferFactory* gpu_memory_buffer_factory, | 185 GpuMemoryBufferFactory* gpu_memory_buffer_factory, |
| 176 gpu::SyncPointManager* sync_point_manager) | 186 gpu::SyncPointManager* sync_point_manager) |
| 177 : ChildThreadImpl(ChildThreadImpl::Options::Builder() | 187 : ChildThreadImpl(ChildThreadImpl::Options::Builder() |
| 178 .InBrowserProcess(params) | 188 .InBrowserProcess(params) |
| 179 .AddStartupFilter(new GpuMemoryBufferMessageFilter( | 189 .AddStartupFilter(new GpuMemoryBufferMessageFilter( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 194 | 204 |
| 195 #if defined(ENABLE_VULKAN) | 205 #if defined(ENABLE_VULKAN) |
| 196 // Temporary Vulkan initialization injection. | 206 // Temporary Vulkan initialization injection. |
| 197 gpu::VulkanSurface::InitializeOneOff(); | 207 gpu::VulkanSurface::InitializeOneOff(); |
| 198 #endif | 208 #endif |
| 199 | 209 |
| 200 if (!gfx::GLSurface::InitializeOneOff()) | 210 if (!gfx::GLSurface::InitializeOneOff()) |
| 201 VLOG(1) << "gfx::GLSurface::InitializeOneOff failed"; | 211 VLOG(1) << "gfx::GLSurface::InitializeOneOff failed"; |
| 202 | 212 |
| 203 g_thread_safe_sender.Get() = thread_safe_sender(); | 213 g_thread_safe_sender.Get() = thread_safe_sender(); |
| 214 g_lazy_tls.Pointer()->Set(this); |
| 204 } | 215 } |
| 205 | 216 |
| 206 GpuChildThread::~GpuChildThread() { | 217 GpuChildThread::~GpuChildThread() { |
| 207 while (!deferred_messages_.empty()) { | 218 while (!deferred_messages_.empty()) { |
| 208 delete deferred_messages_.front(); | 219 delete deferred_messages_.front(); |
| 209 deferred_messages_.pop(); | 220 deferred_messages_.pop(); |
| 210 } | 221 } |
| 222 g_lazy_tls.Pointer()->Set(nullptr); |
| 211 } | 223 } |
| 212 | 224 |
| 213 void GpuChildThread::Shutdown() { | 225 void GpuChildThread::Shutdown() { |
| 214 ChildThreadImpl::Shutdown(); | 226 ChildThreadImpl::Shutdown(); |
| 215 logging::SetLogMessageHandler(NULL); | 227 logging::SetLogMessageHandler(NULL); |
| 216 } | 228 } |
| 217 | 229 |
| 218 void GpuChildThread::Init(const base::Time& process_start_time) { | 230 void GpuChildThread::Init(const base::Time& process_start_time) { |
| 219 process_start_time_ = process_start_time; | 231 process_start_time_ = process_start_time; |
| 220 | 232 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 void GpuChildThread::StoreShaderToDisk(int32_t client_id, | 370 void GpuChildThread::StoreShaderToDisk(int32_t client_id, |
| 359 const std::string& key, | 371 const std::string& key, |
| 360 const std::string& shader) { | 372 const std::string& shader) { |
| 361 Send(new GpuHostMsg_CacheShader(client_id, key, shader)); | 373 Send(new GpuHostMsg_CacheShader(client_id, key, shader)); |
| 362 } | 374 } |
| 363 | 375 |
| 364 void GpuChildThread::OnInitialize(const gpu::GpuPreferences& gpu_preferences) { | 376 void GpuChildThread::OnInitialize(const gpu::GpuPreferences& gpu_preferences) { |
| 365 gpu_preferences_ = gpu_preferences; | 377 gpu_preferences_ = gpu_preferences; |
| 366 | 378 |
| 367 gpu_info_.video_decode_accelerator_capabilities = | 379 gpu_info_.video_decode_accelerator_capabilities = |
| 368 content::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); | 380 content::GpuVideoDecodeAccelerator::GetCapabilities(); |
| 369 gpu_info_.video_encode_accelerator_supported_profiles = | 381 gpu_info_.video_encode_accelerator_supported_profiles = |
| 370 content::GpuVideoEncodeAccelerator::GetSupportedProfiles( | 382 content::GpuVideoEncodeAccelerator::GetSupportedProfiles( |
| 371 gpu_preferences_); | 383 gpu_preferences_); |
| 372 gpu_info_.jpeg_decode_accelerator_supported = | 384 gpu_info_.jpeg_decode_accelerator_supported = |
| 373 content::GpuJpegDecodeAccelerator::IsSupported(); | 385 content::GpuJpegDecodeAccelerator::IsSupported(); |
| 374 | 386 |
| 375 // Record initialization only after collecting the GPU info because that can | 387 // Record initialization only after collecting the GPU info because that can |
| 376 // take a significant amount of time. | 388 // take a significant amount of time. |
| 377 gpu_info_.initialization_time = base::Time::Now() - process_start_time_; | 389 gpu_info_.initialization_time = base::Time::Now() - process_start_time_; |
| 378 Send(new GpuHostMsg_Initialized(!dead_on_arrival_, gpu_info_)); | 390 Send(new GpuHostMsg_Initialized(!dead_on_arrival_, gpu_info_)); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 | 588 |
| 577 void GpuChildThread::BindProcessControlRequest( | 589 void GpuChildThread::BindProcessControlRequest( |
| 578 mojo::InterfaceRequest<mojom::ProcessControl> request) { | 590 mojo::InterfaceRequest<mojom::ProcessControl> request) { |
| 579 DVLOG(1) << "GPU: Binding ProcessControl request"; | 591 DVLOG(1) << "GPU: Binding ProcessControl request"; |
| 580 DCHECK(process_control_); | 592 DCHECK(process_control_); |
| 581 process_control_bindings_.AddBinding(process_control_.get(), | 593 process_control_bindings_.AddBinding(process_control_.get(), |
| 582 std::move(request)); | 594 std::move(request)); |
| 583 } | 595 } |
| 584 | 596 |
| 585 } // namespace content | 597 } // namespace content |
| OLD | NEW |