OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ui/gl/init/gl_initializer.h" | 5 #include "ui/gl/init/gl_initializer.h" |
6 | 6 |
7 #include <dwmapi.h> | 7 #include <dwmapi.h> |
8 | 8 |
9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/lazy_instance.h" | |
15 #include "base/logging.h" | 14 #include "base/logging.h" |
16 #include "base/native_library.h" | 15 #include "base/native_library.h" |
17 #include "base/path_service.h" | 16 #include "base/path_service.h" |
18 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
19 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
20 #include "base/trace_event/trace_event.h" | 19 #include "base/trace_event/trace_event.h" |
21 #include "base/win/windows_version.h" | 20 #include "base/win/windows_version.h" |
22 // TODO(jmadill): Apply to all platforms eventually | |
23 #include "ui/gl/angle_platform_impl.h" | |
24 #include "ui/gl/gl_bindings.h" | 21 #include "ui/gl/gl_bindings.h" |
25 #include "ui/gl/gl_egl_api_implementation.h" | 22 #include "ui/gl/gl_egl_api_implementation.h" |
26 #include "ui/gl/gl_features.h" | 23 #include "ui/gl/gl_features.h" |
27 #include "ui/gl/gl_gl_api_implementation.h" | 24 #include "ui/gl/gl_gl_api_implementation.h" |
28 #include "ui/gl/gl_osmesa_api_implementation.h" | 25 #include "ui/gl/gl_osmesa_api_implementation.h" |
29 #include "ui/gl/gl_surface_egl.h" | 26 #include "ui/gl/gl_surface_egl.h" |
30 #include "ui/gl/gl_surface_wgl.h" | 27 #include "ui/gl/gl_surface_wgl.h" |
31 #include "ui/gl/gl_wgl_api_implementation.h" | 28 #include "ui/gl/gl_wgl_api_implementation.h" |
32 #include "ui/gl/vsync_provider_win.h" | 29 #include "ui/gl/vsync_provider_win.h" |
33 | 30 |
34 namespace gl { | 31 namespace gl { |
35 namespace init { | 32 namespace init { |
36 | 33 |
37 namespace { | 34 namespace { |
38 | 35 |
39 const wchar_t kD3DCompiler[] = L"D3DCompiler_47.dll"; | 36 const wchar_t kD3DCompiler[] = L"D3DCompiler_47.dll"; |
40 | 37 |
41 // TODO(jmadill): Apply to all platforms eventually | |
42 base::LazyInstance<ANGLEPlatformImpl> g_angle_platform_impl = | |
43 LAZY_INSTANCE_INITIALIZER; | |
44 | |
45 ANGLEPlatformShutdownFunc g_angle_platform_shutdown = nullptr; | |
46 | |
47 bool LoadD3DXLibrary(const base::FilePath& module_path, | 38 bool LoadD3DXLibrary(const base::FilePath& module_path, |
48 const base::FilePath::StringType& name) { | 39 const base::FilePath::StringType& name) { |
49 base::NativeLibrary library = | 40 base::NativeLibrary library = |
50 base::LoadNativeLibrary(base::FilePath(name), nullptr); | 41 base::LoadNativeLibrary(base::FilePath(name), nullptr); |
51 if (!library) { | 42 if (!library) { |
52 library = base::LoadNativeLibrary(module_path.Append(name), nullptr); | 43 library = base::LoadNativeLibrary(module_path.Append(name), nullptr); |
53 if (!library) { | 44 if (!library) { |
54 DVLOG(1) << name << " not found."; | 45 DVLOG(1) << name << " not found."; |
55 return false; | 46 return false; |
56 } | 47 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // Register key so that SwiftShader doesn't display watermark logo. | 136 // Register key so that SwiftShader doesn't display watermark logo. |
146 typedef void (__stdcall *RegisterFunc)(const char* key); | 137 typedef void (__stdcall *RegisterFunc)(const char* key); |
147 RegisterFunc reg = reinterpret_cast<RegisterFunc>( | 138 RegisterFunc reg = reinterpret_cast<RegisterFunc>( |
148 base::GetFunctionPointerFromNativeLibrary(gles_library, "Register")); | 139 base::GetFunctionPointerFromNativeLibrary(gles_library, "Register")); |
149 if (reg) { | 140 if (reg) { |
150 reg("SS3GCKK6B448CF63"); | 141 reg("SS3GCKK6B448CF63"); |
151 } | 142 } |
152 } | 143 } |
153 #endif | 144 #endif |
154 | 145 |
155 if (!using_swift_shader) { | |
156 // Init ANGLE platform here, before we call GetPlatformDisplay(). | |
157 // TODO(jmadill): Apply to all platforms eventually | |
158 ANGLEPlatformInitializeFunc angle_platform_init = | |
159 reinterpret_cast<ANGLEPlatformInitializeFunc>( | |
160 base::GetFunctionPointerFromNativeLibrary( | |
161 gles_library, "ANGLEPlatformInitialize")); | |
162 if (angle_platform_init) { | |
163 angle_platform_init(&g_angle_platform_impl.Get()); | |
164 | |
165 g_angle_platform_shutdown = reinterpret_cast<ANGLEPlatformShutdownFunc>( | |
166 base::GetFunctionPointerFromNativeLibrary(gles_library, | |
167 "ANGLEPlatformShutdown")); | |
168 } | |
169 } | |
170 | |
171 GLGetProcAddressProc get_proc_address = | 146 GLGetProcAddressProc get_proc_address = |
172 reinterpret_cast<GLGetProcAddressProc>( | 147 reinterpret_cast<GLGetProcAddressProc>( |
173 base::GetFunctionPointerFromNativeLibrary(egl_library, | 148 base::GetFunctionPointerFromNativeLibrary(egl_library, |
174 "eglGetProcAddress")); | 149 "eglGetProcAddress")); |
175 if (!get_proc_address) { | 150 if (!get_proc_address) { |
176 LOG(ERROR) << "eglGetProcAddress not found."; | 151 LOG(ERROR) << "eglGetProcAddress not found."; |
177 base::UnloadNativeLibrary(egl_library); | 152 base::UnloadNativeLibrary(egl_library); |
178 base::UnloadNativeLibrary(gles_library); | 153 base::UnloadNativeLibrary(gles_library); |
179 return false; | 154 return false; |
180 } | 155 } |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 } | 288 } |
314 | 289 |
315 void InitializeDebugGLBindings() { | 290 void InitializeDebugGLBindings() { |
316 InitializeDebugGLBindingsEGL(); | 291 InitializeDebugGLBindingsEGL(); |
317 InitializeDebugGLBindingsGL(); | 292 InitializeDebugGLBindingsGL(); |
318 InitializeDebugGLBindingsOSMESA(); | 293 InitializeDebugGLBindingsOSMESA(); |
319 InitializeDebugGLBindingsWGL(); | 294 InitializeDebugGLBindingsWGL(); |
320 } | 295 } |
321 | 296 |
322 void ShutdownGLPlatform() { | 297 void ShutdownGLPlatform() { |
323 // TODO(jmadill): Apply to all platforms eventually | 298 GLSurfaceEGL::ShutdownOneOff(); |
324 if (g_angle_platform_shutdown) { | |
325 g_angle_platform_shutdown(); | |
326 } | |
327 | |
328 ClearBindingsEGL(); | 299 ClearBindingsEGL(); |
329 ClearBindingsGL(); | 300 ClearBindingsGL(); |
330 ClearBindingsOSMESA(); | 301 ClearBindingsOSMESA(); |
331 ClearBindingsWGL(); | 302 ClearBindingsWGL(); |
332 } | 303 } |
333 | 304 |
334 } // namespace init | 305 } // namespace init |
335 } // namespace gl | 306 } // namespace gl |
OLD | NEW |