michael@0: /* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */ 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 SHARED_SURFACE_EGL_H_ michael@0: #define SHARED_SURFACE_EGL_H_ michael@0: michael@0: #include "SharedSurfaceGL.h" michael@0: #include "SurfaceFactory.h" michael@0: #include "GLLibraryEGL.h" michael@0: #include "SurfaceTypes.h" michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/Mutex.h" michael@0: michael@0: namespace mozilla { michael@0: namespace gl { michael@0: michael@0: class GLContext; michael@0: class TextureGarbageBin; michael@0: michael@0: class SharedSurface_EGLImage michael@0: : public SharedSurface_GL michael@0: { michael@0: public: michael@0: static SharedSurface_EGLImage* Create(GLContext* prodGL, michael@0: const GLFormats& formats, michael@0: const gfx::IntSize& size, michael@0: bool hasAlpha, michael@0: EGLContext context); michael@0: michael@0: static SharedSurface_EGLImage* Cast(SharedSurface* surf) { michael@0: MOZ_ASSERT(surf->Type() == SharedSurfaceType::EGLImageShare); michael@0: michael@0: return (SharedSurface_EGLImage*)surf; michael@0: } michael@0: michael@0: static bool HasExtensions(GLLibraryEGL* egl, GLContext* gl); michael@0: michael@0: protected: michael@0: mutable Mutex mMutex; michael@0: GLLibraryEGL* const mEGL; michael@0: const GLFormats mFormats; michael@0: GLuint mProdTex; michael@0: EGLImage mImage; michael@0: GLContext* mCurConsGL; michael@0: GLuint mConsTex; michael@0: nsRefPtr mGarbageBin; michael@0: EGLSync mSync; michael@0: michael@0: SharedSurface_EGLImage(GLContext* gl, michael@0: GLLibraryEGL* egl, michael@0: const gfx::IntSize& size, michael@0: bool hasAlpha, michael@0: const GLFormats& formats, michael@0: GLuint prodTex, michael@0: EGLImage image); michael@0: michael@0: EGLDisplay Display() const; michael@0: void UpdateProdTexture(const MutexAutoLock& curAutoLock); michael@0: michael@0: public: michael@0: virtual ~SharedSurface_EGLImage(); michael@0: michael@0: virtual void LockProdImpl() MOZ_OVERRIDE {} michael@0: virtual void UnlockProdImpl() MOZ_OVERRIDE {} michael@0: michael@0: michael@0: virtual void Fence() MOZ_OVERRIDE; michael@0: virtual bool WaitSync() MOZ_OVERRIDE; michael@0: michael@0: virtual GLuint ProdTexture() MOZ_OVERRIDE { michael@0: return mProdTex; michael@0: } michael@0: michael@0: // Implementation-specific functions below: michael@0: // Returns texture and target michael@0: void AcquireConsumerTexture(GLContext* consGL, GLuint* out_texture, GLuint* out_target); michael@0: }; michael@0: michael@0: michael@0: michael@0: class SurfaceFactory_EGLImage michael@0: : public SurfaceFactory_GL michael@0: { michael@0: public: michael@0: // Fallible: michael@0: static SurfaceFactory_EGLImage* Create(GLContext* prodGL, michael@0: const SurfaceCaps& caps); michael@0: michael@0: protected: michael@0: const EGLContext mContext; michael@0: michael@0: SurfaceFactory_EGLImage(GLContext* prodGL, michael@0: EGLContext context, michael@0: const SurfaceCaps& caps) michael@0: : SurfaceFactory_GL(prodGL, SharedSurfaceType::EGLImageShare, caps) michael@0: , mContext(context) michael@0: {} michael@0: michael@0: public: michael@0: virtual SharedSurface* CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE { michael@0: bool hasAlpha = mReadCaps.alpha; michael@0: return SharedSurface_EGLImage::Create(mGL, mFormats, size, hasAlpha, mContext); michael@0: } michael@0: }; michael@0: michael@0: } /* namespace gfx */ michael@0: } /* namespace mozilla */ michael@0: michael@0: #endif /* SHARED_SURFACE_EGL_H_ */