GLContextProviderLinux.cpp (2109B)
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #include "prenv.h" 7 8 #include "GLContextProvider.h" 9 #include "mozilla/gfx/gfxVars.h" 10 11 namespace mozilla::gl { 12 13 using namespace mozilla::gfx; 14 using namespace mozilla::widget; 15 16 #ifdef MOZ_X11 17 static class GLContextProviderGLX sGLContextProviderGLX; 18 #endif 19 static class GLContextProviderEGL sGLContextProviderEGL; 20 21 already_AddRefed<GLContext> GLContextProviderLinux::CreateForCompositorWidget( 22 CompositorWidget* aCompositorWidget, bool aHardwareWebRender, 23 bool aForceAccelerated) { 24 if (gfxVars::UseEGL()) { 25 return sGLContextProviderEGL.CreateForCompositorWidget( 26 aCompositorWidget, aHardwareWebRender, aForceAccelerated); 27 #ifdef MOZ_X11 28 } else { 29 return sGLContextProviderGLX.CreateForCompositorWidget( 30 aCompositorWidget, aHardwareWebRender, aForceAccelerated); 31 #endif 32 } 33 } 34 35 /*static*/ 36 already_AddRefed<GLContext> GLContextProviderLinux::CreateHeadless( 37 const GLContextCreateDesc& desc, nsACString* const out_failureId) { 38 if (gfxVars::UseEGL() || 39 bool(desc.flags & CreateContextFlags::FORBID_HARDWARE)) { 40 // We request EGL if software is required, because we don't know 41 // what X11 is using. It could be software or hardware. 42 return sGLContextProviderEGL.CreateHeadless(desc, out_failureId); 43 #ifdef MOZ_X11 44 } else { 45 return sGLContextProviderGLX.CreateHeadless(desc, out_failureId); 46 #endif 47 } 48 } 49 50 /*static*/ 51 GLContext* GLContextProviderLinux::GetGlobalContext() { 52 if (gfxVars::UseEGL()) { 53 return sGLContextProviderEGL.GetGlobalContext(); 54 #ifdef MOZ_X11 55 } else { 56 return sGLContextProviderGLX.GetGlobalContext(); 57 #endif 58 } 59 } 60 61 /*static*/ 62 void GLContextProviderLinux::Shutdown() { 63 if (gfxVars::UseEGL()) { 64 sGLContextProviderEGL.Shutdown(); 65 #ifdef MOZ_X11 66 } else { 67 sGLContextProviderGLX.Shutdown(); 68 #endif 69 } 70 } 71 72 } // namespace mozilla::gl