| 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 sender_(nullptr) {} |
| 57 |
| 58 // Overridden from IPC::MessageFilter: |
| 59 void OnFilterAdded(IPC::Sender* sender) override { |
| 60 DCHECK(!sender_); |
| 61 sender_ = sender; |
| 62 } |
| 63 void OnFilterRemoved() override { |
| 64 DCHECK(sender_); |
| 65 sender_ = nullptr; |
| 66 } |
| 67 bool OnMessageReceived(const IPC::Message& message) override { |
| 68 DCHECK(sender_); |
| 69 bool handled = true; |
| 70 IPC_BEGIN_MESSAGE_MAP(GpuMemoryBufferMessageFilter, message) |
| 71 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer) |
| 72 IPC_MESSAGE_UNHANDLED(handled = false) |
| 73 IPC_END_MESSAGE_MAP() |
| 74 return handled; |
| 75 } |
| 76 |
| 77 protected: |
| 78 ~GpuMemoryBufferMessageFilter() override {} |
| 79 |
| 80 void OnCreateGpuMemoryBuffer( |
| 81 const GpuMsg_CreateGpuMemoryBuffer_Params& params) { |
| 82 TRACE_EVENT2("gpu", "GpuMemoryBufferMessageFilter::OnCreateGpuMemoryBuffer", |
| 83 "id", params.id, "client_id", params.client_id); |
| 84 sender_->Send(new GpuHostMsg_GpuMemoryBufferCreated( |
| 85 gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( |
| 86 params.id, params.size, params.format, params.usage, |
| 87 params.client_id, params.surface_handle))); |
| 88 } |
| 89 |
| 90 GpuMemoryBufferFactory* const gpu_memory_buffer_factory_; |
| 91 IPC::Sender* sender_; |
| 92 }; |
| 93 |
| 94 ChildThreadImpl::Options GetOptions( |
| 95 GpuMemoryBufferFactory* gpu_memory_buffer_factory) { |
| 48 ChildThreadImpl::Options::Builder builder; | 96 ChildThreadImpl::Options::Builder builder; |
| 49 | 97 |
| 98 builder.AddStartupFilter( |
| 99 new GpuMemoryBufferMessageFilter(gpu_memory_buffer_factory)); |
| 100 |
| 50 #if defined(USE_OZONE) | 101 #if defined(USE_OZONE) |
| 51 IPC::MessageFilter* message_filter = ui::OzonePlatform::GetInstance() | 102 IPC::MessageFilter* message_filter = ui::OzonePlatform::GetInstance() |
| 52 ->GetGpuPlatformSupport() | 103 ->GetGpuPlatformSupport() |
| 53 ->GetMessageFilter(); | 104 ->GetMessageFilter(); |
| 54 if (message_filter) | 105 if (message_filter) |
| 55 builder.AddStartupFilter(message_filter); | 106 builder.AddStartupFilter(message_filter); |
| 56 #endif | 107 #endif |
| 57 | 108 |
| 58 return builder.Build(); | 109 return builder.Build(); |
| 59 } | 110 } |
| 60 | 111 |
| 61 } // namespace | 112 } // namespace |
| 62 | 113 |
| 63 GpuChildThread::GpuChildThread(GpuWatchdogThread* watchdog_thread, | 114 GpuChildThread::GpuChildThread( |
| 64 bool dead_on_arrival, | 115 GpuWatchdogThread* watchdog_thread, |
| 65 const gpu::GPUInfo& gpu_info, | 116 bool dead_on_arrival, |
| 66 const DeferredMessages& deferred_messages) | 117 const gpu::GPUInfo& gpu_info, |
| 67 : ChildThreadImpl(GetOptions()), | 118 const DeferredMessages& deferred_messages, |
| 119 GpuMemoryBufferFactory* gpu_memory_buffer_factory) |
| 120 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), |
| 68 dead_on_arrival_(dead_on_arrival), | 121 dead_on_arrival_(dead_on_arrival), |
| 69 gpu_info_(gpu_info), | 122 gpu_info_(gpu_info), |
| 70 deferred_messages_(deferred_messages), | 123 deferred_messages_(deferred_messages), |
| 71 in_browser_process_(false) { | 124 in_browser_process_(false), |
| 125 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) { |
| 72 watchdog_thread_ = watchdog_thread; | 126 watchdog_thread_ = watchdog_thread; |
| 73 #if defined(OS_WIN) | 127 #if defined(OS_WIN) |
| 74 target_services_ = NULL; | 128 target_services_ = NULL; |
| 75 #endif | 129 #endif |
| 76 g_thread_safe_sender.Get() = thread_safe_sender(); | 130 g_thread_safe_sender.Get() = thread_safe_sender(); |
| 77 } | 131 } |
| 78 | 132 |
| 79 GpuChildThread::GpuChildThread(const InProcessChildThreadParams& params) | 133 GpuChildThread::GpuChildThread(const InProcessChildThreadParams& params) |
| 80 : ChildThreadImpl(ChildThreadImpl::Options::Builder() | 134 : ChildThreadImpl(ChildThreadImpl::Options::Builder() |
| 81 .InBrowserProcess(params) | 135 .InBrowserProcess(params) |
| 82 .Build()), | 136 .Build()), |
| 83 dead_on_arrival_(false), | 137 dead_on_arrival_(false), |
| 84 in_browser_process_(true) { | 138 in_browser_process_(true), |
| 139 gpu_memory_buffer_factory_(nullptr) { |
| 85 #if defined(OS_WIN) | 140 #if defined(OS_WIN) |
| 86 target_services_ = NULL; | 141 target_services_ = NULL; |
| 87 #endif | 142 #endif |
| 88 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 143 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 89 switches::kSingleProcess) || | 144 switches::kSingleProcess) || |
| 90 base::CommandLine::ForCurrentProcess()->HasSwitch( | 145 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 91 switches::kInProcessGPU)); | 146 switches::kInProcessGPU)); |
| 92 | 147 |
| 93 if (!gfx::GLSurface::InitializeOneOff()) | 148 if (!gfx::GLSurface::InitializeOneOff()) |
| 94 VLOG(1) << "gfx::GLSurface::InitializeOneOff failed"; | 149 VLOG(1) << "gfx::GLSurface::InitializeOneOff failed"; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 #endif | 222 #endif |
| 168 | 223 |
| 169 // We don't need to pipe log messages if we are running the GPU thread in | 224 // We don't need to pipe log messages if we are running the GPU thread in |
| 170 // the browser process. | 225 // the browser process. |
| 171 if (!in_browser_process_) | 226 if (!in_browser_process_) |
| 172 logging::SetLogMessageHandler(GpuProcessLogMessageHandler); | 227 logging::SetLogMessageHandler(GpuProcessLogMessageHandler); |
| 173 | 228 |
| 174 // Defer creation of the render thread. This is to prevent it from handling | 229 // Defer creation of the render thread. This is to prevent it from handling |
| 175 // IPC messages before the sandbox has been enabled and all other necessary | 230 // IPC messages before the sandbox has been enabled and all other necessary |
| 176 // initialization has succeeded. | 231 // initialization has succeeded. |
| 177 gpu_channel_manager_.reset( | 232 gpu_channel_manager_.reset(new GpuChannelManager( |
| 178 new GpuChannelManager(GetRouter(), watchdog_thread_.get(), | 233 GetRouter(), watchdog_thread_.get(), |
| 179 ChildProcess::current()->io_task_runner(), | 234 ChildProcess::current()->io_task_runner(), |
| 180 ChildProcess::current()->GetShutDownEvent(), | 235 ChildProcess::current()->GetShutDownEvent(), channel(), |
| 181 channel(), GetAttachmentBroker())); | 236 GetAttachmentBroker(), gpu_memory_buffer_factory_)); |
| 182 | 237 |
| 183 #if defined(USE_OZONE) | 238 #if defined(USE_OZONE) |
| 184 ui::OzonePlatform::GetInstance() | 239 ui::OzonePlatform::GetInstance() |
| 185 ->GetGpuPlatformSupport() | 240 ->GetGpuPlatformSupport() |
| 186 ->OnChannelEstablished(this); | 241 ->OnChannelEstablished(this); |
| 187 #endif | 242 #endif |
| 188 } | 243 } |
| 189 | 244 |
| 190 void GpuChildThread::StopWatchdog() { | 245 void GpuChildThread::StopWatchdog() { |
| 191 if (watchdog_thread_.get()) { | 246 if (watchdog_thread_.get()) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 } | 335 } |
| 281 | 336 |
| 282 void GpuChildThread::OnGpuSwitched() { | 337 void GpuChildThread::OnGpuSwitched() { |
| 283 DVLOG(1) << "GPU: GPU has switched"; | 338 DVLOG(1) << "GPU: GPU has switched"; |
| 284 // Notify observers in the GPU process. | 339 // Notify observers in the GPU process. |
| 285 ui::GpuSwitchingManager::GetInstance()->NotifyGpuSwitched(); | 340 ui::GpuSwitchingManager::GetInstance()->NotifyGpuSwitched(); |
| 286 } | 341 } |
| 287 | 342 |
| 288 } // namespace content | 343 } // namespace content |
| 289 | 344 |
| OLD | NEW |