diff options
author | apatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-23 22:17:10 +0000 |
---|---|---|
committer | apatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-23 22:17:10 +0000 |
commit | 1d3a6d08fcc0759fdd589e48a85f3331cc9f7a98 (patch) | |
tree | fe614bc0b7b1303f746eb2a74408fdaaba78adac /o3d/core/win | |
parent | 5e892c20535dcbeae099f92148feea8473cf1445 (diff) | |
download | chromium_src-1d3a6d08fcc0759fdd589e48a85f3331cc9f7a98.zip chromium_src-1d3a6d08fcc0759fdd589e48a85f3331cc9f7a98.tar.gz chromium_src-1d3a6d08fcc0759fdd589e48a85f3331cc9f7a98.tar.bz2 |
Code to load the software renderer and initialize it. Code to force the software renderer enabled with registry entry even if hardware is capable. Build scripts copy the software renderer dll to the plugin directory on an intall build.
Review URL: http://codereview.chromium.org/147039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19070 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/core/win')
-rw-r--r-- | o3d/core/win/d3d9/install_check.cc | 4 | ||||
-rw-r--r-- | o3d/core/win/d3d9/renderer_d3d9.cc | 61 | ||||
-rw-r--r-- | o3d/core/win/d3d9/software_renderer_d3d9.h | 46 |
3 files changed, 100 insertions, 11 deletions
diff --git a/o3d/core/win/d3d9/install_check.cc b/o3d/core/win/d3d9/install_check.cc index cf4d584..6dfd157 100644 --- a/o3d/core/win/d3d9/install_check.cc +++ b/o3d/core/win/d3d9/install_check.cc @@ -215,8 +215,8 @@ bool D3D9SoftwareInstallCheck(std::string* error) { return false; } - if (!PathAppend(dll_path.get(), _T("O3DExtras\\swrend\\d3d9.dll"))) { - *error = "Failed to compute new plugin location."; + if (!PathAppend(dll_path.get(), _T("O3DExtras\\swiftshader_d3d9.dll"))) { + *error = "Failed to compute new software renderer location."; return false; } diff --git a/o3d/core/win/d3d9/renderer_d3d9.cc b/o3d/core/win/d3d9/renderer_d3d9.cc index ec2c0d3..08e8100 100644 --- a/o3d/core/win/d3d9/renderer_d3d9.cc +++ b/o3d/core/win/d3d9/renderer_d3d9.cc @@ -54,6 +54,7 @@ #include "core/win/d3d9/primitive_d3d9.h" #include "core/win/d3d9/render_surface_d3d9.h" #include "core/win/d3d9/sampler_d3d9.h" +#include "core/win/d3d9/software_renderer_d3d9.h" #include "core/win/d3d9/stream_bank_d3d9.h" #include "core/win/d3d9/texture_d3d9.h" #include "core/win/d3d9/utils_d3d9.h" @@ -297,7 +298,7 @@ bool CheckDeviceCaps(LPDIRECT3D9 d3d, Features* features) { << " for depth/stencil buffers."; return false; } - } + } return true; } @@ -329,11 +330,11 @@ Renderer::InitStatus CreateDirect3D(Direct3DCreate9_Ptr d3d_create_function, // For certain GPU drivers we need to force anti-aliasing off to avoid a // a huge performance hit when certain types of windows are used on the same // desktop as O3D. This function returns true if O3D is running on one -// of these GPUs/Drivers. +// of these GPUs/Drivers. bool ForceAntiAliasingOff(LPDIRECT3D9* d3d) { D3DADAPTER_IDENTIFIER9 identifier; HRESULT hr = (*d3d)->GetAdapterIdentifier(D3DADAPTER_DEFAULT, 0, &identifier); - + unsigned int vendor_id = identifier.VendorId; unsigned int device_id = identifier.DeviceId; unsigned int product = HIWORD(identifier.DriverVersion.HighPart);
@@ -345,14 +346,46 @@ bool ForceAntiAliasingOff(LPDIRECT3D9* d3d) { if (vendor_id == 4098 && // ATI product == 6 && version == 14 && - subversion == 10 && + subversion == 10 && build <= 6800) { return true; - } + } return false; } +namespace { +// Returns whether the ForceSoftwareRenderer value of the Software\Google\o3d +// key is non-zero. +bool IsForceSoftwareRendererEnabled() { + HKEY key; + if (FAILED(RegOpenKeyEx(HKEY_CURRENT_USER, + TEXT("Software\\Google\\o3d"), + 0, + KEY_READ, + &key))) { + return false; + } + + bool enabled = false; + DWORD type; + DWORD value; + DWORD size = sizeof(value); + if (SUCCEEDED(RegQueryValueEx(key, + TEXT("ForceSoftwareRenderer"), + NULL, + &type, + reinterpret_cast<LPBYTE>(&value), + &size))) { + if (type == REG_DWORD && size == sizeof(value) && value) { + enabled = true; + } + } + RegCloseKey(key); + + return enabled; +} +} // Helper function that gets the D3D Interface, checks the available // multisampling modes and selects the most advanced one available to create @@ -368,9 +401,17 @@ Renderer::InitStatus InitializeD3D9Context( int* out_width, int* out_height) { - // Try the hardware renderer first. - Renderer::InitStatus status_hardware = CreateDirect3D( - Direct3DCreate9, d3d, features); + // Check registry to see if the developer has opted to force the software + // renderer. + Renderer::InitStatus status_hardware; + if (IsForceSoftwareRendererEnabled()) { + // Simulate GPU not up to spec. + status_hardware = Renderer::GPU_NOT_UP_TO_SPEC; + } else { + // Create a hardware device. + status_hardware = CreateDirect3D(Direct3DCreate9, d3d, features); + } + if (status_hardware != Renderer::SUCCESS) { Renderer::InitStatus status_software = CreateDirect3D( Direct3DCreate9Software, d3d, features); @@ -387,6 +428,8 @@ Renderer::InitStatus InitializeD3D9Context( } return status_hardware; } + + SetupSoftwareRenderer(*d3d); } D3DDISPLAYMODE d3ddm; @@ -394,7 +437,7 @@ Renderer::InitStatus InitializeD3D9Context( return Renderer::GPU_NOT_UP_TO_SPEC; // NOTE: make sure the backbuffer matches this format, as it is - // currently currently assumed to be 32-bit 8X8R8G8B + // currently assumed to be 32-bit 8X8R8G8B ZeroMemory(d3d_present_parameters, sizeof(*d3d_present_parameters)); d3d_present_parameters->Windowed = !fullscreen; diff --git a/o3d/core/win/d3d9/software_renderer_d3d9.h b/o3d/core/win/d3d9/software_renderer_d3d9.h new file mode 100644 index 0000000..fcfa8ef --- /dev/null +++ b/o3d/core/win/d3d9/software_renderer_d3d9.h @@ -0,0 +1,46 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef O3D_CORE_WIN_D3D9_SOFTWARE_RENDERER_D3D9_H +#define O3D_CORE_WIN_D3D9_SOFTWARE_RENDERER_D3D9_H + +#include <d3d9.h> + +namespace o3d { + +// Not implemented. +inline bool SetupSoftwareRenderer(IDirect3D9* d3d) { + return false;
+} + +} // namespace o3d + +#endif // O3D_CORE_WIN_D3D9_SOFTWARE_RENDERER_D3D9_H |