| 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" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 #include "media/base/android/media_client_android.h" | 53 #include "media/base/android/media_client_android.h" |
| 54 #include "media/gpu/avda_codec_allocator.h" | 54 #include "media/gpu/avda_codec_allocator.h" |
| 55 #endif | 55 #endif |
| 56 | 56 |
| 57 namespace content { | 57 namespace content { |
| 58 namespace { | 58 namespace { |
| 59 | 59 |
| 60 static base::LazyInstance<scoped_refptr<ThreadSafeSender> > | 60 static base::LazyInstance<scoped_refptr<ThreadSafeSender> > |
| 61 g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER; | 61 g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER; |
| 62 | 62 |
| 63 bool GpuProcessLogMessageHandler(int severity, | |
| 64 const char* file, int line, | |
| 65 size_t message_start, | |
| 66 const std::string& str) { | |
| 67 std::string header = str.substr(0, message_start); | |
| 68 std::string message = str.substr(message_start); | |
| 69 | |
| 70 g_thread_safe_sender.Get()->Send( | |
| 71 new GpuHostMsg_OnLogMessage(severity, header, message)); | |
| 72 | |
| 73 return false; | |
| 74 } | |
| 75 | |
| 76 // Message filter used to to handle GpuMsg_CreateGpuMemoryBuffer messages | 63 // Message filter used to to handle GpuMsg_CreateGpuMemoryBuffer messages |
| 77 // on the IO thread. This allows the UI thread in the browser process to remain | 64 // on the IO thread. This allows the UI thread in the browser process to remain |
| 78 // fast at all times. | 65 // fast at all times. |
| 79 class GpuMemoryBufferMessageFilter : public IPC::MessageFilter { | 66 class GpuMemoryBufferMessageFilter : public IPC::MessageFilter { |
| 80 public: | 67 public: |
| 81 explicit GpuMemoryBufferMessageFilter( | 68 explicit GpuMemoryBufferMessageFilter( |
| 82 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) | 69 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) |
| 83 : gpu_memory_buffer_factory_(gpu_memory_buffer_factory), | 70 : gpu_memory_buffer_factory_(gpu_memory_buffer_factory), |
| 84 sender_(nullptr) {} | 71 sender_(nullptr) {} |
| 85 | 72 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 builder.AddStartupFilter(message_filter); | 122 builder.AddStartupFilter(message_filter); |
| 136 #endif | 123 #endif |
| 137 | 124 |
| 138 builder.ConnectToBrowser(true); | 125 builder.ConnectToBrowser(true); |
| 139 | 126 |
| 140 return builder.Build(); | 127 return builder.Build(); |
| 141 } | 128 } |
| 142 | 129 |
| 143 } // namespace | 130 } // namespace |
| 144 | 131 |
| 132 void GpuProcessLogMessageListener::OnMessage(int severity, |
| 133 const char* file, |
| 134 int line, |
| 135 size_t message_start, |
| 136 const std::string& str) { |
| 137 std::string header = str.substr(0, message_start); |
| 138 std::string message = str.substr(message_start); |
| 139 |
| 140 g_thread_safe_sender.Get()->Send( |
| 141 new GpuHostMsg_OnLogMessage(severity, header, message)); |
| 142 } |
| 143 |
| 145 GpuChildThread::GpuChildThread( | 144 GpuChildThread::GpuChildThread( |
| 146 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, | 145 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, |
| 147 bool dead_on_arrival, | 146 bool dead_on_arrival, |
| 148 const gpu::GPUInfo& gpu_info, | 147 const gpu::GPUInfo& gpu_info, |
| 149 const DeferredMessages& deferred_messages, | 148 const DeferredMessages& deferred_messages, |
| 150 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) | 149 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) |
| 151 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), | 150 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), |
| 152 dead_on_arrival_(dead_on_arrival), | 151 dead_on_arrival_(dead_on_arrival), |
| 153 watchdog_thread_(std::move(watchdog_thread)), | 152 watchdog_thread_(std::move(watchdog_thread)), |
| 154 gpu_info_(gpu_info), | 153 gpu_info_(gpu_info), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 184 switches::kInProcessGPU)); | 183 switches::kInProcessGPU)); |
| 185 | 184 |
| 186 g_thread_safe_sender.Get() = thread_safe_sender(); | 185 g_thread_safe_sender.Get() = thread_safe_sender(); |
| 187 } | 186 } |
| 188 | 187 |
| 189 GpuChildThread::~GpuChildThread() { | 188 GpuChildThread::~GpuChildThread() { |
| 190 } | 189 } |
| 191 | 190 |
| 192 void GpuChildThread::Shutdown() { | 191 void GpuChildThread::Shutdown() { |
| 193 ChildThreadImpl::Shutdown(); | 192 ChildThreadImpl::Shutdown(); |
| 194 logging::SetLogMessageHandler(NULL); | 193 if (!in_browser_process_) |
| 194 log_listener_.reset(); |
| 195 } | 195 } |
| 196 | 196 |
| 197 void GpuChildThread::Init(const base::Time& process_start_time) { | 197 void GpuChildThread::Init(const base::Time& process_start_time) { |
| 198 process_start_time_ = process_start_time; | 198 process_start_time_ = process_start_time; |
| 199 | 199 |
| 200 #if defined(OS_ANDROID) | 200 #if defined(OS_ANDROID) |
| 201 // When running in in-process mode, this has been set in the browser at | 201 // When running in in-process mode, this has been set in the browser at |
| 202 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun(). | 202 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun(). |
| 203 if (!in_browser_process_) | 203 if (!in_browser_process_) |
| 204 media::SetMediaClientAndroid(GetContentClient()->GetMediaClientAndroid()); | 204 media::SetMediaClientAndroid(GetContentClient()->GetMediaClientAndroid()); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 | 323 |
| 324 if (dead_on_arrival_) { | 324 if (dead_on_arrival_) { |
| 325 LOG(ERROR) << "Exiting GPU process due to errors during initialization"; | 325 LOG(ERROR) << "Exiting GPU process due to errors during initialization"; |
| 326 base::MessageLoop::current()->QuitWhenIdle(); | 326 base::MessageLoop::current()->QuitWhenIdle(); |
| 327 return; | 327 return; |
| 328 } | 328 } |
| 329 | 329 |
| 330 // We don't need to pipe log messages if we are running the GPU thread in | 330 // We don't need to pipe log messages if we are running the GPU thread in |
| 331 // the browser process. | 331 // the browser process. |
| 332 if (!in_browser_process_) | 332 if (!in_browser_process_) |
| 333 logging::SetLogMessageHandler(GpuProcessLogMessageHandler); | 333 log_listener_ = base::MakeUnique<GpuProcessLogMessageListener>(); |
| 334 | 334 |
| 335 gpu::SyncPointManager* sync_point_manager = nullptr; | 335 gpu::SyncPointManager* sync_point_manager = nullptr; |
| 336 // Note SyncPointManager from ContentGpuClient cannot be owned by this. | 336 // Note SyncPointManager from ContentGpuClient cannot be owned by this. |
| 337 if (GetContentClient()->gpu()) | 337 if (GetContentClient()->gpu()) |
| 338 sync_point_manager = GetContentClient()->gpu()->GetSyncPointManager(); | 338 sync_point_manager = GetContentClient()->gpu()->GetSyncPointManager(); |
| 339 if (!sync_point_manager) { | 339 if (!sync_point_manager) { |
| 340 if (!owned_sync_point_manager_) { | 340 if (!owned_sync_point_manager_) { |
| 341 owned_sync_point_manager_.reset(new gpu::SyncPointManager(false)); | 341 owned_sync_point_manager_.reset(new gpu::SyncPointManager(false)); |
| 342 } | 342 } |
| 343 sync_point_manager = owned_sync_point_manager_.get(); | 343 sync_point_manager = owned_sync_point_manager_.get(); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 | 522 |
| 523 void GpuChildThread::BindServiceFactoryRequest( | 523 void GpuChildThread::BindServiceFactoryRequest( |
| 524 service_manager::mojom::ServiceFactoryRequest request) { | 524 service_manager::mojom::ServiceFactoryRequest request) { |
| 525 DVLOG(1) << "GPU: Binding service_manager::mojom::ServiceFactoryRequest"; | 525 DVLOG(1) << "GPU: Binding service_manager::mojom::ServiceFactoryRequest"; |
| 526 DCHECK(service_factory_); | 526 DCHECK(service_factory_); |
| 527 service_factory_bindings_.AddBinding(service_factory_.get(), | 527 service_factory_bindings_.AddBinding(service_factory_.get(), |
| 528 std::move(request)); | 528 std::move(request)); |
| 529 } | 529 } |
| 530 | 530 |
| 531 } // namespace content | 531 } // namespace content |
| OLD | NEW |