Bug 1849470 - Update in-tree zlib to version 1.3. r=aosmond
[gecko.git] / gfx / layers / CompositorTypes.h
blob6be1af8be38003a922367926a2e2770b21c15ae8
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 <iosfwd>
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"
20 namespace mozilla {
21 namespace layers {
23 /**
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
27 * texture clients.
29 enum class TextureFlags : uint32_t {
30 NO_FLAGS = 0,
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.
45 RB_SWAPPED = 1 << 3,
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.
52 RECYCLE = 1 << 5,
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
55 // deallocation.
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
61 // textures.
62 IMMUTABLE = 1 << 9,
63 // The contents of the texture must be uploaded or copied immediately
64 // during the transaction, because the producer may want to write
65 // to it again.
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.
75 SNAPSHOT = 1 << 14,
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)
85 IS_OPAQUE = 1 << 18,
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.
94 DRM_SOURCE = 1 << 21,
95 // The texture is dummy texture
96 DUMMY_TEXTURE = 1 << 22,
97 // Software decoded video
98 SOFTWARE_DECODED_VIDEO = 1 << 22,
100 // OR union of all valid bits
101 ALL_BITS = (1 << 23) - 1,
102 // the default flags
103 DEFAULT = NO_FLAGS
105 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(TextureFlags)
107 std::ostream& operator<<(std::ostream& aStream, const TextureFlags& aFlags);
109 static inline bool TextureRequiresLocking(TextureFlags aFlags) {
110 // If we're not double buffered, or uploading
111 // within a transaction, then we need to support
112 // locking correctly.
113 return !(aFlags & TextureFlags::IMMUTABLE);
117 * The type of debug diagnostic to enable.
119 enum class DiagnosticTypes : uint8_t {
120 NO_DIAGNOSTIC = 0,
121 TILE_BORDERS = 1 << 0,
122 LAYER_BORDERS = 1 << 1,
123 BIGIMAGE_BORDERS = 1 << 2,
124 FLASH_BORDERS = 1 << 3,
125 ALL_BITS = (1 << 4) - 1
127 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(DiagnosticTypes)
130 * See gfx/layers/Effects.h
132 enum class EffectTypes : uint8_t {
133 RGB,
134 YCBCR,
135 NV12,
136 MAX // sentinel for the count of all effect types
140 * How the Compositable should manage textures.
142 enum class CompositableType : uint8_t {
143 UNKNOWN,
144 IMAGE, // image with single buffering
145 COUNT
148 #ifdef XP_WIN
149 typedef void* SyncHandle;
150 #else
151 typedef uintptr_t SyncHandle;
152 #endif // XP_WIN
155 * Sent from the compositor to the content-side LayerManager, includes
156 * properties of the compositor and should (in the future) include information
157 * about what kinds of buffer and texture clients to create.
159 struct TextureFactoryIdentifier {
160 LayersBackend mParentBackend;
161 WebRenderBackend mWebRenderBackend;
162 WebRenderCompositor mWebRenderCompositor;
163 GeckoProcessType mParentProcessType;
164 int32_t mMaxTextureSize;
165 bool mCompositorUseANGLE;
166 bool mCompositorUseDComp;
167 bool mUseCompositorWnd;
168 bool mSupportsTextureBlitting;
169 bool mSupportsPartialUploads;
170 bool mSupportsComponentAlpha;
171 bool mSupportsD3D11NV12;
172 SyncHandle mSyncHandle;
174 explicit TextureFactoryIdentifier(
175 LayersBackend aLayersBackend = LayersBackend::LAYERS_NONE,
176 GeckoProcessType aParentProcessType = GeckoProcessType_Default,
177 int32_t aMaxTextureSize = 4096, bool aCompositorUseANGLE = false,
178 bool aCompositorUseDComp = false, bool aUseCompositorWnd = false,
179 bool aSupportsTextureBlitting = false,
180 bool aSupportsPartialUploads = false, bool aSupportsComponentAlpha = true,
181 bool aSupportsD3D11NV12 = false, SyncHandle aSyncHandle = 0)
182 : mParentBackend(aLayersBackend),
183 mWebRenderBackend(WebRenderBackend::HARDWARE),
184 mWebRenderCompositor(WebRenderCompositor::DRAW),
185 mParentProcessType(aParentProcessType),
186 mMaxTextureSize(aMaxTextureSize),
187 mCompositorUseANGLE(aCompositorUseANGLE),
188 mCompositorUseDComp(aCompositorUseDComp),
189 mUseCompositorWnd(aUseCompositorWnd),
190 mSupportsTextureBlitting(aSupportsTextureBlitting),
191 mSupportsPartialUploads(aSupportsPartialUploads),
192 mSupportsComponentAlpha(aSupportsComponentAlpha),
193 mSupportsD3D11NV12(aSupportsD3D11NV12),
194 mSyncHandle(aSyncHandle) {}
196 explicit TextureFactoryIdentifier(
197 WebRenderBackend aWebRenderBackend,
198 WebRenderCompositor aWebRenderCompositor,
199 GeckoProcessType aParentProcessType = GeckoProcessType_Default,
200 int32_t aMaxTextureSize = 4096, bool aCompositorUseANGLE = false,
201 bool aCompositorUseDComp = false, bool aUseCompositorWnd = false,
202 bool aSupportsTextureBlitting = false,
203 bool aSupportsPartialUploads = false, bool aSupportsComponentAlpha = true,
204 bool aSupportsD3D11NV12 = false, SyncHandle aSyncHandle = 0)
205 : mParentBackend(LayersBackend::LAYERS_WR),
206 mWebRenderBackend(aWebRenderBackend),
207 mWebRenderCompositor(aWebRenderCompositor),
208 mParentProcessType(aParentProcessType),
209 mMaxTextureSize(aMaxTextureSize),
210 mCompositorUseANGLE(aCompositorUseANGLE),
211 mCompositorUseDComp(aCompositorUseDComp),
212 mUseCompositorWnd(aUseCompositorWnd),
213 mSupportsTextureBlitting(aSupportsTextureBlitting),
214 mSupportsPartialUploads(aSupportsPartialUploads),
215 mSupportsComponentAlpha(aSupportsComponentAlpha),
216 mSupportsD3D11NV12(aSupportsD3D11NV12),
217 mSyncHandle(aSyncHandle) {}
219 bool operator==(const TextureFactoryIdentifier& aOther) const {
220 return mParentBackend == aOther.mParentBackend &&
221 mWebRenderBackend == aOther.mWebRenderBackend &&
222 mWebRenderCompositor == aOther.mWebRenderCompositor &&
223 mParentProcessType == aOther.mParentProcessType &&
224 mMaxTextureSize == aOther.mMaxTextureSize &&
225 mCompositorUseANGLE == aOther.mCompositorUseANGLE &&
226 mCompositorUseDComp == aOther.mCompositorUseDComp &&
227 mUseCompositorWnd == aOther.mUseCompositorWnd &&
228 mSupportsTextureBlitting == aOther.mSupportsTextureBlitting &&
229 mSupportsPartialUploads == aOther.mSupportsPartialUploads &&
230 mSupportsComponentAlpha == aOther.mSupportsComponentAlpha &&
231 mSupportsD3D11NV12 == aOther.mSupportsD3D11NV12 &&
232 mSyncHandle == aOther.mSyncHandle;
237 * Information required by the compositor from the content-side for creating or
238 * using compositables and textures.
239 * XXX - TextureInfo is a bad name: this information is useful for the
240 * compositable, not the Texture. And ith new Textures, only the compositable
241 * type is really useful. This may (should) be removed in the near future.
243 struct TextureInfo {
244 CompositableType mCompositableType;
245 TextureFlags mTextureFlags;
247 TextureInfo()
248 : mCompositableType(CompositableType::UNKNOWN),
249 mTextureFlags(TextureFlags::NO_FLAGS) {}
251 explicit TextureInfo(CompositableType aType,
252 TextureFlags aTextureFlags = TextureFlags::DEFAULT)
253 : mCompositableType(aType), mTextureFlags(aTextureFlags) {}
255 bool operator==(const TextureInfo& aOther) const {
256 return mCompositableType == aOther.mCompositableType &&
257 mTextureFlags == aOther.mTextureFlags;
262 * How a SurfaceDescriptor will be opened.
264 * See ShadowLayerForwarder::OpenDescriptor for example.
266 enum class OpenMode : uint8_t {
267 OPEN_NONE = 0,
268 OPEN_READ = 0x1,
269 OPEN_WRITE = 0x2,
270 // This is only used in conjunction with OMTP to indicate that the DrawTarget
271 // that is being borrowed will be painted asynchronously, and so will outlive
272 // the write lock.
273 OPEN_ASYNC = 0x04,
275 OPEN_READ_WRITE = OPEN_READ | OPEN_WRITE,
276 OPEN_READ_WRITE_ASYNC = OPEN_READ | OPEN_WRITE | OPEN_ASYNC,
277 OPEN_READ_ASYNC = OPEN_READ | OPEN_ASYNC,
278 OPEN_READ_ONLY = OPEN_READ,
279 OPEN_WRITE_ONLY = OPEN_WRITE,
281 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(OpenMode)
283 // The kinds of mask texture a shader can support
284 // We rely on the items in this enum being sequential
285 enum class MaskType : uint8_t {
286 MaskNone = 0, // no mask layer
287 Mask, // mask layer
288 NumMaskTypes
291 } // namespace layers
292 } // namespace mozilla
294 #endif