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 // 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,
82 // The texture is guaranteed to have alpha 1.0 everywhere; some backends
83 // have trouble with RGBX/BGRX formats, so we use RGBA/BGRA but set this
84 // hint when we know alpha is opaque (eg. WebGL)
86 // The ExternalImageId bound to the texture is borrowed and should not be
87 // explicitly released when the texture is freed. This is meant to be used
88 // with WebRenderTextureHost wrapping another TextureHost which was
89 // initialized with its own external image ID.
90 BORROWED_EXTERNAL_ID
= 1 << 19,
91 // The texture is used for remote texture.
92 REMOTE_TEXTURE
= 1 << 20,
93 // The texture is from a DRM source.
96 // OR union of all valid bits
97 ALL_BITS
= (1 << 22) - 1,
101 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(TextureFlags
)
103 std::ostream
& operator<<(std::ostream
& aStream
, const TextureFlags
& aFlags
);
105 static inline bool TextureRequiresLocking(TextureFlags aFlags
) {
106 // If we're not double buffered, or uploading
107 // within a transaction, then we need to support
108 // locking correctly.
109 return !(aFlags
& TextureFlags::IMMUTABLE
);
113 * The type of debug diagnostic to enable.
115 enum class DiagnosticTypes
: uint8_t {
117 TILE_BORDERS
= 1 << 0,
118 LAYER_BORDERS
= 1 << 1,
119 BIGIMAGE_BORDERS
= 1 << 2,
120 FLASH_BORDERS
= 1 << 3,
121 ALL_BITS
= (1 << 4) - 1
123 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(DiagnosticTypes
)
126 * See gfx/layers/Effects.h
128 enum class EffectTypes
: uint8_t {
132 MAX
// sentinel for the count of all effect types
136 * How the Compositable should manage textures.
138 enum class CompositableType
: uint8_t {
140 IMAGE
, // image with single buffering
145 typedef void* SyncHandle
;
147 typedef uintptr_t SyncHandle
;
151 * Sent from the compositor to the content-side LayerManager, includes
152 * properties of the compositor and should (in the future) include information
153 * about what kinds of buffer and texture clients to create.
155 struct TextureFactoryIdentifier
{
156 LayersBackend mParentBackend
;
157 WebRenderBackend mWebRenderBackend
;
158 WebRenderCompositor mWebRenderCompositor
;
159 GeckoProcessType mParentProcessType
;
160 int32_t mMaxTextureSize
;
161 bool mCompositorUseANGLE
;
162 bool mCompositorUseDComp
;
163 bool mUseCompositorWnd
;
164 bool mSupportsTextureBlitting
;
165 bool mSupportsPartialUploads
;
166 bool mSupportsComponentAlpha
;
167 SyncHandle mSyncHandle
;
169 explicit TextureFactoryIdentifier(
170 LayersBackend aLayersBackend
= LayersBackend::LAYERS_NONE
,
171 GeckoProcessType aParentProcessType
= GeckoProcessType_Default
,
172 int32_t aMaxTextureSize
= 4096, bool aCompositorUseANGLE
= false,
173 bool aCompositorUseDComp
= false, bool aUseCompositorWnd
= false,
174 bool aSupportsTextureBlitting
= false,
175 bool aSupportsPartialUploads
= false, bool aSupportsComponentAlpha
= true,
176 SyncHandle aSyncHandle
= 0)
177 : mParentBackend(aLayersBackend
),
178 mWebRenderBackend(WebRenderBackend::HARDWARE
),
179 mWebRenderCompositor(WebRenderCompositor::DRAW
),
180 mParentProcessType(aParentProcessType
),
181 mMaxTextureSize(aMaxTextureSize
),
182 mCompositorUseANGLE(aCompositorUseANGLE
),
183 mCompositorUseDComp(aCompositorUseDComp
),
184 mUseCompositorWnd(aUseCompositorWnd
),
185 mSupportsTextureBlitting(aSupportsTextureBlitting
),
186 mSupportsPartialUploads(aSupportsPartialUploads
),
187 mSupportsComponentAlpha(aSupportsComponentAlpha
),
188 mSyncHandle(aSyncHandle
) {}
190 explicit TextureFactoryIdentifier(
191 WebRenderBackend aWebRenderBackend
,
192 WebRenderCompositor aWebRenderCompositor
,
193 GeckoProcessType aParentProcessType
= GeckoProcessType_Default
,
194 int32_t aMaxTextureSize
= 4096, bool aCompositorUseANGLE
= false,
195 bool aCompositorUseDComp
= false, bool aUseCompositorWnd
= false,
196 bool aSupportsTextureBlitting
= false,
197 bool aSupportsPartialUploads
= false, bool aSupportsComponentAlpha
= true,
198 SyncHandle aSyncHandle
= 0)
199 : mParentBackend(LayersBackend::LAYERS_WR
),
200 mWebRenderBackend(aWebRenderBackend
),
201 mWebRenderCompositor(aWebRenderCompositor
),
202 mParentProcessType(aParentProcessType
),
203 mMaxTextureSize(aMaxTextureSize
),
204 mCompositorUseANGLE(aCompositorUseANGLE
),
205 mCompositorUseDComp(aCompositorUseDComp
),
206 mUseCompositorWnd(aUseCompositorWnd
),
207 mSupportsTextureBlitting(aSupportsTextureBlitting
),
208 mSupportsPartialUploads(aSupportsPartialUploads
),
209 mSupportsComponentAlpha(aSupportsComponentAlpha
),
210 mSyncHandle(aSyncHandle
) {}
212 bool operator==(const TextureFactoryIdentifier
& aOther
) const {
213 return mParentBackend
== aOther
.mParentBackend
&&
214 mWebRenderBackend
== aOther
.mWebRenderBackend
&&
215 mWebRenderCompositor
== aOther
.mWebRenderCompositor
&&
216 mParentProcessType
== aOther
.mParentProcessType
&&
217 mMaxTextureSize
== aOther
.mMaxTextureSize
&&
218 mCompositorUseANGLE
== aOther
.mCompositorUseANGLE
&&
219 mCompositorUseDComp
== aOther
.mCompositorUseDComp
&&
220 mUseCompositorWnd
== aOther
.mUseCompositorWnd
&&
221 mSupportsTextureBlitting
== aOther
.mSupportsTextureBlitting
&&
222 mSupportsPartialUploads
== aOther
.mSupportsPartialUploads
&&
223 mSupportsComponentAlpha
== aOther
.mSupportsComponentAlpha
&&
224 mSyncHandle
== aOther
.mSyncHandle
;
229 * Information required by the compositor from the content-side for creating or
230 * using compositables and textures.
231 * XXX - TextureInfo is a bad name: this information is useful for the
232 * compositable, not the Texture. And ith new Textures, only the compositable
233 * type is really useful. This may (should) be removed in the near future.
236 CompositableType mCompositableType
;
237 TextureFlags mTextureFlags
;
240 : mCompositableType(CompositableType::UNKNOWN
),
241 mTextureFlags(TextureFlags::NO_FLAGS
) {}
243 explicit TextureInfo(CompositableType aType
,
244 TextureFlags aTextureFlags
= TextureFlags::DEFAULT
)
245 : mCompositableType(aType
), mTextureFlags(aTextureFlags
) {}
247 bool operator==(const TextureInfo
& aOther
) const {
248 return mCompositableType
== aOther
.mCompositableType
&&
249 mTextureFlags
== aOther
.mTextureFlags
;
254 * How a SurfaceDescriptor will be opened.
256 * See ShadowLayerForwarder::OpenDescriptor for example.
258 enum class OpenMode
: uint8_t {
262 // This is only used in conjunction with OMTP to indicate that the DrawTarget
263 // that is being borrowed will be painted asynchronously, and so will outlive
267 OPEN_READ_WRITE
= OPEN_READ
| OPEN_WRITE
,
268 OPEN_READ_WRITE_ASYNC
= OPEN_READ
| OPEN_WRITE
| OPEN_ASYNC
,
269 OPEN_READ_ASYNC
= OPEN_READ
| OPEN_ASYNC
,
270 OPEN_READ_ONLY
= OPEN_READ
,
271 OPEN_WRITE_ONLY
= OPEN_WRITE
,
273 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(OpenMode
)
275 // The kinds of mask texture a shader can support
276 // We rely on the items in this enum being sequential
277 enum class MaskType
: uint8_t {
278 MaskNone
= 0, // no mask layer
283 } // namespace layers
284 } // namespace mozilla