Chromium Code Reviews| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/threading/worker_pool.h" | 9 #include "base/threading/worker_pool.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "content/child/child_process.h" | 11 #include "content/child/child_process.h" |
| 12 #include "content/child/thread_safe_sender.h" | 12 #include "content/child/thread_safe_sender.h" |
| 13 #include "content/common/gpu/gpu_memory_buffer_factory.h" | |
| 13 #include "content/common/gpu/gpu_messages.h" | 14 #include "content/common/gpu/gpu_messages.h" |
| 14 #include "content/gpu/gpu_watchdog_thread.h" | 15 #include "content/gpu/gpu_watchdog_thread.h" |
| 15 #include "content/public/common/content_client.h" | 16 #include "content/public/common/content_client.h" |
| 16 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
| 17 #include "gpu/config/gpu_info_collector.h" | 18 #include "gpu/config/gpu_info_collector.h" |
| 18 #include "ipc/ipc_channel_handle.h" | 19 #include "ipc/ipc_channel_handle.h" |
| 19 #include "ipc/ipc_sync_message_filter.h" | 20 #include "ipc/ipc_sync_message_filter.h" |
| 20 #include "ui/gl/gl_implementation.h" | 21 #include "ui/gl/gl_implementation.h" |
| 21 #include "ui/gl/gpu_switching_manager.h" | 22 #include "ui/gl/gpu_switching_manager.h" |
| 22 | 23 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 37 const std::string& str) { | 38 const std::string& str) { |
| 38 std::string header = str.substr(0, message_start); | 39 std::string header = str.substr(0, message_start); |
| 39 std::string message = str.substr(message_start); | 40 std::string message = str.substr(message_start); |
| 40 | 41 |
| 41 g_thread_safe_sender.Get()->Send(new GpuHostMsg_OnLogMessage( | 42 g_thread_safe_sender.Get()->Send(new GpuHostMsg_OnLogMessage( |
| 42 severity, header, message)); | 43 severity, header, message)); |
| 43 | 44 |
| 44 return false; | 45 return false; |
| 45 } | 46 } |
| 46 | 47 |
| 47 ChildThreadImpl::Options GetOptions() { | 48 // Message filter used to to handle GpuMsg_CreateGpuMemoryBuffer messages on |
| 49 // the IO thread. This allows the UI thread in the browser process to remain | |
| 50 // fast at all times. | |
| 51 class GpuMemoryBufferMessageFilter : public IPC::MessageFilter { | |
| 52 public: | |
| 53 explicit GpuMemoryBufferMessageFilter( | |
| 54 GpuMemoryBufferFactory* gpu_memory_buffer_factory) | |
| 55 : gpu_memory_buffer_factory_(gpu_memory_buffer_factory) {} | |
| 56 | |
| 57 // Overridden from IPC::MessageFilter: | |
| 58 bool OnMessageReceived(const IPC::Message& message) override { | |
| 59 bool handled = true; | |
| 60 IPC_BEGIN_MESSAGE_MAP(GpuMemoryBufferMessageFilter, message) | |
| 61 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer) | |
| 62 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 63 IPC_END_MESSAGE_MAP() | |
| 64 return handled; | |
| 65 } | |
| 66 | |
| 67 protected: | |
| 68 ~GpuMemoryBufferMessageFilter() override {} | |
| 69 | |
| 70 void OnCreateGpuMemoryBuffer( | |
| 71 const GpuMsg_CreateGpuMemoryBuffer_Params& params) { | |
| 72 TRACE_EVENT2("gpu", "GpuMemoryBufferMessageFilter::OnCreateGpuMemoryBuffer", | |
| 73 "id", params.id, "client_id", params.client_id); | |
| 74 g_thread_safe_sender.Get()->Send(new GpuHostMsg_GpuMemoryBufferCreated( | |
|
piman
2015/06/25 20:29:00
g_thread_safe_sender causes an extra thread hop (w
reveman
2015/06/25 20:45:25
Done.
| |
| 75 gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( | |
| 76 params.id, params.size, params.format, params.usage, | |
| 77 params.client_id, params.surface_handle))); | |
| 78 } | |
| 79 | |
| 80 GpuMemoryBufferFactory* const gpu_memory_buffer_factory_; | |
| 81 }; | |
| 82 | |
| 83 ChildThreadImpl::Options GetOptions( | |
| 84 GpuMemoryBufferFactory* gpu_memory_buffer_factory) { | |
| 48 ChildThreadImpl::Options::Builder builder; | 85 ChildThreadImpl::Options::Builder builder; |
| 49 | 86 |
| 87 builder.AddStartupFilter( | |
| 88 new GpuMemoryBufferMessageFilter(gpu_memory_buffer_factory)); | |
| 89 | |
| 50 #if defined(USE_OZONE) | 90 #if defined(USE_OZONE) |
| 51 IPC::MessageFilter* message_filter = ui::OzonePlatform::GetInstance() | 91 IPC::MessageFilter* message_filter = ui::OzonePlatform::GetInstance() |
| 52 ->GetGpuPlatformSupport() | 92 ->GetGpuPlatformSupport() |
| 53 ->GetMessageFilter(); | 93 ->GetMessageFilter(); |
| 54 if (message_filter) | 94 if (message_filter) |
| 55 builder.AddStartupFilter(message_filter); | 95 builder.AddStartupFilter(message_filter); |
| 56 #endif | 96 #endif |
| 57 | 97 |
| 58 return builder.Build(); | 98 return builder.Build(); |
| 59 } | 99 } |
| 60 | 100 |
| 61 } // namespace | 101 } // namespace |
| 62 | 102 |
| 63 GpuChildThread::GpuChildThread(GpuWatchdogThread* watchdog_thread, | 103 GpuChildThread::GpuChildThread( |
| 64 bool dead_on_arrival, | 104 GpuWatchdogThread* watchdog_thread, |
| 65 const gpu::GPUInfo& gpu_info, | 105 bool dead_on_arrival, |
| 66 const DeferredMessages& deferred_messages) | 106 const gpu::GPUInfo& gpu_info, |
| 67 : ChildThreadImpl(GetOptions()), | 107 const DeferredMessages& deferred_messages, |
| 108 GpuMemoryBufferFactory* gpu_memory_buffer_factory) | |
| 109 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), | |
| 68 dead_on_arrival_(dead_on_arrival), | 110 dead_on_arrival_(dead_on_arrival), |
| 69 gpu_info_(gpu_info), | 111 gpu_info_(gpu_info), |
| 70 deferred_messages_(deferred_messages), | 112 deferred_messages_(deferred_messages), |
| 71 in_browser_process_(false) { | 113 in_browser_process_(false), |
| 114 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) { | |
| 72 watchdog_thread_ = watchdog_thread; | 115 watchdog_thread_ = watchdog_thread; |
| 73 #if defined(OS_WIN) | 116 #if defined(OS_WIN) |
| 74 target_services_ = NULL; | 117 target_services_ = NULL; |
| 75 #endif | 118 #endif |
| 76 g_thread_safe_sender.Get() = thread_safe_sender(); | 119 g_thread_safe_sender.Get() = thread_safe_sender(); |
| 77 } | 120 } |
| 78 | 121 |
| 79 GpuChildThread::GpuChildThread(const InProcessChildThreadParams& params) | 122 GpuChildThread::GpuChildThread(const InProcessChildThreadParams& params) |
| 80 : ChildThreadImpl(ChildThreadImpl::Options::Builder() | 123 : ChildThreadImpl(ChildThreadImpl::Options::Builder() |
| 81 .InBrowserProcess(params) | 124 .InBrowserProcess(params) |
| 82 .Build()), | 125 .Build()), |
| 83 dead_on_arrival_(false), | 126 dead_on_arrival_(false), |
| 84 in_browser_process_(true) { | 127 in_browser_process_(true), |
| 128 gpu_memory_buffer_factory_(nullptr) { | |
| 85 #if defined(OS_WIN) | 129 #if defined(OS_WIN) |
| 86 target_services_ = NULL; | 130 target_services_ = NULL; |
| 87 #endif | 131 #endif |
| 88 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 132 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 89 switches::kSingleProcess) || | 133 switches::kSingleProcess) || |
| 90 base::CommandLine::ForCurrentProcess()->HasSwitch( | 134 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 91 switches::kInProcessGPU)); | 135 switches::kInProcessGPU)); |
| 92 #if !defined(OS_ANDROID) | 136 #if !defined(OS_ANDROID) |
| 93 // For single process and in-process GPU mode, we need to load and | 137 // For single process and in-process GPU mode, we need to load and |
| 94 // initialize the GL implementation and locate the GL entry points here. | 138 // initialize the GL implementation and locate the GL entry points here. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 #endif | 215 #endif |
| 172 | 216 |
| 173 // We don't need to pipe log messages if we are running the GPU thread in | 217 // We don't need to pipe log messages if we are running the GPU thread in |
| 174 // the browser process. | 218 // the browser process. |
| 175 if (!in_browser_process_) | 219 if (!in_browser_process_) |
| 176 logging::SetLogMessageHandler(GpuProcessLogMessageHandler); | 220 logging::SetLogMessageHandler(GpuProcessLogMessageHandler); |
| 177 | 221 |
| 178 // Defer creation of the render thread. This is to prevent it from handling | 222 // Defer creation of the render thread. This is to prevent it from handling |
| 179 // IPC messages before the sandbox has been enabled and all other necessary | 223 // IPC messages before the sandbox has been enabled and all other necessary |
| 180 // initialization has succeeded. | 224 // initialization has succeeded. |
| 181 gpu_channel_manager_.reset( | 225 gpu_channel_manager_.reset(new GpuChannelManager( |
| 182 new GpuChannelManager(GetRouter(), watchdog_thread_.get(), | 226 GetRouter(), watchdog_thread_.get(), |
| 183 ChildProcess::current()->io_task_runner(), | 227 ChildProcess::current()->io_task_runner(), |
| 184 ChildProcess::current()->GetShutDownEvent(), | 228 ChildProcess::current()->GetShutDownEvent(), channel(), |
| 185 channel(), GetAttachmentBroker())); | 229 GetAttachmentBroker(), gpu_memory_buffer_factory_)); |
| 186 | 230 |
| 187 #if defined(USE_OZONE) | 231 #if defined(USE_OZONE) |
| 188 ui::OzonePlatform::GetInstance() | 232 ui::OzonePlatform::GetInstance() |
| 189 ->GetGpuPlatformSupport() | 233 ->GetGpuPlatformSupport() |
| 190 ->OnChannelEstablished(this); | 234 ->OnChannelEstablished(this); |
| 191 #endif | 235 #endif |
| 192 } | 236 } |
| 193 | 237 |
| 194 void GpuChildThread::StopWatchdog() { | 238 void GpuChildThread::StopWatchdog() { |
| 195 if (watchdog_thread_.get()) { | 239 if (watchdog_thread_.get()) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 } | 328 } |
| 285 | 329 |
| 286 void GpuChildThread::OnGpuSwitched() { | 330 void GpuChildThread::OnGpuSwitched() { |
| 287 DVLOG(1) << "GPU: GPU has switched"; | 331 DVLOG(1) << "GPU: GPU has switched"; |
| 288 // Notify observers in the GPU process. | 332 // Notify observers in the GPU process. |
| 289 ui::GpuSwitchingManager::GetInstance()->NotifyGpuSwitched(); | 333 ui::GpuSwitchingManager::GetInstance()->NotifyGpuSwitched(); |
| 290 } | 334 } |
| 291 | 335 |
| 292 } // namespace content | 336 } // namespace content |
| 293 | 337 |
| OLD | NEW |