1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/command_line.h" 6 #include "base/logging.h" 7 #include "base/message_loop/message_loop.h" 8 #include "base/strings/stringprintf.h" 9 #include "base/sys_info.h" 10 #include "content/browser/gpu/gpu_data_manager_impl.h" 11 #include "content/public/browser/gpu_data_manager_observer.h" 12 #include "content/public/common/content_switches.h" 13 #include "content/test/content_browser_test.h" 14 15 namespace content { 16 17 namespace { 18 19 class TestObserver : public GpuDataManagerObserver { 20 public: 21 explicit TestObserver(base::MessageLoop* message_loop) 22 : message_loop_(message_loop) { 23 } 24 25 virtual ~TestObserver() { } 26 27 virtual void OnGpuInfoUpdate() OVERRIDE { 28 // Display GPU/Driver information. 29 gpu::GPUInfo gpu_info = 30 GpuDataManagerImpl::GetInstance()->GetGPUInfo(); 31 std::string vendor_id = base::StringPrintf( 32 "0x%04x", gpu_info.gpu.vendor_id); 33 std::string device_id = base::StringPrintf( 34 "0x%04x", gpu_info.gpu.device_id); 35 LOG(INFO) << "GPU[0]: vendor_id = " << vendor_id 36 << ", device_id = " << device_id; 37 for (size_t i = 0; i < gpu_info.secondary_gpus.size(); ++i) { 38 gpu::GPUInfo::GPUDevice gpu = gpu_info.secondary_gpus[i]; 39 vendor_id = base::StringPrintf("0x%04x", gpu.vendor_id); 40 device_id = base::StringPrintf("0x%04x", gpu.device_id); 41 LOG(INFO) << "GPU[" << (i + 1) 42 << "]: vendor_id = " << vendor_id 43 << ", device_od = " << device_id; 44 } 45 LOG(INFO) << "GPU Driver: vendor = " << gpu_info.driver_vendor 46 << ", version = " << gpu_info.driver_version 47 << ", date = " << gpu_info.driver_date; 48 49 // Display GL information. 50 LOG(INFO) << "GL: vendor = " << gpu_info.gl_vendor 51 << ", renderer = " << gpu_info.gl_renderer; 52 53 // Display GL window system binding information. 54 LOG(INFO) << "GL Window System: vendor = " << gpu_info.gl_ws_vendor 55 << ", version = " << gpu_info.gl_ws_version; 56 57 // Display OS information. 58 LOG(INFO) << "OS = " << base::SysInfo::OperatingSystemName() 59 << " " << base::SysInfo::OperatingSystemVersion(); 60 61 message_loop_->Quit(); 62 } 63 64 private: 65 base::MessageLoop* message_loop_; 66 }; 67 68 } // namespace anonymous 69 70 class GpuInfoBrowserTest : public ContentBrowserTest { 71 public: 72 GpuInfoBrowserTest() 73 : message_loop_(base::MessageLoop::TYPE_UI) { 74 } 75 76 virtual void SetUp() { 77 // We expect real pixel output for these tests. 78 UseRealGLContexts(); 79 80 ContentBrowserTest::SetUp(); 81 } 82 83 base::MessageLoop* GetMessageLoop() { return &message_loop_; } 84 85 private: 86 base::MessageLoop message_loop_; 87 88 DISALLOW_COPY_AND_ASSIGN(GpuInfoBrowserTest); 89 }; 90 91 IN_PROC_BROWSER_TEST_F(GpuInfoBrowserTest, MANUAL_DisplayGpuInfo) { 92 // crbug.com/262287 93 #if defined(OS_MACOSX) 94 // TODO(zmo): crashing on Mac, and also we don't have the full info 95 // collected. 96 return; 97 #endif 98 #if defined(OS_LINUX) && !defined(NDEBUG) 99 // TODO(zmo): crashing on Linux Debug. 100 return; 101 #endif 102 TestObserver observer(GetMessageLoop()); 103 GpuDataManagerImpl::GetInstance()->AddObserver(&observer); 104 GpuDataManagerImpl::GetInstance()->RequestCompleteGpuInfoIfNeeded(); 105 106 GetMessageLoop()->Run(); 107 } 108 109 } // namespace content 110 111