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" |
(...skipping 25 matching lines...) Expand all Loading... |
36 #else | 36 #else |
37 const char kGLLibraryName[] = "libGL.so.1"; | 37 const char kGLLibraryName[] = "libGL.so.1"; |
38 #endif | 38 #endif |
39 | 39 |
40 const char kGLESv2LibraryName[] = "libGLESv2.so.2"; | 40 const char kGLESv2LibraryName[] = "libGLESv2.so.2"; |
41 const char kEGLLibraryName[] = "libEGL.so.1"; | 41 const char kEGLLibraryName[] = "libEGL.so.1"; |
42 | 42 |
43 } // namespace | 43 } // namespace |
44 | 44 |
45 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { | 45 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { |
| 46 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 47 switches::kEnableUnsafeES3APIs)) { |
| 48 impls->push_back(kGLImplementationDesktopGLCoreProfile); |
| 49 } |
46 impls->push_back(kGLImplementationDesktopGL); | 50 impls->push_back(kGLImplementationDesktopGL); |
47 impls->push_back(kGLImplementationEGLGLES2); | 51 impls->push_back(kGLImplementationEGLGLES2); |
48 impls->push_back(kGLImplementationOSMesaGL); | 52 impls->push_back(kGLImplementationOSMesaGL); |
49 } | 53 } |
50 | 54 |
51 bool InitializeStaticGLBindings(GLImplementation implementation) { | 55 bool InitializeStaticGLBindings(GLImplementation implementation) { |
52 // Prevent reinitialization with a different implementation. Once the gpu | 56 // Prevent reinitialization with a different implementation. Once the gpu |
53 // unit tests have initialized with kGLImplementationMock, we don't want to | 57 // unit tests have initialized with kGLImplementationMock, we don't want to |
54 // later switch to another GL implementation. | 58 // later switch to another GL implementation. |
55 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); | 59 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); |
56 | 60 |
57 // Allow the main thread or another to initialize these bindings | 61 // Allow the main thread or another to initialize these bindings |
58 // after instituting restrictions on I/O. Going forward they will | 62 // after instituting restrictions on I/O. Going forward they will |
59 // likely be used in the browser process on most platforms. The | 63 // likely be used in the browser process on most platforms. The |
60 // one-time initialization cost is small, between 2 and 5 ms. | 64 // one-time initialization cost is small, between 2 and 5 ms. |
61 base::ThreadRestrictions::ScopedAllowIO allow_io; | 65 base::ThreadRestrictions::ScopedAllowIO allow_io; |
62 | 66 |
63 switch (implementation) { | 67 switch (implementation) { |
64 case kGLImplementationOSMesaGL: | 68 case kGLImplementationOSMesaGL: |
65 return InitializeStaticGLBindingsOSMesaGL(); | 69 return InitializeStaticGLBindingsOSMesaGL(); |
66 case kGLImplementationDesktopGL: { | 70 case kGLImplementationDesktopGL: |
| 71 case kGLImplementationDesktopGLCoreProfile: { |
67 base::NativeLibrary library = NULL; | 72 base::NativeLibrary library = NULL; |
68 const base::CommandLine* command_line = | 73 const base::CommandLine* command_line = |
69 base::CommandLine::ForCurrentProcess(); | 74 base::CommandLine::ForCurrentProcess(); |
70 | 75 |
71 if (command_line->HasSwitch(switches::kTestGLLib)) | 76 if (command_line->HasSwitch(switches::kTestGLLib)) |
72 library = LoadLibraryAndPrintError( | 77 library = LoadLibraryAndPrintError( |
73 command_line->GetSwitchValueASCII(switches::kTestGLLib).c_str()); | 78 command_line->GetSwitchValueASCII(switches::kTestGLLib).c_str()); |
74 | 79 |
75 if (!library) { | 80 if (!library) { |
76 library = LoadLibraryAndPrintError(kGLLibraryName); | 81 library = LoadLibraryAndPrintError(kGLLibraryName); |
77 } | 82 } |
78 | 83 |
79 if (!library) | 84 if (!library) |
80 return false; | 85 return false; |
81 | 86 |
82 GLGetProcAddressProc get_proc_address = | 87 GLGetProcAddressProc get_proc_address = |
83 reinterpret_cast<GLGetProcAddressProc>( | 88 reinterpret_cast<GLGetProcAddressProc>( |
84 base::GetFunctionPointerFromNativeLibrary( | 89 base::GetFunctionPointerFromNativeLibrary( |
85 library, "glXGetProcAddress")); | 90 library, "glXGetProcAddress")); |
86 if (!get_proc_address) { | 91 if (!get_proc_address) { |
87 LOG(ERROR) << "glxGetProcAddress not found."; | 92 LOG(ERROR) << "glxGetProcAddress not found."; |
88 base::UnloadNativeLibrary(library); | 93 base::UnloadNativeLibrary(library); |
89 return false; | 94 return false; |
90 } | 95 } |
91 | 96 |
92 SetGLGetProcAddressProc(get_proc_address); | 97 SetGLGetProcAddressProc(get_proc_address); |
93 AddGLNativeLibrary(library); | 98 AddGLNativeLibrary(library); |
94 SetGLImplementation(kGLImplementationDesktopGL); | 99 SetGLImplementation(implementation); |
95 | 100 |
96 InitializeStaticGLBindingsGL(); | 101 InitializeStaticGLBindingsGL(); |
97 InitializeStaticGLBindingsGLX(); | 102 InitializeStaticGLBindingsGLX(); |
98 break; | 103 break; |
99 } | 104 } |
100 case kGLImplementationEGLGLES2: { | 105 case kGLImplementationEGLGLES2: { |
101 base::NativeLibrary gles_library = | 106 base::NativeLibrary gles_library = |
102 LoadLibraryAndPrintError(kGLESv2LibraryName); | 107 LoadLibraryAndPrintError(kGLESv2LibraryName); |
103 if (!gles_library) | 108 if (!gles_library) |
104 return false; | 109 return false; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 } | 149 } |
145 | 150 |
146 | 151 |
147 return true; | 152 return true; |
148 } | 153 } |
149 | 154 |
150 bool InitializeDynamicGLBindings(GLImplementation implementation, | 155 bool InitializeDynamicGLBindings(GLImplementation implementation, |
151 GLContext* context) { | 156 GLContext* context) { |
152 switch (implementation) { | 157 switch (implementation) { |
153 case kGLImplementationOSMesaGL: | 158 case kGLImplementationOSMesaGL: |
154 case kGLImplementationDesktopGL: | 159 case kGLImplementationDesktopGL: |
| 160 case kGLImplementationDesktopGLCoreProfile: |
155 case kGLImplementationEGLGLES2: | 161 case kGLImplementationEGLGLES2: |
156 InitializeDynamicGLBindingsGL(context); | 162 InitializeDynamicGLBindingsGL(context); |
157 break; | 163 break; |
158 case kGLImplementationMockGL: | 164 case kGLImplementationMockGL: |
159 if (!context) { | 165 if (!context) { |
160 scoped_refptr<GLContextStubWithExtensions> mock_context( | 166 scoped_refptr<GLContextStubWithExtensions> mock_context( |
161 new GLContextStubWithExtensions()); | 167 new GLContextStubWithExtensions()); |
162 mock_context->SetGLVersionString("3.0"); | 168 mock_context->SetGLVersionString("3.0"); |
163 InitializeDynamicGLBindingsGL(mock_context.get()); | 169 InitializeDynamicGLBindingsGL(mock_context.get()); |
164 } else | 170 } else |
(...skipping 19 matching lines...) Expand all Loading... |
184 ClearGLBindingsGLX(); | 190 ClearGLBindingsGLX(); |
185 ClearGLBindingsOSMESA(); | 191 ClearGLBindingsOSMESA(); |
186 SetGLImplementation(kGLImplementationNone); | 192 SetGLImplementation(kGLImplementationNone); |
187 | 193 |
188 UnloadGLNativeLibraries(); | 194 UnloadGLNativeLibraries(); |
189 } | 195 } |
190 | 196 |
191 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { | 197 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { |
192 switch (GetGLImplementation()) { | 198 switch (GetGLImplementation()) { |
193 case kGLImplementationDesktopGL: | 199 case kGLImplementationDesktopGL: |
| 200 case kGLImplementationDesktopGLCoreProfile: |
194 return GetGLWindowSystemBindingInfoGLX(info); | 201 return GetGLWindowSystemBindingInfoGLX(info); |
195 case kGLImplementationEGLGLES2: | 202 case kGLImplementationEGLGLES2: |
196 return GetGLWindowSystemBindingInfoEGL(info); | 203 return GetGLWindowSystemBindingInfoEGL(info); |
197 default: | 204 default: |
198 return false; | 205 return false; |
199 } | 206 } |
200 return false; | 207 return false; |
201 } | 208 } |
202 | 209 |
203 } // namespace gfx | 210 } // namespace gfx |
OLD | NEW |