1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef MOZILLA_LAYERS_COMPOSITORTYPES_H
8 #define MOZILLA_LAYERS_COMPOSITORTYPES_H
11 #include <stdint.h> // for uint32_t
12 #include <sys/types.h> // for int32_t
13 #include "LayersTypes.h" // for LayersBackend, etc
14 #include "nsXULAppAPI.h" // for GeckoProcessType, etc
15 #include "mozilla/gfx/Types.h"
16 #include "mozilla/EnumSet.h"
18 #include "mozilla/TypedEnumBits.h"
24 * Flags used by texture clients and texture hosts. These are passed from client
25 * side to host side when textures and compositables are created. Usually set
26 * by the compositableCient, they may be modified by either the compositable or
29 enum class TextureFlags
: uint32_t {
31 // Use nearest-neighbour texture filtering (as opposed to linear filtering).
32 USE_NEAREST_FILTER
= 1 << 0,
33 // The compositor assumes everything is origin-top-left by default.
34 ORIGIN_BOTTOM_LEFT
= 1 << 1,
35 // Force the texture to be represented using a single tile (note that this
36 // means tiled textures, not tiled layers).
37 DISALLOW_BIGIMAGE
= 1 << 2,
38 // The buffer will be treated as if the RB bytes are swapped.
39 // This is useful for rendering using Cairo/Thebes, because there is no
40 // BGRX Android pixel format, and so we have to do byte swapping.
42 // For example, if the GraphicBuffer has an Android pixel format of
43 // PIXEL_FORMAT_RGBA_8888 and isRBSwapped is true, when it is sampled
44 // (for example, with GL), a BGRA shader should be used.
46 // Data in this texture has not been alpha-premultiplied.
47 // XXX - Apparently only used with ImageClient/Host
48 NON_PREMULTIPLIED
= 1 << 4,
49 // The TextureClient should be recycled with recycle callback when no longer
50 // in used. When the texture is used in host side, ref count of TextureClient
51 // is transparently added by ShadowLayerForwarder or ImageBridgeChild.
53 // If DEALLOCATE_CLIENT is set, the shared data is deallocated on the
54 // client side and requires some extra synchronizaion to ensure race-free
56 // The default behaviour is to deallocate on the host side.
57 DEALLOCATE_CLIENT
= 1 << 6,
58 DEALLOCATE_SYNC
= 1 << 6, // XXX - make it a separate flag.
59 DEALLOCATE_MAIN_THREAD
= 1 << 8,
60 // After being shared ith the compositor side, an immutable texture is never
61 // modified, it can only be read. It is safe to not Lock/Unlock immutable
64 // The contents of the texture must be uploaded or copied immediately
65 // during the transaction, because the producer may want to write
67 IMMEDIATE_UPLOAD
= 1 << 10,
68 // The texture is part of a component-alpha pair
69 COMPONENT_ALPHA
= 1 << 11,
70 // The texture is being allocated for a compositor that no longer exists.
71 // This flag is only used in the parent process.
72 INVALID_COMPOSITOR
= 1 << 12,
73 // The texture was created by converting from YCBCR to RGB
74 RGB_FROM_YCBCR
= 1 << 13,
75 // The texture is used for snapshot.
77 // Enable a non blocking read lock.
78 NON_BLOCKING_READ_LOCK
= 1 << 15,
79 // Enable a blocking read lock.
80 BLOCKING_READ_LOCK
= 1 << 16,
81 // Keep TextureClient alive when host side is used
82 WAIT_HOST_USAGE_END
= 1 << 17,
83 // The texture is guaranteed to have alpha 1.0 everywhere; some backends
84 // have trouble with RGBX/BGRX formats, so we use RGBA/BGRA but set this
85 // hint when we know alpha is opaque (eg. WebGL)
88 // OR union of all valid bits
89 ALL_BITS
= (1 << 19) - 1,
93 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(TextureFlags
)
95 std::ostream
& operator<<(std::ostream
& aStream
, const TextureFlags
& aFlags
);
97 static inline bool TextureRequiresLocking(TextureFlags aFlags
) {
98 // If we're not double buffered, or uploading
99 // within a transaction, then we need to support
100 // locking correctly.
101 return !(aFlags
& (TextureFlags::IMMEDIATE_UPLOAD
| TextureFlags::IMMUTABLE
));
105 * The type of debug diagnostic to enable.
107 enum class DiagnosticTypes
: uint8_t {
109 TILE_BORDERS
= 1 << 0,
110 LAYER_BORDERS
= 1 << 1,
111 BIGIMAGE_BORDERS
= 1 << 2,
112 FLASH_BORDERS
= 1 << 3,
113 ALL_BITS
= (1 << 4) - 1
115 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(DiagnosticTypes
)
117 #define DIAGNOSTIC_FLASH_COUNTER_MAX 100
120 * Information about the object that is being diagnosed.
122 enum class DiagnosticFlags
: uint16_t {
131 COMPONENT_ALPHA
= 1 << 7,
132 REGION_RECT
= 1 << 8,
136 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(DiagnosticFlags
)
139 * See gfx/layers/Effects.h
141 enum class EffectTypes
: uint8_t {
145 MAX_SECONDARY
, // sentinel for the count of secondary effect types
152 MAX
// sentinel for the count of all effect types
156 * How the Compositable should manage textures.
158 enum class CompositableType
: uint8_t {
160 CONTENT_TILED
, // tiled painted layer
161 IMAGE
, // image with single buffering
162 IMAGE_BRIDGE
, // ImageBridge protocol
163 CONTENT_SINGLE
, // painted layer interface, single buffering
164 CONTENT_DOUBLE
, // painted layer interface, double buffering
169 typedef void* SyncHandle
;
171 typedef uintptr_t SyncHandle
;
175 * Sent from the compositor to the content-side LayerManager, includes
176 * properties of the compositor and should (in the future) include information
177 * about what kinds of buffer and texture clients to create.
179 struct TextureFactoryIdentifier
{
180 LayersBackend mParentBackend
;
181 WebRenderBackend mWebRenderBackend
;
182 WebRenderCompositor mWebRenderCompositor
;
183 GeckoProcessType mParentProcessType
;
184 int32_t mMaxTextureSize
;
185 bool mSupportsTextureDirectMapping
;
186 bool mCompositorUseANGLE
;
187 bool mCompositorUseDComp
;
188 bool mUseCompositorWnd
;
189 bool mSupportsTextureBlitting
;
190 bool mSupportsPartialUploads
;
191 bool mSupportsComponentAlpha
;
192 bool mUsingAdvancedLayers
;
193 SyncHandle mSyncHandle
;
195 explicit TextureFactoryIdentifier(
196 LayersBackend aLayersBackend
= LayersBackend::LAYERS_NONE
,
197 GeckoProcessType aParentProcessType
= GeckoProcessType_Default
,
198 int32_t aMaxTextureSize
= 4096,
199 bool aSupportsTextureDirectMapping
= false,
200 bool aCompositorUseANGLE
= false, bool aCompositorUseDComp
= false,
201 bool aUseCompositorWnd
= false, bool aSupportsTextureBlitting
= false,
202 bool aSupportsPartialUploads
= false, bool aSupportsComponentAlpha
= true,
203 SyncHandle aSyncHandle
= 0)
204 : mParentBackend(aLayersBackend
),
205 mWebRenderBackend(WebRenderBackend::HARDWARE
),
206 mWebRenderCompositor(WebRenderCompositor::DRAW
),
207 mParentProcessType(aParentProcessType
),
208 mMaxTextureSize(aMaxTextureSize
),
209 mSupportsTextureDirectMapping(aSupportsTextureDirectMapping
),
210 mCompositorUseANGLE(aCompositorUseANGLE
),
211 mCompositorUseDComp(aCompositorUseDComp
),
212 mUseCompositorWnd(aUseCompositorWnd
),
213 mSupportsTextureBlitting(aSupportsTextureBlitting
),
214 mSupportsPartialUploads(aSupportsPartialUploads
),
215 mSupportsComponentAlpha(aSupportsComponentAlpha
),
216 mUsingAdvancedLayers(false),
217 mSyncHandle(aSyncHandle
) {}
219 explicit TextureFactoryIdentifier(
220 WebRenderBackend aWebRenderBackend
,
221 WebRenderCompositor aWebRenderCompositor
,
222 GeckoProcessType aParentProcessType
= GeckoProcessType_Default
,
223 int32_t aMaxTextureSize
= 4096,
224 bool aSupportsTextureDirectMapping
= false,
225 bool aCompositorUseANGLE
= false, bool aCompositorUseDComp
= false,
226 bool aUseCompositorWnd
= false, bool aSupportsTextureBlitting
= false,
227 bool aSupportsPartialUploads
= false, bool aSupportsComponentAlpha
= true,
228 SyncHandle aSyncHandle
= 0)
229 : mParentBackend(LayersBackend::LAYERS_WR
),
230 mWebRenderBackend(aWebRenderBackend
),
231 mWebRenderCompositor(aWebRenderCompositor
),
232 mParentProcessType(aParentProcessType
),
233 mMaxTextureSize(aMaxTextureSize
),
234 mSupportsTextureDirectMapping(aSupportsTextureDirectMapping
),
235 mCompositorUseANGLE(aCompositorUseANGLE
),
236 mCompositorUseDComp(aCompositorUseDComp
),
237 mUseCompositorWnd(aUseCompositorWnd
),
238 mSupportsTextureBlitting(aSupportsTextureBlitting
),
239 mSupportsPartialUploads(aSupportsPartialUploads
),
240 mSupportsComponentAlpha(aSupportsComponentAlpha
),
241 mUsingAdvancedLayers(false),
242 mSyncHandle(aSyncHandle
) {}
244 bool operator==(const TextureFactoryIdentifier
& aOther
) const {
245 return mParentBackend
== aOther
.mParentBackend
&&
246 mWebRenderBackend
== aOther
.mWebRenderBackend
&&
247 mWebRenderCompositor
== aOther
.mWebRenderCompositor
&&
248 mParentProcessType
== aOther
.mParentProcessType
&&
249 mMaxTextureSize
== aOther
.mMaxTextureSize
&&
250 mSupportsTextureDirectMapping
==
251 aOther
.mSupportsTextureDirectMapping
&&
252 mCompositorUseANGLE
== aOther
.mCompositorUseANGLE
&&
253 mCompositorUseDComp
== aOther
.mCompositorUseDComp
&&
254 mUseCompositorWnd
== aOther
.mUseCompositorWnd
&&
255 mSupportsTextureBlitting
== aOther
.mSupportsTextureBlitting
&&
256 mSupportsPartialUploads
== aOther
.mSupportsPartialUploads
&&
257 mSupportsComponentAlpha
== aOther
.mSupportsComponentAlpha
&&
258 mUsingAdvancedLayers
== aOther
.mUsingAdvancedLayers
&&
259 mSyncHandle
== aOther
.mSyncHandle
;
264 * Information required by the compositor from the content-side for creating or
265 * using compositables and textures.
266 * XXX - TextureInfo is a bad name: this information is useful for the
267 * compositable, not the Texture. And ith new Textures, only the compositable
268 * type is really useful. This may (should) be removed in the near future.
271 CompositableType mCompositableType
;
272 TextureFlags mTextureFlags
;
275 : mCompositableType(CompositableType::UNKNOWN
),
276 mTextureFlags(TextureFlags::NO_FLAGS
) {}
278 explicit TextureInfo(CompositableType aType
,
279 TextureFlags aTextureFlags
= TextureFlags::DEFAULT
)
280 : mCompositableType(aType
), mTextureFlags(aTextureFlags
) {}
282 bool operator==(const TextureInfo
& aOther
) const {
283 return mCompositableType
== aOther
.mCompositableType
&&
284 mTextureFlags
== aOther
.mTextureFlags
;
289 * How a SurfaceDescriptor will be opened.
291 * See ShadowLayerForwarder::OpenDescriptor for example.
293 enum class OpenMode
: uint8_t {
297 // This is only used in conjunction with OMTP to indicate that the DrawTarget
298 // that is being borrowed will be painted asynchronously, and so will outlive
302 OPEN_READ_WRITE
= OPEN_READ
| OPEN_WRITE
,
303 OPEN_READ_WRITE_ASYNC
= OPEN_READ
| OPEN_WRITE
| OPEN_ASYNC
,
304 OPEN_READ_ASYNC
= OPEN_READ
| OPEN_ASYNC
,
305 OPEN_READ_ONLY
= OPEN_READ
,
306 OPEN_WRITE_ONLY
= OPEN_WRITE
,
308 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(OpenMode
)
310 // The kinds of mask texture a shader can support
311 // We rely on the items in this enum being sequential
312 enum class MaskType
: uint8_t {
313 MaskNone
= 0, // no mask layer
318 } // namespace layers
319 } // namespace mozilla