michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 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 MOZILLA_GFX_GRALLOCTEXTUREHOST_H michael@0: #define MOZILLA_GFX_GRALLOCTEXTUREHOST_H michael@0: #ifdef MOZ_WIDGET_GONK michael@0: michael@0: #include "mozilla/layers/TextureHostOGL.h" michael@0: #include "mozilla/layers/ShadowLayerUtilsGralloc.h" michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: class GrallocTextureHostOGL; michael@0: michael@0: class GrallocTextureSourceOGL : public NewTextureSource michael@0: , public TextureSourceOGL michael@0: { michael@0: public: michael@0: friend class GrallocTextureHostOGL; michael@0: michael@0: GrallocTextureSourceOGL(CompositorOGL* aCompositor, michael@0: android::GraphicBuffer* aGraphicBuffer, michael@0: gfx::SurfaceFormat aFormat); michael@0: michael@0: virtual ~GrallocTextureSourceOGL(); michael@0: michael@0: virtual bool IsValid() const MOZ_OVERRIDE; michael@0: michael@0: virtual void BindTexture(GLenum aTextureUnit, gfx::Filter aFilter) MOZ_OVERRIDE; michael@0: michael@0: virtual gfx::IntSize GetSize() const MOZ_OVERRIDE; michael@0: michael@0: virtual TextureSourceOGL* AsSourceOGL() MOZ_OVERRIDE { return this; } michael@0: michael@0: virtual GLenum GetTextureTarget() const MOZ_OVERRIDE; michael@0: michael@0: virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; } michael@0: michael@0: virtual GLenum GetWrapMode() const MOZ_OVERRIDE michael@0: { michael@0: return LOCAL_GL_CLAMP_TO_EDGE; michael@0: } michael@0: michael@0: virtual void SetCompositableBackendSpecificData(CompositableBackendSpecificData* aBackendData) MOZ_OVERRIDE; michael@0: michael@0: void DeallocateDeviceData(); michael@0: michael@0: gl::GLContext* gl() const; michael@0: michael@0: virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE; michael@0: michael@0: void ForgetBuffer() michael@0: { michael@0: mGraphicBuffer = nullptr; michael@0: } michael@0: michael@0: TemporaryRef GetAsSurface(); michael@0: michael@0: GLuint GetGLTexture(); michael@0: michael@0: void Lock(); michael@0: michael@0: protected: michael@0: CompositorOGL* mCompositor; michael@0: android::sp mGraphicBuffer; michael@0: EGLImage mEGLImage; michael@0: GLuint mTexture; michael@0: gfx::SurfaceFormat mFormat; michael@0: bool mNeedsReset; michael@0: }; michael@0: michael@0: class GrallocTextureHostOGL : public TextureHost michael@0: #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 michael@0: , public TextureHostOGL michael@0: #endif michael@0: { michael@0: friend class GrallocBufferActor; michael@0: public: michael@0: GrallocTextureHostOGL(TextureFlags aFlags, michael@0: const NewSurfaceDescriptorGralloc& aDescriptor); michael@0: michael@0: virtual ~GrallocTextureHostOGL(); michael@0: michael@0: virtual void Updated(const nsIntRegion* aRegion) MOZ_OVERRIDE {} michael@0: michael@0: virtual bool Lock() MOZ_OVERRIDE; michael@0: michael@0: virtual void Unlock() MOZ_OVERRIDE; michael@0: michael@0: virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE; michael@0: michael@0: virtual void DeallocateSharedData() MOZ_OVERRIDE; michael@0: michael@0: virtual void ForgetSharedData() MOZ_OVERRIDE; michael@0: michael@0: virtual void DeallocateDeviceData() MOZ_OVERRIDE; michael@0: michael@0: virtual gfx::SurfaceFormat GetFormat() const; michael@0: michael@0: virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; } michael@0: michael@0: virtual LayerRenderState GetRenderState() MOZ_OVERRIDE; michael@0: michael@0: virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE michael@0: { michael@0: return mTextureSource; michael@0: } michael@0: michael@0: #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 michael@0: virtual TextureHostOGL* AsHostOGL() MOZ_OVERRIDE michael@0: { michael@0: return this; michael@0: } michael@0: #endif michael@0: michael@0: virtual TemporaryRef GetAsSurface() MOZ_OVERRIDE; michael@0: michael@0: virtual void SetCompositableBackendSpecificData(CompositableBackendSpecificData* aBackendData) MOZ_OVERRIDE; michael@0: michael@0: bool IsValid() const; michael@0: michael@0: virtual const char* Name() MOZ_OVERRIDE { return "GrallocTextureHostOGL"; } michael@0: michael@0: // Forget buffer actor. Used only for hacky fix for bug 966446. michael@0: virtual void ForgetBufferActor() michael@0: { michael@0: mGrallocActor = nullptr; michael@0: } michael@0: michael@0: private: michael@0: GrallocBufferActor* mGrallocActor; michael@0: RefPtr mTextureSource; michael@0: gfx::IntSize mSize; // See comment in textureClientOGL.h michael@0: }; michael@0: michael@0: } // namespace layers michael@0: } // namespace mozilla michael@0: michael@0: #endif michael@0: #endif