diff options
author | jbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-04 00:26:04 +0000 |
---|---|---|
committer | jbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-04 00:26:04 +0000 |
commit | 3119a917f9b4bc9c298187e4960d313d7f7ba53b (patch) | |
tree | 2beaededffef44491ce92aab99a9f059e2f05f01 | |
parent | b7c1fa2b8f31c967dc432b9d5dd1b7f731e34c77 (diff) | |
download | chromium_src-3119a917f9b4bc9c298187e4960d313d7f7ba53b.zip chromium_src-3119a917f9b4bc9c298187e4960d313d7f7ba53b.tar.gz chromium_src-3119a917f9b4bc9c298187e4960d313d7f7ba53b.tar.bz2 |
Add command-line option to enable swiftshader
This adds --use-gl=swiftshader to force that swiftshader be used. --swiftshader-path specifies where to load the libraries from. These arguments will be used when the gpu is on the software rendering list.
BUG=
TEST=
Review URL: http://codereview.chromium.org/8431017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108596 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | content/gpu/gpu_child_thread.cc | 11 | ||||
-rw-r--r-- | content/gpu/gpu_info_collector_win.cc | 8 | ||||
-rw-r--r-- | ui/gfx/gl/gl_implementation.cc | 8 | ||||
-rw-r--r-- | ui/gfx/gl/gl_implementation.h | 3 | ||||
-rw-r--r-- | ui/gfx/gl/gl_implementation_win.cc | 32 | ||||
-rw-r--r-- | ui/gfx/gl/gl_switches.cc | 11 | ||||
-rw-r--r-- | ui/gfx/gl/gl_switches.h | 1 |
7 files changed, 56 insertions, 18 deletions
diff --git a/content/gpu/gpu_child_thread.cc b/content/gpu/gpu_child_thread.cc index 22d7831..0004357 100644 --- a/content/gpu/gpu_child_thread.cc +++ b/content/gpu/gpu_child_thread.cc @@ -102,10 +102,12 @@ void GpuChildThread::OnInitialize() { !CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU)) logging::SetLogMessageHandler(GpuProcessLogMessageHandler); - gpu_info_collector::CollectGraphicsInfo(&gpu_info_); + bool succeeded = gpu_info_collector::CollectGraphicsInfo(&gpu_info_); - content::GetContentClient()->SetGpuInfo(gpu_info_); - LOG(INFO) << "gpu_info_collector::CollectGraphicsInfo complete"; + if (succeeded) { + content::GetContentClient()->SetGpuInfo(gpu_info_); + LOG(INFO) << "gpu_info_collector::CollectGraphicsInfo complete"; + } // Record initialization only after collecting the GPU info because that can // take a significant amount of time. @@ -154,7 +156,8 @@ void GpuChildThread::OnInitialize() { // Ensure the browser process receives the GPU info before a reply to any // subsequent IPC it might send. - Send(new GpuHostMsg_GraphicsInfoCollected(gpu_info_)); + if (succeeded) + Send(new GpuHostMsg_GraphicsInfoCollected(gpu_info_)); } void GpuChildThread::StopWatchdog() { diff --git a/content/gpu/gpu_info_collector_win.cc b/content/gpu/gpu_info_collector_win.cc index 94fd093..aa902c5 100644 --- a/content/gpu/gpu_info_collector_win.cc +++ b/content/gpu/gpu_info_collector_win.cc @@ -8,6 +8,7 @@ #include <d3d9.h> #include <setupapi.h> +#include "base/command_line.h" #include "base/file_path.h" #include "base/logging.h" #include "base/scoped_native_library.h" @@ -63,6 +64,13 @@ namespace gpu_info_collector { bool CollectGraphicsInfo(content::GPUInfo* gpu_info) { DCHECK(gpu_info); + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) { + std::string requested_implementation_name = + CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL); + if (requested_implementation_name == "swiftshader") + return false; + } + if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { gpu_info->finalized = true; return CollectGraphicsInfoGL(gpu_info); diff --git a/ui/gfx/gl/gl_implementation.cc b/ui/gfx/gl/gl_implementation.cc index f7ad2ee..24284f9 100644 --- a/ui/gfx/gl/gl_implementation.cc +++ b/ui/gfx/gl/gl_implementation.cc @@ -30,6 +30,7 @@ typedef std::vector<base::NativeLibrary> LibraryArray; GLImplementation g_gl_implementation = kGLImplementationNone; LibraryArray* g_libraries; GLGetProcAddressProc g_get_proc_address; +bool g_using_swiftshader; void CleanupNativeLibraries(void* unused) { if (g_libraries) { @@ -88,6 +89,9 @@ bool InitializeRequestedGLBindings( if (requested_implementation_name == "any") { requested_implementation = default_implementation; fallback_to_osmesa = true; + } else if (requested_implementation_name == "swiftshader") { + g_using_swiftshader = true; + requested_implementation = kGLImplementationEGLGLES2; } else { requested_implementation = GetNamedGLImplementation(requested_implementation_name); @@ -136,6 +140,10 @@ bool HasDesktopGLFeatures() { kGLImplementationOSMesaGL == g_gl_implementation; } +bool UsingSwiftShader() { + return g_using_swiftshader; +} + void AddGLNativeLibrary(base::NativeLibrary library) { DCHECK(library); diff --git a/ui/gfx/gl/gl_implementation.h b/ui/gfx/gl/gl_implementation.h index 5d5ab55..f675914 100644 --- a/ui/gfx/gl/gl_implementation.h +++ b/ui/gfx/gl/gl_implementation.h @@ -58,6 +58,9 @@ GLImplementation GetNamedGLImplementation(const std::wstring& name); // Get the name of a GL implementation. const char* GetGLImplementationName(GLImplementation implementation); +// Get whether the current GL implementation is swiftshader. +bool UsingSwiftShader(); + // Initialize the preferred GL binding from the given list. The preferred GL // bindings depend on command line switches passed by the user and which GL // implementation is the default on a given platform. diff --git a/ui/gfx/gl/gl_implementation_win.cc b/ui/gfx/gl/gl_implementation_win.cc index 7b74316..bbd6b72 100644 --- a/ui/gfx/gl/gl_implementation_win.cc +++ b/ui/gfx/gl/gl_implementation_win.cc @@ -9,6 +9,7 @@ #include "base/at_exit.h" #include "base/base_paths.h" #include "base/bind.h" +#include "base/command_line.h" #include "base/file_path.h" #include "base/logging.h" #include "base/native_library.h" @@ -19,7 +20,7 @@ #include "ui/gfx/gl/gl_implementation.h" #if defined(ENABLE_SWIFTSHADER) -#include "software_renderer_d3d9.h" +#include "software_renderer.h" #endif namespace gfx { @@ -105,13 +106,6 @@ bool InitializeGLBindings(GLImplementation implementation) { if (!PathService::Get(base::DIR_MODULE, &module_path)) return false; -#if defined(ENABLE_SWIFTSHADER) - base::NativeLibrary swiftshader_library = base::LoadNativeLibrary( - module_path.Append(L"swiftshader_d3d9.dll"), NULL); - - SetupSoftwareRenderer(); -#endif - // Attempt to load D3DX and its dependencies using the default search path // and if that fails, using an absolute path. This is to ensure these DLLs // are loaded before ANGLE is loaded in case they are not in the default @@ -121,11 +115,23 @@ bool InitializeGLBindings(GLImplementation implementation) { LoadD3DXLibrary(module_path, base::StringPrintf(L"d3dx9_%d.dll", D3DX_SDK_VERSION)); + FilePath gles_path; + + if (UsingSwiftShader()) { + const CommandLine* command_line = CommandLine::ForCurrentProcess(); + if (!command_line->HasSwitch(switches::kSwiftShaderPath)) + return false; + gles_path = + command_line->GetSwitchValuePath(switches::kSwiftShaderPath); + } else { + gles_path = module_path; + } + // Load libglesv2.dll before libegl.dll because the latter is dependent on // the former and if there is another version of libglesv2.dll in the dll // search path, it will get loaded instead. base::NativeLibrary gles_library = base::LoadNativeLibrary( - module_path.Append(L"libglesv2.dll"), NULL); + gles_path.Append(L"libglesv2.dll"), NULL); if (!gles_library) { VLOG(1) << "libglesv2.dll not found"; return false; @@ -134,13 +140,19 @@ bool InitializeGLBindings(GLImplementation implementation) { // When using EGL, first try eglGetProcAddress and then Windows // GetProcAddress on both the EGL and GLES2 DLLs. base::NativeLibrary egl_library = base::LoadNativeLibrary( - module_path.Append(L"libegl.dll"), NULL); + gles_path.Append(L"libegl.dll"), NULL); if (!egl_library) { VLOG(1) << "libegl.dll not found."; base::UnloadNativeLibrary(gles_library); return false; } +#if defined(ENABLE_SWIFTSHADER) + if (UsingSwiftShader()) { + SetupSoftwareRenderer(gles_library); + } +#endif + GLGetProcAddressProc get_proc_address = reinterpret_cast<GLGetProcAddressProc>( base::GetFunctionPointerFromNativeLibrary( diff --git a/ui/gfx/gl/gl_switches.cc b/ui/gfx/gl/gl_switches.cc index 3644323..c79397f 100644 --- a/ui/gfx/gl/gl_switches.cc +++ b/ui/gfx/gl/gl_switches.cc @@ -6,10 +6,11 @@ namespace gfx { -const char kGLImplementationDesktopName[] = "desktop"; -const char kGLImplementationOSMesaName[] = "osmesa"; -const char kGLImplementationEGLName[] = "egl"; -const char kGLImplementationMockName[] = "mock"; +const char kGLImplementationDesktopName[] = "desktop"; +const char kGLImplementationOSMesaName[] = "osmesa"; +const char kGLImplementationEGLName[] = "egl"; +const char kGLImplementationSwiftShaderName[] = "swiftshader"; +const char kGLImplementationMockName[] = "mock"; } // namespace gfx @@ -30,6 +31,8 @@ const char kEnableGPUClientLogging[] = "enable-gpu-client-logging"; // osmesa: The OSMesa software renderer. const char kUseGL[] = "use-gl"; +const char kSwiftShaderPath[] = "swiftshader-path"; + // Inform Chrome that a GPU context will not be lost in power saving mode, // screen saving mode, etc. Note that this flag does not ensure that a GPU // context will never be lost in any situations, say, a GPU reset. diff --git a/ui/gfx/gl/gl_switches.h b/ui/gfx/gl/gl_switches.h index fd0cf5f..75ec7ea 100644 --- a/ui/gfx/gl/gl_switches.h +++ b/ui/gfx/gl/gl_switches.h @@ -27,6 +27,7 @@ GL_EXPORT extern const char kEnableGPUServiceLogging[]; GL_EXPORT extern const char kEnableGPUClientLogging[]; GL_EXPORT extern const char kGpuNoContextLost[]; GL_EXPORT extern const char kUseGL[]; +GL_EXPORT extern const char kSwiftShaderPath[]; } // namespace switches |