diff options
author | rlp@chromium.org <rlp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-21 22:31:00 +0000 |
---|---|---|
committer | rlp@chromium.org <rlp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-21 22:31:00 +0000 |
commit | 3d8d1c9f38d1f4f26a56ad03d3fa920791bc50ea (patch) | |
tree | 01f610e88a53cbd3af89ffd2d3b6c63f66728ff1 /chrome | |
parent | eaf16c467545cf40e3ea38960f2b6042743e2a18 (diff) | |
download | chromium_src-3d8d1c9f38d1f4f26a56ad03d3fa920791bc50ea.zip chromium_src-3d8d1c9f38d1f4f26a56ad03d3fa920791bc50ea.tar.gz chromium_src-3d8d1c9f38d1f4f26a56ad03d3fa920791bc50ea.tar.bz2 |
Adding the gpu_info classes to get gpu info. The actual integration will be in another CL. Just want to get the classes and tests in there first.
BUG=38736
TEST=unittests included
Review URL: http://codereview.chromium.org/2733004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50401 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/chrome.gyp | 2 | ||||
-rwxr-xr-x | chrome/chrome_tests.gypi | 3 | ||||
-rw-r--r-- | chrome/gpu/gpu_idirect3d9_mock_win.h | 75 | ||||
-rw-r--r-- | chrome/gpu/gpu_info.h | 67 | ||||
-rw-r--r-- | chrome/gpu/gpu_info_unittest_win.cc | 84 | ||||
-rw-r--r-- | chrome/gpu/gpu_info_win.cc | 112 |
6 files changed, 343 insertions, 0 deletions
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 671e9cf..93b2734 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -685,6 +685,8 @@ 'gpu/gpu_command_buffer_stub.cc', 'gpu/gpu_command_buffer_stub.h', 'gpu/gpu_config.h', + 'gpu/gpu_info_win.cc', + 'gpu/gpu_info.h', 'gpu/gpu_main.cc', 'gpu/gpu_process.cc', 'gpu/gpu_process.h', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 2e92df3..f87178c 100755 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -499,6 +499,7 @@ 'browser', 'browser/sync/protocol/sync_proto.gyp:sync_proto_cpp', 'chrome', + 'chrome_gpu', 'chrome_resources', 'chrome_strings', 'common', @@ -1025,6 +1026,8 @@ 'common/time_format_unittest.cc', 'common/worker_thread_ticker_unittest.cc', 'common/zip_unittest.cc', + 'gpu/gpu_idirect3d9_mock_win.h', + 'gpu/gpu_info_unittest_win.cc', 'renderer/audio_message_filter_unittest.cc', 'renderer/extensions/extension_api_json_validity_unittest.cc', 'renderer/extensions/json_schema_unittest.cc', diff --git a/chrome/gpu/gpu_idirect3d9_mock_win.h b/chrome/gpu/gpu_idirect3d9_mock_win.h new file mode 100644 index 0000000..a7e9107 --- /dev/null +++ b/chrome/gpu/gpu_idirect3d9_mock_win.h @@ -0,0 +1,75 @@ +// Copyright (c) 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_IDIRECT3D9_MOCK_WIN_H__ +#define CHROME_GPU_GPU_IDIRECT3D9_MOCK_WIN_H__ + +#include <d3d9.h> +#include <windows.h> + +#include "testing/gmock/include/gmock/gmock.h" + +class IDirect3D9Mock : public IDirect3D9 { + public: + IDirect3D9Mock() {} + + MOCK_METHOD5_WITH_CALLTYPE( + STDMETHODCALLTYPE, CheckDepthStencilMatch, + HRESULT(UINT Adapter, D3DDEVTYPE DeviceType, + D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, + D3DFORMAT DepthStencilFormat)); + MOCK_METHOD6_WITH_CALLTYPE( + STDMETHODCALLTYPE, CheckDeviceFormat, + HRESULT(UINT Adapter, D3DDEVTYPE DeviceType, + D3DFORMAT AdapterFormat, DWORD Usage, + D3DRESOURCETYPE RType, D3DFORMAT CheckFormat)); + MOCK_METHOD4_WITH_CALLTYPE( + STDMETHODCALLTYPE, CheckDeviceFormatConversion, + HRESULT(UINT Adapter, D3DDEVTYPE DeviceType, + D3DFORMAT SourceFormat, D3DFORMAT TargetFormat)); + MOCK_METHOD6_WITH_CALLTYPE( + STDMETHODCALLTYPE, CheckDeviceMultiSampleType, + HRESULT(UINT Adapter, D3DDEVTYPE DeviceType, + D3DFORMAT SurfaceFormat, BOOL Windowed, + D3DMULTISAMPLE_TYPE MultiSampleType, + DWORD* pQualityLevels)); + MOCK_METHOD5_WITH_CALLTYPE( + STDMETHODCALLTYPE, CheckDeviceType, + HRESULT(UINT Adapter, D3DDEVTYPE DevType, + D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat, + BOOL bWindowed)); + MOCK_METHOD6_WITH_CALLTYPE( + STDMETHODCALLTYPE, CreateDevice, + HRESULT(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, + DWORD BehaviorFlags, + D3DPRESENT_PARAMETERS* pPresentationParameters, + IDirect3DDevice9** ppReturnedDeviceInterface)); + MOCK_METHOD4_WITH_CALLTYPE( + STDMETHODCALLTYPE, EnumAdapterModes, + HRESULT(UINT Adapter, D3DFORMAT Format, UINT Mode, + D3DDISPLAYMODE* pMode)); + MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, GetAdapterCount, UINT()); + MOCK_METHOD2_WITH_CALLTYPE( + STDMETHODCALLTYPE, GetAdapterDisplayMode, + HRESULT(UINT Adapter, D3DDISPLAYMODE* pMode)); + MOCK_METHOD3_WITH_CALLTYPE( + STDMETHODCALLTYPE, GetAdapterIdentifier, + HRESULT(UINT Adapter, DWORD Flags, + D3DADAPTER_IDENTIFIER9* pIdentifier)); + MOCK_METHOD2_WITH_CALLTYPE(STDMETHODCALLTYPE, GetAdapterModeCount, + UINT(UINT Adapter, D3DFORMAT Format)); + MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, GetAdapterMonitor, + HMONITOR(UINT Adapter)); + MOCK_METHOD3_WITH_CALLTYPE(STDMETHODCALLTYPE, GetDeviceCaps, + HRESULT(UINT Adapter, D3DDEVTYPE DeviceType, + D3DCAPS9* pCaps)); + MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, RegisterSoftwareDevice, + HRESULT(void* pInitializeFunction)); + MOCK_METHOD2_WITH_CALLTYPE(STDMETHODCALLTYPE, QueryInterface, + HRESULT(REFIID riid, void** ppvObj)); + MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, AddRef, ULONG()); + MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, Release, ULONG()); +}; + +#endif // CHROME_GPU_GPU_IDIRECT3D9_MOCK_WIN_H__ diff --git a/chrome/gpu/gpu_info.h b/chrome/gpu/gpu_info.h new file mode 100644 index 0000000..4af82fd --- /dev/null +++ b/chrome/gpu/gpu_info.h @@ -0,0 +1,67 @@ +// 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(); + +#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_unittest_win.cc b/chrome/gpu/gpu_info_unittest_win.cc new file mode 100644 index 0000000..195cded --- /dev/null +++ b/chrome/gpu/gpu_info_unittest_win.cc @@ -0,0 +1,84 @@ +// 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 "base/logging.h" +#include "base/scoped_ptr.h" +#include "chrome/gpu/gpu_idirect3d9_mock_win.h" +#include "chrome/gpu/gpu_info.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" + +using ::testing::_; +using ::testing::Return; +using ::testing::SetArgumentPointee; + +class GPUInfoTest : public testing::Test { + public: + GPUInfoTest() { } + virtual ~GPUInfoTest() { } + + 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; + test_identifier_.DriverVersion.QuadPart = 0x6000e000b1e23; // 6.14.11.7715 + test_caps_.PixelShaderVersion = 0xffff0300; // 3.0 + test_caps_.VertexShaderVersion = 0xfffe0300; // 3.0 + + EXPECT_CALL(d3d_, GetAdapterIdentifier(_, _, _)) + .WillOnce(DoAll(SetArgumentPointee<2>(test_identifier_), + Return(D3D_OK))); + EXPECT_CALL(d3d_, Release()); + EXPECT_CALL(d3d_, GetDeviceCaps(_, _, _)) + .WillOnce(DoAll(SetArgumentPointee<2>(test_caps_), + 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); +} + +TEST_F(GPUInfoTest, DeviceIdD3D) { + ASSERT_TRUE(gpu_info()->CollectGraphicsInfoD3D(&d3d_)); + 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(); + 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(); + 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(); + EXPECT_EQ(vs_version, D3DVS_VERSION(3, 0)); +} diff --git a/chrome/gpu/gpu_info_win.cc b/chrome/gpu/gpu_info_win.cc new file mode 100644 index 0000000..a6d4160 --- /dev/null +++ b/chrome/gpu/gpu_info_win.cc @@ -0,0 +1,112 @@ +// 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" + +#include <windows.h> +#include <d3d9.h> + +#include "base/logging.h" +#include "base/scoped_native_library.h" +#include "base/string_util.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_; +} + +bool GPUInfo::CollectGraphicsInfo() { + FilePath d3d_path(base::GetNativeLibraryName(L"d3d9")); + base::ScopedNativeLibrary d3dlib(d3d_path); + + typedef IDirect3D9* (WINAPI *Direct3DCreate9Proc)(UINT); + Direct3DCreate9Proc d3d_create_proc = + static_cast<Direct3DCreate9Proc>( + d3dlib.GetFunctionPointer("Direct3DCreate9")); + + if (!d3d_create_proc) { + return false; + } + IDirect3D9 *d3d = d3d_create_proc(D3D_SDK_VERSION); + if (!d3d) { + return false; + } + return CollectGraphicsInfoD3D(d3d); +} + +bool GPUInfo::CollectGraphicsInfoD3D(IDirect3D9* d3d) { + // Get device information + D3DADAPTER_IDENTIFIER9 identifier; + HRESULT hr = d3d->GetAdapterIdentifier(D3DADAPTER_DEFAULT, 0, &identifier); + if (hr != D3D_OK) { + d3d->Release(); + return false; + } + vendor_id_ = identifier.VendorId; + device_id_ = identifier.DeviceId; + + // Get version information + D3DCAPS9 d3d_caps; + HRESULT caps_result = d3d->GetDeviceCaps(D3DADAPTER_DEFAULT, + D3DDEVTYPE_HAL, + &d3d_caps); + if (caps_result != D3D_OK) { + d3d->Release(); + return false; + } + uint32 driver_major_version_hi = HIWORD(identifier.DriverVersion.HighPart); + 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); + d3d->Release(); + + // Get shader versions + pixel_shader_version_ = d3d_caps.PixelShaderVersion; + vertex_shader_version_ = d3d_caps.VertexShaderVersion; + return true; +} + +bool GPUInfo::CollectGraphicsInfoGL() { + // Taken from http://developer.nvidia.com/object/device_ids.html + DISPLAY_DEVICE dd; + dd.cb = sizeof(DISPLAY_DEVICE); + int i = 0; + std::wstring id; + for (int i = 0; EnumDisplayDevices(NULL, i, &dd, 0); ++i) { + if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) { + id = dd.DeviceID; + break; + } + } + if (id.empty()) { + return false; + } + 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_); + return true; + + // TODO(rlp): Add driver and pixel versions +} |