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_GRALLOCTEXTURECLIENT_H michael@0: #define MOZILLA_GFX_GRALLOCTEXTURECLIENT_H michael@0: #ifdef MOZ_WIDGET_GONK michael@0: michael@0: #include "mozilla/layers/TextureClient.h" michael@0: #include "ISurfaceAllocator.h" // For IsSurfaceDescriptorValid michael@0: #include "mozilla/layers/FenceUtils.h" // for FenceHandle michael@0: #include "mozilla/layers/ShadowLayerUtilsGralloc.h" michael@0: #include michael@0: michael@0: michael@0: namespace android { michael@0: class MediaBuffer; michael@0: }; michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: /** michael@0: * A TextureClient implementation based on android::GraphicBuffer (also referred to michael@0: * as "gralloc"). michael@0: * michael@0: * Gralloc lets us map texture data in memory (accessible through pointers) michael@0: * and also use it directly as an OpenGL texture without the cost of texture michael@0: * uploads. michael@0: * Gralloc buffers can also be shared accros processes. michael@0: * michael@0: * More info about Gralloc here: https://wiki.mozilla.org/Platform/GFX/Gralloc michael@0: * michael@0: * This is only used in Firefox OS michael@0: */ michael@0: class GrallocTextureClientOGL : public BufferTextureClient michael@0: { michael@0: public: michael@0: GrallocTextureClientOGL(GrallocBufferActor* aActor, michael@0: gfx::IntSize aSize, michael@0: gfx::BackendType aMoz2dBackend, michael@0: TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT); michael@0: GrallocTextureClientOGL(ISurfaceAllocator* aAllocator, michael@0: gfx::SurfaceFormat aFormat, michael@0: gfx::BackendType aMoz2dBackend, michael@0: TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT); michael@0: michael@0: ~GrallocTextureClientOGL(); michael@0: michael@0: virtual bool Lock(OpenMode aMode) MOZ_OVERRIDE; michael@0: michael@0: virtual void Unlock() MOZ_OVERRIDE; michael@0: michael@0: virtual bool ImplementsLocking() const MOZ_OVERRIDE { return true; } michael@0: michael@0: virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return false; } michael@0: michael@0: virtual bool IsAllocated() const MOZ_OVERRIDE; michael@0: michael@0: virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) MOZ_OVERRIDE; michael@0: michael@0: virtual TextureClientData* DropTextureData() MOZ_OVERRIDE; michael@0: michael@0: virtual void SetReleaseFenceHandle(FenceHandle aReleaseFenceHandle) MOZ_OVERRIDE; michael@0: michael@0: virtual void WaitReleaseFence() MOZ_OVERRIDE; michael@0: michael@0: void InitWith(GrallocBufferActor* aActor, gfx::IntSize aSize); michael@0: michael@0: void SetTextureFlags(TextureFlags aFlags) { AddFlags(aFlags); } michael@0: michael@0: gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; } michael@0: michael@0: android::sp GetGraphicBuffer() michael@0: { michael@0: return mGraphicBuffer; michael@0: } michael@0: michael@0: android::PixelFormat GetPixelFormat() michael@0: { michael@0: return mGraphicBuffer->getPixelFormat(); michael@0: } michael@0: michael@0: virtual uint8_t* GetBuffer() const MOZ_OVERRIDE; michael@0: michael@0: virtual TemporaryRef GetAsDrawTarget() MOZ_OVERRIDE; michael@0: michael@0: virtual bool AllocateForSurface(gfx::IntSize aSize, michael@0: TextureAllocationFlags aFlags = ALLOC_DEFAULT) MOZ_OVERRIDE; michael@0: michael@0: virtual bool AllocateForYCbCr(gfx::IntSize aYSize, michael@0: gfx::IntSize aCbCrSize, michael@0: StereoMode aStereoMode) MOZ_OVERRIDE; michael@0: michael@0: bool AllocateForGLRendering(gfx::IntSize aSize); michael@0: michael@0: bool AllocateGralloc(gfx::IntSize aYSize, uint32_t aAndroidFormat, uint32_t aUsage); michael@0: michael@0: virtual bool Allocate(uint32_t aSize) MOZ_OVERRIDE; michael@0: michael@0: virtual size_t GetBufferSize() const MOZ_OVERRIDE; michael@0: michael@0: /** michael@0: * Hold android::MediaBuffer. michael@0: * MediaBuffer needs to be add refed to keep MediaBuffer alive michael@0: * during TextureClient is in use. michael@0: */ michael@0: void SetMediaBuffer(android::MediaBuffer* aMediaBuffer) michael@0: { michael@0: mMediaBuffer = aMediaBuffer; michael@0: } michael@0: michael@0: android::MediaBuffer* GetMediaBuffer() michael@0: { michael@0: return mMediaBuffer; michael@0: } michael@0: michael@0: protected: michael@0: /** michael@0: * Unfortunately, until bug 879681 is fixed we need to use a GrallocBufferActor. michael@0: */ michael@0: GrallocBufferActor* mGrallocActor; michael@0: michael@0: android::sp mGraphicBuffer; michael@0: michael@0: /** michael@0: * Points to a mapped gralloc buffer between calls to lock and unlock. michael@0: * Should be null outside of the lock-unlock pair. michael@0: */ michael@0: uint8_t* mMappedBuffer; michael@0: michael@0: RefPtr mDrawTarget; michael@0: michael@0: /** michael@0: * android::GraphicBuffer has a size information. But there are cases michael@0: * that GraphicBuffer's size and actual video's size are different. michael@0: * Extra size member is necessary. See Bug 850566. michael@0: */ michael@0: gfx::IntSize mSize; michael@0: michael@0: android::MediaBuffer* mMediaBuffer; michael@0: }; michael@0: michael@0: } // namespace layers michael@0: } // namespace mozilla michael@0: michael@0: #endif // MOZ_WIDGET_GONK michael@0: #endif