summaryrefslogtreecommitdiffstats
path: root/gfx/layers/CompositorTypes.h
blob: fe1695a2e5b44bb5fe1ae687a2414eeffafdfb47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef MOZILLA_LAYERS_COMPOSITORTYPES_H
#define MOZILLA_LAYERS_COMPOSITORTYPES_H

#include <iosfwd>
#include <stdint.h>       // for uint32_t
#include <sys/types.h>    // for int32_t
#include "LayersTypes.h"  // for LayersBackend, etc
#include "nsXULAppAPI.h"  // for GeckoProcessType, etc
#include "mozilla/gfx/Types.h"
#include "mozilla/layers/SyncObject.h"
#include "mozilla/EnumSet.h"

#include "mozilla/TypedEnumBits.h"

namespace mozilla {
namespace layers {

/**
 * Flags used by texture clients and texture hosts. These are passed from client
 * side to host side when textures and compositables are created. Usually set
 * by the compositableCient, they may be modified by either the compositable or
 * texture clients.
 */
enum class TextureFlags : uint32_t {
  NO_FLAGS = 0,
  // Use nearest-neighbour texture filtering (as opposed to linear filtering).
  USE_NEAREST_FILTER = 1 << 0,
  // The compositor assumes everything is origin-top-left by default.
  ORIGIN_BOTTOM_LEFT = 1 << 1,
  // Force the texture to be represented using a single tile (note that this
  // means tiled textures, not tiled layers).
  DISALLOW_BIGIMAGE = 1 << 2,
  // The buffer will be treated as if the RB bytes are swapped.
  // This is useful for rendering using Cairo/Thebes, because there is no
  // BGRX Android pixel format, and so we have to do byte swapping.
  //
  // For example, if the GraphicBuffer has an Android pixel format of
  // PIXEL_FORMAT_RGBA_8888 and isRBSwapped is true, when it is sampled
  // (for example, with GL), a BGRA shader should be used.
  RB_SWAPPED = 1 << 3,
  // Data in this texture has not been alpha-premultiplied.
  // XXX - Apparently only used with ImageClient/Host
  NON_PREMULTIPLIED = 1 << 4,
  // The TextureClient should be recycled with recycle callback when no longer
  // in used. When the texture is used in host side, ref count of TextureClient
  // is transparently added by ShadowLayerForwarder or ImageBridgeChild.
  RECYCLE = 1 << 5,
  // If DEALLOCATE_CLIENT is set, the shared data is deallocated on the
  // client side and requires some extra synchronizaion to ensure race-free
  // deallocation.
  // The default behaviour is to deallocate on the host side.
  DEALLOCATE_CLIENT = 1 << 6,
  DEALLOCATE_SYNC = 1 << 6,  // XXX - make it a separate flag.
  // After being shared ith the compositor side, an immutable texture is never
  // modified, it can only be read. It is safe to not Lock/Unlock immutable
  // textures.
  IMMUTABLE = 1 << 9,
  // The contents of the texture must be uploaded or copied immediately
  // during the transaction, because the producer may want to write
  // to it again.
  IMMEDIATE_UPLOAD = 1 << 10,
  // The texture is part of a component-alpha pair
  COMPONENT_ALPHA = 1 << 11,
  // The texture is being allocated for a compositor that no longer exists.
  // This flag is only used in the parent process.
  INVALID_COMPOSITOR = 1 << 12,
  // The texture was created by converting from YCBCR to RGB
  RGB_FROM_YCBCR = 1 << 13,
  // The texture is used for snapshot.
  SNAPSHOT = 1 << 14,
  // Enable a non blocking read lock.
  NON_BLOCKING_READ_LOCK = 1 << 15,
  // Enable a blocking read lock.
  BLOCKING_READ_LOCK = 1 << 16,
  // Keep TextureClient alive when host side is used
  WAIT_HOST_USAGE_END = 1 << 17,
  // The texture is guaranteed to have alpha 1.0 everywhere; some backends
  // have trouble with RGBX/BGRX formats, so we use RGBA/BGRA but set this
  // hint when we know alpha is opaque (eg. WebGL)
  IS_OPAQUE = 1 << 18,
  // The ExternalImageId bound to the texture is borrowed and should not be
  // explicitly released when the texture is freed. This is meant to be used
  // with WebRenderTextureHost wrapping another TextureHost which was
  // initialized with its own external image ID.
  BORROWED_EXTERNAL_ID = 1 << 19,
  // The texture is used for remote texture.
  REMOTE_TEXTURE = 1 << 20,
  // The texture is from a DRM source.
  DRM_SOURCE = 1 << 21,
  // The texture is dummy texture
  DUMMY_TEXTURE = 1 << 22,
  // Software decoded video
  SOFTWARE_DECODED_VIDEO = 1 << 23,
  // Whether the remote texture must wait for its owner to be created.
  WAIT_FOR_REMOTE_TEXTURE_OWNER = 1 << 24,

