OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
jonathan.backer
2011/07/26 14:56:27
This seems very similar to gl_implementation_linux
| |
5 #include <vector> | |
6 | |
7 #include "base/base_paths.h" | |
8 #include "base/command_line.h" | |
9 #include "base/file_path.h" | |
10 #include "base/logging.h" | |
11 #include "base/native_library.h" | |
12 #include "base/path_service.h" | |
13 #include "ui/gfx/gl/gl_bindings.h" | |
14 #include "ui/gfx/gl/gl_implementation.h" | |
15 | |
16 namespace gfx { | |
17 namespace { | |
18 | |
19 // TODO(piman): it should be Desktop GL marshalling from double to float. Today | |
20 // on native GLES, we do float->double->float. | |
21 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { | |
22 glClearDepthf(static_cast<GLclampf>(depth)); | |
23 } | |
24 | |
25 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, | |
26 GLclampd z_far) { | |
27 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far)); | |
28 } | |
29 | |
30 // Load a library, printing an error message on failure. | |
31 base::NativeLibrary LoadLibrary(const FilePath& filename) { | |
32 std::string error; | |
33 base::NativeLibrary library = base::LoadNativeLibrary(filename, | |
34 &error); | |
35 if (!library) { | |
36 VLOG(1) << "Failed to load " << filename.MaybeAsASCII() << ": " << error; | |
37 return NULL; | |
38 } | |
39 return library; | |
40 } | |
41 | |
42 base::NativeLibrary LoadLibrary(const char* filename) { | |
43 return LoadLibrary(FilePath(filename)); | |
44 } | |
45 | |
46 } // namespace anonymous | |
47 | |
48 bool InitializeGLBindings(GLImplementation implementation) { | |
49 // Prevent reinitialization with a different implementation. Once the gpu | |
50 // unit tests have initialized with kGLImplementationMock, we don't want to | |
51 // later switch to another GL implementation. | |
52 if (GetGLImplementation() != kGLImplementationNone) | |
53 return true; | |
54 | |
55 switch (implementation) { | |
56 case kGLImplementationEGLGLES2: { | |
57 base::NativeLibrary gles_library = LoadLibrary("libGLESv2.so"); | |
58 if (!gles_library) | |
59 return false; | |
60 base::NativeLibrary egl_library = LoadLibrary("libEGL.so"); | |
61 if (!egl_library) | |
62 return false; | |
63 | |
64 GLGetProcAddressProc get_proc_address = | |
65 reinterpret_cast<GLGetProcAddressProc>( | |
66 base::GetFunctionPointerFromNativeLibrary( | |
67 egl_library, "eglGetProcAddress")); | |
68 if (!get_proc_address) { | |
69 LOG(ERROR) << "eglGetProcAddress not found."; | |
70 base::UnloadNativeLibrary(egl_library); | |
71 base::UnloadNativeLibrary(gles_library); | |
72 return false; | |
73 } | |
74 | |
75 SetGLGetProcAddressProc(get_proc_address); | |
76 AddGLNativeLibrary(egl_library); | |
77 AddGLNativeLibrary(gles_library); | |
78 SetGLImplementation(kGLImplementationEGLGLES2); | |
79 | |
80 InitializeGLBindingsGL(); | |
81 InitializeGLBindingsEGL(); | |
82 | |
83 // These two functions take single precision float rather than double | |
84 // precision float parameters in GLES. | |
85 ::gfx::g_glClearDepth = MarshalClearDepthToClearDepthf; | |
86 ::gfx::g_glDepthRange = MarshalDepthRangeToDepthRangef; | |
87 break; | |
88 } | |
89 case kGLImplementationMockGL: { | |
90 SetGLGetProcAddressProc(GetMockGLProcAddress); | |
91 SetGLImplementation(kGLImplementationMockGL); | |
92 InitializeGLBindingsGL(); | |
93 break; | |
94 } | |
95 default: | |
96 return false; | |
97 } | |
98 | |
99 | |
100 return true; | |
101 } | |
102 | |
103 void InitializeDebugGLBindings() { | |
104 InitializeDebugGLBindingsEGL(); | |
105 InitializeDebugGLBindingsGL(); | |
106 } | |
107 | |
108 } // namespace gfx | |
OLD | NEW |