|
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 AndroidDirectTexture_h_ |
|
7 #define AndroidDirectTexture_h_ |
|
8 |
|
9 #include "gfxTypes.h" |
|
10 #include "mozilla/Mutex.h" |
|
11 #include "AndroidGraphicBuffer.h" |
|
12 |
|
13 struct nsIntRect; |
|
14 |
|
15 namespace mozilla { |
|
16 |
|
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(); |
|
30 |
|
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); |
|
34 |
|
35 bool Reallocate(uint32_t aWidth, uint32_t aHeight); |
|
36 bool Reallocate(uint32_t aWidth, uint32_t aHeight, gfxImageFormat aFormat); |
|
37 |
|
38 uint32_t Width() { return mWidth; } |
|
39 uint32_t Height() { return mHeight; } |
|
40 |
|
41 bool Bind(); |
|
42 |
|
43 private: |
|
44 mozilla::Mutex mLock; |
|
45 bool mNeedFlip; |
|
46 |
|
47 uint32_t mWidth; |
|
48 uint32_t mHeight; |
|
49 gfxImageFormat mFormat; |
|
50 |
|
51 AndroidGraphicBuffer* mFrontBuffer; |
|
52 AndroidGraphicBuffer* mBackBuffer; |
|
53 |
|
54 AndroidGraphicBuffer* mPendingReallocBuffer; |
|
55 void ReallocPendingBuffer(); |
|
56 }; |
|
57 |
|
58 } /* mozilla */ |
|
59 #endif /* AndroidDirectTexture_h_ */ |