  // OR union of all valid bits
  ALL_BITS = (1 << 25) - 1,
  // the default flags
  DEFAULT = NO_FLAGS
};
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(TextureFlags)

std::ostream& operator<<(std::ostream& aStream, const TextureFlags& aFlags);

static inline bool TextureRequiresLocking(TextureFlags aFlags) {
  // If we're not double buffered, or uploading
  // within a transaction, then we need to support
  // locking correctly.
  return !(aFlags & TextureFlags::IMMUTABLE);
}

/**
 * The type of debug diagnostic to enable.
 */
enum class DiagnosticTypes : uint8_t {
  NO_DIAGNOSTIC = 0,
  TILE_BORDERS = 1 << 0,
  LAYER_BORDERS = 1 << 1,
  BIGIMAGE_BORDERS = 1 << 2,
  FLASH_BORDERS = 1 << 3,
  ALL_BITS = (1 << 4) - 1
};
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(DiagnosticTypes)

/**
 * See gfx/layers/Effects.h
 */
enum class EffectTypes : uint8_t {
  RGB,
  YCBCR,
  NV12,
  MAX  // sentinel for the count of all effect types
};

/**
 * How the Compositable should manage textures.
 */
enum class CompositableType : uint8_t {
  UNKNOWN,
  IMAGE,  // image with single buffering
  COUNT
};

/**
 * Sent from the compositor to the content-side LayerManager, includes
 * properties of the compositor and should (in the future) include information
 * about what kinds of buffer and texture clients to create.
 */
struct TextureFactoryIdentifier {
  LayersBackend mParentBackend;
  WebRenderBackend mWebRenderBackend;
  WebRenderCompositor mWebRenderCompositor;
  GeckoProcessType mParentProcessType;
  int32_t mMaxTextureSize;
  bool mCompositorUseANGLE;
  bool mCompositorUseDComp;
  bool mUseCompositorWnd;
  bool mSupportsTextureBlitting;
  bool mSupportsPartialUploads;
  bool mSupportsComponentAlpha;
  bool mSupportsD3D11NV12;
  SyncHandle mSyncHandle;

  explicit TextureFactoryIdentifier(
      LayersBackend aLayersBackend = LayersBackend::LAYERS_NONE,
      GeckoProcessType aParentProcessType = GeckoProcessType_Default,
      int32_t aMaxTextureSize = 4096, bool aCompositorUseANGLE = false,
      bool aCompositorUseDComp = false, bool aUseCompositorWnd = false,
      bool aSupportsTextureBlitting = false,
      bool aSupportsPartialUploads = false, bool aSupportsComponentAlpha = true,
      bool aSupportsD3D11NV12 = false, SyncHandle aSyncHandle = {})
      : mParentBackend(aLayersBackend),
        mWebRenderBackend(WebRenderBackend::HARDWARE),
        mWebRenderCompositor(WebRenderCompositor::DRAW),
        mParentProcessType(aParentProcessType),
        mMaxTextureSize(aMaxTextureSize),
        mCompositorUseANGLE(aCompositorUseANGLE),
        mCompositorUseDComp(aCompositorUseDComp),
        mUseCompositorWnd(aUseCompositorWnd),
        mSupportsTextureBlitting(aSupportsTextureBlitting),
        mSupportsPartialUploads(aSupportsPartialUploads),
        mSupportsComponentAlpha(aSupportsComponentAlpha),
        mSupportsD3D11NV12(aSupportsD3D11NV12),
        mSyncHandle(aSyncHandle) {}

