| 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/browser/gpu/gpu_internals_ui.h" | 5 #include "content/browser/gpu/gpu_internals_ui.h" |
| 6 | 6 |
| 7 #if defined(OS_LINUX) && defined(USE_X11) | 7 #if defined(OS_LINUX) && defined(USE_X11) |
| 8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/environment.h" | 16 #include "base/environment.h" |
| 17 #include "base/i18n/time_formatting.h" | 17 #include "base/i18n/time_formatting.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 20 #include "base/sys_info.h" | 20 #include "base/sys_info.h" |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
| 22 #include "content/browser/gpu/compositor_util.h" | 23 #include "content/browser/gpu/compositor_util.h" |
| 23 #include "content/browser/gpu/gpu_data_manager_impl.h" | 24 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 24 #include "content/grit/content_resources.h" | 25 #include "content/grit/content_resources.h" |
| 25 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/browser/gpu_data_manager_observer.h" | 27 #include "content/public/browser/gpu_data_manager_observer.h" |
| 27 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/browser/web_ui.h" | 29 #include "content/public/browser/web_ui.h" |
| 29 #include "content/public/browser/web_ui_data_source.h" | 30 #include "content/public/browser/web_ui_data_source.h" |
| 30 #include "content/public/browser/web_ui_message_handler.h" | 31 #include "content/public/browser/web_ui_message_handler.h" |
| 31 #include "content/public/common/content_client.h" | 32 #include "content/public/common/content_client.h" |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 #if defined(OS_WIN) | 226 #if defined(OS_WIN) |
| 226 scoped_ptr<base::Value> dx_info = base::Value::CreateNullValue(); | 227 scoped_ptr<base::Value> dx_info = base::Value::CreateNullValue(); |
| 227 if (gpu_info.dx_diagnostics.children.size()) | 228 if (gpu_info.dx_diagnostics.children.size()) |
| 228 dx_info.reset(DxDiagNodeToList(gpu_info.dx_diagnostics)); | 229 dx_info.reset(DxDiagNodeToList(gpu_info.dx_diagnostics)); |
| 229 info->Set("diagnostics", dx_info.Pass()); | 230 info->Set("diagnostics", dx_info.Pass()); |
| 230 #endif | 231 #endif |
| 231 | 232 |
| 232 return info; | 233 return info; |
| 233 } | 234 } |
| 234 | 235 |
| 236 const char* BufferFormatToString(gfx::BufferFormat format) { |
| 237 switch (format) { |
| 238 case gfx::BufferFormat::ATC: |
| 239 return "ATC"; |
| 240 case gfx::BufferFormat::ATCIA: |
| 241 return "ATCIA"; |
| 242 case gfx::BufferFormat::DXT1: |
| 243 return "DXT1"; |
| 244 case gfx::BufferFormat::DXT5: |
| 245 return "DXT5"; |
| 246 case gfx::BufferFormat::ETC1: |
| 247 return "ETC1"; |
| 248 case gfx::BufferFormat::R_8: |
| 249 return "R_8"; |
| 250 case gfx::BufferFormat::RGBA_4444: |
| 251 return "RGBA_4444"; |
| 252 case gfx::BufferFormat::RGBX_8888: |
| 253 return "RGBX_8888"; |
| 254 case gfx::BufferFormat::RGBA_8888: |
| 255 return "RGBA_8888"; |
| 256 case gfx::BufferFormat::BGRX_8888: |
| 257 return "BGRX_8888"; |
| 258 case gfx::BufferFormat::BGRA_8888: |
| 259 return "BGRA_8888"; |
| 260 case gfx::BufferFormat::YUV_420: |
| 261 return "YUV_420"; |
| 262 case gfx::BufferFormat::YUV_420_BIPLANAR: |
| 263 return "YUV_420_BIPLANAR"; |
| 264 case gfx::BufferFormat::UYVY_422: |
| 265 return "UYVY_422"; |
| 266 } |
| 267 NOTREACHED(); |
| 268 return nullptr; |
| 269 } |
| 270 |
| 271 const char* BufferUsageToString(gfx::BufferUsage usage) { |
| 272 switch (usage) { |
| 273 case gfx::BufferUsage::GPU_READ: |
| 274 return "GPU_READ"; |
| 275 case gfx::BufferUsage::GPU_READ_WRITE: |
| 276 return "GPU_READ_WRITE"; |
| 277 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE: |
| 278 return "GPU_READ_CPU_READ_WRITE"; |
| 279 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT: |
| 280 return "GPU_READ_CPU_READ_WRITE_PERSISTENT"; |
| 281 } |
| 282 NOTREACHED(); |
| 283 return nullptr; |
| 284 } |
| 285 |
| 286 base::DictionaryValue* GpuMemoryBufferInfoAsDictionaryValue() { |
| 287 base::ListValue* gpu_memory_buffer_info = new base::ListValue(); |
| 288 |
| 289 BrowserGpuMemoryBufferManager* gpu_memory_buffer_manager = |
| 290 BrowserGpuMemoryBufferManager::current(); |
| 291 |
| 292 for (size_t format = 0; |
| 293 format < static_cast<size_t>(gfx::BufferFormat::LAST) + 1; format++) { |
| 294 std::string native_usage_support; |
| 295 for (size_t usage = 0; |
| 296 usage < static_cast<size_t>(gfx::BufferUsage::LAST) + 1; usage++) { |
| 297 if (gpu_memory_buffer_manager->IsNativeGpuMemoryBufferConfiguration( |
| 298 static_cast<gfx::BufferFormat>(format), |
| 299 static_cast<gfx::BufferUsage>(usage))) |
| 300 native_usage_support = base::StringPrintf( |
| 301 "%s%s %s", native_usage_support.c_str(), |
| 302 native_usage_support.empty() ? "" : ",", |
| 303 BufferUsageToString(static_cast<gfx::BufferUsage>(usage))); |
| 304 } |
| 305 if (native_usage_support.empty()) |
| 306 native_usage_support = base::StringPrintf("Software only"); |
| 307 |
| 308 gpu_memory_buffer_info->Append(NewDescriptionValuePair( |
| 309 BufferFormatToString(static_cast<gfx::BufferFormat>(format)), |
| 310 native_usage_support)); |
| 311 } |
| 312 |
| 313 base::DictionaryValue* info = new base::DictionaryValue(); |
| 314 info->Set("gpu_memory_buffer_info", gpu_memory_buffer_info); |
| 315 |
| 316 return info; |
| 317 } |
| 318 |
| 235 // This class receives javascript messages from the renderer. | 319 // This class receives javascript messages from the renderer. |
| 236 // Note that the WebUI infrastructure runs on the UI thread, therefore all of | 320 // Note that the WebUI infrastructure runs on the UI thread, therefore all of |
| 237 // this class's methods are expected to run on the UI thread. | 321 // this class's methods are expected to run on the UI thread. |
| 238 class GpuMessageHandler | 322 class GpuMessageHandler |
| 239 : public WebUIMessageHandler, | 323 : public WebUIMessageHandler, |
| 240 public base::SupportsWeakPtr<GpuMessageHandler>, | 324 public base::SupportsWeakPtr<GpuMessageHandler>, |
| 241 public GpuDataManagerObserver, | 325 public GpuDataManagerObserver, |
| 242 public ui::GpuSwitchingObserver { | 326 public ui::GpuSwitchingObserver { |
| 243 public: | 327 public: |
| 244 GpuMessageHandler(); | 328 GpuMessageHandler(); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 feature_status->Set("problems", GetProblems()); | 486 feature_status->Set("problems", GetProblems()); |
| 403 base::ListValue* workarounds = new base::ListValue(); | 487 base::ListValue* workarounds = new base::ListValue(); |
| 404 for (const std::string& workaround : GetDriverBugWorkarounds()) | 488 for (const std::string& workaround : GetDriverBugWorkarounds()) |
| 405 workarounds->AppendString(workaround); | 489 workarounds->AppendString(workaround); |
| 406 feature_status->Set("workarounds", workarounds); | 490 feature_status->Set("workarounds", workarounds); |
| 407 gpu_info_val->Set("featureStatus", feature_status); | 491 gpu_info_val->Set("featureStatus", feature_status); |
| 408 | 492 |
| 409 // Send GPU Info to javascript. | 493 // Send GPU Info to javascript. |
| 410 web_ui()->CallJavascriptFunction("browserBridge.onGpuInfoUpdate", | 494 web_ui()->CallJavascriptFunction("browserBridge.onGpuInfoUpdate", |
| 411 *(gpu_info_val.get())); | 495 *(gpu_info_val.get())); |
| 496 |
| 497 // Get GpuMemoryBuffer Info. |
| 498 scoped_ptr<base::DictionaryValue> gpu_memory_buffer_info_val( |
| 499 GpuMemoryBufferInfoAsDictionaryValue()); |
| 500 |
| 501 // Send GpuMemoryBuffer Info to javascript. |
| 502 web_ui()->CallJavascriptFunction("browserBridge.onGpuMemoryBufferInfoUpdate", |
| 503 *(gpu_memory_buffer_info_val.get())); |
| 412 } | 504 } |
| 413 | 505 |
| 414 void GpuMessageHandler::OnGpuSwitched() { | 506 void GpuMessageHandler::OnGpuSwitched() { |
| 415 GpuDataManagerImpl::GetInstance()->RequestCompleteGpuInfoIfNeeded(); | 507 GpuDataManagerImpl::GetInstance()->RequestCompleteGpuInfoIfNeeded(); |
| 416 } | 508 } |
| 417 | 509 |
| 418 } // namespace | 510 } // namespace |
| 419 | 511 |
| 420 | 512 |
| 421 //////////////////////////////////////////////////////////////////////////////// | 513 //////////////////////////////////////////////////////////////////////////////// |
| 422 // | 514 // |
| 423 // GpuInternalsUI | 515 // GpuInternalsUI |
| 424 // | 516 // |
| 425 //////////////////////////////////////////////////////////////////////////////// | 517 //////////////////////////////////////////////////////////////////////////////// |
| 426 | 518 |
| 427 GpuInternalsUI::GpuInternalsUI(WebUI* web_ui) | 519 GpuInternalsUI::GpuInternalsUI(WebUI* web_ui) |
| 428 : WebUIController(web_ui) { | 520 : WebUIController(web_ui) { |
| 429 web_ui->AddMessageHandler(new GpuMessageHandler()); | 521 web_ui->AddMessageHandler(new GpuMessageHandler()); |
| 430 | 522 |
| 431 // Set up the chrome://gpu/ source. | 523 // Set up the chrome://gpu/ source. |
| 432 BrowserContext* browser_context = | 524 BrowserContext* browser_context = |
| 433 web_ui->GetWebContents()->GetBrowserContext(); | 525 web_ui->GetWebContents()->GetBrowserContext(); |
| 434 WebUIDataSource::Add(browser_context, CreateGpuHTMLSource()); | 526 WebUIDataSource::Add(browser_context, CreateGpuHTMLSource()); |
| 435 } | 527 } |
| 436 | 528 |
| 437 } // namespace content | 529 } // namespace content |
| OLD | NEW |