michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim: set ts=8 sts=4 et sw=4 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef GLCONTEXTEGL_H_ michael@0: #define GLCONTEXTEGL_H_ michael@0: michael@0: #include "GLContext.h" michael@0: #include "GLLibraryEGL.h" michael@0: michael@0: #ifdef MOZ_WIDGET_GONK michael@0: #include "HwcComposer2D.h" michael@0: #endif michael@0: michael@0: namespace mozilla { michael@0: namespace gl { michael@0: michael@0: class GLContextEGL : public GLContext michael@0: { michael@0: friend class TextureImageEGL; michael@0: michael@0: static already_AddRefed michael@0: CreateGLContext(const SurfaceCaps& caps, michael@0: GLContextEGL *shareContext, michael@0: bool isOffscreen, michael@0: EGLConfig config, michael@0: EGLSurface surface); michael@0: michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GLContextEGL) michael@0: GLContextEGL(const SurfaceCaps& caps, michael@0: GLContext* shareContext, michael@0: bool isOffscreen, michael@0: EGLConfig config, michael@0: EGLSurface surface, michael@0: EGLContext context); michael@0: michael@0: ~GLContextEGL(); michael@0: michael@0: virtual GLContextType GetContextType() const MOZ_OVERRIDE { return GLContextType::EGL; } michael@0: michael@0: static GLContextEGL* Cast(GLContext* gl) { michael@0: MOZ_ASSERT(gl->GetContextType() == GLContextType::EGL); michael@0: return static_cast(gl); michael@0: } michael@0: michael@0: bool Init() MOZ_OVERRIDE; michael@0: michael@0: virtual bool IsDoubleBuffered() const MOZ_OVERRIDE { michael@0: return mIsDoubleBuffered; michael@0: } michael@0: michael@0: void SetIsDoubleBuffered(bool aIsDB) { michael@0: mIsDoubleBuffered = aIsDB; michael@0: } michael@0: michael@0: virtual bool SupportsRobustness() const MOZ_OVERRIDE { michael@0: return sEGLLibrary.HasRobustness(); michael@0: } michael@0: michael@0: virtual bool IsANGLE() const MOZ_OVERRIDE { michael@0: return sEGLLibrary.IsANGLE(); michael@0: } michael@0: michael@0: virtual bool BindTexImage() MOZ_OVERRIDE; michael@0: michael@0: virtual bool ReleaseTexImage() MOZ_OVERRIDE; michael@0: michael@0: void SetEGLSurfaceOverride(EGLSurface surf); michael@0: michael@0: virtual bool MakeCurrentImpl(bool aForce) MOZ_OVERRIDE; michael@0: michael@0: virtual bool IsCurrent() MOZ_OVERRIDE; michael@0: michael@0: virtual bool RenewSurface() MOZ_OVERRIDE; michael@0: michael@0: virtual void ReleaseSurface() MOZ_OVERRIDE; michael@0: michael@0: virtual bool SetupLookupFunction() MOZ_OVERRIDE; michael@0: michael@0: virtual bool SwapBuffers() MOZ_OVERRIDE; michael@0: michael@0: // hold a reference to the given surface michael@0: // for the lifetime of this context. michael@0: void HoldSurface(gfxASurface *aSurf); michael@0: michael@0: EGLContext GetEGLContext() { michael@0: return mContext; michael@0: } michael@0: michael@0: bool BindTex2DOffscreen(GLContext *aOffscreen); michael@0: void UnbindTex2DOffscreen(GLContext *aOffscreen); michael@0: void BindOffscreenFramebuffer(); michael@0: michael@0: static already_AddRefed michael@0: CreateEGLPixmapOffscreenContext(const gfxIntSize& size); michael@0: michael@0: static already_AddRefed michael@0: CreateEGLPBufferOffscreenContext(const gfxIntSize& size); michael@0: michael@0: protected: michael@0: friend class GLContextProviderEGL; michael@0: michael@0: EGLConfig mConfig; michael@0: EGLSurface mSurface; michael@0: EGLSurface mSurfaceOverride; michael@0: EGLContext mContext; michael@0: nsRefPtr mThebesSurface; michael@0: bool mBound; michael@0: michael@0: bool mIsPBuffer; michael@0: bool mIsDoubleBuffered; michael@0: bool mCanBindToTexture; michael@0: bool mShareWithEGLImage; michael@0: #ifdef MOZ_WIDGET_GONK michael@0: nsRefPtr mHwc; michael@0: #endif michael@0: bool mOwnsContext; michael@0: michael@0: static EGLSurface CreatePBufferSurfaceTryingPowerOfTwo(EGLConfig config, michael@0: EGLenum bindToTextureFormat, michael@0: gfxIntSize& pbsize); michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif // GLCONTEXTEGL_H_