1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* vim: set ts=8 sts=4 et sw=4 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 GLCONTEXTEGL_H_ 8 #define GLCONTEXTEGL_H_ 9 10 #include "GLContext.h" 11 #include "GLLibraryEGL.h" 12 13 namespace mozilla { 14 namespace widget { 15 class CompositorWidget; 16 } // namespace widget 17 namespace gl { 18 19 class GLContextEGL : public GLContext { 20 friend class TextureImageEGL; 21 22 static already_AddRefed<GLContextEGL> CreateGLContext( 23 CreateContextFlags flags, const SurfaceCaps& caps, bool isOffscreen, 24 EGLConfig config, EGLSurface surface, nsACString* const out_failureId); 25 26 public: 27 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GLContextEGL, override) 28 GLContextEGL(CreateContextFlags flags, const SurfaceCaps& caps, 29 bool isOffscreen, EGLConfig config, EGLSurface surface, 30 EGLContext context); 31 32 ~GLContextEGL(); 33 GetContextType()34 virtual GLContextType GetContextType() const override { 35 return GLContextType::EGL; 36 } 37 Cast(GLContext * gl)38 static GLContextEGL* Cast(GLContext* gl) { 39 MOZ_ASSERT(gl->GetContextType() == GLContextType::EGL); 40 return static_cast<GLContextEGL*>(gl); 41 } 42 43 bool Init() override; 44 IsDoubleBuffered()45 virtual bool IsDoubleBuffered() const override { return mIsDoubleBuffered; } 46 SetIsDoubleBuffered(bool aIsDB)47 void SetIsDoubleBuffered(bool aIsDB) { mIsDoubleBuffered = aIsDB; } 48 IsANGLE()49 virtual bool IsANGLE() const override { return sEGLLibrary.IsANGLE(); } 50 IsWARP()51 virtual bool IsWARP() const override { return sEGLLibrary.IsWARP(); } 52 53 virtual bool BindTexImage() override; 54 55 virtual bool ReleaseTexImage() override; 56 57 void SetEGLSurfaceOverride(EGLSurface surf); GetEGLSurfaceOverride()58 EGLSurface GetEGLSurfaceOverride() { return mSurfaceOverride; } 59 60 virtual bool MakeCurrentImpl() const override; 61 62 virtual bool IsCurrentImpl() const override; 63 64 virtual bool RenewSurface(widget::CompositorWidget* aWidget) override; 65 66 virtual void ReleaseSurface() override; 67 68 virtual bool SetupLookupFunction() override; 69 70 virtual bool SwapBuffers() override; 71 72 virtual void GetWSIInfo(nsCString* const out) const override; 73 74 // hold a reference to the given surface 75 // for the lifetime of this context. 76 void HoldSurface(gfxASurface* aSurf); 77 GetEGLSurface()78 EGLSurface GetEGLSurface() const { return mSurface; } 79 GetEGLDisplay()80 EGLDisplay GetEGLDisplay() const { return sEGLLibrary.Display(); } 81 82 bool BindTex2DOffscreen(GLContext* aOffscreen); 83 void UnbindTex2DOffscreen(GLContext* aOffscreen); 84 void BindOffscreenFramebuffer(); 85 86 static already_AddRefed<GLContextEGL> CreateEGLPBufferOffscreenContext( 87 CreateContextFlags flags, const gfx::IntSize& size, 88 const SurfaceCaps& minCaps, nsACString* const out_FailureId); 89 90 protected: 91 friend class GLContextProviderEGL; 92 friend class GLContextEGLFactory; 93 94 public: 95 const EGLConfig mConfig; 96 97 protected: 98 EGLSurface mSurface; 99 100 public: 101 const EGLContext mContext; 102 103 protected: 104 EGLSurface mSurfaceOverride; 105 RefPtr<gfxASurface> mThebesSurface; 106 bool mBound; 107 108 bool mIsPBuffer; 109 bool mIsDoubleBuffered; 110 bool mCanBindToTexture; 111 bool mShareWithEGLImage; 112 bool mOwnsContext; 113 114 static EGLSurface CreatePBufferSurfaceTryingPowerOfTwo( 115 EGLConfig config, EGLenum bindToTextureFormat, gfx::IntSize& pbsize); 116 #if defined(MOZ_WIDGET_ANDROID) 117 public: 118 EGLSurface CreateCompatibleSurface(void* aWindow); 119 #endif // defined(MOZ_WIDGET_ANDROID) 120 }; 121 122 bool CreateConfig(EGLConfig* config, int32_t depth, bool enableDepthBuffer); 123 124 } // namespace gl 125 } // namespace mozilla 126 127 #endif // GLCONTEXTEGL_H_ 128