[email protected] | f091824 | 2012-02-18 00:30:50 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 5 | #include "content/gpu/gpu_child_thread.h" |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 6 | |
[email protected] | 8075105 | 2011-11-12 17:10:58 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | ca405d2 | 2013-06-25 23:28:55 | [diff] [blame] | 8 | #include "base/lazy_instance.h" |
[email protected] | ac9ba8fe | 2010-12-30 18:08:36 | [diff] [blame] | 9 | #include "base/threading/worker_pool.h" |
[email protected] | 274aa588 | 2010-07-15 21:12:23 | [diff] [blame] | 10 | #include "build/build_config.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 11 | #include "content/child/child_process.h" |
[email protected] | ca405d2 | 2013-06-25 23:28:55 | [diff] [blame] | 12 | #include "content/child/thread_safe_sender.h" |
[email protected] | 202b54ff | 2011-04-22 21:36:38 | [diff] [blame] | 13 | #include "content/common/gpu/gpu_messages.h" |
[email protected] | 623c0bd | 2011-03-12 01:00:41 | [diff] [blame] | 14 | #include "content/gpu/gpu_watchdog_thread.h" |
[email protected] | 085170ca | 2012-05-17 20:27:28 | [diff] [blame] | 15 | #include "content/public/common/content_client.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 16 | #include "content/public/common/content_switches.h" |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 17 | #include "gpu/config/gpu_info_collector.h" |
[email protected] | 939856a | 2010-08-24 20:29:02 | [diff] [blame] | 18 | #include "ipc/ipc_channel_handle.h" |
[email protected] | 8c81e9ecc | 2012-04-25 00:42:27 | [diff] [blame] | 19 | #include "ipc/ipc_sync_message_filter.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 20 | #include "ui/gl/gl_implementation.h" |
ccameron | 17d5109 | 2014-10-24 22:17:07 | [diff] [blame] | 21 | #include "ui/gl/gpu_switching_manager.h" |
[email protected] | 7709e71 | 2011-01-07 17:57:31 | [diff] [blame] | 22 | |
[email protected] | 929881f | 2014-06-20 21:00:36 | [diff] [blame] | 23 | #if defined(USE_OZONE) |
[email protected] | 929881f | 2014-06-20 21:00:36 | [diff] [blame] | 24 | #include "ui/ozone/public/gpu_platform_support.h" |
[email protected] | f88a8f7 | 2014-07-11 18:07:49 | [diff] [blame] | 25 | #include "ui/ozone/public/ozone_platform.h" |
[email protected] | 929881f | 2014-06-20 21:00:36 | [diff] [blame] | 26 | #endif |
| 27 | |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 28 | namespace content { |
[email protected] | 7709e71 | 2011-01-07 17:57:31 | [diff] [blame] | 29 | namespace { |
| 30 | |
[email protected] | ca405d2 | 2013-06-25 23:28:55 | [diff] [blame] | 31 | static base::LazyInstance<scoped_refptr<ThreadSafeSender> > |
| 32 | g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER; |
| 33 | |
[email protected] | 9158f2f | 2011-01-27 21:08:57 | [diff] [blame] | 34 | bool GpuProcessLogMessageHandler(int severity, |
| 35 | const char* file, int line, |
| 36 | size_t message_start, |
| 37 | const std::string& str) { |
[email protected] | e6ff5a3 | 2011-01-31 20:36:22 | [diff] [blame] | 38 | std::string header = str.substr(0, message_start); |
[email protected] | 9158f2f | 2011-01-27 21:08:57 | [diff] [blame] | 39 | std::string message = str.substr(message_start); |
[email protected] | 8c81e9ecc | 2012-04-25 00:42:27 | [diff] [blame] | 40 | |
[email protected] | ca405d2 | 2013-06-25 23:28:55 | [diff] [blame] | 41 | g_thread_safe_sender.Get()->Send(new GpuHostMsg_OnLogMessage( |
| 42 | severity, header, message)); |
[email protected] | 8c81e9ecc | 2012-04-25 00:42:27 | [diff] [blame] | 43 | |
[email protected] | 9158f2f | 2011-01-27 21:08:57 | [diff] [blame] | 44 | return false; |
| 45 | } |
| 46 | |
jam | 8a021512a | 2015-02-03 18:16:08 | [diff] [blame] | 47 | ChildThreadImpl::Options GetOptions() { |
| 48 | ChildThreadImpl::Options options; |
alexst | 6154ce77 | 2015-01-21 12:41:41 | [diff] [blame] | 49 | |
| 50 | #if defined(USE_OZONE) |
| 51 | IPC::MessageFilter* message_filter = ui::OzonePlatform::GetInstance() |
| 52 | ->GetGpuPlatformSupport() |
| 53 | ->GetMessageFilter(); |
| 54 | if (message_filter) |
| 55 | options.startup_filters.push_back(message_filter); |
| 56 | #endif |
| 57 | |
| 58 | return options; |
| 59 | } |
| 60 | |
[email protected] | e6ff5a3 | 2011-01-31 20:36:22 | [diff] [blame] | 61 | } // namespace |
[email protected] | 9158f2f | 2011-01-27 21:08:57 | [diff] [blame] | 62 | |
[email protected] | db6101db | 2012-10-25 15:20:08 | [diff] [blame] | 63 | GpuChildThread::GpuChildThread(GpuWatchdogThread* watchdog_thread, |
| 64 | bool dead_on_arrival, |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 65 | const gpu::GPUInfo& gpu_info, |
| 66 | const DeferredMessages& deferred_messages) |
jam | 8a021512a | 2015-02-03 18:16:08 | [diff] [blame] | 67 | : ChildThreadImpl(GetOptions()), |
alexst | 6154ce77 | 2015-01-21 12:41:41 | [diff] [blame] | 68 | dead_on_arrival_(dead_on_arrival), |
[email protected] | 50749e0 | 2013-03-08 04:56:53 | [diff] [blame] | 69 | gpu_info_(gpu_info), |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 70 | deferred_messages_(deferred_messages), |
[email protected] | 50749e0 | 2013-03-08 04:56:53 | [diff] [blame] | 71 | in_browser_process_(false) { |
[email protected] | db6101db | 2012-10-25 15:20:08 | [diff] [blame] | 72 | watchdog_thread_ = watchdog_thread; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 73 | #if defined(OS_WIN) |
[email protected] | 5abe630 | 2011-12-20 23:44:32 | [diff] [blame] | 74 | target_services_ = NULL; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 75 | #endif |
[email protected] | ca405d2 | 2013-06-25 23:28:55 | [diff] [blame] | 76 | g_thread_safe_sender.Get() = thread_safe_sender(); |
[email protected] | 0b2cec6 | 2011-07-22 18:13:28 | [diff] [blame] | 77 | } |
[email protected] | 9158f2f | 2011-01-27 21:08:57 | [diff] [blame] | 78 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 79 | GpuChildThread::GpuChildThread(const std::string& channel_id) |
jam | 8a021512a | 2015-02-03 18:16:08 | [diff] [blame] | 80 | : ChildThreadImpl(Options(channel_id, false)), |
[email protected] | 50749e0 | 2013-03-08 04:56:53 | [diff] [blame] | 81 | dead_on_arrival_(false), |
| 82 | in_browser_process_(true) { |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 83 | #if defined(OS_WIN) |
| 84 | target_services_ = NULL; |
| 85 | #endif |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 86 | DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 87 | switches::kSingleProcess) || |
| 88 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 89 | switches::kInProcessGPU)); |
[email protected] | af7c5d9 | 2014-02-03 19:53:15 | [diff] [blame] | 90 | #if !defined(OS_ANDROID) |
[email protected] | 50749e0 | 2013-03-08 04:56:53 | [diff] [blame] | 91 | // For single process and in-process GPU mode, we need to load and |
| 92 | // initialize the GL implementation and locate the GL entry points here. |
[email protected] | af7c5d9 | 2014-02-03 19:53:15 | [diff] [blame] | 93 | // On Android, GLSurface::InitializeOneOff() is called from BrowserMainLoop |
| 94 | // before getting here. crbug.com/326295 |
| 95 | if (!gfx::GLSurface::InitializeOneOff()) |
| 96 | VLOG(1) << "gfx::GLSurface::InitializeOneOff failed"; |
| 97 | #endif |
[email protected] | ca405d2 | 2013-06-25 23:28:55 | [diff] [blame] | 98 | g_thread_safe_sender.Get() = thread_safe_sender(); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 99 | } |
| 100 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 101 | GpuChildThread::~GpuChildThread() { |
[email protected] | ce79d851 | 2013-04-22 22:44:41 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | void GpuChildThread::Shutdown() { |
jam | 8a021512a | 2015-02-03 18:16:08 | [diff] [blame] | 105 | ChildThreadImpl::Shutdown(); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 106 | logging::SetLogMessageHandler(NULL); |
| 107 | } |
| 108 | |
| 109 | void GpuChildThread::Init(const base::Time& process_start_time) { |
| 110 | process_start_time_ = process_start_time; |
| 111 | } |
| 112 | |
| 113 | bool GpuChildThread::Send(IPC::Message* msg) { |
| 114 | // The GPU process must never send a synchronous IPC message to the browser |
[email protected] | 4c0e289d | 2011-06-01 03:45:51 | [diff] [blame] | 115 | // process. This could result in deadlock. |
| 116 | DCHECK(!msg->is_sync()); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 117 | |
jam | 8a021512a | 2015-02-03 18:16:08 | [diff] [blame] | 118 | return ChildThreadImpl::Send(msg); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | bool GpuChildThread::OnControlMessageReceived(const IPC::Message& msg) { |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 122 | bool handled = true; |
[email protected] | e44d134 | 2014-05-16 21:29:33 | [diff] [blame] | 123 | IPC_BEGIN_MESSAGE_MAP(GpuChildThread, msg) |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 124 | IPC_MESSAGE_HANDLER(GpuMsg_Initialize, OnInitialize) |
| 125 | IPC_MESSAGE_HANDLER(GpuMsg_CollectGraphicsInfo, OnCollectGraphicsInfo) |
[email protected] | fb246af | 2012-08-18 03:11:41 | [diff] [blame] | 126 | IPC_MESSAGE_HANDLER(GpuMsg_GetVideoMemoryUsageStats, |
| 127 | OnGetVideoMemoryUsageStats) |
[email protected] | 184e3f380 | 2011-05-04 20:48:52 | [diff] [blame] | 128 | IPC_MESSAGE_HANDLER(GpuMsg_Clean, OnClean) |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 129 | IPC_MESSAGE_HANDLER(GpuMsg_Crash, OnCrash) |
| 130 | IPC_MESSAGE_HANDLER(GpuMsg_Hang, OnHang) |
[email protected] | 31583a9d | 2012-11-30 00:37:17 | [diff] [blame] | 131 | IPC_MESSAGE_HANDLER(GpuMsg_DisableWatchdog, OnDisableWatchdog) |
ccameron | 17d5109 | 2014-10-24 22:17:07 | [diff] [blame] | 132 | IPC_MESSAGE_HANDLER(GpuMsg_GpuSwitched, OnGpuSwitched) |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 133 | IPC_MESSAGE_UNHANDLED(handled = false) |
[email protected] | e44d134 | 2014-05-16 21:29:33 | [diff] [blame] | 134 | IPC_END_MESSAGE_MAP() |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 135 | |
| 136 | if (handled) |
| 137 | return true; |
| 138 | |
[email protected] | 929881f | 2014-06-20 21:00:36 | [diff] [blame] | 139 | #if defined(USE_OZONE) |
| 140 | if (ui::OzonePlatform::GetInstance() |
| 141 | ->GetGpuPlatformSupport() |
| 142 | ->OnMessageReceived(msg)) |
| 143 | return true; |
| 144 | #endif |
| 145 | |
[email protected] | f24a1e2b | 2011-04-08 01:48:48 | [diff] [blame] | 146 | return gpu_channel_manager_.get() && |
| 147 | gpu_channel_manager_->OnMessageReceived(msg); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | void GpuChildThread::OnInitialize() { |
[email protected] | 0e8cac7 | 2014-03-22 00:37:18 | [diff] [blame] | 151 | // Record initialization only after collecting the GPU info because that can |
| 152 | // take a significant amount of time. |
| 153 | gpu_info_.initialization_time = base::Time::Now() - process_start_time_; |
[email protected] | fd00eee5 | 2013-05-24 22:32:28 | [diff] [blame] | 154 | Send(new GpuHostMsg_Initialized(!dead_on_arrival_, gpu_info_)); |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 155 | while (!deferred_messages_.empty()) { |
| 156 | Send(deferred_messages_.front()); |
| 157 | deferred_messages_.pop(); |
| 158 | } |
[email protected] | 9665973 | 2012-08-24 01:55:17 | [diff] [blame] | 159 | |
[email protected] | 0b2cec6 | 2011-07-22 18:13:28 | [diff] [blame] | 160 | if (dead_on_arrival_) { |
[email protected] | d7c2942 | 2014-03-11 06:08:57 | [diff] [blame] | 161 | LOG(ERROR) << "Exiting GPU process due to errors during initialization"; |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 162 | base::MessageLoop::current()->Quit(); |
[email protected] | 37cfa2a | 2012-08-20 20:29:39 | [diff] [blame] | 163 | return; |
[email protected] | 0b2cec6 | 2011-07-22 18:13:28 | [diff] [blame] | 164 | } |
| 165 | |
[email protected] | e9875de7 | 2013-01-24 01:55:06 | [diff] [blame] | 166 | #if defined(OS_ANDROID) |
[email protected] | b38864d | 2013-05-24 14:42:36 | [diff] [blame] | 167 | base::PlatformThread::SetThreadPriority( |
| 168 | base::PlatformThread::CurrentHandle(), |
| 169 | base::kThreadPriority_Display); |
[email protected] | e9875de7 | 2013-01-24 01:55:06 | [diff] [blame] | 170 | #endif |
| 171 | |
[email protected] | 2d9de411 | 2011-05-27 03:18:36 | [diff] [blame] | 172 | // We don't need to pipe log messages if we are running the GPU thread in |
| 173 | // the browser process. |
[email protected] | 2d3de545 | 2013-01-18 10:03:40 | [diff] [blame] | 174 | if (!in_browser_process_) |
[email protected] | 2d9de411 | 2011-05-27 03:18:36 | [diff] [blame] | 175 | logging::SetLogMessageHandler(GpuProcessLogMessageHandler); |
[email protected] | 602cf9fda | 2011-04-22 16:53:30 | [diff] [blame] | 176 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 177 | // Defer creation of the render thread. This is to prevent it from handling |
| 178 | // IPC messages before the sandbox has been enabled and all other necessary |
| 179 | // initialization has succeeded. |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 180 | gpu_channel_manager_.reset( |
[email protected] | 4795329 | 2014-03-13 10:15:37 | [diff] [blame] | 181 | new GpuChannelManager(GetRouter(), |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 182 | watchdog_thread_.get(), |
| 183 | ChildProcess::current()->io_message_loop_proxy(), |
alexst | 0269a5c | 2014-09-10 05:15:12 | [diff] [blame] | 184 | ChildProcess::current()->GetShutDownEvent(), |
| 185 | channel())); |
[email protected] | 929881f | 2014-06-20 21:00:36 | [diff] [blame] | 186 | |
| 187 | #if defined(USE_OZONE) |
alexst | 6154ce77 | 2015-01-21 12:41:41 | [diff] [blame] | 188 | ui::OzonePlatform::GetInstance() |
| 189 | ->GetGpuPlatformSupport() |
| 190 | ->OnChannelEstablished(this); |
[email protected] | 929881f | 2014-06-20 21:00:36 | [diff] [blame] | 191 | #endif |
[email protected] | 7709e71 | 2011-01-07 17:57:31 | [diff] [blame] | 192 | } |
| 193 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 194 | void GpuChildThread::StopWatchdog() { |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 195 | if (watchdog_thread_.get()) { |
[email protected] | 7709e71 | 2011-01-07 17:57:31 | [diff] [blame] | 196 | watchdog_thread_->Stop(); |
| 197 | } |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 198 | } |
| 199 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 200 | void GpuChildThread::OnCollectGraphicsInfo() { |
[email protected] | 7741f2e | 2012-12-06 01:29:13 | [diff] [blame] | 201 | #if defined(OS_WIN) |
| 202 | // GPU full info collection should only happen on un-sandboxed GPU process |
| 203 | // or single process/in-process gpu mode on Windows. |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 204 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
[email protected] | 7741f2e | 2012-12-06 01:29:13 | [diff] [blame] | 205 | DCHECK(command_line->HasSwitch(switches::kDisableGpuSandbox) || |
[email protected] | 2d3de545 | 2013-01-18 10:03:40 | [diff] [blame] | 206 | in_browser_process_); |
[email protected] | 7741f2e | 2012-12-06 01:29:13 | [diff] [blame] | 207 | #endif // OS_WIN |
[email protected] | f3f79b10 | 2011-01-27 00:19:37 | [diff] [blame] | 208 | |
[email protected] | 0e8cac7 | 2014-03-22 00:37:18 | [diff] [blame] | 209 | gpu::CollectInfoResult result = |
| 210 | gpu::CollectContextGraphicsInfo(&gpu_info_); |
| 211 | switch (result) { |
| 212 | case gpu::kCollectInfoFatalFailure: |
| 213 | LOG(ERROR) << "gpu::CollectGraphicsInfo failed (fatal)."; |
| 214 | // TODO(piman): can we signal overall failure? |
| 215 | break; |
| 216 | case gpu::kCollectInfoNonFatalFailure: |
anujk.sharma | 98e81a1 | 2014-11-14 04:54:21 | [diff] [blame] | 217 | DVLOG(1) << "gpu::CollectGraphicsInfo failed (non-fatal)."; |
[email protected] | 0e8cac7 | 2014-03-22 00:37:18 | [diff] [blame] | 218 | break; |
zmo | 84eae5e | 2014-09-05 01:36:23 | [diff] [blame] | 219 | case gpu::kCollectInfoNone: |
| 220 | NOTREACHED(); |
| 221 | break; |
[email protected] | 0e8cac7 | 2014-03-22 00:37:18 | [diff] [blame] | 222 | case gpu::kCollectInfoSuccess: |
| 223 | break; |
| 224 | } |
[email protected] | 7741f2e | 2012-12-06 01:29:13 | [diff] [blame] | 225 | GetContentClient()->SetGpuInfo(gpu_info_); |
[email protected] | 085170ca | 2012-05-17 20:27:28 | [diff] [blame] | 226 | |
| 227 | #if defined(OS_WIN) |
[email protected] | 87a735d | 2012-12-07 01:52:44 | [diff] [blame] | 228 | // This is slow, but it's the only thing the unsandboxed GPU process does, |
| 229 | // and GpuDataManager prevents us from sending multiple collecting requests, |
| 230 | // so it's OK to be blocking. |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 231 | gpu::GetDxDiagnostics(&gpu_info_.dx_diagnostics); |
zmo | 84eae5e | 2014-09-05 01:36:23 | [diff] [blame] | 232 | gpu_info_.dx_diagnostics_info_state = gpu::kCollectInfoSuccess; |
[email protected] | 87a735d | 2012-12-07 01:52:44 | [diff] [blame] | 233 | #endif // OS_WIN |
[email protected] | 085170ca | 2012-05-17 20:27:28 | [diff] [blame] | 234 | |
[email protected] | 87a735d | 2012-12-07 01:52:44 | [diff] [blame] | 235 | Send(new GpuHostMsg_GraphicsInfoCollected(gpu_info_)); |
| 236 | |
| 237 | #if defined(OS_WIN) |
[email protected] | 2d3de545 | 2013-01-18 10:03:40 | [diff] [blame] | 238 | if (!in_browser_process_) { |
[email protected] | 87a735d | 2012-12-07 01:52:44 | [diff] [blame] | 239 | // The unsandboxed GPU process fulfilled its duty. Rest in peace. |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 240 | base::MessageLoop::current()->Quit(); |
[email protected] | 085170ca | 2012-05-17 20:27:28 | [diff] [blame] | 241 | } |
[email protected] | 7741f2e | 2012-12-06 01:29:13 | [diff] [blame] | 242 | #endif // OS_WIN |
[email protected] | cadc050 | 2010-09-10 20:27:13 | [diff] [blame] | 243 | } |
[email protected] | 43ed628 | 2010-09-15 20:07:19 | [diff] [blame] | 244 | |
[email protected] | fb246af | 2012-08-18 03:11:41 | [diff] [blame] | 245 | void GpuChildThread::OnGetVideoMemoryUsageStats() { |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 246 | GPUVideoMemoryUsageStats video_memory_usage_stats; |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 247 | if (gpu_channel_manager_) |
[email protected] | fb246af | 2012-08-18 03:11:41 | [diff] [blame] | 248 | gpu_channel_manager_->gpu_memory_manager()->GetVideoMemoryUsageStats( |
[email protected] | 879c7dfd | 2012-12-19 21:44:37 | [diff] [blame] | 249 | &video_memory_usage_stats); |
[email protected] | fb246af | 2012-08-18 03:11:41 | [diff] [blame] | 250 | Send(new GpuHostMsg_VideoMemoryUsageStats(video_memory_usage_stats)); |
| 251 | } |
| 252 | |
[email protected] | 184e3f380 | 2011-05-04 20:48:52 | [diff] [blame] | 253 | void GpuChildThread::OnClean() { |
anujk.sharma | 98e81a1 | 2014-11-14 04:54:21 | [diff] [blame] | 254 | DVLOG(1) << "GPU: Removing all contexts"; |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 255 | if (gpu_channel_manager_) |
[email protected] | 184e3f380 | 2011-05-04 20:48:52 | [diff] [blame] | 256 | gpu_channel_manager_->LoseAllContexts(); |
| 257 | } |
| 258 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 259 | void GpuChildThread::OnCrash() { |
anujk.sharma | 98e81a1 | 2014-11-14 04:54:21 | [diff] [blame] | 260 | DVLOG(1) << "GPU: Simulating GPU crash"; |
[email protected] | 43ed628 | 2010-09-15 20:07:19 | [diff] [blame] | 261 | // Good bye, cruel world. |
| 262 | volatile int* it_s_the_end_of_the_world_as_we_know_it = NULL; |
| 263 | *it_s_the_end_of_the_world_as_we_know_it = 0xdead; |
| 264 | } |
[email protected] | 259750d | 2010-09-24 06:14:00 | [diff] [blame] | 265 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 266 | void GpuChildThread::OnHang() { |
anujk.sharma | 98e81a1 | 2014-11-14 04:54:21 | [diff] [blame] | 267 | DVLOG(1) << "GPU: Simulating GPU hang"; |
[email protected] | 981c1c5 | 2010-12-01 20:09:24 | [diff] [blame] | 268 | for (;;) { |
| 269 | // Do not sleep here. The GPU watchdog timer tracks the amount of user |
| 270 | // time this thread is using and it doesn't use much while calling Sleep. |
| 271 | } |
[email protected] | 259750d | 2010-09-24 06:14:00 | [diff] [blame] | 272 | } |
[email protected] | 41579ae | 2010-11-15 22:31:26 | [diff] [blame] | 273 | |
[email protected] | 31583a9d | 2012-11-30 00:37:17 | [diff] [blame] | 274 | void GpuChildThread::OnDisableWatchdog() { |
anujk.sharma | 98e81a1 | 2014-11-14 04:54:21 | [diff] [blame] | 275 | DVLOG(1) << "GPU: Disabling watchdog thread"; |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 276 | if (watchdog_thread_.get()) { |
[email protected] | 31583a9d | 2012-11-30 00:37:17 | [diff] [blame] | 277 | // Disarm the watchdog before shutting down the message loop. This prevents |
| 278 | // the future posting of tasks to the message loop. |
| 279 | if (watchdog_thread_->message_loop()) |
| 280 | watchdog_thread_->PostAcknowledge(); |
| 281 | // Prevent rearming. |
| 282 | watchdog_thread_->Stop(); |
| 283 | } |
| 284 | } |
| 285 | |
ccameron | 17d5109 | 2014-10-24 22:17:07 | [diff] [blame] | 286 | void GpuChildThread::OnGpuSwitched() { |
anujk.sharma | 98e81a1 | 2014-11-14 04:54:21 | [diff] [blame] | 287 | DVLOG(1) << "GPU: GPU has switched"; |
ccameron | 17d5109 | 2014-10-24 22:17:07 | [diff] [blame] | 288 | // Notify observers in the GPU process. |
| 289 | ui::GpuSwitchingManager::GetInstance()->NotifyGpuSwitched(); |
| 290 | } |
| 291 | |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 292 | } // namespace content |
| 293 | |