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