|
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 MOZILLA_GFX_GRALLOCTEXTURECLIENT_H |
|
7 #define MOZILLA_GFX_GRALLOCTEXTURECLIENT_H |
|
8 #ifdef MOZ_WIDGET_GONK |
|
9 |
|
10 #include "mozilla/layers/TextureClient.h" |
|
11 #include "ISurfaceAllocator.h" // For IsSurfaceDescriptorValid |
|
12 #include "mozilla/layers/FenceUtils.h" // for FenceHandle |
|
13 #include "mozilla/layers/ShadowLayerUtilsGralloc.h" |
|
14 #include <ui/GraphicBuffer.h> |
|
15 |
|
16 |
|
17 namespace android { |
|
18 class MediaBuffer; |
|
19 }; |
|
20 |
|
21 namespace mozilla { |
|
22 namespace layers { |
|
23 |
|
24 /** |
|
25 * A TextureClient implementation based on android::GraphicBuffer (also referred to |
|
26 * as "gralloc"). |
|
27 * |
|
28 * Gralloc lets us map texture data in memory (accessible through pointers) |
|
29 * and also use it directly as an OpenGL texture without the cost of texture |
|
30 * uploads. |
|
31 * Gralloc buffers can also be shared accros processes. |
|
32 * |
|
33 * More info about Gralloc here: https://wiki.mozilla.org/Platform/GFX/Gralloc |
|
34 * |
|
35 * This is only used in Firefox OS |
|
36 */ |
|
37 class GrallocTextureClientOGL : public BufferTextureClient |
|
38 { |
|
39 public: |
|
40 GrallocTextureClientOGL(GrallocBufferActor* aActor, |
|
41 gfx::IntSize aSize, |
|
42 gfx::BackendType aMoz2dBackend, |
|
43 TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT); |
|
44 GrallocTextureClientOGL(ISurfaceAllocator* aAllocator, |
|
45 gfx::SurfaceFormat aFormat, |
|
46 gfx::BackendType aMoz2dBackend, |
|
47 TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT); |
|
48 |
|
49 ~GrallocTextureClientOGL(); |
|
50 |
|
51 virtual bool Lock(OpenMode aMode) MOZ_OVERRIDE; |
|
52 |
|
53 virtual void Unlock() MOZ_OVERRIDE; |
|
54 |
|
55 virtual bool ImplementsLocking() const MOZ_OVERRIDE { return true; } |
|
56 |
|
57 virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return false; } |
|
58 |
|
59 virtual bool IsAllocated() const MOZ_OVERRIDE; |
|
60 |
|
61 virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) MOZ_OVERRIDE; |
|
62 |
|
63 virtual TextureClientData* DropTextureData() MOZ_OVERRIDE; |
|
64 |
|
65 virtual void SetReleaseFenceHandle(FenceHandle aReleaseFenceHandle) MOZ_OVERRIDE; |
|
66 |
|
67 virtual void WaitReleaseFence() MOZ_OVERRIDE; |
|
68 |
|
69 void InitWith(GrallocBufferActor* aActor, gfx::IntSize aSize); |
|
70 |
|
71 void SetTextureFlags(TextureFlags aFlags) { AddFlags(aFlags); } |
|
72 |
|
73 gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; } |
|
74 |
|
75 android::sp<android::GraphicBuffer> GetGraphicBuffer() |
|
76 { |
|
77 return mGraphicBuffer; |
|
78 } |
|
79 |
|
80 android::PixelFormat GetPixelFormat() |
|
81 { |
|
82 return mGraphicBuffer->getPixelFormat(); |
|
83 } |
|
84 |
|
85 virtual uint8_t* GetBuffer() const MOZ_OVERRIDE; |
|
86 |
|
87 virtual TemporaryRef<gfx::DrawTarget> GetAsDrawTarget() MOZ_OVERRIDE; |
|
88 |
|
89 virtual bool AllocateForSurface(gfx::IntSize aSize, |
|
90 TextureAllocationFlags aFlags = ALLOC_DEFAULT) MOZ_OVERRIDE; |
|
91 |
|
92 virtual bool AllocateForYCbCr(gfx::IntSize aYSize, |
|
93 gfx::IntSize aCbCrSize, |
|
94 StereoMode aStereoMode) MOZ_OVERRIDE; |
|
95 |
|
96 bool AllocateForGLRendering(gfx::IntSize aSize); |
|
97 |
|
98 bool AllocateGralloc(gfx::IntSize aYSize, uint32_t aAndroidFormat, uint32_t aUsage); |
|
99 |
|
100 virtual bool Allocate(uint32_t aSize) MOZ_OVERRIDE; |
|
101 |
|
102 virtual size_t GetBufferSize() const MOZ_OVERRIDE; |
|
103 |
|
104 /** |
|
105 * Hold android::MediaBuffer. |
|
106 * MediaBuffer needs to be add refed to keep MediaBuffer alive |
|
107 * during TextureClient is in use. |
|
108 */ |
|
109 void SetMediaBuffer(android::MediaBuffer* aMediaBuffer) |
|
110 { |
|
111 mMediaBuffer = aMediaBuffer; |
|
112 } |
|
113 |
|
114 android::MediaBuffer* GetMediaBuffer() |
|
115 { |
|
116 return mMediaBuffer; |
|
117 } |
|
118 |
|
119 protected: |
|
120 /** |
|
121 * Unfortunately, until bug 879681 is fixed we need to use a GrallocBufferActor. |
|
122 */ |
|
123 GrallocBufferActor* mGrallocActor; |
|
124 |
|
125 android::sp<android::GraphicBuffer> mGraphicBuffer; |
|
126 |
|
127 /** |
|
128 * Points to a mapped gralloc buffer between calls to lock and unlock. |
|
129 * Should be null outside of the lock-unlock pair. |
|
130 */ |
|
131 uint8_t* mMappedBuffer; |
|
132 |
|
133 RefPtr<gfx::DrawTarget> mDrawTarget; |
|
134 |
|
135 /** |
|
136 * android::GraphicBuffer has a size information. But there are cases |
|
137 * that GraphicBuffer's size and actual video's size are different. |
|
138 * Extra size member is necessary. See Bug 850566. |
|
139 */ |
|
140 gfx::IntSize mSize; |
|
141 |
|
142 android::MediaBuffer* mMediaBuffer; |
|
143 }; |
|
144 |
|
145 } // namespace layers |
|
146 } // namespace mozilla |
|
147 |
|
148 #endif // MOZ_WIDGET_GONK |
|
149 #endif |