OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/base_paths.h" | 8 #include "base/base_paths.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { | 38 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { |
39 glClearDepthf(static_cast<GLclampf>(depth)); | 39 glClearDepthf(static_cast<GLclampf>(depth)); |
40 } | 40 } |
41 | 41 |
42 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, | 42 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, |
43 GLclampd z_far) { | 43 GLclampd z_far) { |
44 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far)); | 44 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far)); |
45 } | 45 } |
46 | 46 |
47 bool LoadD3DXLibrary(const FilePath& module_path, | 47 bool LoadD3DXLibrary(const base::FilePath& module_path, |
48 const FilePath::StringType& name) { | 48 const base::FilePath::StringType& name) { |
49 base::NativeLibrary library = base::LoadNativeLibrary(FilePath(name), NULL); | 49 base::NativeLibrary library = |
| 50 base::LoadNativeLibrary(base::FilePath(name), NULL); |
50 if (!library) { | 51 if (!library) { |
51 library = base::LoadNativeLibrary(module_path.Append(name), NULL); | 52 library = base::LoadNativeLibrary(module_path.Append(name), NULL); |
52 if (!library) { | 53 if (!library) { |
53 DVLOG(1) << name << " not found."; | 54 DVLOG(1) << name << " not found."; |
54 return false; | 55 return false; |
55 } | 56 } |
56 } | 57 } |
57 return true; | 58 return true; |
58 } | 59 } |
59 | 60 |
(...skipping 13 matching lines...) Expand all Loading... |
73 return true; | 74 return true; |
74 | 75 |
75 // Allow the main thread or another to initialize these bindings | 76 // Allow the main thread or another to initialize these bindings |
76 // after instituting restrictions on I/O. Going forward they will | 77 // after instituting restrictions on I/O. Going forward they will |
77 // likely be used in the browser process on most platforms. The | 78 // likely be used in the browser process on most platforms. The |
78 // one-time initialization cost is small, between 2 and 5 ms. | 79 // one-time initialization cost is small, between 2 and 5 ms. |
79 base::ThreadRestrictions::ScopedAllowIO allow_io; | 80 base::ThreadRestrictions::ScopedAllowIO allow_io; |
80 | 81 |
81 switch (implementation) { | 82 switch (implementation) { |
82 case kGLImplementationOSMesaGL: { | 83 case kGLImplementationOSMesaGL: { |
83 FilePath module_path; | 84 base::FilePath module_path; |
84 if (!PathService::Get(base::DIR_MODULE, &module_path)) { | 85 if (!PathService::Get(base::DIR_MODULE, &module_path)) { |
85 LOG(ERROR) << "PathService::Get failed."; | 86 LOG(ERROR) << "PathService::Get failed."; |
86 return false; | 87 return false; |
87 } | 88 } |
88 | 89 |
89 base::NativeLibrary library = base::LoadNativeLibrary( | 90 base::NativeLibrary library = base::LoadNativeLibrary( |
90 module_path.Append(L"osmesa.dll"), NULL); | 91 module_path.Append(L"osmesa.dll"), NULL); |
91 if (!library) { | 92 if (!library) { |
92 DVLOG(1) << "osmesa.dll not found"; | 93 DVLOG(1) << "osmesa.dll not found"; |
93 return false; | 94 return false; |
(...skipping 11 matching lines...) Expand all Loading... |
105 | 106 |
106 SetGLGetProcAddressProc(get_proc_address); | 107 SetGLGetProcAddressProc(get_proc_address); |
107 AddGLNativeLibrary(library); | 108 AddGLNativeLibrary(library); |
108 SetGLImplementation(kGLImplementationOSMesaGL); | 109 SetGLImplementation(kGLImplementationOSMesaGL); |
109 | 110 |
110 InitializeGLBindingsGL(); | 111 InitializeGLBindingsGL(); |
111 InitializeGLBindingsOSMESA(); | 112 InitializeGLBindingsOSMESA(); |
112 break; | 113 break; |
113 } | 114 } |
114 case kGLImplementationEGLGLES2: { | 115 case kGLImplementationEGLGLES2: { |
115 FilePath module_path; | 116 base::FilePath module_path; |
116 if (!PathService::Get(base::DIR_MODULE, &module_path)) | 117 if (!PathService::Get(base::DIR_MODULE, &module_path)) |
117 return false; | 118 return false; |
118 | 119 |
119 // Attempt to load the D3DX shader compiler using the default search path | 120 // Attempt to load the D3DX shader compiler using the default search path |
120 // and if that fails, using an absolute path. This is to ensure these DLLs | 121 // and if that fails, using an absolute path. This is to ensure these DLLs |
121 // are loaded before ANGLE is loaded in case they are not in the default | 122 // are loaded before ANGLE is loaded in case they are not in the default |
122 // search path. Prefer the post vista version. | 123 // search path. Prefer the post vista version. |
123 if (base::win::GetVersion() < base::win::VERSION_VISTA || | 124 if (base::win::GetVersion() < base::win::VERSION_VISTA || |
124 !LoadD3DXLibrary(module_path, kPostVistaD3DCompiler)) { | 125 !LoadD3DXLibrary(module_path, kPostVistaD3DCompiler)) { |
125 LoadD3DXLibrary(module_path, kPreVistaD3DCompiler); | 126 LoadD3DXLibrary(module_path, kPreVistaD3DCompiler); |
126 } | 127 } |
127 | 128 |
128 FilePath gles_path; | 129 base::FilePath gles_path; |
129 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 130 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
130 bool using_swift_shader = | 131 bool using_swift_shader = |
131 command_line->GetSwitchValueASCII(switches::kUseGL) == "swiftshader"; | 132 command_line->GetSwitchValueASCII(switches::kUseGL) == "swiftshader"; |
132 if (using_swift_shader) { | 133 if (using_swift_shader) { |
133 if (!command_line->HasSwitch(switches::kSwiftShaderPath)) | 134 if (!command_line->HasSwitch(switches::kSwiftShaderPath)) |
134 return false; | 135 return false; |
135 gles_path = | 136 gles_path = |
136 command_line->GetSwitchValuePath(switches::kSwiftShaderPath); | 137 command_line->GetSwitchValuePath(switches::kSwiftShaderPath); |
137 // Preload library | 138 // Preload library |
138 LoadLibrary(L"ddraw.dll"); | 139 LoadLibrary(L"ddraw.dll"); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 // These two functions take single precision float rather than double | 189 // These two functions take single precision float rather than double |
189 // precision float parameters in GLES. | 190 // precision float parameters in GLES. |
190 ::gfx::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf; | 191 ::gfx::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf; |
191 ::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef; | 192 ::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef; |
192 break; | 193 break; |
193 } | 194 } |
194 case kGLImplementationDesktopGL: { | 195 case kGLImplementationDesktopGL: { |
195 // When using Windows OpenGL, first try wglGetProcAddress and then | 196 // When using Windows OpenGL, first try wglGetProcAddress and then |
196 // Windows GetProcAddress. | 197 // Windows GetProcAddress. |
197 base::NativeLibrary library = base::LoadNativeLibrary( | 198 base::NativeLibrary library = base::LoadNativeLibrary( |
198 FilePath(L"opengl32.dll"), NULL); | 199 base::FilePath(L"opengl32.dll"), NULL); |
199 if (!library) { | 200 if (!library) { |
200 DVLOG(1) << "opengl32.dll not found"; | 201 DVLOG(1) << "opengl32.dll not found"; |
201 return false; | 202 return false; |
202 } | 203 } |
203 | 204 |
204 GLGetProcAddressProc get_proc_address = | 205 GLGetProcAddressProc get_proc_address = |
205 reinterpret_cast<GLGetProcAddressProc>( | 206 reinterpret_cast<GLGetProcAddressProc>( |
206 base::GetFunctionPointerFromNativeLibrary( | 207 base::GetFunctionPointerFromNativeLibrary( |
207 library, "wglGetProcAddress")); | 208 library, "wglGetProcAddress")); |
208 if (!get_proc_address) { | 209 if (!get_proc_address) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 void ClearGLBindings() { | 268 void ClearGLBindings() { |
268 ClearGLBindingsEGL(); | 269 ClearGLBindingsEGL(); |
269 ClearGLBindingsGL(); | 270 ClearGLBindingsGL(); |
270 ClearGLBindingsOSMESA(); | 271 ClearGLBindingsOSMESA(); |
271 ClearGLBindingsWGL(); | 272 ClearGLBindingsWGL(); |
272 SetGLImplementation(kGLImplementationNone); | 273 SetGLImplementation(kGLImplementationNone); |
273 UnloadGLNativeLibraries(); | 274 UnloadGLNativeLibraries(); |
274 } | 275 } |
275 | 276 |
276 } // namespace gfx | 277 } // namespace gfx |
OLD | NEW |