  explicit TextureFactoryIdentifier(
      WebRenderBackend aWebRenderBackend,
      WebRenderCompositor aWebRenderCompositor,
      GeckoProcessType aParentProcessType = GeckoProcessType_Default,
      int32_t aMaxTextureSize = 4096, bool aCompositorUseANGLE = false,
      bool aCompositorUseDComp = false, bool aUseCompositorWnd = false,
      bool aSupportsTextureBlitting = false,
      bool aSupportsPartialUploads = false, bool aSupportsComponentAlpha = true,
      bool aSupportsD3D11NV12 = false, SyncHandle aSyncHandle = {})
      : mParentBackend(LayersBackend::LAYERS_WR),
        mWebRenderBackend(aWebRenderBackend),
        mWebRenderCompositor(aWebRenderCompositor),
        mParentProcessType(aParentProcessType),
        mMaxTextureSize(aMaxTextureSize),
        mCompositorUseANGLE(aCompositorUseANGLE),
        mCompositorUseDComp(aCompositorUseDComp),
        mUseCompositorWnd(aUseCompositorWnd),
        mSupportsTextureBlitting(aSupportsTextureBlitting),
        mSupportsPartialUploads(aSupportsPartialUploads),
        mSupportsComponentAlpha(aSupportsComponentAlpha),
        mSupportsD3D11NV12(aSupportsD3D11NV12),
        mSyncHandle(aSyncHandle) {}
};

/**
 * Information required by the compositor from the content-side for creating or
 * using compositables and textures.
 * XXX - TextureInfo is a bad name: this information is useful for the
 * compositable, not the Texture. And ith new Textures, only the compositable
 * type is really useful. This may (should) be removed in the near future.
 */
struct TextureInfo {
  CompositableType mCompositableType;
  TextureFlags mTextureFlags;

  TextureInfo()
      : mCompositableType(CompositableType::UNKNOWN),
        mTextureFlags(TextureFlags::NO_FLAGS) {}

  explicit TextureInfo(CompositableType aType,
                       TextureFlags aTextureFlags = TextureFlags::DEFAULT)
      : mCompositableType(aType), mTextureFlags(aTextureFlags) {}

  bool operator==(const TextureInfo& aOther) const {
    return mCompositableType == aOther.mCompositableType &&
           mTextureFlags == aOther.mTextureFlags;
  }
};

/**
 * How a SurfaceDescriptor will be opened.
 *
 * See ShadowLayerForwarder::OpenDescriptor for example.
 */
enum class OpenMode : uint8_t {
  OPEN_NONE = 0,
  OPEN_READ = 0x1,
  OPEN_WRITE = 0x2,
  // This is only used in conjunction with OMTP to indicate that the DrawTarget
  // that is being borrowed will be painted asynchronously, and so will outlive
  // the write lock.
  OPEN_ASYNC = 0x04,

  OPEN_READ_WRITE = OPEN_READ | OPEN_WRITE,
  OPEN_READ_WRITE_ASYNC = OPEN_READ | OPEN_WRITE | OPEN_ASYNC,
  OPEN_READ_ASYNC = OPEN_READ | OPEN_ASYNC,
  OPEN_READ_ONLY = OPEN_READ,
  OPEN_WRITE_ONLY = OPEN_WRITE,
};
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(OpenMode)

// The kinds of mask texture a shader can support
// We rely on the items in this enum being sequential
enum class MaskType : uint8_t {
  MaskNone = 0,  // no mask layer
  Mask,          // mask layer
  NumMaskTypes
};

}  // namespace layers
}  // namespace mozilla

#endif