Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef AndroidDirectTexture_h_ |
michael@0 | 7 | #define AndroidDirectTexture_h_ |
michael@0 | 8 | |
michael@0 | 9 | #include "gfxTypes.h" |
michael@0 | 10 | #include "mozilla/Mutex.h" |
michael@0 | 11 | #include "AndroidGraphicBuffer.h" |
michael@0 | 12 | |
michael@0 | 13 | struct nsIntRect; |
michael@0 | 14 | |
michael@0 | 15 | namespace mozilla { |
michael@0 | 16 | |
michael@0 | 17 | /** |
michael@0 | 18 | * This is a thread safe wrapper around AndroidGraphicBuffer that handles |
michael@0 | 19 | * double buffering. Each call to Bind() flips the buffer when necessary. |
michael@0 | 20 | * |
michael@0 | 21 | * You need to be careful when destroying an instance of this class. If either |
michael@0 | 22 | * buffer is locked by the application of the driver/hardware, bad things will |
michael@0 | 23 | * happen. Be sure that the OpenGL texture is no longer on the screen. |
michael@0 | 24 | */ |
michael@0 | 25 | class AndroidDirectTexture |
michael@0 | 26 | { |
michael@0 | 27 | public: |
michael@0 | 28 | AndroidDirectTexture(uint32_t width, uint32_t height, uint32_t usage, gfxImageFormat format); |
michael@0 | 29 | virtual ~AndroidDirectTexture(); |
michael@0 | 30 | |
michael@0 | 31 | bool Lock(uint32_t usage, unsigned char **bits); |
michael@0 | 32 | bool Lock(uint32_t usage, const nsIntRect& rect, unsigned char **bits); |
michael@0 | 33 | bool Unlock(bool aFlip = true); |
michael@0 | 34 | |
michael@0 | 35 | bool Reallocate(uint32_t aWidth, uint32_t aHeight); |
michael@0 | 36 | bool Reallocate(uint32_t aWidth, uint32_t aHeight, gfxImageFormat aFormat); |
michael@0 | 37 | |
michael@0 | 38 | uint32_t Width() { return mWidth; } |
michael@0 | 39 | uint32_t Height() { return mHeight; } |
michael@0 | 40 | |
michael@0 | 41 | bool Bind(); |
michael@0 | 42 | |
michael@0 | 43 | private: |
michael@0 | 44 | mozilla::Mutex mLock; |
michael@0 | 45 | bool mNeedFlip; |
michael@0 | 46 | |
michael@0 | 47 | uint32_t mWidth; |
michael@0 | 48 | uint32_t mHeight; |
michael@0 | 49 | gfxImageFormat mFormat; |
michael@0 | 50 | |
michael@0 | 51 | AndroidGraphicBuffer* mFrontBuffer; |
michael@0 | 52 | AndroidGraphicBuffer* mBackBuffer; |
michael@0 | 53 | |
michael@0 | 54 | AndroidGraphicBuffer* mPendingReallocBuffer; |
michael@0 | 55 | void ReallocPendingBuffer(); |
michael@0 | 56 | }; |
michael@0 | 57 | |
michael@0 | 58 | } /* mozilla */ |
michael@0 | 59 | #endif /* AndroidDirectTexture_h_ */ |