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
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef AndroidGraphicBuffer_h_
7 #define AndroidGraphicBuffer_h_
9 #include "gfxTypes.h"
11 typedef void* EGLImageKHR;
12 typedef void* EGLClientBuffer;
14 struct nsIntRect;
16 namespace mozilla {
18 /**
19 * This class allows access to Android's direct texturing mechanism. Locking
20 * the buffer gives you a pointer you can read/write to directly. It is fully
21 * threadsafe, but you probably really want to use the AndroidDirectTexture
22 * class which will handle double buffering.
23 *
24 * In order to use the buffer in OpenGL, just call Bind() and it will attach
25 * to whatever texture is bound to GL_TEXTURE_2D.
26 */
27 class AndroidGraphicBuffer
28 {
29 public:
30 enum {
31 UsageSoftwareRead = 1,
32 UsageSoftwareWrite = 1 << 1,
33 UsageTexture = 1 << 2,
34 UsageTarget = 1 << 3,
35 Usage2D = 1 << 4
36 };
38 AndroidGraphicBuffer(uint32_t width, uint32_t height, uint32_t usage, gfxImageFormat format);
39 virtual ~AndroidGraphicBuffer();
41 int Lock(uint32_t usage, unsigned char **bits);
42 int Lock(uint32_t usage, const nsIntRect& rect, unsigned char **bits);
43 int Unlock();
44 bool Reallocate(uint32_t aWidth, uint32_t aHeight, gfxImageFormat aFormat);
46 uint32_t Width() { return mWidth; }
47 uint32_t Height() { return mHeight; }
49 bool Bind();
51 static bool IsBlacklisted();
53 private:
54 uint32_t mWidth;
55 uint32_t mHeight;
56 uint32_t mUsage;
57 gfxImageFormat mFormat;
59 bool EnsureInitialized();
60 bool EnsureEGLImage();
62 void DestroyBuffer();
63 bool EnsureBufferCreated();
65 uint32_t GetAndroidUsage(uint32_t aUsage);
66 uint32_t GetAndroidFormat(gfxImageFormat aFormat);
68 void *mHandle;
69 void *mEGLImage;
70 };
72 } /* mozilla */
73 #endif /* AndroidGraphicBuffer_h_ */