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 AndroidDirectTexture_h_ michael@0: #define AndroidDirectTexture_h_ michael@0: michael@0: #include "gfxTypes.h" michael@0: #include "mozilla/Mutex.h" michael@0: #include "AndroidGraphicBuffer.h" michael@0: michael@0: struct nsIntRect; michael@0: michael@0: namespace mozilla { michael@0: michael@0: /** michael@0: * This is a thread safe wrapper around AndroidGraphicBuffer that handles michael@0: * double buffering. Each call to Bind() flips the buffer when necessary. michael@0: * michael@0: * You need to be careful when destroying an instance of this class. If either michael@0: * buffer is locked by the application of the driver/hardware, bad things will michael@0: * happen. Be sure that the OpenGL texture is no longer on the screen. michael@0: */ michael@0: class AndroidDirectTexture michael@0: { michael@0: public: michael@0: AndroidDirectTexture(uint32_t width, uint32_t height, uint32_t usage, gfxImageFormat format); michael@0: virtual ~AndroidDirectTexture(); michael@0: michael@0: bool Lock(uint32_t usage, unsigned char **bits); michael@0: bool Lock(uint32_t usage, const nsIntRect& rect, unsigned char **bits); michael@0: bool Unlock(bool aFlip = true); michael@0: michael@0: bool Reallocate(uint32_t aWidth, uint32_t aHeight); 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: private: michael@0: mozilla::Mutex mLock; michael@0: bool mNeedFlip; michael@0: michael@0: uint32_t mWidth; michael@0: uint32_t mHeight; michael@0: gfxImageFormat mFormat; michael@0: michael@0: AndroidGraphicBuffer* mFrontBuffer; michael@0: AndroidGraphicBuffer* mBackBuffer; michael@0: michael@0: AndroidGraphicBuffer* mPendingReallocBuffer; michael@0: void ReallocPendingBuffer(); michael@0: }; michael@0: michael@0: } /* mozilla */ michael@0: #endif /* AndroidDirectTexture_h_ */