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 AndroidDirectTexture_h_
7 #define AndroidDirectTexture_h_
9 #include "gfxTypes.h"
10 #include "mozilla/Mutex.h"
11 #include "AndroidGraphicBuffer.h"
13 struct nsIntRect;
15 namespace mozilla {
17 /**
18 * This is a thread safe wrapper around AndroidGraphicBuffer that handles
19 * double buffering. Each call to Bind() flips the buffer when necessary.
20 *
21 * You need to be careful when destroying an instance of this class. If either
22 * buffer is locked by the application of the driver/hardware, bad things will
23 * happen. Be sure that the OpenGL texture is no longer on the screen.
24 */
25 class AndroidDirectTexture
26 {
27 public:
28 AndroidDirectTexture(uint32_t width, uint32_t height, uint32_t usage, gfxImageFormat format);
29 virtual ~AndroidDirectTexture();
31 bool Lock(uint32_t usage, unsigned char **bits);
32 bool Lock(uint32_t usage, const nsIntRect& rect, unsigned char **bits);
33 bool Unlock(bool aFlip = true);
35 bool Reallocate(uint32_t aWidth, uint32_t aHeight);
36 bool Reallocate(uint32_t aWidth, uint32_t aHeight, gfxImageFormat aFormat);
38 uint32_t Width() { return mWidth; }
39 uint32_t Height() { return mHeight; }
41 bool Bind();
43 private:
44 mozilla::Mutex mLock;
45 bool mNeedFlip;
47 uint32_t mWidth;
48 uint32_t mHeight;
49 gfxImageFormat mFormat;
51 AndroidGraphicBuffer* mFrontBuffer;
52 AndroidGraphicBuffer* mBackBuffer;
54 AndroidGraphicBuffer* mPendingReallocBuffer;
55 void ReallocPendingBuffer();
56 };
58 } /* mozilla */
59 #endif /* AndroidDirectTexture_h_ */