summaryrefslogtreecommitdiffstats
path: root/chrome/gpu
diff options
context:
space:
mode:
authorrlp@chromium.org <rlp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-09 16:10:43 +0000
committerrlp@chromium.org <rlp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-09 16:10:43 +0000
commit1bf14bcd62453cb53e21097a61fcefb0c5cc213b (patch)
tree31b6391aeec0832a7efe4f9b7bd22f4eca1ca127 /chrome/gpu
parent2233a372c11e86d3268a3bbcdd8f7f1d305243eb (diff)
downloadchromium_src-1bf14bcd62453cb53e21097a61fcefb0c5cc213b.zip
chromium_src-1bf14bcd62453cb53e21097a61fcefb0c5cc213b.tar.gz
chromium_src-1bf14bcd62453cb53e21097a61fcefb0c5cc213b.tar.bz2
Moving gpu_info to common so that it can be used by param traits. Pulling the collection out into a separate class.
BUG=38736 TEST=existing unittests Review URL: http://codereview.chromium.org/2914001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51967 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/gpu')
-rw-r--r--chrome/gpu/gpu_info.cc36
-rw-r--r--chrome/gpu/gpu_info.h73
-rw-r--r--chrome/gpu/gpu_info_collector.h36
-rw-r--r--chrome/gpu/gpu_info_collector_linux.cc14
-rw-r--r--chrome/gpu/gpu_info_collector_mac.mm14
-rw-r--r--chrome/gpu/gpu_info_collector_win.cc (renamed from chrome/gpu/gpu_info_win.cc)48
-rw-r--r--chrome/gpu/gpu_info_unittest_win.cc37
7 files changed, 113 insertions, 145 deletions
diff --git a/chrome/gpu/gpu_info.cc b/chrome/gpu/gpu_info.cc
deleted file mode 100644
index 36ff12a..0000000
--- a/chrome/gpu/gpu_info.cc
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (c) 2006-2010 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 "chrome/gpu/gpu_info.h"
-
-uint32 GPUInfo::vendor_id() const {
- return vendor_id_;
-}
-
-uint32 GPUInfo::device_id() const {
- return device_id_;
-}
-
-std::wstring GPUInfo::driver_version() const {
- return driver_version_;
-}
-
-uint32 GPUInfo::pixel_shader_version() const {
- return pixel_shader_version_;
-}
-
-uint32 GPUInfo::vertex_shader_version() const {
- return vertex_shader_version_;
-}
-
-void GPUInfo::SetGraphicsInfo(uint32 vendor_id, uint32 device_id,
- const std::wstring& driver_version,
- uint32 pixel_shader_version,
- uint32 vertex_shader_version) {
- vendor_id_ = vendor_id;
- device_id_ = device_id;
- driver_version_ = driver_version;
- pixel_shader_version_ = pixel_shader_version;
- vertex_shader_version_ = vertex_shader_version;
-}
diff --git a/chrome/gpu/gpu_info.h b/chrome/gpu/gpu_info.h
deleted file mode 100644
index 12b0369..0000000
--- a/chrome/gpu/gpu_info.h
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright (c) 2006-2010 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.
-
-#ifndef CHROME_GPU_GPU_INFO_H__
-#define CHROME_GPU_GPU_INFO_H__
-
-// Provides access to the GPU information for the system
-// on which chrome is currently running.
-
-#include <string>
-
-#include "base/basictypes.h"
-
-struct IDirect3D9;
-
-class GPUInfo {
- public:
- GPUInfo() {}
- ~GPUInfo() {}
-
- // Return the DWORD (uint32) representing the graphics card vendor id.
- uint32 vendor_id() const;
-
- // Return the DWORD (uint32) representing the graphics card device id.
- // Device ids are unique to vendor, not to one another.
- uint32 device_id() const;
-
- // Return the version of the graphics driver currently installed.
- // This will typically be something
- std::wstring driver_version() const;
-
- // Return the version of the pixel/fragment shader used by the gpu.
- // This will typically be a number less than 10 so storing as a float
- // should be okay.
- uint32 pixel_shader_version() const;
-
- // Return the version of the vertex shader used by the gpu.
- // This will typically be a number less than 10 so storing as a float
- // should be okay.
- uint32 vertex_shader_version() const;
-
- // Populate variables with necessary graphics card information.
- // Returns true on success.
- bool CollectGraphicsInfo();
-
- // Populate variables with passed in values
- void SetGraphicsInfo(uint32 vendor_id, uint32 device_id,
- const std::wstring& driver_version,
- uint32 pixel_shader_version,
- uint32 vertex_shader_version);
-
-#if defined(OS_WIN)
- // Windows provides two ways of doing graphics so we need two ways of
- // collecting info based on what's on a user's machine.
- // The selection between the two methods is done in the cc file.
-
- // A D3D argument is passed in for testing purposes
- bool CollectGraphicsInfoD3D(IDirect3D9* d3d);
-
- // The GL version of collecting information
- bool CollectGraphicsInfoGL();
-#endif
-
- private:
- uint32 vendor_id_;
- uint32 device_id_;
- std::wstring driver_version_;
- uint32 pixel_shader_version_;
- uint32 vertex_shader_version_;
-};
-
-#endif // CHROME_GPU_GPU_INFO_H__
diff --git a/chrome/gpu/gpu_info_collector.h b/chrome/gpu/gpu_info_collector.h
new file mode 100644
index 0000000..8be89bd
--- /dev/null
+++ b/chrome/gpu/gpu_info_collector.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2006-2010 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.
+
+#ifndef CHROME_GPU_GPU_INFO_COLLECTOR_H__
+#define CHROME_GPU_GPU_INFO_COLLECTOR_H__
+
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "chrome/common/gpu_info.h"
+
+struct IDirect3D9;
+
+namespace gpu_info_collector {
+
+// Populate variables with necessary graphics card information.
+// Returns true on success.
+bool CollectGraphicsInfo(GPUInfo& gpu_info);
+
+#if defined(OS_WIN)
+// Windows provides two ways of doing graphics so we need two ways of
+// collecting info based on what's on a user's machine.
+// The selection between the two methods is done in the cc file.
+
+// A D3D argument is passed in for testing purposes
+bool CollectGraphicsInfoD3D(IDirect3D9* d3d, GPUInfo& gpu_info);
+
+// The GL version of collecting information
+bool CollectGraphicsInfoGL(GPUInfo& gpu_info);
+#endif
+
+} // namespace gpu_info_collector
+
+#endif // CHROME_GPU_GPU_INFO_COLLECTOR_H__
diff --git a/chrome/gpu/gpu_info_collector_linux.cc b/chrome/gpu/gpu_info_collector_linux.cc
new file mode 100644
index 0000000..d6e08b4
--- /dev/null
+++ b/chrome/gpu/gpu_info_collector_linux.cc
@@ -0,0 +1,14 @@
+// Copyright (c) 2006-2010 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 "chrome/gpu/gpu_info_collector.h"
+
+namespace gpu_info_collector {
+
+bool CollectGraphicsInfo(GPUInfo& gpu_info) {
+ // TODO(rlp): complete this function
+ return true;
+}
+
+} // namespace gpu_info_collector
diff --git a/chrome/gpu/gpu_info_collector_mac.mm b/chrome/gpu/gpu_info_collector_mac.mm
new file mode 100644
index 0000000..d6e08b4
--- /dev/null
+++ b/chrome/gpu/gpu_info_collector_mac.mm
@@ -0,0 +1,14 @@
+// Copyright (c) 2006-2010 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 "chrome/gpu/gpu_info_collector.h"
+
+namespace gpu_info_collector {
+
+bool CollectGraphicsInfo(GPUInfo& gpu_info) {
+ // TODO(rlp): complete this function
+ return true;
+}
+
+} // namespace gpu_info_collector
diff --git a/chrome/gpu/gpu_info_win.cc b/chrome/gpu/gpu_info_collector_win.cc
index 529b1ab..07b7c5b 100644
--- a/chrome/gpu/gpu_info_win.cc
+++ b/chrome/gpu/gpu_info_collector_win.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/gpu/gpu_info.h"
+#include "chrome/gpu/gpu_info_collector.h"
#include <windows.h>
#include <d3d9.h>
@@ -11,7 +11,9 @@
#include "base/scoped_native_library.h"
#include "base/string_util.h"
-bool GPUInfo::CollectGraphicsInfo() {
+namespace gpu_info_collector {
+
+bool CollectGraphicsInfo(GPUInfo& gpu_info) {
FilePath d3d_path(base::GetNativeLibraryName(L"d3d9"));
base::ScopedNativeLibrary d3dlib(d3d_path);
@@ -27,10 +29,11 @@ bool GPUInfo::CollectGraphicsInfo() {
if (!d3d) {
return false;
}
- return CollectGraphicsInfoD3D(d3d);
+ return CollectGraphicsInfoD3D(d3d, gpu_info);
}
-bool GPUInfo::CollectGraphicsInfoD3D(IDirect3D9* d3d) {
+bool CollectGraphicsInfoD3D(IDirect3D9* d3d,
+ GPUInfo& gpu_info) {
// Get device information
D3DADAPTER_IDENTIFIER9 identifier;
HRESULT hr = d3d->GetAdapterIdentifier(D3DADAPTER_DEFAULT, 0, &identifier);
@@ -38,8 +41,8 @@ bool GPUInfo::CollectGraphicsInfoD3D(IDirect3D9* d3d) {
d3d->Release();
return false;
}
- vendor_id_ = identifier.VendorId;
- device_id_ = identifier.DeviceId;
+ uint32 vendor_id = identifier.VendorId;
+ uint32 device_id = identifier.DeviceId;
// Get version information
D3DCAPS9 d3d_caps;
@@ -54,20 +57,23 @@ bool GPUInfo::CollectGraphicsInfoD3D(IDirect3D9* d3d) {
uint32 driver_major_version_lo = LOWORD(identifier.DriverVersion.HighPart);
uint32 driver_minor_version_hi = HIWORD(identifier.DriverVersion.LowPart);
uint32 driver_minor_version_lo = LOWORD(identifier.DriverVersion.LowPart);
- driver_version_ = StringPrintf(L"%d.%d.%d.%d",
- driver_major_version_hi,
- driver_major_version_lo,
- driver_minor_version_hi,
- driver_minor_version_lo);
+ std::wstring driver_version = StringPrintf(L"%d.%d.%d.%d",
+ driver_major_version_hi,
+ driver_major_version_lo,
+ driver_minor_version_hi,
+ driver_minor_version_lo);
d3d->Release();
// Get shader versions
- pixel_shader_version_ = d3d_caps.PixelShaderVersion;
- vertex_shader_version_ = d3d_caps.VertexShaderVersion;
+ uint32 pixel_shader_version = d3d_caps.PixelShaderVersion;
+ uint32 vertex_shader_version = d3d_caps.VertexShaderVersion;
+
+ gpu_info.SetGraphicsInfo(vendor_id, device_id, driver_version,
+ pixel_shader_version, vertex_shader_version);
return true;
}
-bool GPUInfo::CollectGraphicsInfoGL() {
+bool CollectGraphicsInfoGL(GPUInfo& gpu_info) {
// Taken from http://developer.nvidia.com/object/device_ids.html
DISPLAY_DEVICE dd;
dd.cb = sizeof(DISPLAY_DEVICE);
@@ -82,11 +88,21 @@ bool GPUInfo::CollectGraphicsInfoGL() {
if (id.empty()) {
return false;
}
+ uint32 vendor_id;
+ uint32 device_id;
std::wstring vendorid = id.substr(8, 4);
std::wstring deviceid = id.substr(17, 4);
- swscanf_s(vendorid.c_str(), L"%x", &vendor_id_);
- swscanf_s(deviceid.c_str(), L"%x", &device_id_);
+ swscanf_s(vendorid.c_str(), L"%x", &vendor_id);
+ swscanf_s(deviceid.c_str(), L"%x", &device_id);
+
+ std::wstring driver_version = L"";
+ uint32 pixel_shader_version = 0;
+ uint32 vertex_shader_version = 0;
+ gpu_info.SetGraphicsInfo(vendor_id, device_id, driver_version,
+ pixel_shader_version, vertex_shader_version);
return true;
// TODO(rlp): Add driver and pixel versions
}
+
+} // namespace gpu_info_collector
diff --git a/chrome/gpu/gpu_info_unittest_win.cc b/chrome/gpu/gpu_info_unittest_win.cc
index 195cded..45a064d 100644
--- a/chrome/gpu/gpu_info_unittest_win.cc
+++ b/chrome/gpu/gpu_info_unittest_win.cc
@@ -4,8 +4,9 @@
#include "base/logging.h"
#include "base/scoped_ptr.h"
+#include "chrome/common/gpu_info.h"
#include "chrome/gpu/gpu_idirect3d9_mock_win.h"
-#include "chrome/gpu/gpu_info.h"
+#include "chrome/gpu/gpu_info_collector.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -20,9 +21,6 @@ class GPUInfoTest : public testing::Test {
protected:
void SetUp() {
- gpu_info_.reset(new GPUInfo());
- ASSERT_TRUE(gpu_info() != NULL);
-
// Test variables taken from Lenovo T61
test_identifier_.VendorId = 0x10de;
test_identifier_.DeviceId = 0x429;
@@ -39,46 +37,45 @@ class GPUInfoTest : public testing::Test {
Return(D3D_OK)));
}
void TearDown() {
- gpu_info_.reset();
}
public:
- GPUInfo* gpu_info() {
- return gpu_info_.get();
- }
-
IDirect3D9Mock d3d_;
private:
- scoped_ptr<GPUInfo> gpu_info_;
D3DADAPTER_IDENTIFIER9 test_identifier_;
D3DCAPS9 test_caps_;
};
TEST_F(GPUInfoTest, VendorIdD3D) {
- ASSERT_TRUE(gpu_info()->CollectGraphicsInfoD3D(&d3d_));
- EXPECT_EQ(gpu_info()->vendor_id(), 0x10de);
+ GPUInfo gpu_info;
+ ASSERT_TRUE(gpu_info_collector::CollectGraphicsInfoD3D(&d3d_, gpu_info));
+ EXPECT_EQ(gpu_info.vendor_id(), 0x10de);
}
TEST_F(GPUInfoTest, DeviceIdD3D) {
- ASSERT_TRUE(gpu_info()->CollectGraphicsInfoD3D(&d3d_));
- EXPECT_EQ(gpu_info()->device_id(), 0x429);
+ GPUInfo gpu_info;
+ ASSERT_TRUE(gpu_info_collector::CollectGraphicsInfoD3D(&d3d_, gpu_info));
+ EXPECT_EQ(gpu_info.device_id(), 0x429);
}
TEST_F(GPUInfoTest, DriverVersionD3D) {
- ASSERT_TRUE(gpu_info()->CollectGraphicsInfoD3D(&d3d_));
- std::wstring driver_version = gpu_info()->driver_version();
+ GPUInfo gpu_info;
+ ASSERT_TRUE(gpu_info_collector::CollectGraphicsInfoD3D(&d3d_, gpu_info));
+ std::wstring driver_version = gpu_info.driver_version();
EXPECT_FALSE(driver_version.empty());
EXPECT_EQ(driver_version, L"6.14.11.7715");
}
TEST_F(GPUInfoTest, PixelShaderVersionD3D) {
- ASSERT_TRUE(gpu_info()->CollectGraphicsInfoD3D(&d3d_));
- uint32 ps_version = gpu_info()->pixel_shader_version();
+ GPUInfo gpu_info;
+ ASSERT_TRUE(gpu_info_collector::CollectGraphicsInfoD3D(&d3d_, gpu_info));
+ uint32 ps_version = gpu_info.pixel_shader_version();
EXPECT_EQ(ps_version, D3DPS_VERSION(3, 0));
}
TEST_F(GPUInfoTest, VertexShaderVersionD3D) {
- ASSERT_TRUE(gpu_info()->CollectGraphicsInfoD3D(&d3d_));
- uint32 vs_version = gpu_info()->vertex_shader_version();
+ GPUInfo gpu_info;
+ ASSERT_TRUE(gpu_info_collector::CollectGraphicsInfoD3D(&d3d_, gpu_info));
+ uint32 vs_version = gpu_info.vertex_shader_version();
EXPECT_EQ(vs_version, D3DVS_VERSION(3, 0));
}