tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

CompositorTypes.h (10764B)


      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/. */
      6 
      7 #ifndef MOZILLA_LAYERS_COMPOSITORTYPES_H
      8 #define MOZILLA_LAYERS_COMPOSITORTYPES_H
      9 
     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 
     18 #include "mozilla/TypedEnumBits.h"
     19 
     20 namespace mozilla {
     21 namespace layers {
     22 
     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.
     28 */
     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.
     41  //
     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 << 23,
     99  // Whether the remote texture must wait for its owner to be created.
    100  WAIT_FOR_REMOTE_TEXTURE_OWNER = 1 << 24,
    101  // Buffer is allocated by buffer provider like Canvas2D
    102  ALLOC_BY_BUFFER_PROVIDER = 1 << 25,
    103 
    104  // OR union of all valid bits
    105  ALL_BITS = (1 << 26) - 1,
    106  // the default flags
    107  DEFAULT = NO_FLAGS
    108 };
    109 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(TextureFlags)
    110 
    111 std::ostream& operator<<(std::ostream& aStream, const TextureFlags& aFlags);
    112 
    113 static inline bool TextureRequiresLocking(TextureFlags aFlags) {
    114  // If we're not double buffered, or uploading
    115  // within a transaction, then we need to support
    116  // locking correctly.
    117  return !(aFlags & TextureFlags::IMMUTABLE);
    118 }
    119 
    120 /**
    121 * The type of debug diagnostic to enable.
    122 */
    123 enum class DiagnosticTypes : uint8_t {
    124  NO_DIAGNOSTIC = 0,
    125  TILE_BORDERS = 1 << 0,
    126  LAYER_BORDERS = 1 << 1,
    127  BIGIMAGE_BORDERS = 1 << 2,
    128  FLASH_BORDERS = 1 << 3,
    129  ALL_BITS = (1 << 4) - 1
    130 };
    131 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(DiagnosticTypes)
    132 
    133 /**
    134 * See gfx/layers/Effects.h
    135 */
    136 enum class EffectTypes : uint8_t {
    137  ROUNDED_CLIP,
    138  RGB,
    139  YCBCR,
    140  NV12,
    141  MAX  // sentinel for the count of all effect types
    142 };
    143 
    144 /**
    145 * How the Compositable should manage textures.
    146 */
    147 enum class CompositableType : uint8_t {
    148  UNKNOWN,
    149  IMAGE,  // image with single buffering
    150  COUNT
    151 };
    152 
    153 enum class ImageUsageType : uint8_t {
    154  UNKNOWN,
    155  WebRenderImageData,
    156  WebRenderFallbackData,
    157  Canvas,
    158  OffscreenCanvas,
    159  VideoFrameContainer,
    160  RemoteVideoDecoder,
    161  BlackImage,
    162  Webrtc,
    163  WebCodecs,
    164  COUNT
    165 };
    166 
    167 /**
    168 * Sent from the compositor to the content-side LayerManager, includes
    169 * properties of the compositor and should (in the future) include information
    170 * about what kinds of buffer and texture clients to create.
    171 */
    172 struct TextureFactoryIdentifier {
    173  LayersBackend mParentBackend;
    174  WebRenderBackend mWebRenderBackend;
    175  WebRenderCompositor mWebRenderCompositor;
    176  GeckoProcessType mParentProcessType;
    177  int32_t mMaxTextureSize;
    178  bool mCompositorUseANGLE;
    179  bool mCompositorUseDComp;
    180  bool mUseLayerCompositor;
    181  bool mUseCompositorWnd;
    182  bool mSupportsTextureBlitting;
    183  bool mSupportsPartialUploads;
    184  bool mSupportsComponentAlpha;
    185  bool mSupportsD3D11NV12;
    186  SyncHandle mSyncHandle;
    187 
    188  explicit TextureFactoryIdentifier(
    189      LayersBackend aLayersBackend = LayersBackend::LAYERS_NONE,
    190      GeckoProcessType aParentProcessType = GeckoProcessType_Default,
    191      int32_t aMaxTextureSize = 4096, bool aCompositorUseANGLE = false,
    192      bool aCompositorUseDComp = false, bool aUseLayerCompositor = false,
    193      bool aUseCompositorWnd = false, bool aSupportsTextureBlitting = false,
    194      bool aSupportsPartialUploads = false, bool aSupportsComponentAlpha = true,
    195      bool aSupportsD3D11NV12 = false, SyncHandle aSyncHandle = {})
    196      : mParentBackend(aLayersBackend),
    197        mWebRenderBackend(WebRenderBackend::HARDWARE),
    198        mWebRenderCompositor(WebRenderCompositor::DRAW),
    199        mParentProcessType(aParentProcessType),
    200        mMaxTextureSize(aMaxTextureSize),
    201        mCompositorUseANGLE(aCompositorUseANGLE),
    202        mCompositorUseDComp(aCompositorUseDComp),
    203        mUseLayerCompositor(aUseLayerCompositor),
    204        mUseCompositorWnd(aUseCompositorWnd),
    205        mSupportsTextureBlitting(aSupportsTextureBlitting),
    206        mSupportsPartialUploads(aSupportsPartialUploads),
    207        mSupportsComponentAlpha(aSupportsComponentAlpha),
    208        mSupportsD3D11NV12(aSupportsD3D11NV12),
    209        mSyncHandle(aSyncHandle) {}
    210 
    211  explicit TextureFactoryIdentifier(
    212      WebRenderBackend aWebRenderBackend,
    213      WebRenderCompositor aWebRenderCompositor,
    214      GeckoProcessType aParentProcessType = GeckoProcessType_Default,
    215      int32_t aMaxTextureSize = 4096, bool aCompositorUseANGLE = false,
    216      bool aCompositorUseDComp = false, bool aUseLayerCompositor = false,
    217      bool aUseCompositorWnd = false, bool aSupportsTextureBlitting = false,
    218      bool aSupportsPartialUploads = false, bool aSupportsComponentAlpha = true,
    219      bool aSupportsD3D11NV12 = false, SyncHandle aSyncHandle = {})
    220      : mParentBackend(LayersBackend::LAYERS_WR),
    221        mWebRenderBackend(aWebRenderBackend),
    222        mWebRenderCompositor(aWebRenderCompositor),
    223        mParentProcessType(aParentProcessType),
    224        mMaxTextureSize(aMaxTextureSize),
    225        mCompositorUseANGLE(aCompositorUseANGLE),
    226        mCompositorUseDComp(aCompositorUseDComp),
    227        mUseLayerCompositor(aUseLayerCompositor),
    228        mUseCompositorWnd(aUseCompositorWnd),
    229        mSupportsTextureBlitting(aSupportsTextureBlitting),
    230        mSupportsPartialUploads(aSupportsPartialUploads),
    231        mSupportsComponentAlpha(aSupportsComponentAlpha),
    232        mSupportsD3D11NV12(aSupportsD3D11NV12),
    233        mSyncHandle(aSyncHandle) {}
    234 };
    235 
    236 /**
    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.
    242 */
    243 struct TextureInfo {
    244  CompositableType mCompositableType;
    245  ImageUsageType mUsageType;
    246  TextureFlags mTextureFlags;
    247 
    248  TextureInfo()
    249      : mCompositableType(CompositableType::UNKNOWN),
    250        mUsageType(ImageUsageType::UNKNOWN),
    251        mTextureFlags(TextureFlags::NO_FLAGS) {}
    252 
    253  TextureInfo(CompositableType aType, ImageUsageType aUsageType,
    254              TextureFlags aTextureFlags)
    255      : mCompositableType(aType),
    256        mUsageType(aUsageType),
    257        mTextureFlags(aTextureFlags) {}
    258 
    259  bool operator==(const TextureInfo& aOther) const {
    260    return mCompositableType == aOther.mCompositableType &&
    261           mTextureFlags == aOther.mTextureFlags;
    262  }
    263 };
    264 
    265 /**
    266 * How a SurfaceDescriptor will be opened.
    267 *
    268 * See ShadowLayerForwarder::OpenDescriptor for example.
    269 */
    270 enum class OpenMode : uint8_t {
    271  OPEN_NONE = 0,
    272  OPEN_READ = 0x1,
    273  OPEN_WRITE = 0x2,
    274 
    275  OPEN_READ_WRITE = OPEN_READ | OPEN_WRITE,
    276  OPEN_READ_ONLY = OPEN_READ,
    277  OPEN_WRITE_ONLY = OPEN_WRITE,
    278 };
    279 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(OpenMode)
    280 
    281 // The kinds of complex clip a shader can support
    282 // We rely on the items in this enum being sequential
    283 enum class ClipType : uint8_t {
    284  ClipNone = 0,  // no complex clip
    285  RoundedRect,
    286  NumClipTypes
    287 };
    288 
    289 }  // namespace layers
    290 }  // namespace mozilla
    291 
    292 #endif