Bug 1760967 [wpt PR 33319] - Pin remaining dependencies in tools/ci/requirements_buil...
[gecko.git] / gfx / gl / GLContextEGL.h
blob4586ce493e33795fb955372a55455ebcda26ba7a
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 GLCONTEXTEGL_H_
8 #define GLCONTEXTEGL_H_
10 #include "GLContext.h"
11 #include "GLLibraryEGL.h"
12 #include "nsRegion.h"
13 #include <memory>
15 namespace mozilla {
16 namespace layers {
17 class SurfaceTextureImage;
18 } // namespace layers
19 namespace widget {
20 class CompositorWidget;
21 } // namespace widget
22 namespace gl {
24 inline std::shared_ptr<EglDisplay> DefaultEglDisplay(
25 nsACString* const out_failureId) {
26 const auto lib = GLLibraryEGL::Get(out_failureId);
27 if (!lib) {
28 return nullptr;
30 return lib->DefaultDisplay(out_failureId);
33 // -
35 class GLContextEGL final : public GLContext {
36 public:
37 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GLContextEGL, override)
39 static RefPtr<GLContextEGL> CreateGLContext(
40 std::shared_ptr<EglDisplay>, const GLContextDesc&, EGLConfig config,
41 EGLSurface surface, const bool useGles, nsACString* const out_failureId);
43 private:
44 GLContextEGL(std::shared_ptr<EglDisplay>, const GLContextDesc&,
45 EGLConfig config, EGLSurface surface, EGLContext context);
46 ~GLContextEGL();
48 public:
49 virtual GLContextType GetContextType() const override {
50 return GLContextType::EGL;
53 static GLContextEGL* Cast(GLContext* gl) {
54 MOZ_ASSERT(gl->GetContextType() == GLContextType::EGL);
55 return static_cast<GLContextEGL*>(gl);
58 bool Init() override;
60 virtual bool IsDoubleBuffered() const override { return mIsDoubleBuffered; }
62 void SetIsDoubleBuffered(bool aIsDB) { mIsDoubleBuffered = aIsDB; }
64 virtual bool IsANGLE() const override { return mEgl->mLib->IsANGLE(); }
65 virtual bool IsWARP() const override { return mEgl->mIsWARP; }
67 virtual bool BindTexImage() override;
69 virtual bool ReleaseTexImage() override;
71 void SetEGLSurfaceOverride(EGLSurface surf);
72 EGLSurface GetEGLSurfaceOverride() { return mSurfaceOverride; }
74 virtual bool MakeCurrentImpl() const override;
76 virtual bool IsCurrentImpl() const override;
78 virtual bool RenewSurface(widget::CompositorWidget* aWidget) override;
80 virtual void ReleaseSurface() override;
82 Maybe<SymbolLoader> GetSymbolLoader() const override;
84 virtual bool SwapBuffers() override;
86 virtual void SetDamage(const nsIntRegion& aDamageRegion) override;
88 GLint GetBufferAge() const override;
90 virtual void GetWSIInfo(nsCString* const out) const override;
92 EGLSurface GetEGLSurface() const { return mSurface; }
94 bool HasExtBufferAge() const;
95 bool HasKhrPartialUpdate() const;
97 bool BindTex2DOffscreen(GLContext* aOffscreen);
98 void UnbindTex2DOffscreen(GLContext* aOffscreen);
99 void BindOffscreenFramebuffer();
101 void Destroy();
103 static RefPtr<GLContextEGL> CreateEGLPBufferOffscreenContext(
104 std::shared_ptr<EglDisplay>, const GLContextCreateDesc&,
105 const gfx::IntSize& size, nsACString* const out_FailureId);
106 static RefPtr<GLContextEGL> CreateEGLPBufferOffscreenContextImpl(
107 std::shared_ptr<EglDisplay>, const GLContextCreateDesc&,
108 const gfx::IntSize& size, bool aUseGles, nsACString* const out_FailureId);
110 static EGLSurface CreateEGLSurfaceForCompositorWidget(
111 widget::CompositorWidget* aCompositorWidget, const EGLConfig aConfig);
113 #ifdef MOZ_X11
114 static bool FindVisual(int* const out_visualId);
115 #endif
117 protected:
118 friend class GLContextProviderEGL;
119 friend class GLContextEGLFactory;
121 virtual void OnMarkDestroyed() override;
123 public:
124 const std::shared_ptr<EglDisplay> mEgl;
125 const EGLConfig mConfig;
126 const EGLContext mContext;
128 protected:
129 EGLSurface mSurface;
130 const EGLSurface mFallbackSurface;
132 EGLSurface mSurfaceOverride = EGL_NO_SURFACE;
133 bool mBound = false;
135 bool mIsPBuffer = false;
136 bool mIsDoubleBuffered = false;
137 bool mCanBindToTexture = false;
138 bool mShareWithEGLImage = false;
139 bool mOwnsContext = true;
141 nsIntRegion mDamageRegion;
143 static EGLSurface CreatePBufferSurfaceTryingPowerOfTwo(
144 EglDisplay&, EGLConfig, EGLenum bindToTextureFormat,
145 gfx::IntSize& pbsize);
147 static EGLSurface CreateWaylandBufferSurface(EglDisplay&, EGLConfig,
148 gfx::IntSize& pbsize);
150 public:
151 EGLSurface CreateCompatibleSurface(void* aWindow) const;
154 bool CreateConfig(EglDisplay&, EGLConfig* aConfig, int32_t aDepth,
155 bool aEnableDepthBuffer, bool aUseGles,
156 bool aAllowFallback = true);
158 } // namespace gl
159 } // namespace mozilla
161 #endif // GLCONTEXTEGL_H_