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
10 #include <stdint.h> // for uint32_t
11 #include <sys/types.h> // for int32_t
12 #include "LayersTypes.h" // for LayersBackend, etc
13 #include "nsXULAppAPI.h" // for GeckoProcessType, etc
14 #include "mozilla/gfx/Types.h"
15 #include "mozilla/EnumSet.h"
17 #include "mozilla/TypedEnumBits.h"
23 * Flags used by texture clients and texture hosts. These are passed from client
24 * side to host side when textures and compositables are created. Usually set
25 * by the compositableCient, they may be modified by either the compositable or
28 enum class TextureFlags
: uint32_t {
30 // Use nearest-neighbour texture filtering (as opposed to linear filtering).
31 USE_NEAREST_FILTER
= 1 << 0,
32 // The compositor assumes everything is origin-top-left by default.
33 ORIGIN_BOTTOM_LEFT
= 1 << 1,
34 // Force the texture to be represented using a single tile (note that this
35 // means tiled textures, not tiled layers).
36 DISALLOW_BIGIMAGE
= 1 << 2,
37 // The buffer will be treated as if the RB bytes are swapped.
38 // This is useful for rendering using Cairo/Thebes, because there is no
39 // BGRX Android pixel format, and so we have to do byte swapping.
41 // For example, if the GraphicBuffer has an Android pixel format of
42 // PIXEL_FORMAT_RGBA_8888 and isRBSwapped is true, when it is sampled
43 // (for example, with GL), a BGRA shader should be used.
45 // Data in this texture has not been alpha-premultiplied.
46 // XXX - Apparently only used with ImageClient/Host
47 NON_PREMULTIPLIED
= 1 << 4,
48 // The TextureClient should be recycled with recycle callback when no longer
49 // in used. When the texture is used in host side, ref count of TextureClient
50 // is transparently added by ShadowLayerForwarder or ImageBridgeChild.
52 // If DEALLOCATE_CLIENT is set, the shared data is deallocated on the
53 // client side and requires some extra synchronizaion to ensure race-free
55 // The default behaviour is to deallocate on the host side.
56 DEALLOCATE_CLIENT
= 1 << 6,
57 DEALLOCATE_SYNC
= 1 << 6, // XXX - make it a separate flag.
58 DEALLOCATE_MAIN_THREAD
= 1 << 8,
59 // After being shared ith the compositor side, an immutable texture is never
60 // modified, it can only be read. It is safe to not Lock/Unlock immutable
63 // The contents of the texture must be uploaded or copied immediately
64 // during the transaction, because the producer may want to write
66 IMMEDIATE_UPLOAD
= 1 << 10,
67 // The texture is part of a component-alpha pair
68 COMPONENT_ALPHA
= 1 << 11,
69 // The texture is being allocated for a compositor that no longer exists.
70 // This flag is only used in the parent process.
71 INVALID_COMPOSITOR
= 1 << 12,
72 // The texture was created by converting from YCBCR to RGB
73 RGB_FROM_YCBCR
= 1 << 13,
74 // The texture is used for snapshot.
76 // Enable a non blocking read lock.
77 NON_BLOCKING_READ_LOCK
= 1 << 15,
78 // Enable a blocking read lock.
79 BLOCKING_READ_LOCK
= 1 << 16,
80 // Keep TextureClient alive when host side is used
81 WAIT_HOST_USAGE_END
= 1 << 17,
83 // OR union of all valid bits
84 ALL_BITS
= (1 << 18) - 1,
88 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(TextureFlags
)
90 static inline bool TextureRequiresLocking(TextureFlags aFlags
) {
91 // If we're not double buffered, or uploading
92 // within a transaction, then we need to support
94 return !(aFlags
& (TextureFlags::IMMEDIATE_UPLOAD
| TextureFlags::IMMUTABLE
));
98 * The type of debug diagnostic to enable.
100 enum class DiagnosticTypes
: uint8_t {
102 TILE_BORDERS
= 1 << 0,
103 LAYER_BORDERS
= 1 << 1,
104 BIGIMAGE_BORDERS
= 1 << 2,
105 FLASH_BORDERS
= 1 << 3,
106 ALL_BITS
= (1 << 4) - 1
108 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(DiagnosticTypes
)
110 #define DIAGNOSTIC_FLASH_COUNTER_MAX 100
113 * Information about the object that is being diagnosed.
115 enum class DiagnosticFlags
: uint16_t {
124 COMPONENT_ALPHA
= 1 << 7,
125 REGION_RECT
= 1 << 8,
129 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(DiagnosticFlags
)
132 * See gfx/layers/Effects.h
134 enum class EffectTypes
: uint8_t {
138 MAX_SECONDARY
, // sentinel for the count of secondary effect types
145 MAX
// sentinel for the count of all effect types
149 * How the Compositable should manage textures.
151 enum class CompositableType
: uint8_t {
153 CONTENT_TILED
, // tiled painted layer
154 IMAGE
, // image with single buffering
155 IMAGE_BRIDGE
, // ImageBridge protocol
156 CONTENT_SINGLE
, // painted layer interface, single buffering
157 CONTENT_DOUBLE
, // painted layer interface, double buffering
162 typedef void* SyncHandle
;
164 typedef uintptr_t SyncHandle
;
168 * Sent from the compositor to the content-side LayerManager, includes
169 * properties of the compositor and should (in the future) include information
170 * about what kinds of buffer and texture clients to create.
172 struct TextureFactoryIdentifier
{
173 LayersBackend mParentBackend
;
174 GeckoProcessType mParentProcessType
;
175 int32_t mMaxTextureSize
;
176 bool mSupportsTextureDirectMapping
;
177 bool mCompositorUseANGLE
;
178 bool mCompositorUseDComp
;
179 bool mUseCompositorWnd
;
180 bool mSupportsTextureBlitting
;
181 bool mSupportsPartialUploads
;
182 bool mSupportsComponentAlpha
;
183 bool mUsingAdvancedLayers
;
184 SyncHandle mSyncHandle
;
186 explicit TextureFactoryIdentifier(
187 LayersBackend aLayersBackend
= LayersBackend::LAYERS_NONE
,
188 GeckoProcessType aParentProcessType
= GeckoProcessType_Default
,
189 int32_t aMaxTextureSize
= 4096,
190 bool aSupportsTextureDirectMapping
= false,
191 bool aCompositorUseANGLE
= false, bool aCompositorUseDComp
= false,
192 bool aUseCompositorWnd
= false, bool aSupportsTextureBlitting
= false,
193 bool aSupportsPartialUploads
= false, bool aSupportsComponentAlpha
= true,
194 SyncHandle aSyncHandle
= 0)
195 : mParentBackend(aLayersBackend
),
196 mParentProcessType(aParentProcessType
),
197 mMaxTextureSize(aMaxTextureSize
),
198 mSupportsTextureDirectMapping(aSupportsTextureDirectMapping
),
199 mCompositorUseANGLE(aCompositorUseANGLE
),
200 mCompositorUseDComp(aCompositorUseDComp
),
201 mUseCompositorWnd(aUseCompositorWnd
),
202 mSupportsTextureBlitting(aSupportsTextureBlitting
),
203 mSupportsPartialUploads(aSupportsPartialUploads
),
204 mSupportsComponentAlpha(aSupportsComponentAlpha
),
205 mUsingAdvancedLayers(false),
206 mSyncHandle(aSyncHandle
) {}
208 bool operator==(const TextureFactoryIdentifier
& aOther
) const {
209 return mParentBackend
== aOther
.mParentBackend
&&
210 mParentProcessType
== aOther
.mParentProcessType
&&
211 mMaxTextureSize
== aOther
.mMaxTextureSize
&&
212 mSupportsTextureDirectMapping
==
213 aOther
.mSupportsTextureDirectMapping
&&
214 mCompositorUseANGLE
== aOther
.mCompositorUseANGLE
&&
215 mCompositorUseDComp
== aOther
.mCompositorUseDComp
&&
216 mUseCompositorWnd
== aOther
.mUseCompositorWnd
&&
217 mSupportsTextureBlitting
== aOther
.mSupportsTextureBlitting
&&
218 mSupportsPartialUploads
== aOther
.mSupportsPartialUploads
&&
219 mSupportsComponentAlpha
== aOther
.mSupportsComponentAlpha
&&
220 mUsingAdvancedLayers
== aOther
.mUsingAdvancedLayers
&&
221 mSyncHandle
== aOther
.mSyncHandle
;
226 * Information required by the compositor from the content-side for creating or
227 * using compositables and textures.
228 * XXX - TextureInfo is a bad name: this information is useful for the
229 * compositable, not the Texture. And ith new Textures, only the compositable
230 * type is really useful. This may (should) be removed in the near future.
233 CompositableType mCompositableType
;
234 TextureFlags mTextureFlags
;
237 : mCompositableType(CompositableType::UNKNOWN
),
238 mTextureFlags(TextureFlags::NO_FLAGS
) {}
240 explicit TextureInfo(CompositableType aType
,
241 TextureFlags aTextureFlags
= TextureFlags::DEFAULT
)
242 : mCompositableType(aType
), mTextureFlags(aTextureFlags
) {}
244 bool operator==(const TextureInfo
& aOther
) const {
245 return mCompositableType
== aOther
.mCompositableType
&&
246 mTextureFlags
== aOther
.mTextureFlags
;
251 * How a SurfaceDescriptor will be opened.
253 * See ShadowLayerForwarder::OpenDescriptor for example.
255 enum class OpenMode
: uint8_t {
259 // This is only used in conjunction with OMTP to indicate that the DrawTarget
260 // that is being borrowed will be painted asynchronously, and so will outlive
264 OPEN_READ_WRITE
= OPEN_READ
| OPEN_WRITE
,
265 OPEN_READ_WRITE_ASYNC
= OPEN_READ
| OPEN_WRITE
| OPEN_ASYNC
,
266 OPEN_READ_ASYNC
= OPEN_READ
| OPEN_ASYNC
,
267 OPEN_READ_ONLY
= OPEN_READ
,
268 OPEN_WRITE_ONLY
= OPEN_WRITE
,
270 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(OpenMode
)
272 // The kinds of mask texture a shader can support
273 // We rely on the items in this enum being sequential
274 enum class MaskType
: uint8_t {
275 MaskNone
= 0, // no mask layer
280 } // namespace layers
281 } // namespace mozilla