Bug 1836072 [wpt PR 40324] - Fix scrollbar-width repaint issues on non viewports...
[gecko.git] / gfx / gl / GLContextEGL.h
blob93ff12808a676c59fa8a362fce478110d42c57bb
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&,
41 EGLConfig surfaceConfig, EGLSurface surface, const bool useGles,
42 EGLConfig contextConfig, nsACString* const out_failureId);
44 private:
45 GLContextEGL(std::shared_ptr<EglDisplay>, const GLContextDesc&,
46 EGLConfig surfaceConfig, EGLSurface surface, EGLContext context);
47 ~GLContextEGL();
49 public:
50 virtual GLContextType GetContextType() const override {
51 return GLContextType::EGL;
54 static GLContextEGL* Cast(GLContext* gl) {
55 MOZ_ASSERT(gl->GetContextType() == GLContextType::EGL);
56 return static_cast<GLContextEGL*>(gl);
59 bool Init() override;
61 virtual bool IsDoubleBuffered() const override { return mIsDoubleBuffered; }
63 void SetIsDoubleBuffered(bool aIsDB) { mIsDoubleBuffered = aIsDB; }
65 virtual bool IsANGLE() const override { return mEgl->mLib->IsANGLE(); }
66 virtual bool IsWARP() const override { return mEgl->mIsWARP; }
68 virtual bool BindTexImage() override;
70 virtual bool ReleaseTexImage() override;
72 void SetEGLSurfaceOverride(EGLSurface surf);
73 EGLSurface GetEGLSurfaceOverride() { return mSurfaceOverride; }
75 virtual bool MakeCurrentImpl() const override;
77 virtual bool IsCurrentImpl() const override;
79 virtual bool RenewSurface(widget::CompositorWidget* aWidget) override;
81 virtual void ReleaseSurface() override;
83 Maybe<SymbolLoader> GetSymbolLoader() const override;
85 virtual bool SwapBuffers() override;
87 virtual void SetDamage(const nsIntRegion& aDamageRegion) override;
89 GLint GetBufferAge() const override;
91 virtual void GetWSIInfo(nsCString* const out) const override;
93 EGLSurface GetEGLSurface() const { return mSurface; }
95 bool HasExtBufferAge() const;
96 bool HasKhrPartialUpdate() const;
98 bool BindTex2DOffscreen(GLContext* aOffscreen);
99 void UnbindTex2DOffscreen(GLContext* aOffscreen);
100 void BindOffscreenFramebuffer();
102 void Destroy();
104 static RefPtr<GLContextEGL> CreateWithoutSurface(
105 std::shared_ptr<EglDisplay>, const GLContextCreateDesc&,
106 nsACString* const out_FailureId);
107 static RefPtr<GLContextEGL> CreateEGLSurfacelessContext(
108 const std::shared_ptr<EglDisplay> display,
109 const GLContextCreateDesc& desc, nsACString* const out_failureId);
111 static EGLSurface CreateEGLSurfaceForCompositorWidget(
112 widget::CompositorWidget* aCompositorWidget, const EGLConfig aConfig);
114 #ifdef MOZ_X11
115 static bool FindVisual(int* const out_visualId);
116 #endif
118 protected:
119 friend class GLContextProviderEGL;
120 friend class GLContextEGLFactory;
122 virtual void OnMarkDestroyed() override;
124 public:
125 const std::shared_ptr<EglDisplay> mEgl;
126 const EGLConfig mSurfaceConfig;
127 const EGLContext mContext;
129 protected:
130 EGLSurface mSurface;
131 const EGLSurface mFallbackSurface;
133 EGLSurface mSurfaceOverride = EGL_NO_SURFACE;
134 bool mBound = false;
136 bool mIsPBuffer = false;
137 bool mIsDoubleBuffered = false;
138 bool mCanBindToTexture = false;
139 bool mShareWithEGLImage = false;
140 bool mOwnsContext = true;
142 nsIntRegion mDamageRegion;
144 static EGLSurface CreatePBufferSurfaceTryingPowerOfTwo(
145 EglDisplay&, EGLConfig, EGLenum bindToTextureFormat,
146 gfx::IntSize& pbsize);
148 #ifdef MOZ_WAYLAND
149 static EGLSurface CreateWaylandBufferSurface(EglDisplay&, EGLConfig,
150 gfx::IntSize& pbsize);
151 #endif
153 public:
154 EGLSurface CreateCompatibleSurface(void* aWindow) const;
157 bool CreateConfig(EglDisplay&, EGLConfig* aConfig, int32_t aDepth,
158 bool aEnableDepthBuffer, bool aUseGles,
159 bool aAllowFallback = true);
161 } // namespace gl
162 } // namespace mozilla
164 #endif // GLCONTEXTEGL_H_