Chromium Code Reviews| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | |
| 6 #include "ui/gl/gl_bindings.h" | 7 #include "ui/gl/gl_bindings.h" |
| 7 #include "ui/gl/gl_context_stub_with_extensions.h" | 8 #include "ui/gl/gl_context_stub_with_extensions.h" |
| 8 #include "ui/gl/gl_egl_api_implementation.h" | 9 #include "ui/gl/gl_egl_api_implementation.h" |
| 9 #include "ui/gl/gl_gl_api_implementation.h" | 10 #include "ui/gl/gl_gl_api_implementation.h" |
| 10 #include "ui/gl/gl_implementation.h" | 11 #include "ui/gl/gl_implementation.h" |
| 11 #include "ui/gl/gl_implementation_osmesa.h" | 12 #include "ui/gl/gl_implementation_osmesa.h" |
| 12 #include "ui/gl/gl_osmesa_api_implementation.h" | 13 #include "ui/gl/gl_osmesa_api_implementation.h" |
| 13 #include "ui/ozone/public/ozone_platform.h" | 14 #include "ui/ozone/public/ozone_platform.h" |
| 14 #include "ui/ozone/public/surface_factory_ozone.h" | 15 #include "ui/ozone/public/surface_factory_ozone.h" |
| 15 | 16 |
| 17 #if defined(USE_GLX) | |
| 18 #include "ui/gl/gl_glx_api_implementation.h" | |
| 19 #endif | |
| 20 | |
| 16 namespace gfx { | 21 namespace gfx { |
| 17 | 22 |
| 18 namespace { | 23 namespace { |
| 19 | 24 |
| 20 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { | 25 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { |
| 21 glClearDepthf(static_cast<GLclampf>(depth)); | 26 glClearDepthf(static_cast<GLclampf>(depth)); |
| 22 } | 27 } |
| 23 | 28 |
| 24 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, | 29 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, |
| 25 GLclampd z_far) { | 30 GLclampd z_far) { |
| 26 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far)); | 31 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far)); |
| 27 } | 32 } |
| 28 | 33 |
| 34 #if defined(USE_GLX) | |
| 35 #if defined(OS_OPENBSD) | |
| 36 const char kGLLibraryName[] = "libGL.so"; | |
| 37 #else | |
| 38 const char kGLLibraryName[] = "libGL.so.1"; | |
| 39 #endif | |
| 40 #endif | |
| 41 | |
| 29 } // namespace | 42 } // namespace |
| 30 | 43 |
| 31 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { | 44 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { |
| 45 #if defined(USE_GLX) | |
| 46 // TODO: Discuss/change this before submitting CL. | |
|
rjkroege
2016/04/27 19:08:12
See my previous mutter. I don't really like this.
| |
| 47 ui::OzonePlatform::InitializeForGPU(); | |
| 48 // DesktopGL implies GLX on Linux. We only support GLX running the Ozone X11 | |
| 49 // platform, which requires a runtime check. | |
| 50 if (ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone()->SupportsGLX()) | |
| 51 impls->push_back(kGLImplementationDesktopGL); | |
| 52 #endif | |
| 32 impls->push_back(kGLImplementationEGLGLES2); | 53 impls->push_back(kGLImplementationEGLGLES2); |
| 33 impls->push_back(kGLImplementationOSMesaGL); | 54 impls->push_back(kGLImplementationOSMesaGL); |
| 34 } | 55 } |
| 35 | 56 |
| 36 bool InitializeStaticGLBindings(GLImplementation implementation) { | 57 bool InitializeStaticGLBindings(GLImplementation implementation) { |
| 37 // Prevent reinitialization with a different implementation. Once the gpu | 58 // Prevent reinitialization with a different implementation. Once the gpu |
| 38 // unit tests have initialized with kGLImplementationMock, we don't want to | 59 // unit tests have initialized with kGLImplementationMock, we don't want to |
| 39 // later switch to another GL implementation. | 60 // later switch to another GL implementation. |
| 40 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); | 61 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); |
| 41 ui::OzonePlatform::InitializeForGPU(); | 62 ui::OzonePlatform::InitializeForGPU(); |
| 42 | 63 |
| 43 switch (implementation) { | 64 switch (implementation) { |
| 44 case kGLImplementationOSMesaGL: | 65 case kGLImplementationOSMesaGL: |
| 45 return InitializeStaticGLBindingsOSMesaGL(); | 66 return InitializeStaticGLBindingsOSMesaGL(); |
| 67 #if defined(USE_GLX) | |
| 68 case kGLImplementationDesktopGL: { | |
| 69 const base::CommandLine* command_line = | |
| 70 base::CommandLine::ForCurrentProcess(); | |
| 71 | |
| 72 base::NativeLibrary library = nullptr; | |
| 73 if (command_line->HasSwitch(switches::kTestGLLib)) { | |
| 74 library = LoadLibraryAndPrintError( | |
| 75 command_line->GetSwitchValueASCII(switches::kTestGLLib).c_str()); | |
| 76 } else { | |
| 77 library = LoadLibraryAndPrintError(kGLLibraryName); | |
| 78 } | |
| 79 | |
| 80 if (!library) | |
| 81 return false; | |
| 82 | |
| 83 GLGetProcAddressProc get_proc_address = | |
| 84 reinterpret_cast<GLGetProcAddressProc>( | |
| 85 base::GetFunctionPointerFromNativeLibrary(library, | |
| 86 "glXGetProcAddress")); | |
| 87 if (!get_proc_address) { | |
| 88 LOG(ERROR) << "glxGetProcAddress not found."; | |
| 89 base::UnloadNativeLibrary(library); | |
| 90 return false; | |
| 91 } | |
| 92 | |
| 93 SetGLGetProcAddressProc(get_proc_address); | |
| 94 AddGLNativeLibrary(library); | |
| 95 SetGLImplementation(kGLImplementationDesktopGL); | |
| 96 | |
| 97 InitializeStaticGLBindingsGL(); | |
| 98 InitializeStaticGLBindingsGLX(); | |
| 99 break; | |
| 100 } | |
| 101 #endif | |
| 46 case kGLImplementationEGLGLES2: | 102 case kGLImplementationEGLGLES2: |
| 47 if (!ui::OzonePlatform::GetInstance() | 103 if (!ui::OzonePlatform::GetInstance() |
| 48 ->GetSurfaceFactoryOzone() | 104 ->GetSurfaceFactoryOzone() |
| 49 ->LoadEGLGLES2Bindings(base::Bind(&AddGLNativeLibrary), | 105 ->LoadEGLGLES2Bindings(base::Bind(&AddGLNativeLibrary), |
| 50 base::Bind(&SetGLGetProcAddressProc))) | 106 base::Bind(&SetGLGetProcAddressProc))) |
| 51 return false; | 107 return false; |
| 52 SetGLImplementation(kGLImplementationEGLGLES2); | 108 SetGLImplementation(kGLImplementationEGLGLES2); |
| 53 InitializeStaticGLBindingsGL(); | 109 InitializeStaticGLBindingsGL(); |
| 54 InitializeStaticGLBindingsEGL(); | 110 InitializeStaticGLBindingsEGL(); |
| 55 | 111 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 69 return false; | 125 return false; |
| 70 } | 126 } |
| 71 | 127 |
| 72 return true; | 128 return true; |
| 73 } | 129 } |
| 74 | 130 |
| 75 bool InitializeDynamicGLBindings(GLImplementation implementation, | 131 bool InitializeDynamicGLBindings(GLImplementation implementation, |
| 76 GLContext* context) { | 132 GLContext* context) { |
| 77 switch (implementation) { | 133 switch (implementation) { |
| 78 case kGLImplementationOSMesaGL: | 134 case kGLImplementationOSMesaGL: |
| 135 case kGLImplementationDesktopGL: | |
| 79 case kGLImplementationEGLGLES2: | 136 case kGLImplementationEGLGLES2: |
| 80 InitializeDynamicGLBindingsGL(context); | 137 InitializeDynamicGLBindingsGL(context); |
| 81 break; | 138 break; |
| 82 case kGLImplementationMockGL: | 139 case kGLImplementationMockGL: |
| 83 if (!context) { | 140 if (!context) { |
| 84 scoped_refptr<GLContextStubWithExtensions> mock_context( | 141 scoped_refptr<GLContextStubWithExtensions> mock_context( |
| 85 new GLContextStubWithExtensions()); | 142 new GLContextStubWithExtensions()); |
| 86 mock_context->SetGLVersionString("3.0"); | 143 mock_context->SetGLVersionString("3.0"); |
| 87 InitializeDynamicGLBindingsGL(mock_context.get()); | 144 InitializeDynamicGLBindingsGL(mock_context.get()); |
| 88 } else { | 145 } else { |
| 89 InitializeDynamicGLBindingsGL(context); | 146 InitializeDynamicGLBindingsGL(context); |
| 90 } | 147 } |
| 91 break; | 148 break; |
| 92 default: | 149 default: |
| 93 return false; | 150 return false; |
| 94 } | 151 } |
| 95 | 152 |
| 96 return true; | 153 return true; |
| 97 } | 154 } |
| 98 | 155 |
| 99 void InitializeDebugGLBindings() { | 156 void InitializeDebugGLBindings() { |
| 100 InitializeDebugGLBindingsEGL(); | 157 InitializeDebugGLBindingsEGL(); |
| 101 InitializeDebugGLBindingsGL(); | 158 InitializeDebugGLBindingsGL(); |
| 159 #if defined(USE_GLX) | |
| 160 InitializeDebugGLBindingsGLX(); | |
| 161 #endif | |
| 102 InitializeDebugGLBindingsOSMESA(); | 162 InitializeDebugGLBindingsOSMESA(); |
| 103 } | 163 } |
| 104 | 164 |
| 105 void ClearGLBindings() { | 165 void ClearGLBindings() { |
| 106 ClearGLBindingsEGL(); | 166 ClearGLBindingsEGL(); |
| 107 ClearGLBindingsGL(); | 167 ClearGLBindingsGL(); |
| 168 #if defined(USE_GLX) | |
| 169 ClearGLBindingsGLX(); | |
| 170 #endif | |
| 108 ClearGLBindingsOSMESA(); | 171 ClearGLBindingsOSMESA(); |
| 109 SetGLImplementation(kGLImplementationNone); | 172 SetGLImplementation(kGLImplementationNone); |
| 110 UnloadGLNativeLibraries(); | 173 UnloadGLNativeLibraries(); |
| 111 } | 174 } |
| 112 | 175 |
| 113 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { | 176 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { |
| 114 switch (GetGLImplementation()) { | 177 switch (GetGLImplementation()) { |
| 178 #if defined(USE_GLX) | |
| 179 case kGLImplementationDesktopGL: | |
| 180 return GetGLWindowSystemBindingInfoGLX(info); | |
| 181 #endif | |
| 115 case kGLImplementationEGLGLES2: | 182 case kGLImplementationEGLGLES2: |
| 116 return GetGLWindowSystemBindingInfoEGL(info); | 183 return GetGLWindowSystemBindingInfoEGL(info); |
| 117 default: | 184 default: |
| 118 return false; | 185 return false; |
| 119 } | 186 } |
| 120 return false; | 187 return false; |
| 121 } | 188 } |
| 122 | 189 |
| 123 } // namespace gfx | 190 } // namespace gfx |
| OLD | NEW |