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