Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: chrome/gpu/gpu_info_collector_win.cc

Issue 6346007: Refactor and improve gpu_info_collector: collect information on linux;... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: This should turn three trybots green Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/gpu/gpu_info_collector_unittest.cc ('k') | chrome/gpu/gpu_info_unittest_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/gpu/gpu_info_collector.h" 5 #include "chrome/gpu/gpu_info_collector.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <d3d9.h> 8 #include <d3d9.h>
9 9
10 #include "app/gfx/gl/gl_context_egl.h" 10 #include "app/gfx/gl/gl_context_egl.h"
11 #include "app/gfx/gl/gl_implementation.h" 11 #include "app/gfx/gl/gl_implementation.h"
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/scoped_native_library.h" 13 #include "base/scoped_native_library.h"
14 #include "base/string_number_conversions.h"
14 #include "base/string_util.h" 15 #include "base/string_util.h"
15 16
16 // ANGLE seems to require that main.h be included before any other ANGLE header. 17 // ANGLE seems to require that main.h be included before any other ANGLE header.
17 #include "libEGL/main.h" 18 #include "libEGL/main.h"
18 #include "libEGL/Display.h" 19 #include "libEGL/Display.h"
19 20
20 namespace gpu_info_collector { 21 namespace gpu_info_collector {
21 22
22 bool CollectGraphicsInfo(GPUInfo* gpu_info) { 23 bool CollectGraphicsInfo(GPUInfo* gpu_info) {
23 // TODO: collect OpenGL info if not using ANGLE? 24 DCHECK(gpu_info);
24 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) 25
25 return true; 26 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) {
27 gpu_info->SetProgress(GPUInfo::kComplete);
28 return CollectGraphicsInfoGL(gpu_info);
29 }
30
31 // TODO(zmo): the following code only works if running on top of ANGLE.
32 // Need to handle the case when running on top of real EGL/GLES2 drivers.
26 33
27 egl::Display* display = static_cast<egl::Display*>( 34 egl::Display* display = static_cast<egl::Display*>(
28 gfx::BaseEGLContext::GetDisplay()); 35 gfx::BaseEGLContext::GetDisplay());
29 if (!display) 36 if (!display)
30 return false; 37 return false;
31 38
32 IDirect3DDevice9* device = display->getDevice(); 39 IDirect3DDevice9* device = display->getDevice();
33 if (!device) 40 if (!device)
34 return false; 41 return false;
35 42
36 IDirect3D9* d3d = NULL; 43 IDirect3D9* d3d = NULL;
37 if (FAILED(device->GetDirect3D(&d3d))) 44 if (FAILED(device->GetDirect3D(&d3d)))
38 return false; 45 return false;
39 46
40 if (!CollectGraphicsInfoD3D(d3d, gpu_info)) 47 if (!CollectGraphicsInfoD3D(d3d, gpu_info))
41 return false; 48 return false;
42 49
43 // DirectX diagnostics are collected asynchronously because it takes a 50 // DirectX diagnostics are collected asynchronously because it takes a
44 // couple of seconds. Do not mark as complete until that is done. 51 // couple of seconds. Do not mark as complete until that is done.
45 gpu_info->SetProgress(GPUInfo::kPartial); 52 gpu_info->SetProgress(GPUInfo::kPartial);
46
47 return true; 53 return true;
48 } 54 }
49 55
50 bool CollectGraphicsInfoD3D(IDirect3D9* d3d, GPUInfo* gpu_info) { 56 bool CollectGraphicsInfoD3D(IDirect3D9* d3d, GPUInfo* gpu_info) {
51 DCHECK(d3d); 57 DCHECK(d3d);
52 DCHECK(gpu_info); 58 DCHECK(gpu_info);
53 59
54 // Get device information 60 bool succeed = true;
61
62 // Get device/driver information
55 D3DADAPTER_IDENTIFIER9 identifier; 63 D3DADAPTER_IDENTIFIER9 identifier;
56 HRESULT hr = d3d->GetAdapterIdentifier(D3DADAPTER_DEFAULT, 0, &identifier); 64 if (d3d->GetAdapterIdentifier(D3DADAPTER_DEFAULT, 0, &identifier) == D3D_OK) {
57 if (hr != D3D_OK) { 65 gpu_info->SetVideoCardInfo(identifier.VendorId, identifier.DeviceId);
58 d3d->Release(); 66
59 return false; 67 uint32 driver_major_version_hi = HIWORD(identifier.DriverVersion.HighPart);
68 uint32 driver_major_version_lo = LOWORD(identifier.DriverVersion.HighPart);
69 uint32 driver_minor_version_hi = HIWORD(identifier.DriverVersion.LowPart);
70 uint32 driver_minor_version_lo = LOWORD(identifier.DriverVersion.LowPart);
71 std::string driver_version = StringPrintf("%d.%d.%d.%d",
72 driver_major_version_hi,
73 driver_major_version_lo,
74 driver_minor_version_hi,
75 driver_minor_version_lo);
76 gpu_info->SetDriverInfo("", driver_version);
77 } else {
78 succeed = false;
60 } 79 }
61 uint32 vendor_id = identifier.VendorId;
62 uint32 device_id = identifier.DeviceId;
63 80
64 // Get version information 81 // Get version information
65 D3DCAPS9 d3d_caps; 82 D3DCAPS9 d3d_caps;
66 HRESULT caps_result = d3d->GetDeviceCaps(D3DADAPTER_DEFAULT, 83 if (d3d->GetDeviceCaps(D3DADAPTER_DEFAULT,
67 D3DDEVTYPE_HAL, 84 D3DDEVTYPE_HAL,
68 &d3d_caps); 85 &d3d_caps) == D3D_OK) {
69 if (caps_result != D3D_OK) { 86 gpu_info->SetShaderVersion(d3d_caps.PixelShaderVersion,
70 d3d->Release(); 87 d3d_caps.VertexShaderVersion);
71 return false; 88 } else {
89 succeed = false;
72 } 90 }
73 uint32 driver_major_version_hi = HIWORD(identifier.DriverVersion.HighPart);
74 uint32 driver_major_version_lo = LOWORD(identifier.DriverVersion.HighPart);
75 uint32 driver_minor_version_hi = HIWORD(identifier.DriverVersion.LowPart);
76 uint32 driver_minor_version_lo = LOWORD(identifier.DriverVersion.LowPart);
77 std::wstring driver_version = StringPrintf(L"%d.%d.%d.%d",
78 driver_major_version_hi,
79 driver_major_version_lo,
80 driver_minor_version_hi,
81 driver_minor_version_lo);
82 91
92 // Get can_lose_context
83 bool can_lose_context = false; 93 bool can_lose_context = false;
84 IDirect3D9Ex* d3dex = NULL; 94 IDirect3D9Ex* d3dex = NULL;
85 if (SUCCEEDED(d3d->QueryInterface(__uuidof(IDirect3D9Ex), 95 if (SUCCEEDED(d3d->QueryInterface(__uuidof(IDirect3D9Ex),
86 reinterpret_cast<void**>(&d3dex)))) { 96 reinterpret_cast<void**>(&d3dex)))) {
87 d3dex->Release(); 97 d3dex->Release();
88 } else { 98 } else {
89 can_lose_context = true; 99 can_lose_context = true;
90 } 100 }
101 gpu_info->SetCanLoseContext(can_lose_context);
91 102
92 d3d->Release(); 103 d3d->Release();
93
94 // Get shader versions
95 uint32 pixel_shader_version = d3d_caps.PixelShaderVersion;
96 uint32 vertex_shader_version = d3d_caps.VertexShaderVersion;
97
98 gpu_info->SetGraphicsInfo(vendor_id,
99 device_id,
100 driver_version,
101 pixel_shader_version,
102 vertex_shader_version,
103 0,
104 can_lose_context);
105 return true; 104 return true;
106 } 105 }
107 106
108 bool CollectGraphicsInfoGL(GPUInfo* gpu_info) { 107 bool CollectVideoCardInfo(GPUInfo* gpu_info) {
108 DCHECK(gpu_info);
109
109 // Taken from http://developer.nvidia.com/object/device_ids.html 110 // Taken from http://developer.nvidia.com/object/device_ids.html
110 DISPLAY_DEVICE dd; 111 DISPLAY_DEVICE dd;
111 dd.cb = sizeof(DISPLAY_DEVICE); 112 dd.cb = sizeof(DISPLAY_DEVICE);
112 int i = 0; 113 int i = 0;
113 std::wstring id; 114 std::wstring id;
114 for (int i = 0; EnumDisplayDevices(NULL, i, &dd, 0); ++i) { 115 for (int i = 0; EnumDisplayDevices(NULL, i, &dd, 0); ++i) {
115 if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) { 116 if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
116 id = dd.DeviceID; 117 id = dd.DeviceID;
117 break; 118 break;
118 } 119 }
119 } 120 }
120 if (id.empty()) { 121
121 return false; 122 if (id.length() > 20) {
123 int vendor_id = 0, device_id = 0;
124 std::wstring vendor_id_string = id.substr(8, 4);
125 std::wstring device_id_string = id.substr(17, 4);
126 base::HexStringToInt(WideToASCII(vendor_id_string), &vendor_id);
127 base::HexStringToInt(WideToASCII(device_id_string), &device_id);
128 gpu_info->SetVideoCardInfo(vendor_id, device_id);
129 return true;
122 } 130 }
123 uint32 vendor_id; 131 return false;
124 uint32 device_id; 132 }
125 std::wstring vendorid = id.substr(8, 4);
126 std::wstring deviceid = id.substr(17, 4);
127 swscanf_s(vendorid.c_str(), L"%x", &vendor_id);
128 swscanf_s(deviceid.c_str(), L"%x", &device_id);
129 133
130 std::wstring driver_version = L""; 134 bool CollectDriverInfo(GPUInfo* gpu_info) {
131 uint32 pixel_shader_version = 0; 135 DCHECK(gpu_info);
132 uint32 vertex_shader_version = 0;
133 gpu_info->SetGraphicsInfo(vendor_id, device_id, driver_version,
134 pixel_shader_version,
135 vertex_shader_version,
136 0, // GL version of 0 indicates D3D
137 false);
138 return true;
139 136
140 // TODO(rlp): Add driver and pixel versions 137 std::string gl_version_string = gpu_info->gl_version_string();
138
139 // TODO(zmo): We assume the driver version is in the end of GL_VERSION
140 // string. Need to verify if it is true for majority drivers.
141
142 size_t pos = gl_version_string.find_last_not_of("0123456789.");
143 if (pos != std::string::npos && pos < gl_version_string.length() - 1) {
144 gpu_info->SetDriverInfo("", gl_version_string.substr(pos + 1));
145 return true;
146 }
147 return false;
141 } 148 }
142 149
143 } // namespace gpu_info_collector 150 } // namespace gpu_info_collector
OLDNEW
« no previous file with comments | « chrome/gpu/gpu_info_collector_unittest.cc ('k') | chrome/gpu/gpu_info_unittest_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698