| 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" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 IPC_END_MESSAGE_MAP_EX() | 112 IPC_END_MESSAGE_MAP_EX() |
| 113 | 113 |
| 114 if (handled) | 114 if (handled) |
| 115 return true; | 115 return true; |
| 116 | 116 |
| 117 return gpu_channel_manager_.get() && | 117 return gpu_channel_manager_.get() && |
| 118 gpu_channel_manager_->OnMessageReceived(msg); | 118 gpu_channel_manager_->OnMessageReceived(msg); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void GpuChildThread::OnInitialize() { | 121 void GpuChildThread::OnInitialize() { |
| 122 // Record initialization only after collecting the GPU info because that can |
| 123 // take a significant amount of time. |
| 124 gpu_info_.initialization_time = base::Time::Now() - process_start_time_; |
| 122 Send(new GpuHostMsg_Initialized(!dead_on_arrival_, gpu_info_)); | 125 Send(new GpuHostMsg_Initialized(!dead_on_arrival_, gpu_info_)); |
| 123 while (!deferred_messages_.empty()) { | 126 while (!deferred_messages_.empty()) { |
| 124 Send(deferred_messages_.front()); | 127 Send(deferred_messages_.front()); |
| 125 deferred_messages_.pop(); | 128 deferred_messages_.pop(); |
| 126 } | 129 } |
| 127 | 130 |
| 128 if (dead_on_arrival_) { | 131 if (dead_on_arrival_) { |
| 129 LOG(ERROR) << "Exiting GPU process due to errors during initialization"; | 132 LOG(ERROR) << "Exiting GPU process due to errors during initialization"; |
| 130 base::MessageLoop::current()->Quit(); | 133 base::MessageLoop::current()->Quit(); |
| 131 return; | 134 return; |
| 132 } | 135 } |
| 133 | 136 |
| 134 #if defined(OS_ANDROID) | 137 #if defined(OS_ANDROID) |
| 135 base::PlatformThread::SetThreadPriority( | 138 base::PlatformThread::SetThreadPriority( |
| 136 base::PlatformThread::CurrentHandle(), | 139 base::PlatformThread::CurrentHandle(), |
| 137 base::kThreadPriority_Display); | 140 base::kThreadPriority_Display); |
| 138 #endif | 141 #endif |
| 139 | 142 |
| 140 // We don't need to pipe log messages if we are running the GPU thread in | 143 // We don't need to pipe log messages if we are running the GPU thread in |
| 141 // the browser process. | 144 // the browser process. |
| 142 if (!in_browser_process_) | 145 if (!in_browser_process_) |
| 143 logging::SetLogMessageHandler(GpuProcessLogMessageHandler); | 146 logging::SetLogMessageHandler(GpuProcessLogMessageHandler); |
| 144 | 147 |
| 145 // Record initialization only after collecting the GPU info because that can | |
| 146 // take a significant amount of time. | |
| 147 gpu_info_.initialization_time = base::Time::Now() - process_start_time_; | |
| 148 | |
| 149 // Defer creation of the render thread. This is to prevent it from handling | 148 // Defer creation of the render thread. This is to prevent it from handling |
| 150 // IPC messages before the sandbox has been enabled and all other necessary | 149 // IPC messages before the sandbox has been enabled and all other necessary |
| 151 // initialization has succeeded. | 150 // initialization has succeeded. |
| 152 gpu_channel_manager_.reset( | 151 gpu_channel_manager_.reset( |
| 153 new GpuChannelManager(GetRouter(), | 152 new GpuChannelManager(GetRouter(), |
| 154 watchdog_thread_.get(), | 153 watchdog_thread_.get(), |
| 155 ChildProcess::current()->io_message_loop_proxy(), | 154 ChildProcess::current()->io_message_loop_proxy(), |
| 156 ChildProcess::current()->GetShutDownEvent())); | 155 ChildProcess::current()->GetShutDownEvent())); |
| 157 | |
| 158 // Ensure the browser process receives the GPU info before a reply to any | |
| 159 // subsequent IPC it might send. | |
| 160 if (!in_browser_process_) | |
| 161 Send(new GpuHostMsg_GraphicsInfoCollected(gpu_info_)); | |
| 162 } | 156 } |
| 163 | 157 |
| 164 void GpuChildThread::StopWatchdog() { | 158 void GpuChildThread::StopWatchdog() { |
| 165 if (watchdog_thread_.get()) { | 159 if (watchdog_thread_.get()) { |
| 166 watchdog_thread_->Stop(); | 160 watchdog_thread_->Stop(); |
| 167 } | 161 } |
| 168 } | 162 } |
| 169 | 163 |
| 170 void GpuChildThread::OnCollectGraphicsInfo() { | 164 void GpuChildThread::OnCollectGraphicsInfo() { |
| 171 #if defined(OS_WIN) | 165 #if defined(OS_WIN) |
| 172 // GPU full info collection should only happen on un-sandboxed GPU process | 166 // GPU full info collection should only happen on un-sandboxed GPU process |
| 173 // or single process/in-process gpu mode on Windows. | 167 // or single process/in-process gpu mode on Windows. |
| 174 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 168 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 175 DCHECK(command_line->HasSwitch(switches::kDisableGpuSandbox) || | 169 DCHECK(command_line->HasSwitch(switches::kDisableGpuSandbox) || |
| 176 in_browser_process_); | 170 in_browser_process_); |
| 177 #endif // OS_WIN | 171 #endif // OS_WIN |
| 178 | 172 |
| 179 if (!gpu::CollectContextGraphicsInfo(&gpu_info_)) | 173 gpu::CollectInfoResult result = |
| 180 VLOG(1) << "gpu::CollectGraphicsInfo failed"; | 174 gpu::CollectContextGraphicsInfo(&gpu_info_); |
| 175 switch (result) { |
| 176 case gpu::kCollectInfoFatalFailure: |
| 177 LOG(ERROR) << "gpu::CollectGraphicsInfo failed (fatal)."; |
| 178 // TODO(piman): can we signal overall failure? |
| 179 break; |
| 180 case gpu::kCollectInfoNonFatalFailure: |
| 181 VLOG(1) << "gpu::CollectGraphicsInfo failed (non-fatal)."; |
| 182 break; |
| 183 case gpu::kCollectInfoSuccess: |
| 184 break; |
| 185 } |
| 181 GetContentClient()->SetGpuInfo(gpu_info_); | 186 GetContentClient()->SetGpuInfo(gpu_info_); |
| 182 | 187 |
| 183 #if defined(OS_WIN) | 188 #if defined(OS_WIN) |
| 184 // This is slow, but it's the only thing the unsandboxed GPU process does, | 189 // This is slow, but it's the only thing the unsandboxed GPU process does, |
| 185 // and GpuDataManager prevents us from sending multiple collecting requests, | 190 // and GpuDataManager prevents us from sending multiple collecting requests, |
| 186 // so it's OK to be blocking. | 191 // so it's OK to be blocking. |
| 187 gpu::GetDxDiagnostics(&gpu_info_.dx_diagnostics); | 192 gpu::GetDxDiagnostics(&gpu_info_.dx_diagnostics); |
| 188 gpu_info_.finalized = true; | 193 gpu_info_.finalized = true; |
| 189 #endif // OS_WIN | 194 #endif // OS_WIN |
| 190 | 195 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 // the future posting of tasks to the message loop. | 239 // the future posting of tasks to the message loop. |
| 235 if (watchdog_thread_->message_loop()) | 240 if (watchdog_thread_->message_loop()) |
| 236 watchdog_thread_->PostAcknowledge(); | 241 watchdog_thread_->PostAcknowledge(); |
| 237 // Prevent rearming. | 242 // Prevent rearming. |
| 238 watchdog_thread_->Stop(); | 243 watchdog_thread_->Stop(); |
| 239 } | 244 } |
| 240 } | 245 } |
| 241 | 246 |
| 242 } // namespace content | 247 } // namespace content |
| 243 | 248 |
| OLD | NEW |