OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/base_paths.h" | |
6 #include "base/command_line.h" | |
7 #include "base/file_path.h" | |
8 #include "base/logging.h" | |
9 #include "base/native_library.h" | |
10 #include "base/path_service.h" | |
11 #include "ui/gfx/gl/gl_bindings.h" | |
12 #include "ui/gfx/gl/gl_implementation.h" | |
13 | |
14 namespace gfx { | |
15 | |
16 namespace { | |
17 | |
18 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { | |
19 glClearDepthf(static_cast<GLclampf>(depth)); | |
20 } | |
21 | |
22 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, | |
23 GLclampd z_far) { | |
24 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far)); | |
25 } | |
26 | |
27 base::NativeLibrary LoadLibrary(const FilePath& filename) { | |
28 std::string error; | |
29 base::NativeLibrary library = base::LoadNativeLibrary(filename, &error); | |
30 if (!library) { | |
31 DVLOG(1) << "Failed to load " << filename.MaybeAsASCII() << ": " << error; | |
32 return NULL; | |
33 } | |
34 return library; | |
35 } | |
36 | |
37 base::NativeLibrary LoadLibrary(const char* filename) { | |
38 return LoadLibrary(FilePath(filename)); | |
39 } | |
40 | |
41 } // namespace anonymous | |
42 | |
43 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { | |
44 impls->push_back(kGLImplementationEGLGLES2); | |
45 } | |
46 | |
47 bool InitializeGLBindings(GLImplementation implementation) { | |
48 // Prevent reinitialization with a different implementation. Once the gpu | |
49 // unit tests have initialized with kGLImplementationMock, we don't want to | |
50 // later switch to another GL implementation. | |
51 if (GetGLImplementation() != kGLImplementationNone) | |
52 return true; | |
53 | |
54 switch (implementation) { | |
55 case kGLImplementationEGLGLES2: { | |
56 base::NativeLibrary gles_library = LoadLibrary("libGLESv2.so"); | |
57 if (!gles_library) | |
58 return false; | |
59 base::NativeLibrary egl_library = LoadLibrary("libEGL.so"); | |
60 if (!egl_library) { | |
61 base::UnloadNativeLibrary(gles_library); | |
62 return false; | |
63 } | |
64 | |
65 GLGetProcAddressProc get_proc_address = | |
66 reinterpret_cast<GLGetProcAddressProc>( | |
67 base::GetFunctionPointerFromNativeLibrary( | |
68 egl_library, "eglGetProcAddress")); | |
69 if (!get_proc_address) { | |
70 LOG(ERROR) << "eglGetProcAddress not found."; | |
71 base::UnloadNativeLibrary(egl_library); | |
72 base::UnloadNativeLibrary(gles_library); | |
73 return false; | |
74 } | |
75 | |
76 SetGLGetProcAddressProc(get_proc_address); | |
77 AddGLNativeLibrary(egl_library); | |
78 AddGLNativeLibrary(gles_library); | |
79 SetGLImplementation(kGLImplementationEGLGLES2); | |
80 | |
81 InitializeGLBindingsGL(); | |
82 InitializeGLBindingsEGL(); | |
83 | |
84 // These two functions take single precision float rather than double | |
85 // precision float parameters in GLES. | |
86 ::gfx::g_glClearDepth = MarshalClearDepthToClearDepthf; | |
87 ::gfx::g_glDepthRange = MarshalDepthRangeToDepthRangef; | |
88 break; | |
89 } | |
90 case kGLImplementationMockGL: { | |
91 SetGLGetProcAddressProc(GetMockGLProcAddress); | |
92 SetGLImplementation(kGLImplementationMockGL); | |
93 InitializeGLBindingsGL(); | |
94 break; | |
95 } | |
96 default: | |
97 NOTIMPLEMENTED() << "InitializeGLBindings on Android"; | |
98 return false; | |
99 } | |
100 | |
101 return true; | |
102 } | |
103 | |
104 bool InitializeGLExtensionBindings(GLImplementation implementation, | |
105 GLContext* context) { | |
106 switch (implementation) { | |
107 case kGLImplementationEGLGLES2: | |
108 InitializeGLExtensionBindingsGL(context); | |
109 InitializeGLExtensionBindingsEGL(context); | |
110 break; | |
111 case kGLImplementationMockGL: | |
112 InitializeGLExtensionBindingsGL(context); | |
113 break; | |
114 default: | |
115 return false; | |
116 } | |
117 | |
118 return true; | |
119 } | |
120 | |
121 void InitializeDebugGLBindings() { | |
122 } | |
123 | |
124 void ClearGLBindings() { | |
125 ClearGLBindingsEGL(); | |
126 ClearGLBindingsGL(); | |
127 SetGLImplementation(kGLImplementationNone); | |
128 | |
129 UnloadGLNativeLibraries(); | |
130 } | |
131 | |
132 } // namespace gfx | |
OLD | NEW |