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/layers/SyncObject.h"
17 #include "mozilla/EnumSet.h"
19 #include "mozilla/TypedEnumBits.h"
25 * Flags used by texture clients and texture hosts. These are passed from client
26 * side to host side when textures and compositables are created. Usually set
27 * by the compositableCient, they may be modified by either the compositable or
30 enum class TextureFlags
: uint32_t {
32 // Use nearest-neighbour texture filtering (as opposed to linear filtering).
33 USE_NEAREST_FILTER
= 1 << 0,
34 // The compositor assumes everything is origin-top-left by default.
35 ORIGIN_BOTTOM_LEFT
= 1 << 1,
36 // Force the texture to be represented using a single tile (note that this
37 // means tiled textures, not tiled layers).
38 DISALLOW_BIGIMAGE
= 1 << 2,
39 // The buffer will be treated as if the RB bytes are swapped.
40 // This is useful for rendering using Cairo/Thebes, because there is no
41 // BGRX Android pixel format, and so we have to do byte swapping.
43 // For example, if the GraphicBuffer has an Android pixel format of
44 // PIXEL_FORMAT_RGBA_8888 and isRBSwapped is true, when it is sampled
45 // (for example, with GL), a BGRA shader should be used.
47 // Data in this texture has not been alpha-premultiplied.
48 // XXX - Apparently only used with ImageClient/Host
49 NON_PREMULTIPLIED
= 1 << 4,
50 // The TextureClient should be recycled with recycle callback when no longer
51 // in used. When the texture is used in host side, ref count of TextureClient
52 // is transparently added by ShadowLayerForwarder or ImageBridgeChild.
54 // If DEALLOCATE_CLIENT is set, the shared data is deallocated on the
55 // client side and requires some extra synchronizaion to ensure race-free
57 // The default behaviour is to deallocate on the host side.
58 DEALLOCATE_CLIENT
= 1 << 6,
59 DEALLOCATE_SYNC
= 1 << 6, // XXX - make it a separate flag.
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)
87 // The ExternalImageId bound to the texture is borrowed and should not be
88 // explicitly released when the texture is freed. This is meant to be used
89 // with WebRenderTextureHost wrapping another TextureHost which was
90 // initialized with its own external image ID.
91 BORROWED_EXTERNAL_ID
= 1 << 19,
92 // The texture is used for remote texture.
93 REMOTE_TEXTURE
= 1 << 20,
94 // The texture is from a DRM source.
96 // The texture is dummy texture
97 DUMMY_TEXTURE
= 1 << 22,
98 // Software decoded video
99 SOFTWARE_DECODED_VIDEO
= 1 << 23,
100 // Whether the remote texture must wait for its owner to be created.
101 WAIT_FOR_REMOTE_TEXTURE_OWNER
= 1 << 24,
103 // OR union of all valid bits
104 ALL_BITS
= (1 << 25) - 1,
108 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(TextureFlags
)
110 std::ostream
& operator<<(std::ostream
& aStream
, const TextureFlags
& aFlags
);
112 static inline bool TextureRequiresLocking(TextureFlags aFlags
) {
113 // If we're not double buffered, or uploading
114 // within a transaction, then we need to support
115 // locking correctly.
116 return !(aFlags
& TextureFlags::IMMUTABLE
);
120 * The type of debug diagnostic to enable.
122 enum class DiagnosticTypes
: uint8_t {
124 TILE_BORDERS
= 1 << 0,
125 LAYER_BORDERS
= 1 << 1,
126 BIGIMAGE_BORDERS
= 1 << 2,
127 FLASH_BORDERS
= 1 << 3,
128 ALL_BITS
= (1 << 4) - 1
130 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(DiagnosticTypes
)
133 * See gfx/layers/Effects.h
135 enum class EffectTypes
: uint8_t {
139 MAX
// sentinel for the count of all effect types
143 * How the Compositable should manage textures.
145 enum class CompositableType
: uint8_t {
147 IMAGE
, // image with single buffering
151 enum class ImageUsageType
: uint8_t {
154 WebRenderFallbackData
,
166 * Sent from the compositor to the content-side LayerManager, includes
167 * properties of the compositor and should (in the future) include information
168 * about what kinds of buffer and texture clients to create.
170 struct TextureFactoryIdentifier
{
171 LayersBackend mParentBackend
;
172 WebRenderBackend mWebRenderBackend
;
173 WebRenderCompositor mWebRenderCompositor
;
174 GeckoProcessType mParentProcessType
;
175 int32_t mMaxTextureSize
;
176 bool mCompositorUseANGLE
;
177 bool mCompositorUseDComp
;
178 bool mUseCompositorWnd
;
179 bool mSupportsTextureBlitting
;
180 bool mSupportsPartialUploads
;
181 bool mSupportsComponentAlpha
;
182 bool mSupportsD3D11NV12
;
183 SyncHandle mSyncHandle
;
185 explicit TextureFactoryIdentifier(
186 LayersBackend aLayersBackend
= LayersBackend::LAYERS_NONE
,
187 GeckoProcessType aParentProcessType
= GeckoProcessType_Default
,
188 int32_t aMaxTextureSize
= 4096, bool aCompositorUseANGLE
= false,
189 bool aCompositorUseDComp
= false, bool aUseCompositorWnd
= false,
190 bool aSupportsTextureBlitting
= false,
191 bool aSupportsPartialUploads
= false, bool aSupportsComponentAlpha
= true,
192 bool aSupportsD3D11NV12
= false, SyncHandle aSyncHandle
= {})
193 : mParentBackend(aLayersBackend
),
194 mWebRenderBackend(WebRenderBackend::HARDWARE
),
195 mWebRenderCompositor(WebRenderCompositor::DRAW
),
196 mParentProcessType(aParentProcessType
),
197 mMaxTextureSize(aMaxTextureSize
),
198 mCompositorUseANGLE(aCompositorUseANGLE
),
199 mCompositorUseDComp(aCompositorUseDComp
),
200 mUseCompositorWnd(aUseCompositorWnd
),
201 mSupportsTextureBlitting(aSupportsTextureBlitting
),
202 mSupportsPartialUploads(aSupportsPartialUploads
),
203 mSupportsComponentAlpha(aSupportsComponentAlpha
),
204 mSupportsD3D11NV12(aSupportsD3D11NV12
),
205 mSyncHandle(aSyncHandle
) {}
207 explicit TextureFactoryIdentifier(
208 WebRenderBackend aWebRenderBackend
,
209 WebRenderCompositor aWebRenderCompositor
,
210 GeckoProcessType aParentProcessType
= GeckoProcessType_Default
,
211 int32_t aMaxTextureSize
= 4096, bool aCompositorUseANGLE
= false,
212 bool aCompositorUseDComp
= false, bool aUseCompositorWnd
= false,
213 bool aSupportsTextureBlitting
= false,
214 bool aSupportsPartialUploads
= false, bool aSupportsComponentAlpha
= true,
215 bool aSupportsD3D11NV12
= false, SyncHandle aSyncHandle
= {})
216 : mParentBackend(LayersBackend::LAYERS_WR
),
217 mWebRenderBackend(aWebRenderBackend
),
218 mWebRenderCompositor(aWebRenderCompositor
),
219 mParentProcessType(aParentProcessType
),
220 mMaxTextureSize(aMaxTextureSize
),
221 mCompositorUseANGLE(aCompositorUseANGLE
),
222 mCompositorUseDComp(aCompositorUseDComp
),
223 mUseCompositorWnd(aUseCompositorWnd
),
224 mSupportsTextureBlitting(aSupportsTextureBlitting
),
225 mSupportsPartialUploads(aSupportsPartialUploads
),
226 mSupportsComponentAlpha(aSupportsComponentAlpha
),
227 mSupportsD3D11NV12(aSupportsD3D11NV12
),
228 mSyncHandle(aSyncHandle
) {}
232 * Information required by the compositor from the content-side for creating or
233 * using compositables and textures.
234 * XXX - TextureInfo is a bad name: this information is useful for the
235 * compositable, not the Texture. And ith new Textures, only the compositable
236 * type is really useful. This may (should) be removed in the near future.
239 CompositableType mCompositableType
;
240 ImageUsageType mUsageType
;
241 TextureFlags mTextureFlags
;
244 : mCompositableType(CompositableType::UNKNOWN
),
245 mUsageType(ImageUsageType::UNKNOWN
),
246 mTextureFlags(TextureFlags::NO_FLAGS
) {}
248 TextureInfo(CompositableType aType
, ImageUsageType aUsageType
,
249 TextureFlags aTextureFlags
)
250 : mCompositableType(aType
),
251 mUsageType(aUsageType
),
252 mTextureFlags(aTextureFlags
) {}
254 bool operator==(const TextureInfo
& aOther
) const {
255 return mCompositableType
== aOther
.mCompositableType
&&
256 mTextureFlags
== aOther
.mTextureFlags
;
261 * How a SurfaceDescriptor will be opened.
263 * See ShadowLayerForwarder::OpenDescriptor for example.
265 enum class OpenMode
: uint8_t {
269 // This is only used in conjunction with OMTP to indicate that the DrawTarget
270 // that is being borrowed will be painted asynchronously, and so will outlive
274 OPEN_READ_WRITE
= OPEN_READ
| OPEN_WRITE
,
275 OPEN_READ_WRITE_ASYNC
= OPEN_READ
| OPEN_WRITE
| OPEN_ASYNC
,
276 OPEN_READ_ASYNC
= OPEN_READ
| OPEN_ASYNC
,
277 OPEN_READ_ONLY
= OPEN_READ
,
278 OPEN_WRITE_ONLY
= OPEN_WRITE
,
280 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(OpenMode
)
282 // The kinds of mask texture a shader can support
283 // We rely on the items in this enum being sequential
284 enum class MaskType
: uint8_t {
285 MaskNone
= 0, // no mask layer
290 } // namespace layers
291 } // namespace mozilla