widget/android/AndroidGraphicBuffer.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

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 AndroidGraphicBuffer_h_
michael@0 7 #define AndroidGraphicBuffer_h_
michael@0 8
michael@0 9 #include "gfxTypes.h"
michael@0 10
michael@0 11 typedef void* EGLImageKHR;
michael@0 12 typedef void* EGLClientBuffer;
michael@0 13
michael@0 14 struct nsIntRect;
michael@0 15
michael@0 16 namespace mozilla {
michael@0 17
michael@0 18 /**
michael@0 19 * This class allows access to Android's direct texturing mechanism. Locking
michael@0 20 * the buffer gives you a pointer you can read/write to directly. It is fully
michael@0 21 * threadsafe, but you probably really want to use the AndroidDirectTexture
michael@0 22 * class which will handle double buffering.
michael@0 23 *
michael@0 24 * In order to use the buffer in OpenGL, just call Bind() and it will attach
michael@0 25 * to whatever texture is bound to GL_TEXTURE_2D.
michael@0 26 */
michael@0 27 class AndroidGraphicBuffer
michael@0 28 {
michael@0 29 public:
michael@0 30 enum {
michael@0 31 UsageSoftwareRead = 1,
michael@0 32 UsageSoftwareWrite = 1 << 1,
michael@0 33 UsageTexture = 1 << 2,
michael@0 34 UsageTarget = 1 << 3,
michael@0 35 Usage2D = 1 << 4
michael@0 36 };
michael@0 37
michael@0 38 AndroidGraphicBuffer(uint32_t width, uint32_t height, uint32_t usage, gfxImageFormat format);
michael@0 39 virtual ~AndroidGraphicBuffer();
michael@0 40
michael@0 41 int Lock(uint32_t usage, unsigned char **bits);
michael@0 42 int Lock(uint32_t usage, const nsIntRect& rect, unsigned char **bits);
michael@0 43 int Unlock();
michael@0 44 bool Reallocate(uint32_t aWidth, uint32_t aHeight, gfxImageFormat aFormat);
michael@0 45
michael@0 46 uint32_t Width() { return mWidth; }
michael@0 47 uint32_t Height() { return mHeight; }
michael@0 48
michael@0 49 bool Bind();
michael@0 50
michael@0 51 static bool IsBlacklisted();
michael@0 52
michael@0 53 private:
michael@0 54 uint32_t mWidth;
michael@0 55 uint32_t mHeight;
michael@0 56 uint32_t mUsage;
michael@0 57 gfxImageFormat mFormat;
michael@0 58
michael@0 59 bool EnsureInitialized();
michael@0 60 bool EnsureEGLImage();
michael@0 61
michael@0 62 void DestroyBuffer();
michael@0 63 bool EnsureBufferCreated();
michael@0 64
michael@0 65 uint32_t GetAndroidUsage(uint32_t aUsage);
michael@0 66 uint32_t GetAndroidFormat(gfxImageFormat aFormat);
michael@0 67
michael@0 68 void *mHandle;
michael@0 69 void *mEGLImage;
michael@0 70 };
michael@0 71
michael@0 72 } /* mozilla */
michael@0 73 #endif /* AndroidGraphicBuffer_h_ */

mercurial