This source file includes following definitions.
- GpuProcessLogMessageHandler
- in_browser_process_
- in_browser_process_
- Shutdown
- Init
- Send
- OnControlMessageReceived
- OnInitialize
- StopWatchdog
- OnCollectGraphicsInfo
- OnGetVideoMemoryUsageStats
- OnClean
- OnCrash
- OnHang
- OnDisableWatchdog
#include "content/gpu/gpu_child_thread.h"
#include "base/bind.h"
#include "base/lazy_instance.h"
#include "base/threading/worker_pool.h"
#include "build/build_config.h"
#include "content/child/child_process.h"
#include "content/child/thread_safe_sender.h"
#include "content/common/gpu/gpu_messages.h"
#include "content/gpu/gpu_watchdog_thread.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_switches.h"
#include "gpu/config/gpu_info_collector.h"
#include "ipc/ipc_channel_handle.h"
#include "ipc/ipc_sync_message_filter.h"
#include "ui/gl/gl_implementation.h"
namespace content {
namespace {
static base::LazyInstance<scoped_refptr<ThreadSafeSender> >
g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER;
bool GpuProcessLogMessageHandler(int severity,
const char* file, int line,
size_t message_start,
const std::string& str) {
std::string header = str.substr(0, message_start);
std::string message = str.substr(message_start);
g_thread_safe_sender.Get()->Send(new GpuHostMsg_OnLogMessage(
severity, header, message));
return false;
}
}
GpuChildThread::GpuChildThread(GpuWatchdogThread* watchdog_thread,
bool dead_on_arrival,
const gpu::GPUInfo& gpu_info,
const DeferredMessages& deferred_messages)
: dead_on_arrival_(dead_on_arrival),
gpu_info_(gpu_info),
deferred_messages_(deferred_messages),
in_browser_process_(false) {
watchdog_thread_ = watchdog_thread;
#if defined(OS_WIN)
target_services_ = NULL;
#endif
g_thread_safe_sender.Get() = thread_safe_sender();
}
GpuChildThread::GpuChildThread(const std::string& channel_id)
: ChildThread(channel_id),
dead_on_arrival_(false),
in_browser_process_(true) {
#if defined(OS_WIN)
target_services_ = NULL;
#endif
DCHECK(
CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) ||
CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU));
#if !defined(OS_ANDROID)
if (!gfx::GLSurface::InitializeOneOff())
VLOG(1) << "gfx::GLSurface::InitializeOneOff failed";
#endif
g_thread_safe_sender.Get() = thread_safe_sender();
}
GpuChildThread::~GpuChildThread() {
}
void GpuChildThread::Shutdown() {
ChildThread::Shutdown();
logging::SetLogMessageHandler(NULL);
}
void GpuChildThread::Init(const base::Time& process_start_time) {
process_start_time_ = process_start_time;
}
bool GpuChildThread::Send(IPC::Message* msg) {
DCHECK(!msg->is_sync());
return ChildThread::Send(msg);
}
bool GpuChildThread::OnControlMessageReceived(const IPC::Message& msg) {
bool msg_is_ok = true;
bool handled = true;
IPC_BEGIN_MESSAGE_MAP_EX(GpuChildThread, msg, msg_is_ok)
IPC_MESSAGE_HANDLER(GpuMsg_Initialize, OnInitialize)
IPC_MESSAGE_HANDLER(GpuMsg_CollectGraphicsInfo, OnCollectGraphicsInfo)
IPC_MESSAGE_HANDLER(GpuMsg_GetVideoMemoryUsageStats,
OnGetVideoMemoryUsageStats)
IPC_MESSAGE_HANDLER(GpuMsg_Clean, OnClean)
IPC_MESSAGE_HANDLER(GpuMsg_Crash, OnCrash)
IPC_MESSAGE_HANDLER(GpuMsg_Hang, OnHang)
IPC_MESSAGE_HANDLER(GpuMsg_DisableWatchdog, OnDisableWatchdog)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP_EX()
if (handled)
return true;
return gpu_channel_manager_.get() &&
gpu_channel_manager_->OnMessageReceived(msg);
}
void GpuChildThread::OnInitialize() {
gpu_info_.initialization_time = base::Time::Now() - process_start_time_;
Send(new GpuHostMsg_Initialized(!dead_on_arrival_, gpu_info_));
while (!deferred_messages_.empty()) {
Send(deferred_messages_.front());
deferred_messages_.pop();
}
if (dead_on_arrival_) {
LOG(ERROR) << "Exiting GPU process due to errors during initialization";
base::MessageLoop::current()->Quit();
return;
}
#if defined(OS_ANDROID)
base::PlatformThread::SetThreadPriority(
base::PlatformThread::CurrentHandle(),
base::kThreadPriority_Display);
#endif
if (!in_browser_process_)
logging::SetLogMessageHandler(GpuProcessLogMessageHandler);
gpu_channel_manager_.reset(
new GpuChannelManager(GetRouter(),
watchdog_thread_.get(),
ChildProcess::current()->io_message_loop_proxy(),
ChildProcess::current()->GetShutDownEvent()));
}
void GpuChildThread::StopWatchdog() {
if (watchdog_thread_.get()) {
watchdog_thread_->Stop();
}
}
void GpuChildThread::OnCollectGraphicsInfo() {
#if defined(OS_WIN)
CommandLine* command_line = CommandLine::ForCurrentProcess();
DCHECK(command_line->HasSwitch(switches::kDisableGpuSandbox) ||
in_browser_process_);
#endif
gpu::CollectInfoResult result =
gpu::CollectContextGraphicsInfo(&gpu_info_);
switch (result) {
case gpu::kCollectInfoFatalFailure:
LOG(ERROR) << "gpu::CollectGraphicsInfo failed (fatal).";
break;
case gpu::kCollectInfoNonFatalFailure:
VLOG(1) << "gpu::CollectGraphicsInfo failed (non-fatal).";
break;
case gpu::kCollectInfoSuccess:
break;
}
GetContentClient()->SetGpuInfo(gpu_info_);
#if defined(OS_WIN)
gpu::GetDxDiagnostics(&gpu_info_.dx_diagnostics);
gpu_info_.finalized = true;
#endif
Send(new GpuHostMsg_GraphicsInfoCollected(gpu_info_));
#if defined(OS_WIN)
if (!in_browser_process_) {
base::MessageLoop::current()->Quit();
}
#endif
}
void GpuChildThread::OnGetVideoMemoryUsageStats() {
GPUVideoMemoryUsageStats video_memory_usage_stats;
if (gpu_channel_manager_)
gpu_channel_manager_->gpu_memory_manager()->GetVideoMemoryUsageStats(
&video_memory_usage_stats);
Send(new GpuHostMsg_VideoMemoryUsageStats(video_memory_usage_stats));
}
void GpuChildThread::OnClean() {
VLOG(1) << "GPU: Removing all contexts";
if (gpu_channel_manager_)
gpu_channel_manager_->LoseAllContexts();
}
void GpuChildThread::OnCrash() {
VLOG(1) << "GPU: Simulating GPU crash";
volatile int* it_s_the_end_of_the_world_as_we_know_it = NULL;
*it_s_the_end_of_the_world_as_we_know_it = 0xdead;
}
void GpuChildThread::OnHang() {
VLOG(1) << "GPU: Simulating GPU hang";
for (;;) {
}
}
void GpuChildThread::OnDisableWatchdog() {
VLOG(1) << "GPU: Disabling watchdog thread";
if (watchdog_thread_.get()) {
if (watchdog_thread_->message_loop())
watchdog_thread_->PostAcknowledge();
watchdog_thread_->Stop();
}
}
}