1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/android/AndroidDirectTexture.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,59 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef AndroidDirectTexture_h_ 1.10 +#define AndroidDirectTexture_h_ 1.11 + 1.12 +#include "gfxTypes.h" 1.13 +#include "mozilla/Mutex.h" 1.14 +#include "AndroidGraphicBuffer.h" 1.15 + 1.16 +struct nsIntRect; 1.17 + 1.18 +namespace mozilla { 1.19 + 1.20 +/** 1.21 + * This is a thread safe wrapper around AndroidGraphicBuffer that handles 1.22 + * double buffering. Each call to Bind() flips the buffer when necessary. 1.23 + * 1.24 + * You need to be careful when destroying an instance of this class. If either 1.25 + * buffer is locked by the application of the driver/hardware, bad things will 1.26 + * happen. Be sure that the OpenGL texture is no longer on the screen. 1.27 + */ 1.28 +class AndroidDirectTexture 1.29 +{ 1.30 +public: 1.31 + AndroidDirectTexture(uint32_t width, uint32_t height, uint32_t usage, gfxImageFormat format); 1.32 + virtual ~AndroidDirectTexture(); 1.33 + 1.34 + bool Lock(uint32_t usage, unsigned char **bits); 1.35 + bool Lock(uint32_t usage, const nsIntRect& rect, unsigned char **bits); 1.36 + bool Unlock(bool aFlip = true); 1.37 + 1.38 + bool Reallocate(uint32_t aWidth, uint32_t aHeight); 1.39 + bool Reallocate(uint32_t aWidth, uint32_t aHeight, gfxImageFormat aFormat); 1.40 + 1.41 + uint32_t Width() { return mWidth; } 1.42 + uint32_t Height() { return mHeight; } 1.43 + 1.44 + bool Bind(); 1.45 + 1.46 +private: 1.47 + mozilla::Mutex mLock; 1.48 + bool mNeedFlip; 1.49 + 1.50 + uint32_t mWidth; 1.51 + uint32_t mHeight; 1.52 + gfxImageFormat mFormat; 1.53 + 1.54 + AndroidGraphicBuffer* mFrontBuffer; 1.55 + AndroidGraphicBuffer* mBackBuffer; 1.56 + 1.57 + AndroidGraphicBuffer* mPendingReallocBuffer; 1.58 + void ReallocPendingBuffer(); 1.59 +}; 1.60 + 1.61 +} /* mozilla */ 1.62 +#endif /* AndroidDirectTexture_h_ */