1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/android/AndroidGraphicBuffer.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,73 @@ 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 AndroidGraphicBuffer_h_ 1.10 +#define AndroidGraphicBuffer_h_ 1.11 + 1.12 +#include "gfxTypes.h" 1.13 + 1.14 +typedef void* EGLImageKHR; 1.15 +typedef void* EGLClientBuffer; 1.16 + 1.17 +struct nsIntRect; 1.18 + 1.19 +namespace mozilla { 1.20 + 1.21 +/** 1.22 + * This class allows access to Android's direct texturing mechanism. Locking 1.23 + * the buffer gives you a pointer you can read/write to directly. It is fully 1.24 + * threadsafe, but you probably really want to use the AndroidDirectTexture 1.25 + * class which will handle double buffering. 1.26 + * 1.27 + * In order to use the buffer in OpenGL, just call Bind() and it will attach 1.28 + * to whatever texture is bound to GL_TEXTURE_2D. 1.29 + */ 1.30 +class AndroidGraphicBuffer 1.31 +{ 1.32 +public: 1.33 + enum { 1.34 + UsageSoftwareRead = 1, 1.35 + UsageSoftwareWrite = 1 << 1, 1.36 + UsageTexture = 1 << 2, 1.37 + UsageTarget = 1 << 3, 1.38 + Usage2D = 1 << 4 1.39 + }; 1.40 + 1.41 + AndroidGraphicBuffer(uint32_t width, uint32_t height, uint32_t usage, gfxImageFormat format); 1.42 + virtual ~AndroidGraphicBuffer(); 1.43 + 1.44 + int Lock(uint32_t usage, unsigned char **bits); 1.45 + int Lock(uint32_t usage, const nsIntRect& rect, unsigned char **bits); 1.46 + int Unlock(); 1.47 + bool Reallocate(uint32_t aWidth, uint32_t aHeight, gfxImageFormat aFormat); 1.48 + 1.49 + uint32_t Width() { return mWidth; } 1.50 + uint32_t Height() { return mHeight; } 1.51 + 1.52 + bool Bind(); 1.53 + 1.54 + static bool IsBlacklisted(); 1.55 + 1.56 +private: 1.57 + uint32_t mWidth; 1.58 + uint32_t mHeight; 1.59 + uint32_t mUsage; 1.60 + gfxImageFormat mFormat; 1.61 + 1.62 + bool EnsureInitialized(); 1.63 + bool EnsureEGLImage(); 1.64 + 1.65 + void DestroyBuffer(); 1.66 + bool EnsureBufferCreated(); 1.67 + 1.68 + uint32_t GetAndroidUsage(uint32_t aUsage); 1.69 + uint32_t GetAndroidFormat(gfxImageFormat aFormat); 1.70 + 1.71 + void *mHandle; 1.72 + void *mEGLImage; 1.73 +}; 1.74 + 1.75 +} /* mozilla */ 1.76 +#endif /* AndroidGraphicBuffer_h_ */