1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/gpu/gpu_internals_ui.h"
#if defined(OS_LINUX) && defined(USE_X11)
#include <X11/Xlib.h>
#endif
#include <string>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/command_line.h"
#include "base/environment.h"
#include "base/i18n/time_formatting.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/sys_info.h"
#include "base/values.h"
#include "content/browser/gpu/compositor_util.h"
#include "content/browser/gpu/gpu_data_manager_impl.h"
#include "content/grit/content_resources.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/gpu_data_manager_observer.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "gpu/config/gpu_feature_type.h"
#include "gpu/config/gpu_info.h"
#include "third_party/angle/src/common/version.h"
#include "ui/gl/gpu_switching_manager.h"
#if defined(OS_WIN)
#include "ui/base/win/shell.h"
#endif
#if defined(OS_LINUX) && defined(USE_X11)
#include "ui/base/x/x11_util.h"
#include "ui/gfx/x/x11_atom_cache.h"
#endif
namespace content {
namespace {
WebUIDataSource* CreateGpuHTMLSource() {
WebUIDataSource* source = WebUIDataSource::Create(kChromeUIGpuHost);
source->SetJsonPath("strings.js");
source->AddResourcePath("gpu_internals.js", IDR_GPU_INTERNALS_JS);
source->SetDefaultResource(IDR_GPU_INTERNALS_HTML);
return source;
}
base::DictionaryValue* NewDescriptionValuePair(const std::string& desc,
const std::string& value) {
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetString("description", desc);
dict->SetString("value", value);
return dict;
}
base::DictionaryValue* NewDescriptionValuePair(const std::string& desc,
base::Value* value) {
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetString("description", desc);
dict->Set("value", value);
return dict;
}
#if defined(OS_WIN)
// Output DxDiagNode tree as nested array of {description,value} pairs
base::ListValue* DxDiagNodeToList(const gpu::DxDiagNode& node) {
base::ListValue* list = new base::ListValue();
for (std::map<std::string, std::string>::const_iterator it =
node.values.begin();
it != node.values.end();
++it) {
list->Append(NewDescriptionValuePair(it->first, it->second));
}
for (std::map<std::string, gpu::DxDiagNode>::const_iterator it =
node.children.begin();
it != node.children.end();
++it) {
base::ListValue* sublist = DxDiagNodeToList(it->second);
list->Append(NewDescriptionValuePair(it->first, sublist));
}
return list;
}
#endif
std::string GPUDeviceToString(const gpu::GPUInfo::GPUDevice& gpu) {
std::string vendor = base::StringPrintf("0x%04x", gpu.vendor_id);
if (!gpu.vendor_string.empty())
vendor += " [" + gpu.vendor_string + "]";
std::string device = base::StringPrintf("0x%04x", gpu.device_id);
if (!gpu.device_string.empty())
device += " [" + gpu.device_string + "]";
return base::StringPrintf("VENDOR = %s, DEVICE= %s%s",
vendor.c_str(), device.c_str(), gpu.active ? " *ACTIVE*" : "");
}
base::DictionaryValue* GpuInfoAsDictionaryValue() {
gpu::GPUInfo gpu_info = GpuDataManagerImpl::GetInstance()->GetGPUInfo();
base::ListValue* basic_info = new base::ListValue();
basic_info->Append(NewDescriptionValuePair(
"Initialization time",
base::Int64ToString(gpu_info.initialization_time.InMilliseconds())));
basic_info->Append(NewDescriptionValuePair(
"Sandboxed", new base::FundamentalValue(gpu_info.sandboxed)));
basic_info->Append(NewDescriptionValuePair(
"GPU0", GPUDeviceToString(gpu_info.gpu)));
for (size_t i = 0; i < gpu_info.secondary_gpus.size(); ++i) {
basic_info->Append(NewDescriptionValuePair(
base::StringPrintf("GPU%d", static_cast<int>(i + 1)),
GPUDeviceToString(gpu_info.secondary_gpus[i])));
}
basic_info->Append(NewDescriptionValuePair(
"Optimus", new base::FundamentalValue(gpu_info.optimus)));
basic_info->Append(NewDescriptionValuePair(
"AMD switchable", new base::FundamentalValue(gpu_info.amd_switchable)));
if (gpu_info.lenovo_dcute) {
basic_info->Append(NewDescriptionValuePair(
"Lenovo dCute", new base::FundamentalValue(true)));
}
if (gpu_info.display_link_version.IsValid()) {
basic_info->Append(NewDescriptionValuePair(
"DisplayLink Version", gpu_info.display_link_version.GetString()));
}
#if defined(OS_WIN)
std::string compositor =
ui::win::IsAeroGlassEnabled() ? "Aero Glass" : "none";
basic_info->Append(
NewDescriptionValuePair("Desktop compositing", compositor));
if (GpuDataManagerImpl::GetInstance()->ShouldUseWarp()) {
basic_info->Append(NewDescriptionValuePair("Using WARP",
new base::FundamentalValue(true)));
}
#endif
basic_info->Append(
NewDescriptionValuePair("Driver vendor", gpu_info.driver_vendor));
basic_info->Append(NewDescriptionValuePair("Driver version",
gpu_info.driver_version));
basic_info->Append(NewDescriptionValuePair("Driver date",
gpu_info.driver_date));
basic_info->Append(NewDescriptionValuePair("Pixel shader version",
gpu_info.pixel_shader_version));
basic_info->Append(NewDescriptionValuePair("Vertex shader version",
gpu_info.vertex_shader_version));
basic_info->Append(NewDescriptionValuePair("Machine model name",
gpu_info.machine_model_name));
basic_info->Append(NewDescriptionValuePair("Machine model version",
gpu_info.machine_model_version));
basic_info->Append(NewDescriptionValuePair("GL_VENDOR",
gpu_info.gl_vendor));
basic_info->Append(NewDescriptionValuePair("GL_RENDERER",
gpu_info.gl_renderer));
basic_info->Append(NewDescriptionValuePair("GL_VERSION",
gpu_info.gl_version));
basic_info->Append(NewDescriptionValuePair("GL_EXTENSIONS",
gpu_info.gl_extensions));
basic_info->Append(NewDescriptionValuePair("Window system binding vendor",
gpu_info.gl_ws_vendor));
basic_info->Append(NewDescriptionValuePair("Window system binding version",
gpu_info.gl_ws_version));
basic_info->Append(NewDescriptionValuePair("Window system binding extensions",
gpu_info.gl_ws_extensions));
#if defined(OS_LINUX) && defined(USE_X11)
basic_info->Append(NewDescriptionValuePair("Window manager",
ui::GuessWindowManagerName()));
{
scoped_ptr<base::Environment> env(base::Environment::Create());
std::string value;
const char kXDGCurrentDesktop[] = "XDG_CURRENT_DESKTOP";
if (env->GetVar(kXDGCurrentDesktop, &value))
basic_info->Append(NewDescriptionValuePair(kXDGCurrentDesktop, value));
const char kGDMSession[] = "GDMSESSION";
if (env->GetVar(kGDMSession, &value))
basic_info->Append(NewDescriptionValuePair(kGDMSession, value));
const char* kAtomsToCache[] = {
"_NET_WM_CM_S0",
NULL
};
ui::X11AtomCache atom_cache(gfx::GetXDisplay(), kAtomsToCache);
std::string compositing_manager = XGetSelectionOwner(
gfx::GetXDisplay(),
atom_cache.GetAtom("_NET_WM_CM_S0")) != None ? "Yes" : "No";
basic_info->Append(
NewDescriptionValuePair("Compositing manager", compositing_manager));
}
#endif
std::string direct_rendering = gpu_info.direct_rendering ? "Yes" : "No";
basic_info->Append(
NewDescriptionValuePair("Direct rendering", direct_rendering));
std::string reset_strategy =
base::StringPrintf("0x%04x", gpu_info.gl_reset_notification_strategy);
basic_info->Append(NewDescriptionValuePair(
"Reset notification strategy", reset_strategy));
basic_info->Append(NewDescriptionValuePair(
"GPU process crash count",
new base::FundamentalValue(gpu_info.process_crash_count)));
base::DictionaryValue* info = new base::DictionaryValue();
info->Set("basic_info", basic_info);
#if defined(OS_WIN)
base::ListValue* perf_info = new base::ListValue();
perf_info->Append(NewDescriptionValuePair(
"Graphics",
base::StringPrintf("%.1f", gpu_info.performance_stats.graphics)));
perf_info->Append(NewDescriptionValuePair(
"Gaming",
base::StringPrintf("%.1f", gpu_info.performance_stats.gaming)));
perf_info->Append(NewDescriptionValuePair(
"Overall",
base::StringPrintf("%.1f", gpu_info.performance_stats.overall)));
info->Set("performance_info", perf_info);
base::Value* dx_info = gpu_info.dx_diagnostics.children.size() ?
DxDiagNodeToList(gpu_info.dx_diagnostics) :
base::Value::CreateNullValue();
info->Set("diagnostics", dx_info);
#endif
return info;
}
// This class receives javascript messages from the renderer.
// Note that the WebUI infrastructure runs on the UI thread, therefore all of
// this class's methods are expected to run on the UI thread.
class GpuMessageHandler
: public WebUIMessageHandler,
public base::SupportsWeakPtr<GpuMessageHandler>,
public GpuDataManagerObserver,
public ui::GpuSwitchingObserver {
public:
GpuMessageHandler();
~GpuMessageHandler() override;
// WebUIMessageHandler implementation.
void RegisterMessages() override;
// GpuDataManagerObserver implementation.
void OnGpuInfoUpdate() override;
// ui::GpuSwitchingObserver implementation.
void OnGpuSwitched() override;
// Messages
void OnBrowserBridgeInitialized(const base::ListValue* list);
void OnCallAsync(const base::ListValue* list);
// Submessages dispatched from OnCallAsync
base::Value* OnRequestClientInfo(const base::ListValue* list);
base::Value* OnRequestLogMessages(const base::ListValue* list);
private:
// True if observing the GpuDataManager (re-attaching as observer would
// DCHECK).
bool observing_;
DISALLOW_COPY_AND_ASSIGN(GpuMessageHandler);
};
////////////////////////////////////////////////////////////////////////////////
//
// GpuMessageHandler
//
////////////////////////////////////////////////////////////////////////////////
GpuMessageHandler::GpuMessageHandler()
: observing_(false) {
}
GpuMessageHandler::~GpuMessageHandler() {
ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this);
GpuDataManagerImpl::GetInstance()->RemoveObserver(this);
}
/* BrowserBridge.callAsync prepends a requestID to these messages. */
void GpuMessageHandler::RegisterMessages() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
web_ui()->RegisterMessageCallback("browserBridgeInitialized",
base::Bind(&GpuMessageHandler::OnBrowserBridgeInitialized,
base::Unretained(this)));
web_ui()->RegisterMessageCallback("callAsync",
base::Bind(&GpuMessageHandler::OnCallAsync,
base::Unretained(this)));
}
void GpuMessageHandler::OnCallAsync(const base::ListValue* args) {
DCHECK_GE(args->GetSize(), static_cast<size_t>(2));
// unpack args into requestId, submessage and submessageArgs
bool ok;
const base::Value* requestId;
ok = args->Get(0, &requestId);
DCHECK(ok);
std::string submessage;
ok = args->GetString(1, &submessage);
DCHECK(ok);
base::ListValue* submessageArgs = new base::ListValue();
for (size_t i = 2; i < args->GetSize(); ++i) {
const base::Value* arg;
ok = args->Get(i, &arg);
DCHECK(ok);
base::Value* argCopy = arg->DeepCopy();
submessageArgs->Append(argCopy);
}
// call the submessage handler
base::Value* ret = NULL;
if (submessage == "requestClientInfo") {
ret = OnRequestClientInfo(submessageArgs);
} else if (submessage == "requestLogMessages") {
ret = OnRequestLogMessages(submessageArgs);
} else { // unrecognized submessage
NOTREACHED();
delete submessageArgs;
return;
}
delete submessageArgs;
// call BrowserBridge.onCallAsyncReply with result
if (ret) {
web_ui()->CallJavascriptFunction("browserBridge.onCallAsyncReply",
*requestId,
*ret);
delete ret;
} else {
web_ui()->CallJavascriptFunction("browserBridge.onCallAsyncReply",
*requestId);
}
}
void GpuMessageHandler::OnBrowserBridgeInitialized(
const base::ListValue* args) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Watch for changes in GPUInfo
if (!observing_) {
GpuDataManagerImpl::GetInstance()->AddObserver(this);
ui::GpuSwitchingManager::GetInstance()->AddObserver(this);
}
observing_ = true;
// Tell GpuDataManager it should have full GpuInfo. If the
// Gpu process has not run yet, this will trigger its launch.
GpuDataManagerImpl::GetInstance()->RequestCompleteGpuInfoIfNeeded();
// Run callback immediately in case the info is ready and no update in the
// future.
OnGpuInfoUpdate();
}
base::Value* GpuMessageHandler::OnRequestClientInfo(
const base::ListValue* list) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetString("version", GetContentClient()->GetProduct());
dict->SetString("command_line",
base::CommandLine::ForCurrentProcess()->GetCommandLineString());
dict->SetString("operating_system",
base::SysInfo::OperatingSystemName() + " " +
base::SysInfo::OperatingSystemVersion());
dict->SetString("angle_commit_id", ANGLE_COMMIT_HASH);
dict->SetString("graphics_backend", "Skia");
dict->SetString("blacklist_version",
GpuDataManagerImpl::GetInstance()->GetBlacklistVersion());
dict->SetString("driver_bug_list_version",
GpuDataManagerImpl::GetInstance()->GetDriverBugListVersion());
return dict;
}
base::Value* GpuMessageHandler::OnRequestLogMessages(const base::ListValue*) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
return GpuDataManagerImpl::GetInstance()->GetLogMessages();
}
void GpuMessageHandler::OnGpuInfoUpdate() {
// Get GPU Info.
scoped_ptr<base::DictionaryValue> gpu_info_val(GpuInfoAsDictionaryValue());
// Add in blacklisting features
base::DictionaryValue* feature_status = new base::DictionaryValue;
feature_status->Set("featureStatus", GetFeatureStatus());
feature_status->Set("problems", GetProblems());
base::ListValue* workarounds = new base::ListValue();
for (const std::string& workaround : GetDriverBugWorkarounds())
workarounds->AppendString(workaround);
feature_status->Set("workarounds", workarounds);
gpu_info_val->Set("featureStatus", feature_status);
// Send GPU Info to javascript.
web_ui()->CallJavascriptFunction("browserBridge.onGpuInfoUpdate",
*(gpu_info_val.get()));
}
void GpuMessageHandler::OnGpuSwitched() {
GpuDataManagerImpl::GetInstance()->RequestCompleteGpuInfoIfNeeded();
}
} // namespace
////////////////////////////////////////////////////////////////////////////////
//
// GpuInternalsUI
//
////////////////////////////////////////////////////////////////////////////////
GpuInternalsUI::GpuInternalsUI(WebUI* web_ui)
: WebUIController(web_ui) {
web_ui->AddMessageHandler(new GpuMessageHandler());
// Set up the chrome://gpu/ source.
BrowserContext* browser_context =
web_ui->GetWebContents()->GetBrowserContext();
WebUIDataSource::Add(browser_context, CreateGpuHTMLSource());
}
} // namespace content
|