GLContextGLX.h (2781B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef GLCONTEXTGLX_H_ 8 #define GLCONTEXTGLX_H_ 9 10 #include "GLContext.h" 11 #include "GLXLibrary.h" 12 #include "mozilla/X11Util.h" 13 14 namespace mozilla { 15 namespace gl { 16 17 class GLContextGLX : public GLContext { 18 public: 19 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GLContextGLX, override) 20 static already_AddRefed<GLContextGLX> CreateGLContext( 21 const GLContextDesc&, std::shared_ptr<gfx::XlibDisplay> display, 22 GLXDrawable drawable, GLXFBConfig cfg, Drawable ownedPixmap = X11None); 23 24 static bool FindVisual(Display* display, int screen, int* const out_visualId); 25 26 // Finds a GLXFBConfig compatible with the provided window. 27 static bool FindFBConfigForWindow(Display* display, int screen, Window window, 28 GLXFBConfig* const out_config, 29 int* const out_visid, bool aWebRender); 30 31 virtual ~GLContextGLX(); 32 33 GLContextType GetContextType() const override { return GLContextType::GLX; } 34 35 static GLContextGLX* Cast(GLContext* gl) { 36 MOZ_ASSERT(gl->GetContextType() == GLContextType::GLX); 37 return static_cast<GLContextGLX*>(gl); 38 } 39 40 bool Init() override; 41 42 bool MakeCurrentImpl() const override; 43 44 bool IsCurrentImpl() const override; 45 46 Maybe<SymbolLoader> GetSymbolLoader() const override; 47 48 bool IsDoubleBuffered() const override; 49 50 bool SwapBuffers() override; 51 52 GLint GetBufferAge() const override; 53 54 void GetWSIInfo(nsCString* const out) const override; 55 56 // Overrides the current GLXDrawable backing the context and makes the 57 // context current. 58 bool OverrideDrawable(GLXDrawable drawable); 59 60 // Undoes the effect of a drawable override. 61 bool RestoreDrawable(); 62 63 private: 64 friend class GLContextProviderGLX; 65 66 GLContextGLX(const GLContextDesc&, std::shared_ptr<gfx::XlibDisplay> aDisplay, 67 GLXDrawable aDrawable, GLXContext aContext, bool aDoubleBuffered, 68 Drawable aOwnedPixmap = X11None); 69 70 const GLXContext mContext; 71 const std::shared_ptr<gfx::XlibDisplay> mDisplay; 72 const GLXDrawable mDrawable; 73 // The X pixmap associated with the GLX pixmap. If this is provided, then this 74 // class assumes responsibility for freeing both. Otherwise, the user of this 75 // class is responsibility for freeing the drawables. 76 const Drawable mOwnedPixmap; 77 const bool mDoubleBuffered; 78 79 GLXLibrary* const mGLX; 80 81 const bool mOwnsContext = true; 82 }; 83 84 } // namespace gl 85 } // namespace mozilla 86 87 #endif // GLCONTEXTGLX_H_