Bug 1200595 - Gralloc TextureData implementation. r=sotaro

This commit is contained in:
Nicolas Silva
2015-10-15 17:53:37 +02:00
parent 75de75b2f5
commit bd5414e7ad
20 changed files with 535 additions and 524 deletions

View File

@@ -25,131 +25,113 @@ class SharedSurface;
namespace layers {
/**
* A TextureClient implementation based on android::GraphicBuffer (also referred to
* as "gralloc").
*
* Gralloc lets us map texture data in memory (accessible through pointers)
* and also use it directly as an OpenGL texture without the cost of texture
* uploads.
* Gralloc buffers can also be shared accros processes.
*
* More info about Gralloc here: https://wiki.mozilla.org/Platform/GFX/Gralloc
*
* This is only used in Firefox OS
*/
class GrallocTextureClientOGL : public TextureClient
{
/// A TextureData implementation based on android::GraphicBuffer (also referred to
/// as "gralloc").
///
/// Gralloc lets us map texture data in memory (accessible through pointers)
/// and also use it directly as an OpenGL texture without the cost of texture
/// uploads.
/// Gralloc buffers can also be shared accros processes.
///
/// More info about Gralloc here: https://wiki.mozilla.org/Platform/GFX/Gralloc
///
/// This is only used in Firefox OS
class GrallocTextureData : public TextureData {
public:
GrallocTextureClientOGL(ISurfaceAllocator* aAllocator,
gfx::SurfaceFormat aFormat,
gfx::BackendType aMoz2dBackend,
TextureFlags aFlags = TextureFlags::DEFAULT);
typedef uint32_t AndroidFormat;
~GrallocTextureClientOGL();
virtual bool Serialize(SurfaceDescriptor& aOutDescriptor) override;
virtual bool Lock(OpenMode aMode) override;
virtual bool Lock(OpenMode aMode, FenceHandle* aFence) override;
virtual void Unlock() override;
virtual bool ImplementsLocking() const override { return true; }
virtual gfx::IntSize GetSize() const override { return mSize; }
virtual gfx::SurfaceFormat GetFormat() const override { return mFormat; }
virtual already_AddRefed<gfx::DrawTarget> BorrowDrawTarget() override;
virtual bool CanExposeMappedData() const override { return true; }
virtual bool BorrowMappedData(MappedTextureData& aMap) override;
virtual bool SupportsMoz2D() const override { return true; }
virtual bool HasInternalBuffer() const override { return false; }
virtual bool IsAllocated() const override;
virtual bool HasSynchronization() const override { return true; }
virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) override;
virtual void Deallocate(ISurfaceAllocator*) override;
virtual void SetRemoveFromCompositableWaiter(AsyncTransactionWaiter* aWaiter) override;
virtual void Forget(ISurfaceAllocator*) override;
virtual void WaitForBufferOwnership(bool aWaitReleaseFence = true) override;
static GrallocTextureData* CreateForDrawing(gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
gfx::BackendType aMoz2dBackend,
ISurfaceAllocator* aAllocator);
GrallocTextureClientOGL* AsGrallocTextureClientOGL() override {
return this;
}
static GrallocTextureData* CreateForYCbCr(gfx::IntSize aYSize, gfx::IntSize aCbCrSize,
ISurfaceAllocator* aAllocator);
void SetTextureFlags(TextureFlags aFlags) { AddFlags(aFlags); }
static GrallocTextureData* CreateForGLRendering(gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
ISurfaceAllocator* aAllocator);
gfx::IntSize GetSize() const override { return mSize; }
static GrallocTextureData* Create(gfx::IntSize aSize, AndroidFormat aFormat,
gfx::BackendType aMoz2DBackend, uint32_t aUsage,
ISurfaceAllocator* aAllocator);
android::sp<android::GraphicBuffer> GetGraphicBuffer()
{
return mGraphicBuffer;
}
android::PixelFormat GetPixelFormat()
{
return mGraphicBuffer->getPixelFormat();
}
static already_AddRefed<TextureClient>
TextureClientFromSharedSurface(gl::SharedSurface* abstractSurf, TextureFlags flags);
virtual gfx::DrawTarget* BorrowDrawTarget() override;
virtual void UpdateFromSurface(gfx::SourceSurface* aSurface) override;
virtual bool AllocateForSurface(gfx::IntSize aSize,
TextureAllocationFlags aFlags = ALLOC_DEFAULT) override;
virtual bool AllocateForYCbCr(gfx::IntSize aYSize,
gfx::IntSize aCbCrSize,
StereoMode aStereoMode);
bool AllocateForGLRendering(gfx::IntSize aSize);
bool AllocateGralloc(gfx::IntSize aYSize, uint32_t aAndroidFormat, uint32_t aUsage);
void SetIsOpaque(bool aIsOpaque) { mIsOpaque = aIsOpaque; }
/**
* Hold android::MediaBuffer.
* MediaBuffer needs to be add refed to keep MediaBuffer alive
* during TextureClient is in use.
*/
void SetMediaBuffer(android::MediaBuffer* aMediaBuffer)
{
mMediaBuffer = aMediaBuffer;
}
android::MediaBuffer* GetMediaBuffer()
{
return mMediaBuffer;
}
virtual already_AddRefed<TextureClient>
CreateSimilar(TextureFlags aFlags = TextureFlags::DEFAULT,
virtual TextureData*
CreateSimilar(ISurfaceAllocator* aAllocator,
TextureFlags aFlags = TextureFlags::DEFAULT,
TextureAllocationFlags aAllocFlags = ALLOC_DEFAULT) const override;
static already_AddRefed<TextureClient> FromSharedSurface(gl::SharedSurface* surf,
TextureFlags flags);
// use ClientTexture's default implementation
virtual bool UpdateFromSurface(gfx::SourceSurface* aSurface) override;
/// Hold android::MediaBuffer.
/// MediaBuffer needs to be add refed to keep MediaBuffer alive while the texture
/// is in use.
///
/// TODO - ideally we should be able to put the MediaBuffer in the texture's
/// constructor and not expose these methods.
void SetMediaBuffer(android::MediaBuffer* aMediaBuffer) { mMediaBuffer = aMediaBuffer; }
android::MediaBuffer* GetMediaBuffer() { return mMediaBuffer; }
android::sp<android::GraphicBuffer> GetGraphicBuffer() { return mGraphicBuffer; }
virtual void WaitForFence(FenceHandle* aFence) override;
~GrallocTextureData();
protected:
gfx::SurfaceFormat mFormat;
GrallocTextureData(MaybeMagicGrallocBufferHandle aGrallocHandle,
gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
gfx::BackendType aMoz2DBackend);
gfx::IntSize mSize;
gfx::BackendType mBackend;
OpenMode mOpenMode;
gfx::SurfaceFormat mFormat;
gfx::BackendType mMoz2DBackend;
/**
* Unfortunately, until bug 879681 is fixed we need to use a GrallocBufferActor.
*/
MaybeMagicGrallocBufferHandle mGrallocHandle;
RefPtr<AsyncTransactionWaiter> mRemoveFromCompositableWaiter;
android::sp<android::GraphicBuffer> mGraphicBuffer;
/**
* Points to a mapped gralloc buffer between calls to lock and unlock.
* Should be null outside of the lock-unlock pair.
*/
// Points to a mapped gralloc buffer between calls to lock and unlock.
// Should be null outside of the lock-unlock pair.
uint8_t* mMappedBuffer;
RefPtr<gfx::DrawTarget> mDrawTarget;
android::MediaBuffer* mMediaBuffer;
bool mIsOpaque;
bool mLocked;
};
gfx::SurfaceFormat SurfaceFormatForPixelFormat(android::PixelFormat aFormat);
already_AddRefed<TextureClient> CreateGrallocTextureClientForDrawing(gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
gfx::BackendType aMoz2dBackend, TextureFlags aFlags,
ISurfaceAllocator* aAllocator);
} // namespace layers
} // namespace mozilla