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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
10 #include "ui/gl/gl_bindings.h" | 10 #include "ui/gl/gl_bindings.h" |
| 11 #include "ui/gl/gl_context_mock_version.h" |
11 #include "ui/gl/gl_egl_api_implementation.h" | 12 #include "ui/gl/gl_egl_api_implementation.h" |
12 #include "ui/gl/gl_gl_api_implementation.h" | 13 #include "ui/gl/gl_gl_api_implementation.h" |
13 #include "ui/gl/gl_glx_api_implementation.h" | 14 #include "ui/gl/gl_glx_api_implementation.h" |
14 #include "ui/gl/gl_implementation.h" | 15 #include "ui/gl/gl_implementation.h" |
15 #include "ui/gl/gl_implementation_linux.h" | 16 #include "ui/gl/gl_implementation_linux.h" |
16 #include "ui/gl/gl_osmesa_api_implementation.h" | 17 #include "ui/gl/gl_osmesa_api_implementation.h" |
17 #include "ui/gl/gl_switches.h" | 18 #include "ui/gl/gl_switches.h" |
18 | 19 |
19 namespace gfx { | 20 namespace gfx { |
20 namespace { | 21 namespace { |
(...skipping 10 matching lines...) Expand all Loading... |
31 } | 32 } |
32 | 33 |
33 } // namespace | 34 } // namespace |
34 | 35 |
35 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { | 36 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { |
36 impls->push_back(kGLImplementationDesktopGL); | 37 impls->push_back(kGLImplementationDesktopGL); |
37 impls->push_back(kGLImplementationEGLGLES2); | 38 impls->push_back(kGLImplementationEGLGLES2); |
38 impls->push_back(kGLImplementationOSMesaGL); | 39 impls->push_back(kGLImplementationOSMesaGL); |
39 } | 40 } |
40 | 41 |
41 bool InitializeGLBindings(GLImplementation implementation) { | 42 bool InitializeStaticGLBindings(GLImplementation implementation) { |
42 // Prevent reinitialization with a different implementation. Once the gpu | 43 // Prevent reinitialization with a different implementation. Once the gpu |
43 // unit tests have initialized with kGLImplementationMock, we don't want to | 44 // unit tests have initialized with kGLImplementationMock, we don't want to |
44 // later switch to another GL implementation. | 45 // later switch to another GL implementation. |
45 if (GetGLImplementation() != kGLImplementationNone) | 46 if (GetGLImplementation() != kGLImplementationNone) |
46 return true; | 47 return true; |
47 | 48 |
48 // Allow the main thread or another to initialize these bindings | 49 // Allow the main thread or another to initialize these bindings |
49 // after instituting restrictions on I/O. Going forward they will | 50 // after instituting restrictions on I/O. Going forward they will |
50 // likely be used in the browser process on most platforms. The | 51 // likely be used in the browser process on most platforms. The |
51 // one-time initialization cost is small, between 2 and 5 ms. | 52 // one-time initialization cost is small, between 2 and 5 ms. |
52 base::ThreadRestrictions::ScopedAllowIO allow_io; | 53 base::ThreadRestrictions::ScopedAllowIO allow_io; |
53 | 54 |
54 switch (implementation) { | 55 switch (implementation) { |
55 case kGLImplementationOSMesaGL: | 56 case kGLImplementationOSMesaGL: |
56 return InitializeGLBindingsOSMesaGL(); | 57 return InitializeStaticGLBindingsOSMesaGL(); |
57 case kGLImplementationDesktopGL: { | 58 case kGLImplementationDesktopGL: { |
58 base::NativeLibrary library = NULL; | 59 base::NativeLibrary library = NULL; |
59 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 60 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
60 | 61 |
61 if (command_line->HasSwitch(switches::kTestGLLib)) | 62 if (command_line->HasSwitch(switches::kTestGLLib)) |
62 library = LoadLibrary(command_line->GetSwitchValueASCII( | 63 library = LoadLibrary(command_line->GetSwitchValueASCII( |
63 switches::kTestGLLib).c_str()); | 64 switches::kTestGLLib).c_str()); |
64 | 65 |
65 if (!library) { | 66 if (!library) { |
66 #if defined(OS_OPENBSD) | 67 #if defined(OS_OPENBSD) |
(...skipping 13 matching lines...) Expand all Loading... |
80 if (!get_proc_address) { | 81 if (!get_proc_address) { |
81 LOG(ERROR) << "glxGetProcAddress not found."; | 82 LOG(ERROR) << "glxGetProcAddress not found."; |
82 base::UnloadNativeLibrary(library); | 83 base::UnloadNativeLibrary(library); |
83 return false; | 84 return false; |
84 } | 85 } |
85 | 86 |
86 SetGLGetProcAddressProc(get_proc_address); | 87 SetGLGetProcAddressProc(get_proc_address); |
87 AddGLNativeLibrary(library); | 88 AddGLNativeLibrary(library); |
88 SetGLImplementation(kGLImplementationDesktopGL); | 89 SetGLImplementation(kGLImplementationDesktopGL); |
89 | 90 |
90 InitializeGLBindingsGL(); | 91 InitializeStaticGLBindingsGL(); |
91 InitializeGLBindingsGLX(); | 92 InitializeStaticGLBindingsGLX(); |
92 break; | 93 break; |
93 } | 94 } |
94 case kGLImplementationEGLGLES2: { | 95 case kGLImplementationEGLGLES2: { |
95 base::NativeLibrary gles_library = LoadLibrary("libGLESv2.so.2"); | 96 base::NativeLibrary gles_library = LoadLibrary("libGLESv2.so.2"); |
96 if (!gles_library) | 97 if (!gles_library) |
97 return false; | 98 return false; |
98 base::NativeLibrary egl_library = LoadLibrary("libEGL.so.1"); | 99 base::NativeLibrary egl_library = LoadLibrary("libEGL.so.1"); |
99 if (!egl_library) { | 100 if (!egl_library) { |
100 base::UnloadNativeLibrary(gles_library); | 101 base::UnloadNativeLibrary(gles_library); |
101 return false; | 102 return false; |
102 } | 103 } |
103 | 104 |
104 GLGetProcAddressProc get_proc_address = | 105 GLGetProcAddressProc get_proc_address = |
105 reinterpret_cast<GLGetProcAddressProc>( | 106 reinterpret_cast<GLGetProcAddressProc>( |
106 base::GetFunctionPointerFromNativeLibrary( | 107 base::GetFunctionPointerFromNativeLibrary( |
107 egl_library, "eglGetProcAddress")); | 108 egl_library, "eglGetProcAddress")); |
108 if (!get_proc_address) { | 109 if (!get_proc_address) { |
109 LOG(ERROR) << "eglGetProcAddress not found."; | 110 LOG(ERROR) << "eglGetProcAddress not found."; |
110 base::UnloadNativeLibrary(egl_library); | 111 base::UnloadNativeLibrary(egl_library); |
111 base::UnloadNativeLibrary(gles_library); | 112 base::UnloadNativeLibrary(gles_library); |
112 return false; | 113 return false; |
113 } | 114 } |
114 | 115 |
115 SetGLGetProcAddressProc(get_proc_address); | 116 SetGLGetProcAddressProc(get_proc_address); |
116 AddGLNativeLibrary(egl_library); | 117 AddGLNativeLibrary(egl_library); |
117 AddGLNativeLibrary(gles_library); | 118 AddGLNativeLibrary(gles_library); |
118 SetGLImplementation(kGLImplementationEGLGLES2); | 119 SetGLImplementation(kGLImplementationEGLGLES2); |
119 | 120 |
120 InitializeGLBindingsGL(); | 121 InitializeStaticGLBindingsGL(); |
121 InitializeGLBindingsEGL(); | 122 InitializeStaticGLBindingsEGL(); |
122 | 123 |
123 // These two functions take single precision float rather than double | 124 // These two functions take single precision float rather than double |
124 // precision float parameters in GLES. | 125 // precision float parameters in GLES. |
125 ::gfx::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf; | 126 ::gfx::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf; |
126 ::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef; | 127 ::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef; |
127 break; | 128 break; |
128 } | 129 } |
129 case kGLImplementationMockGL: { | 130 case kGLImplementationMockGL: { |
130 SetGLGetProcAddressProc(GetMockGLProcAddress); | 131 SetGLGetProcAddressProc(GetMockGLProcAddress); |
131 SetGLImplementation(kGLImplementationMockGL); | 132 SetGLImplementation(kGLImplementationMockGL); |
132 InitializeGLBindingsGL(); | 133 InitializeStaticGLBindingsGL(); |
133 break; | 134 break; |
134 } | 135 } |
135 default: | 136 default: |
136 return false; | 137 return false; |
137 } | 138 } |
138 | 139 |
139 | 140 |
140 return true; | 141 return true; |
141 } | 142 } |
142 | 143 |
143 bool InitializeGLExtensionBindings(GLImplementation implementation, | 144 bool InitializeDynamicGLBindings(GLImplementation implementation, |
144 GLContext* context) { | 145 GLContext* context) { |
145 switch (implementation) { | 146 switch (implementation) { |
146 case kGLImplementationOSMesaGL: | 147 case kGLImplementationOSMesaGL: |
147 InitializeGLExtensionBindingsGL(context); | 148 InitializeDynamicGLBindingsGL(context); |
148 InitializeGLExtensionBindingsOSMESA(context); | 149 InitializeDynamicGLBindingsOSMESA(context); |
149 break; | 150 break; |
150 case kGLImplementationDesktopGL: | 151 case kGLImplementationDesktopGL: |
151 InitializeGLExtensionBindingsGL(context); | 152 InitializeDynamicGLBindingsGL(context); |
152 InitializeGLExtensionBindingsGLX(context); | 153 InitializeDynamicGLBindingsGLX(context); |
153 break; | 154 break; |
154 case kGLImplementationEGLGLES2: | 155 case kGLImplementationEGLGLES2: |
155 InitializeGLExtensionBindingsGL(context); | 156 InitializeDynamicGLBindingsGL(context); |
156 InitializeGLExtensionBindingsEGL(context); | 157 InitializeDynamicGLBindingsEGL(context); |
157 break; | 158 break; |
158 case kGLImplementationMockGL: | 159 case kGLImplementationMockGL: |
159 InitializeGLExtensionBindingsGL(context); | 160 { |
| 161 scoped_refptr<GLContextMockVersion> mock_context( |
| 162 new GLContextMockVersion("3.0")); |
| 163 InitializeDynamicGLBindingsGL(mock_context.get()); |
| 164 } |
160 break; | 165 break; |
161 default: | 166 default: |
162 return false; | 167 return false; |
163 } | 168 } |
164 | 169 |
165 return true; | 170 return true; |
166 } | 171 } |
167 | 172 |
168 void InitializeDebugGLBindings() { | 173 void InitializeDebugGLBindings() { |
169 InitializeDebugGLBindingsEGL(); | 174 InitializeDebugGLBindingsEGL(); |
(...skipping 18 matching lines...) Expand all Loading... |
188 return GetGLWindowSystemBindingInfoGLX(info); | 193 return GetGLWindowSystemBindingInfoGLX(info); |
189 case kGLImplementationEGLGLES2: | 194 case kGLImplementationEGLGLES2: |
190 return GetGLWindowSystemBindingInfoEGL(info); | 195 return GetGLWindowSystemBindingInfoEGL(info); |
191 default: | 196 default: |
192 return false; | 197 return false; |
193 } | 198 } |
194 return false; | 199 return false; |
195 } | 200 } |
196 | 201 |
197 } // namespace gfx | 202 } // namespace gfx |
OLD | NEW |