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 AndroidGraphicBuffer_h_ michael@0: #define AndroidGraphicBuffer_h_ michael@0: michael@0: #include "gfxTypes.h" michael@0: michael@0: typedef void* EGLImageKHR; michael@0: typedef void* EGLClientBuffer; michael@0: michael@0: struct nsIntRect; michael@0: michael@0: namespace mozilla { michael@0: michael@0: /** michael@0: * This class allows access to Android's direct texturing mechanism. Locking michael@0: * the buffer gives you a pointer you can read/write to directly. It is fully michael@0: * threadsafe, but you probably really want to use the AndroidDirectTexture michael@0: * class which will handle double buffering. michael@0: * michael@0: * In order to use the buffer in OpenGL, just call Bind() and it will attach michael@0: * to whatever texture is bound to GL_TEXTURE_2D. michael@0: */ michael@0: class AndroidGraphicBuffer michael@0: { michael@0: public: michael@0: enum { michael@0: UsageSoftwareRead = 1, michael@0: UsageSoftwareWrite = 1 << 1, michael@0: UsageTexture = 1 << 2, michael@0: UsageTarget = 1 << 3, michael@0: Usage2D = 1 << 4 michael@0: }; michael@0: michael@0: AndroidGraphicBuffer(uint32_t width, uint32_t height, uint32_t usage, gfxImageFormat format); michael@0: virtual ~AndroidGraphicBuffer(); michael@0: michael@0: int Lock(uint32_t usage, unsigned char **bits); michael@0: int Lock(uint32_t usage, const nsIntRect& rect, unsigned char **bits); michael@0: int Unlock(); michael@0: bool Reallocate(uint32_t aWidth, uint32_t aHeight, gfxImageFormat aFormat); michael@0: michael@0: uint32_t Width() { return mWidth; } michael@0: uint32_t Height() { return mHeight; } michael@0: michael@0: bool Bind(); michael@0: michael@0: static bool IsBlacklisted(); michael@0: michael@0: private: michael@0: uint32_t mWidth; michael@0: uint32_t mHeight; michael@0: uint32_t mUsage; michael@0: gfxImageFormat mFormat; michael@0: michael@0: bool EnsureInitialized(); michael@0: bool EnsureEGLImage(); michael@0: michael@0: void DestroyBuffer(); michael@0: bool EnsureBufferCreated(); michael@0: michael@0: uint32_t GetAndroidUsage(uint32_t aUsage); michael@0: uint32_t GetAndroidFormat(gfxImageFormat aFormat); michael@0: michael@0: void *mHandle; michael@0: void *mEGLImage; michael@0: }; michael@0: michael@0: } /* mozilla */ michael@0: #endif /* AndroidGraphicBuffer_h_ */