|
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/. */ |
|
5 |
|
6 #ifndef AndroidGraphicBuffer_h_ |
|
7 #define AndroidGraphicBuffer_h_ |
|
8 |
|
9 #include "gfxTypes.h" |
|
10 |
|
11 typedef void* EGLImageKHR; |
|
12 typedef void* EGLClientBuffer; |
|
13 |
|
14 struct nsIntRect; |
|
15 |
|
16 namespace mozilla { |
|
17 |
|
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 }; |
|
37 |
|
38 AndroidGraphicBuffer(uint32_t width, uint32_t height, uint32_t usage, gfxImageFormat format); |
|
39 virtual ~AndroidGraphicBuffer(); |
|
40 |
|
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); |
|
45 |
|
46 uint32_t Width() { return mWidth; } |
|
47 uint32_t Height() { return mHeight; } |
|
48 |
|
49 bool Bind(); |
|
50 |
|
51 static bool IsBlacklisted(); |
|
52 |
|
53 private: |
|
54 uint32_t mWidth; |
|
55 uint32_t mHeight; |
|
56 uint32_t mUsage; |
|
57 gfxImageFormat mFormat; |
|
58 |
|
59 bool EnsureInitialized(); |
|
60 bool EnsureEGLImage(); |
|
61 |
|
62 void DestroyBuffer(); |
|
63 bool EnsureBufferCreated(); |
|
64 |
|
65 uint32_t GetAndroidUsage(uint32_t aUsage); |
|
66 uint32_t GetAndroidFormat(gfxImageFormat aFormat); |
|
67 |
|
68 void *mHandle; |
|
69 void *mEGLImage; |
|
70 }; |
|
71 |
|
72 } /* mozilla */ |
|
73 #endif /* AndroidGraphicBuffer_h_ */ |