Update configs. IGNORE BROKEN CHANGESETS CLOSED TREE NO BUG a=release ba=release
[gecko.git] / gfx / layers / CompositorTypes.h
blobfe1695a2e5b44bb5fe1ae687a2414eeffafdfb47
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/layers/SyncObject.h"
17 #include "mozilla/EnumSet.h"
19 #include "mozilla/TypedEnumBits.h"
21 namespace mozilla {
22 namespace layers {
24 /**
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
28 * texture clients.
30 enum class TextureFlags : uint32_t {
31 NO_FLAGS = 0,
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.
46 RB_SWAPPED = 1 << 3,
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.
53 RECYCLE = 1 << 5,
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
56 // deallocation.
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
62 // textures.
63 IMMUTABLE = 1 << 9,
64 // The contents of the texture must be uploaded or copied immediately
65 // during the transaction, because the producer may want to write
66 // to it again.
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.
76 SNAPSHOT = 1 << 14,
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)
86 IS_OPAQUE = 1 << 18,
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.
95 DRM_SOURCE = 1 << 21,
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,
105 // the default flags
106 DEFAULT = NO_FLAGS
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 {
123 NO_DIAGNOSTIC = 0,
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 {
136 RGB,
137 YCBCR,
138 NV12,
139 MAX // sentinel for the count of all effect types
143 * How the Compositable should manage textures.
145 enum class CompositableType : uint8_t {
146 UNKNOWN,
147 IMAGE, // image with single buffering
148 COUNT
152 * Sent from the compositor to the content-side LayerManager, includes
153 * properties of the compositor and should (in the future) include information
154 * about what kinds of buffer and texture clients to create.
156 struct TextureFactoryIdentifier {
157 LayersBackend mParentBackend;
158 WebRenderBackend mWebRenderBackend;
159 WebRenderCompositor mWebRenderCompositor;
160 GeckoProcessType mParentProcessType;
161 int32_t mMaxTextureSize;
162 bool mCompositorUseANGLE;
163 bool mCompositorUseDComp;
164 bool mUseCompositorWnd;
165 bool mSupportsTextureBlitting;
166 bool mSupportsPartialUploads;
167 bool mSupportsComponentAlpha;
168 bool mSupportsD3D11NV12;
169 SyncHandle mSyncHandle;
171 explicit TextureFactoryIdentifier(
172 LayersBackend aLayersBackend = LayersBackend::LAYERS_NONE,
173 GeckoProcessType aParentProcessType = GeckoProcessType_Default,
174 int32_t aMaxTextureSize = 4096, bool aCompositorUseANGLE = false,
175 bool aCompositorUseDComp = false, bool aUseCompositorWnd = false,
176 bool aSupportsTextureBlitting = false,
177 bool aSupportsPartialUploads = false, bool aSupportsComponentAlpha = true,
178 bool aSupportsD3D11NV12 = false, SyncHandle aSyncHandle = {})
179 : mParentBackend(aLayersBackend),
180 mWebRenderBackend(WebRenderBackend::HARDWARE),
181 mWebRenderCompositor(WebRenderCompositor::DRAW),
182 mParentProcessType(aParentProcessType),
183 mMaxTextureSize(aMaxTextureSize),
184 mCompositorUseANGLE(aCompositorUseANGLE),
185 mCompositorUseDComp(aCompositorUseDComp),
186 mUseCompositorWnd(aUseCompositorWnd),
187 mSupportsTextureBlitting(aSupportsTextureBlitting),
188 mSupportsPartialUploads(aSupportsPartialUploads),
189 mSupportsComponentAlpha(aSupportsComponentAlpha),
190 mSupportsD3D11NV12(aSupportsD3D11NV12),
191 mSyncHandle(aSyncHandle) {}
193 explicit TextureFactoryIdentifier(
194 WebRenderBackend aWebRenderBackend,
195 WebRenderCompositor aWebRenderCompositor,
196 GeckoProcessType aParentProcessType = GeckoProcessType_Default,
197 int32_t aMaxTextureSize = 4096, bool aCompositorUseANGLE = false,
198 bool aCompositorUseDComp = false, bool aUseCompositorWnd = false,
199 bool aSupportsTextureBlitting = false,
200 bool aSupportsPartialUploads = false, bool aSupportsComponentAlpha = true,
201 bool aSupportsD3D11NV12 = false, SyncHandle aSyncHandle = {})
202 : mParentBackend(LayersBackend::LAYERS_WR),
203 mWebRenderBackend(aWebRenderBackend),
204 mWebRenderCompositor(aWebRenderCompositor),
205 mParentProcessType(aParentProcessType),
206 mMaxTextureSize(aMaxTextureSize),
207 mCompositorUseANGLE(aCompositorUseANGLE),
208 mCompositorUseDComp(aCompositorUseDComp),
209 mUseCompositorWnd(aUseCompositorWnd),
210 mSupportsTextureBlitting(aSupportsTextureBlitting),
211 mSupportsPartialUploads(aSupportsPartialUploads),
212 mSupportsComponentAlpha(aSupportsComponentAlpha),
213 mSupportsD3D11NV12(aSupportsD3D11NV12),
214 mSyncHandle(aSyncHandle) {}
218 * Information required by the compositor from the content-side for creating or
219 * using compositables and textures.
220 * XXX - TextureInfo is a bad name: this information is useful for the
221 * compositable, not the Texture. And ith new Textures, only the compositable
222 * type is really useful. This may (should) be removed in the near future.
224 struct TextureInfo {
225 CompositableType mCompositableType;
226 TextureFlags mTextureFlags;
228 TextureInfo()
229 : mCompositableType(CompositableType::UNKNOWN),
230 mTextureFlags(TextureFlags::NO_FLAGS) {}
232 explicit TextureInfo(CompositableType aType,
233 TextureFlags aTextureFlags = TextureFlags::DEFAULT)
234 : mCompositableType(aType), mTextureFlags(aTextureFlags) {}
236 bool operator==(const TextureInfo& aOther) const {
237 return mCompositableType == aOther.mCompositableType &&
238 mTextureFlags == aOther.mTextureFlags;
243 * How a SurfaceDescriptor will be opened.
245 * See ShadowLayerForwarder::OpenDescriptor for example.
247 enum class OpenMode : uint8_t {
248 OPEN_NONE = 0,
249 OPEN_READ = 0x1,
250 OPEN_WRITE = 0x2,
251 // This is only used in conjunction with OMTP to indicate that the DrawTarget
252 // that is being borrowed will be painted asynchronously, and so will outlive
253 // the write lock.
254 OPEN_ASYNC = 0x04,
256 OPEN_READ_WRITE = OPEN_READ | OPEN_WRITE,
257 OPEN_READ_WRITE_ASYNC = OPEN_READ | OPEN_WRITE | OPEN_ASYNC,
258 OPEN_READ_ASYNC = OPEN_READ | OPEN_ASYNC,
259 OPEN_READ_ONLY = OPEN_READ,
260 OPEN_WRITE_ONLY = OPEN_WRITE,
262 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(OpenMode)
264 // The kinds of mask texture a shader can support
265 // We rely on the items in this enum being sequential
266 enum class MaskType : uint8_t {
267 MaskNone = 0, // no mask layer
268 Mask, // mask layer
269 NumMaskTypes
272 } // namespace layers
273 } // namespace mozilla
275 #endif