|
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_LAYERS_COMPOSITORTYPES_H |
|
7 #define MOZILLA_LAYERS_COMPOSITORTYPES_H |
|
8 |
|
9 #include <stdint.h> // for uint32_t |
|
10 #include <sys/types.h> // for int32_t |
|
11 #include "LayersTypes.h" // for LayersBackend, etc |
|
12 #include "nsXULAppAPI.h" // for GeckoProcessType, etc |
|
13 |
|
14 namespace mozilla { |
|
15 namespace layers { |
|
16 |
|
17 typedef int32_t SurfaceDescriptorType; |
|
18 const SurfaceDescriptorType SURFACEDESCRIPTOR_UNKNOWN = 0; |
|
19 |
|
20 /** |
|
21 * Flags used by texture clients and texture hosts. These are passed from client |
|
22 * side to host side when textures and compositables are created. Usually set |
|
23 * by the compositableCient, they may be modified by either the compositable or |
|
24 * texture clients. |
|
25 * |
|
26 * XXX - switch to all caps constant names which seems to be the standard in gecko |
|
27 */ |
|
28 typedef uint32_t TextureFlags; |
|
29 // Use nearest-neighbour texture filtering (as opposed to linear filtering). |
|
30 const TextureFlags TEXTURE_USE_NEAREST_FILTER = 1 << 0; |
|
31 // The texture should be flipped around the y-axis when composited. |
|
32 const TextureFlags TEXTURE_NEEDS_Y_FLIP = 1 << 1; |
|
33 // Force the texture to be represented using a single tile (note that this means |
|
34 // tiled textures, not tiled layers). |
|
35 const TextureFlags TEXTURE_DISALLOW_BIGIMAGE = 1 << 2; |
|
36 // Allow using 'repeat' mode for wrapping. |
|
37 const TextureFlags TEXTURE_ALLOW_REPEAT = 1 << 3; |
|
38 // The texture represents a tile which is newly created. |
|
39 const TextureFlags TEXTURE_NEW_TILE = 1 << 4; |
|
40 // The texture is part of a component-alpha pair |
|
41 const TextureFlags TEXTURE_COMPONENT_ALPHA = 1 << 5; |
|
42 // The buffer will be treated as if the RB bytes are swapped. |
|
43 // This is useful for rendering using Cairo/Thebes, because there is no |
|
44 // BGRX Android pixel format, and so we have to do byte swapping. |
|
45 // |
|
46 // For example, if the GraphicBuffer has an Android pixel format of |
|
47 // PIXEL_FORMAT_RGBA_8888 and isRBSwapped is true, when it is sampled |
|
48 // (for example, with GL), a BGRA shader should be used. |
|
49 const TextureFlags TEXTURE_RB_SWAPPED = 1 << 6; |
|
50 |
|
51 const TextureFlags TEXTURE_FRONT = 1 << 12; |
|
52 // A texture host on white for component alpha |
|
53 const TextureFlags TEXTURE_ON_WHITE = 1 << 13; |
|
54 // A texture host on black for component alpha |
|
55 const TextureFlags TEXTURE_ON_BLACK = 1 << 14; |
|
56 // A texture host that supports tiling |
|
57 const TextureFlags TEXTURE_TILE = 1 << 15; |
|
58 // A texture should be recycled when no longer in used |
|
59 const TextureFlags TEXTURE_RECYCLE = 1 << 16; |
|
60 // Texture contents should be initialized |
|
61 // from the previous texture. |
|
62 const TextureFlags TEXTURE_COPY_PREVIOUS = 1 << 24; |
|
63 // Who is responsible for deallocating the shared data. |
|
64 // if TEXTURE_DEALLOCATE_CLIENT is set, the shared data is deallocated on the |
|
65 // client side and requires some extra synchronizaion to ensure race-free |
|
66 // deallocation. |
|
67 // The default behaviour is to deallocate on the host side. |
|
68 const TextureFlags TEXTURE_DEALLOCATE_CLIENT = 1 << 25; |
|
69 // After being shared ith the compositor side, an immutable texture is never |
|
70 // modified, it can only be read. It is safe to not Lock/Unlock immutable |
|
71 // textures. |
|
72 const TextureFlags TEXTURE_IMMUTABLE = 1 << 27; |
|
73 // The contents of the texture must be uploaded or copied immediately |
|
74 // during the transaction, because the producer may want to write |
|
75 // to it again. |
|
76 const TextureFlags TEXTURE_IMMEDIATE_UPLOAD = 1 << 28; |
|
77 // The texture is going to be used as part of a double |
|
78 // buffered pair, and so we can guarantee that the producer/consumer |
|
79 // won't be racing to access its contents. |
|
80 const TextureFlags TEXTURE_DOUBLE_BUFFERED = 1 << 29; |
|
81 // We've previously tried a texture and it didn't work for some reason. If there |
|
82 // is a fallback available, try that. |
|
83 const TextureFlags TEXTURE_ALLOC_FALLBACK = 1 << 31; |
|
84 |
|
85 // the default flags |
|
86 const TextureFlags TEXTURE_FLAGS_DEFAULT = TEXTURE_FRONT; |
|
87 |
|
88 static inline bool |
|
89 TextureRequiresLocking(TextureFlags aFlags) |
|
90 { |
|
91 // If we're not double buffered, or uploading |
|
92 // within a transaction, then we need to support |
|
93 // locking correctly. |
|
94 return !(aFlags & (TEXTURE_IMMEDIATE_UPLOAD | |
|
95 TEXTURE_DOUBLE_BUFFERED | |
|
96 TEXTURE_IMMUTABLE)); |
|
97 } |
|
98 |
|
99 /** |
|
100 * The type of debug diagnostic to enable. |
|
101 */ |
|
102 typedef uint32_t DiagnosticTypes; |
|
103 const DiagnosticTypes DIAGNOSTIC_NONE = 0; |
|
104 const DiagnosticTypes DIAGNOSTIC_TILE_BORDERS = 1 << 0; |
|
105 const DiagnosticTypes DIAGNOSTIC_LAYER_BORDERS = 1 << 1; |
|
106 const DiagnosticTypes DIAGNOSTIC_BIGIMAGE_BORDERS = 1 << 2; |
|
107 const DiagnosticTypes DIAGNOSTIC_FLASH_BORDERS = 1 << 3; |
|
108 |
|
109 #define DIAGNOSTIC_FLASH_COUNTER_MAX 100 |
|
110 |
|
111 /** |
|
112 * Information about the object that is being diagnosed. |
|
113 */ |
|
114 typedef uint32_t DiagnosticFlags; |
|
115 const DiagnosticFlags DIAGNOSTIC_IMAGE = 1 << 0; |
|
116 const DiagnosticFlags DIAGNOSTIC_CONTENT = 1 << 1; |
|
117 const DiagnosticFlags DIAGNOSTIC_CANVAS = 1 << 2; |
|
118 const DiagnosticFlags DIAGNOSTIC_COLOR = 1 << 3; |
|
119 const DiagnosticFlags DIAGNOSTIC_CONTAINER = 1 << 4; |
|
120 const DiagnosticFlags DIAGNOSTIC_TILE = 1 << 5; |
|
121 const DiagnosticFlags DIAGNOSTIC_BIGIMAGE = 1 << 6; |
|
122 const DiagnosticFlags DIAGNOSTIC_COMPONENT_ALPHA = 1 << 7; |
|
123 const DiagnosticFlags DIAGNOSTIC_REGION_RECT = 1 << 8; |
|
124 |
|
125 /** |
|
126 * See gfx/layers/Effects.h |
|
127 */ |
|
128 enum EffectTypes |
|
129 { |
|
130 EFFECT_MASK, |
|
131 EFFECT_MAX_SECONDARY, // sentinel for the count of secondary effect types |
|
132 EFFECT_RGB, |
|
133 EFFECT_YCBCR, |
|
134 EFFECT_COMPONENT_ALPHA, |
|
135 EFFECT_SOLID_COLOR, |
|
136 EFFECT_RENDER_TARGET, |
|
137 EFFECT_MAX //sentinel for the count of all effect types |
|
138 }; |
|
139 |
|
140 /** |
|
141 * How the Compositable should manage textures. |
|
142 */ |
|
143 enum CompositableType |
|
144 { |
|
145 BUFFER_UNKNOWN, |
|
146 // the deprecated compositable types |
|
147 BUFFER_IMAGE_SINGLE, // image/canvas with a single texture, single buffered |
|
148 BUFFER_IMAGE_BUFFERED, // canvas, double buffered |
|
149 BUFFER_BRIDGE, // image bridge protocol |
|
150 BUFFER_CONTENT_INC, // thebes layer interface, only sends incremental |
|
151 // updates to a texture on the compositor side. |
|
152 // somewhere in the middle |
|
153 BUFFER_TILED, // tiled thebes layer |
|
154 BUFFER_SIMPLE_TILED, |
|
155 // the new compositable types |
|
156 COMPOSITABLE_IMAGE, // image with single buffering |
|
157 COMPOSITABLE_CONTENT_SINGLE, // thebes layer interface, single buffering |
|
158 COMPOSITABLE_CONTENT_DOUBLE, // thebes layer interface, double buffering |
|
159 BUFFER_COUNT |
|
160 }; |
|
161 |
|
162 /** |
|
163 * How the texture host is used for composition, |
|
164 */ |
|
165 enum DeprecatedTextureHostFlags |
|
166 { |
|
167 TEXTURE_HOST_DEFAULT = 0, // The default texture host for the given |
|
168 // SurfaceDescriptor |
|
169 TEXTURE_HOST_TILED = 1 << 0, // A texture host that supports tiling |
|
170 TEXTURE_HOST_COPY_PREVIOUS = 1 << 1 // Texture contents should be initialized |
|
171 // from the previous texture. |
|
172 }; |
|
173 |
|
174 /** |
|
175 * Sent from the compositor to the content-side LayerManager, includes properties |
|
176 * of the compositor and should (in the future) include information about what |
|
177 * kinds of buffer and texture clients to create. |
|
178 */ |
|
179 struct TextureFactoryIdentifier |
|
180 { |
|
181 LayersBackend mParentBackend; |
|
182 GeckoProcessType mParentProcessId; |
|
183 int32_t mMaxTextureSize; |
|
184 bool mSupportsTextureBlitting; |
|
185 bool mSupportsPartialUploads; |
|
186 |
|
187 TextureFactoryIdentifier(LayersBackend aLayersBackend = LayersBackend::LAYERS_NONE, |
|
188 GeckoProcessType aParentProcessId = GeckoProcessType_Default, |
|
189 int32_t aMaxTextureSize = 0, |
|
190 bool aSupportsTextureBlitting = false, |
|
191 bool aSupportsPartialUploads = false) |
|
192 : mParentBackend(aLayersBackend) |
|
193 , mParentProcessId(aParentProcessId) |
|
194 , mMaxTextureSize(aMaxTextureSize) |
|
195 , mSupportsTextureBlitting(aSupportsTextureBlitting) |
|
196 , mSupportsPartialUploads(aSupportsPartialUploads) |
|
197 {} |
|
198 }; |
|
199 |
|
200 /** |
|
201 * Identify a texture to a compositable. Many textures can have the same id, but |
|
202 * the id is unique for any texture owned by a particular compositable. |
|
203 * XXX - This is now redundant with TextureFlags. it ill be removed along with |
|
204 * deprecated texture classes. |
|
205 */ |
|
206 typedef uint32_t TextureIdentifier; |
|
207 const TextureIdentifier TextureFront = 1; |
|
208 const TextureIdentifier TextureBack = 2; |
|
209 const TextureIdentifier TextureOnWhiteFront = 3; |
|
210 const TextureIdentifier TextureOnWhiteBack = 4; |
|
211 |
|
212 /** |
|
213 * Information required by the compositor from the content-side for creating or |
|
214 * using compositables and textures. |
|
215 * XXX - TextureInfo is a bad name: this information is useful for the compositable, |
|
216 * not the Texture. And ith new Textures, only the compositable type is really |
|
217 * useful. This may (should) be removed in the near future. |
|
218 */ |
|
219 struct TextureInfo |
|
220 { |
|
221 CompositableType mCompositableType; |
|
222 uint32_t mDeprecatedTextureHostFlags; |
|
223 uint32_t mTextureFlags; |
|
224 |
|
225 TextureInfo() |
|
226 : mCompositableType(BUFFER_UNKNOWN) |
|
227 , mDeprecatedTextureHostFlags(0) |
|
228 , mTextureFlags(0) |
|
229 {} |
|
230 |
|
231 TextureInfo(CompositableType aType) |
|
232 : mCompositableType(aType) |
|
233 , mDeprecatedTextureHostFlags(0) |
|
234 , mTextureFlags(0) |
|
235 {} |
|
236 |
|
237 bool operator==(const TextureInfo& aOther) const |
|
238 { |
|
239 return mCompositableType == aOther.mCompositableType && |
|
240 mDeprecatedTextureHostFlags == aOther.mDeprecatedTextureHostFlags && |
|
241 mTextureFlags == aOther.mTextureFlags; |
|
242 } |
|
243 }; |
|
244 |
|
245 /** |
|
246 * How a SurfaceDescriptor will be opened. |
|
247 * |
|
248 * See ShadowLayerForwarder::OpenDescriptor for example. |
|
249 */ |
|
250 typedef uint32_t OpenMode; |
|
251 const OpenMode OPEN_READ = 0x1; |
|
252 const OpenMode OPEN_WRITE = 0x2; |
|
253 const OpenMode OPEN_READ_WRITE = OPEN_READ|OPEN_WRITE; |
|
254 const OpenMode OPEN_READ_ONLY = OPEN_READ; |
|
255 const OpenMode OPEN_WRITE_ONLY = OPEN_WRITE; |
|
256 |
|
257 // The kinds of mask texture a shader can support |
|
258 // We rely on the items in this enum being sequential |
|
259 enum MaskType { |
|
260 MaskNone = 0, // no mask layer |
|
261 Mask2d, // mask layer for layers with 2D transforms |
|
262 Mask3d, // mask layer for layers with 3D transforms |
|
263 NumMaskTypes |
|
264 }; |
|
265 |
|
266 } // namespace layers |
|
267 } // namespace mozilla |
|
268 |
|
269 #endif |