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_GRALLOC_H_ michael@0: #define SHARED_SURFACE_GRALLOC_H_ michael@0: michael@0: #include "SharedSurfaceGL.h" michael@0: #include "mozilla/layers/ISurfaceAllocator.h" michael@0: #include "mozilla/layers/LayersSurfaces.h" michael@0: #include "mozilla/layers/TextureClient.h" michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: class ISurfaceAllocator; michael@0: } michael@0: michael@0: namespace gl { michael@0: class GLContext; michael@0: class GLLibraryEGL; michael@0: michael@0: class SharedSurface_Gralloc michael@0: : public SharedSurface_GL michael@0: { michael@0: public: michael@0: static SharedSurface_Gralloc* Create(GLContext* prodGL, michael@0: const GLFormats& formats, michael@0: const gfx::IntSize& size, michael@0: bool hasAlpha, michael@0: layers::ISurfaceAllocator* allocator); michael@0: michael@0: static SharedSurface_Gralloc* Cast(SharedSurface* surf) { michael@0: MOZ_ASSERT(surf->Type() == SharedSurfaceType::Gralloc); michael@0: michael@0: return (SharedSurface_Gralloc*)surf; michael@0: } michael@0: michael@0: protected: michael@0: GLLibraryEGL* const mEGL; michael@0: RefPtr mAllocator; michael@0: RefPtr mTextureClient; michael@0: const GLuint mProdTex; michael@0: michael@0: SharedSurface_Gralloc(GLContext* prodGL, michael@0: const gfx::IntSize& size, michael@0: bool hasAlpha, michael@0: GLLibraryEGL* egl, michael@0: layers::ISurfaceAllocator* allocator, michael@0: layers::TextureClient* textureClient, michael@0: GLuint prodTex) michael@0: : SharedSurface_GL(SharedSurfaceType::Gralloc, michael@0: AttachmentType::GLTexture, michael@0: prodGL, michael@0: size, michael@0: hasAlpha) michael@0: , mEGL(egl) michael@0: , mAllocator(allocator) michael@0: , mTextureClient(textureClient) michael@0: , mProdTex(prodTex) michael@0: {} michael@0: michael@0: static bool HasExtensions(GLLibraryEGL* egl, GLContext* gl); michael@0: michael@0: public: michael@0: virtual ~SharedSurface_Gralloc(); michael@0: michael@0: virtual void Fence() MOZ_OVERRIDE; michael@0: virtual bool WaitSync() MOZ_OVERRIDE; michael@0: michael@0: virtual void LockProdImpl() MOZ_OVERRIDE {} michael@0: virtual void UnlockProdImpl() MOZ_OVERRIDE {} michael@0: michael@0: virtual GLuint ProdTexture() MOZ_OVERRIDE { michael@0: return mProdTex; michael@0: } michael@0: michael@0: layers::TextureClient* GetTextureClient() { michael@0: return mTextureClient; michael@0: } michael@0: }; michael@0: michael@0: class SurfaceFactory_Gralloc michael@0: : public SurfaceFactory_GL michael@0: { michael@0: protected: michael@0: RefPtr mAllocator; michael@0: michael@0: public: michael@0: SurfaceFactory_Gralloc(GLContext* prodGL, michael@0: const SurfaceCaps& caps, michael@0: layers::ISurfaceAllocator* allocator = nullptr); michael@0: michael@0: virtual SharedSurface* CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE { michael@0: bool hasAlpha = mReadCaps.alpha; michael@0: if (!mAllocator) { michael@0: return nullptr; michael@0: } michael@0: return SharedSurface_Gralloc::Create(mGL, mFormats, size, hasAlpha, mAllocator); michael@0: } michael@0: }; michael@0: michael@0: } /* namespace gl */ michael@0: } /* namespace mozilla */ michael@0: michael@0: #endif /* SHARED_SURFACE_GRALLOC_H_ */