Bug 1703443 - pt 6. Move RunNextCollectorTimer() into CCGCScheduler r=smaug
[gecko.git] / gfx / gl / GLContextEGL.h
blob46a1e78b50ab8e676054c1ab394cfbaafaf022e9
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 class gfxASurface;
16 namespace mozilla {
17 namespace layers {
18 class SurfaceTextureImage;
19 } // namespace layers
20 namespace widget {
21 class CompositorWidget;
22 } // namespace widget
23 namespace gl {
25 RefPtr<GLLibraryEGL> DefaultEglLibrary(nsACString* const out_failureId);
27 inline std::shared_ptr<EglDisplay> DefaultEglDisplay(
28 nsACString* const out_failureId) {
29 const auto lib = DefaultEglLibrary(out_failureId);
30 if (!lib) {
31 return nullptr;
33 return lib->DefaultDisplay(out_failureId);
36 // -
38 class GLContextEGL final : public GLContext {
39 public:
40 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GLContextEGL, override)
42 static RefPtr<GLContextEGL> CreateGLContext(
43 std::shared_ptr<EglDisplay>, const GLContextDesc&, EGLConfig config,
44 EGLSurface surface, const bool useGles, nsACString* const out_failureId);
46 private:
47 GLContextEGL(std::shared_ptr<EglDisplay>, const GLContextDesc&,
48 EGLConfig config, EGLSurface surface, EGLContext context);
49 ~GLContextEGL();
51 public:
52 virtual GLContextType GetContextType() const override {
53 return GLContextType::EGL;
56 static GLContextEGL* Cast(GLContext* gl) {
57 MOZ_ASSERT(gl->GetContextType() == GLContextType::EGL);
58 return static_cast<GLContextEGL*>(gl);
61 bool Init() override;
63 virtual bool IsDoubleBuffered() const override { return mIsDoubleBuffered; }
65 void SetIsDoubleBuffered(bool aIsDB) { mIsDoubleBuffered = aIsDB; }
67 virtual bool IsANGLE() const override { return mEgl->mLib->IsANGLE(); }
68 virtual bool IsWARP() const override { return mEgl->mIsWARP; }
70 virtual bool BindTexImage() override;
72 virtual bool ReleaseTexImage() override;
74 void SetEGLSurfaceOverride(EGLSurface surf);
75 EGLSurface GetEGLSurfaceOverride() { return mSurfaceOverride; }
77 virtual bool MakeCurrentImpl() const override;
79 virtual bool IsCurrentImpl() const override;
81 virtual bool RenewSurface(widget::CompositorWidget* aWidget) override;
83 virtual void ReleaseSurface() override;
85 Maybe<SymbolLoader> GetSymbolLoader() const override;
87 virtual bool SwapBuffers() override;
89 virtual void SetDamage(const nsIntRegion& aDamageRegion) override;
91 GLint GetBufferAge() const override;
93 virtual void GetWSIInfo(nsCString* const out) const override;
95 // hold a reference to the given surface
96 // for the lifetime of this context.
97 void HoldSurface(gfxASurface* aSurf);
99 EGLSurface GetEGLSurface() const { return mSurface; }
101 bool HasExtBufferAge() const;
102 bool HasKhrPartialUpdate() const;
104 bool BindTex2DOffscreen(GLContext* aOffscreen);
105 void UnbindTex2DOffscreen(GLContext* aOffscreen);
106 void BindOffscreenFramebuffer();
108 void Destroy();
110 static RefPtr<GLContextEGL> CreateEGLPBufferOffscreenContext(
111 std::shared_ptr<EglDisplay>, const GLContextCreateDesc&,
112 const gfx::IntSize& size, nsACString* const out_FailureId);
113 static RefPtr<GLContextEGL> CreateEGLPBufferOffscreenContextImpl(
114 std::shared_ptr<EglDisplay>, const GLContextCreateDesc&,
115 const gfx::IntSize& size, bool aUseGles, nsACString* const out_FailureId);
117 static EGLSurface CreateEGLSurfaceForCompositorWidget(
118 widget::CompositorWidget* aCompositorWidget, const EGLConfig aConfig);
120 #ifdef MOZ_X11
121 static bool FindVisual(bool aUseWebRender, bool useAlpha,
122 int* const out_visualId);
123 #endif
125 protected:
126 friend class GLContextProviderEGL;
127 friend class GLContextEGLFactory;
129 virtual void OnMarkDestroyed() override;
131 public:
132 const std::shared_ptr<EglDisplay> mEgl;
133 const EGLConfig mConfig;
134 const EGLContext mContext;
136 protected:
137 EGLSurface mSurface;
138 const EGLSurface mFallbackSurface;
140 EGLSurface mSurfaceOverride = EGL_NO_SURFACE;
141 RefPtr<gfxASurface> mThebesSurface;
142 bool mBound = false;
144 bool mIsPBuffer = false;
145 bool mIsDoubleBuffered = false;
146 bool mCanBindToTexture = false;
147 bool mShareWithEGLImage = false;
148 bool mOwnsContext = true;
150 nsIntRegion mDamageRegion;
152 static EGLSurface CreatePBufferSurfaceTryingPowerOfTwo(
153 EglDisplay&, EGLConfig, EGLenum bindToTextureFormat,
154 gfx::IntSize& pbsize);
156 static EGLSurface CreateWaylandBufferSurface(EglDisplay&, EGLConfig,
157 gfx::IntSize& pbsize);
159 public:
160 EGLSurface CreateCompatibleSurface(void* aWindow) const;
163 // -
164 // aVisual is used in Linux only to exactly match window and framebuffer
165 // visuals on NVIDIA drivers (Bug 1478454).
166 bool CreateConfig(EglDisplay&, EGLConfig* aConfig, int32_t depth,
167 bool aEnableDepthBuffer, bool aUseGles, int aVisual = 0);
169 } // namespace gl
170 } // namespace mozilla
172 #endif // GLCONTEXTEGL_H_