| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <d3dx9.h> |
| 6 |
| 5 #include <vector> | 7 #include <vector> |
| 6 | 8 |
| 9 #include "base/at_exit.h" |
| 7 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| 11 #include "base/bind.h" |
| 8 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 9 #include "base/logging.h" | 13 #include "base/logging.h" |
| 10 #include "base/native_library.h" | 14 #include "base/native_library.h" |
| 11 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/stringprintf.h" |
| 12 #include "ui/gfx/gl/gl_bindings.h" | 17 #include "ui/gfx/gl/gl_bindings.h" |
| 13 #include "ui/gfx/gl/gl_implementation.h" | 18 #include "ui/gfx/gl/gl_implementation.h" |
| 14 | 19 |
| 15 #if defined(ENABLE_SWIFTSHADER) | 20 #if defined(ENABLE_SWIFTSHADER) |
| 16 #include "software_renderer_d3d9.h" | 21 #include "software_renderer_d3d9.h" |
| 17 #endif | 22 #endif |
| 18 | 23 |
| 19 namespace gfx { | 24 namespace gfx { |
| 20 | 25 |
| 21 namespace { | 26 namespace { |
| 22 | 27 |
| 23 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { | 28 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { |
| 24 glClearDepthf(static_cast<GLclampf>(depth)); | 29 glClearDepthf(static_cast<GLclampf>(depth)); |
| 25 } | 30 } |
| 26 | 31 |
| 27 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, | 32 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, |
| 28 GLclampd z_far) { | 33 GLclampd z_far) { |
| 29 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far)); | 34 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far)); |
| 30 } | 35 } |
| 31 | 36 |
| 37 bool LoadD3DXLibrary(const FilePath& module_path, |
| 38 const FilePath::StringType& name) { |
| 39 base::NativeLibrary library = base::LoadNativeLibrary(FilePath(name), NULL); |
| 40 if (!library) { |
| 41 library = base::LoadNativeLibrary(module_path.Append(name), NULL); |
| 42 if (!library) { |
| 43 VLOG(1) << name << " not found."; |
| 44 return false; |
| 45 } |
| 46 } |
| 47 |
| 48 base::AtExitManager::RegisterTask( |
| 49 base::Bind(base::UnloadNativeLibrary, library)); |
| 50 |
| 51 return true; |
| 52 } |
| 53 |
| 32 } // namespace anonymous | 54 } // namespace anonymous |
| 33 | 55 |
| 34 bool InitializeGLBindings(GLImplementation implementation) { | 56 bool InitializeGLBindings(GLImplementation implementation) { |
| 35 // Prevent reinitialization with a different implementation. Once the gpu | 57 // Prevent reinitialization with a different implementation. Once the gpu |
| 36 // unit tests have initialized with kGLImplementationMock, we don't want to | 58 // unit tests have initialized with kGLImplementationMock, we don't want to |
| 37 // later switch to another GL implementation. | 59 // later switch to another GL implementation. |
| 38 if (GetGLImplementation() != kGLImplementationNone) | 60 if (GetGLImplementation() != kGLImplementationNone) |
| 39 return true; | 61 return true; |
| 40 | 62 |
| 41 switch (implementation) { | 63 switch (implementation) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 if (!PathService::Get(base::DIR_MODULE, &module_path)) | 98 if (!PathService::Get(base::DIR_MODULE, &module_path)) |
| 77 return false; | 99 return false; |
| 78 | 100 |
| 79 #if defined(ENABLE_SWIFTSHADER) | 101 #if defined(ENABLE_SWIFTSHADER) |
| 80 base::NativeLibrary swiftshader_library = base::LoadNativeLibrary( | 102 base::NativeLibrary swiftshader_library = base::LoadNativeLibrary( |
| 81 module_path.Append(L"swiftshader_d3d9.dll"), NULL); | 103 module_path.Append(L"swiftshader_d3d9.dll"), NULL); |
| 82 | 104 |
| 83 SetupSoftwareRenderer(); | 105 SetupSoftwareRenderer(); |
| 84 #endif | 106 #endif |
| 85 | 107 |
| 108 // Attempt to load D3DX and its dependencies using the default search path |
| 109 // and if that fails, using an absolute path. This is to ensure these DLLs |
| 110 // are loaded before ANGLE is loaded in case they are not in the default |
| 111 // search path. |
| 112 LoadD3DXLibrary(module_path, base::StringPrintf(L"d3dcompiler_%d.dll", |
| 113 D3DX_SDK_VERSION)); |
| 114 LoadD3DXLibrary(module_path, base::StringPrintf(L"d3dx9_%d.dll", |
| 115 D3DX_SDK_VERSION)); |
| 116 |
| 86 // Load libglesv2.dll before libegl.dll because the latter is dependent on | 117 // Load libglesv2.dll before libegl.dll because the latter is dependent on |
| 87 // the former and if there is another version of libglesv2.dll in the dll | 118 // the former and if there is another version of libglesv2.dll in the dll |
| 88 // search path, it will get loaded. | 119 // search path, it will get loaded instead. |
| 89 base::NativeLibrary gles_library = base::LoadNativeLibrary( | 120 base::NativeLibrary gles_library = base::LoadNativeLibrary( |
| 90 module_path.Append(L"libglesv2.dll"), NULL); | 121 module_path.Append(L"libglesv2.dll"), NULL); |
| 91 if (!gles_library) { | 122 if (!gles_library) { |
| 92 VLOG(1) << "libglesv2.dll not found"; | 123 VLOG(1) << "libglesv2.dll not found"; |
| 93 return false; | 124 return false; |
| 94 } | 125 } |
| 95 | 126 |
| 96 // When using EGL, first try eglGetProcAddress and then Windows | 127 // When using EGL, first try eglGetProcAddress and then Windows |
| 97 // GetProcAddress on both the EGL and GLES2 DLLs. | 128 // GetProcAddress on both the EGL and GLES2 DLLs. |
| 98 base::NativeLibrary egl_library = base::LoadNativeLibrary( | 129 base::NativeLibrary egl_library = base::LoadNativeLibrary( |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 } | 201 } |
| 171 | 202 |
| 172 void InitializeDebugGLBindings() { | 203 void InitializeDebugGLBindings() { |
| 173 InitializeDebugGLBindingsEGL(); | 204 InitializeDebugGLBindingsEGL(); |
| 174 InitializeDebugGLBindingsGL(); | 205 InitializeDebugGLBindingsGL(); |
| 175 InitializeDebugGLBindingsOSMESA(); | 206 InitializeDebugGLBindingsOSMESA(); |
| 176 InitializeDebugGLBindingsWGL(); | 207 InitializeDebugGLBindingsWGL(); |
| 177 } | 208 } |
| 178 | 209 |
| 179 } // namespace gfx | 210 } // namespace gfx |
| OLD | NEW |