Bug 1883287 - Don't wait for the hidden window to be created on Linux to load the...
[gecko.git] / gfx / gl / GLContextGLX.h
blobb6f6e9a959137b06cd4a564471705d35dc603fa6
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/. */
7 #ifndef GLCONTEXTGLX_H_
8 #define GLCONTEXTGLX_H_
10 #include "GLContext.h"
11 #include "GLXLibrary.h"
12 #include "mozilla/X11Util.h"
14 namespace mozilla {
15 namespace gl {
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);
24 static bool FindVisual(Display* display, int screen, int* const out_visualId);
26 // Finds a GLXFBConfig compatible with the provided window.
27 static bool FindFBConfigForWindow(
28 Display* display, int screen, Window window,
29 GLXFBConfig* const out_config, int* const out_visid, bool aWebRender);
31 virtual ~GLContextGLX();
33 GLContextType GetContextType() const override { return GLContextType::GLX; }
35 static GLContextGLX* Cast(GLContext* gl) {
36 MOZ_ASSERT(gl->GetContextType() == GLContextType::GLX);
37 return static_cast<GLContextGLX*>(gl);
40 bool Init() override;
42 bool MakeCurrentImpl() const override;
44 bool IsCurrentImpl() const override;
46 Maybe<SymbolLoader> GetSymbolLoader() const override;
48 bool IsDoubleBuffered() const override;
50 bool SwapBuffers() override;
52 GLint GetBufferAge() const override;
54 void GetWSIInfo(nsCString* const out) const override;
56 // Overrides the current GLXDrawable backing the context and makes the
57 // context current.
58 bool OverrideDrawable(GLXDrawable drawable);
60 // Undoes the effect of a drawable override.
61 bool RestoreDrawable();
63 private:
64 friend class GLContextProviderGLX;
66 GLContextGLX(const GLContextDesc&, std::shared_ptr<gfx::XlibDisplay> aDisplay,
67 GLXDrawable aDrawable, GLXContext aContext, bool aDoubleBuffered,
68 Drawable aOwnedPixmap = X11None);
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;
79 GLXLibrary* const mGLX;
81 const bool mOwnsContext = true;
84 } // namespace gl
85 } // namespace mozilla
87 #endif // GLCONTEXTGLX_H_