gfx/layers/CompositorTypes.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/CompositorTypes.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,269 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 +* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +* License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef MOZILLA_LAYERS_COMPOSITORTYPES_H
    1.10 +#define MOZILLA_LAYERS_COMPOSITORTYPES_H
    1.11 +
    1.12 +#include <stdint.h>                     // for uint32_t
    1.13 +#include <sys/types.h>                  // for int32_t
    1.14 +#include "LayersTypes.h"                // for LayersBackend, etc
    1.15 +#include "nsXULAppAPI.h"                // for GeckoProcessType, etc
    1.16 +
    1.17 +namespace mozilla {
    1.18 +namespace layers {
    1.19 +
    1.20 +typedef int32_t SurfaceDescriptorType;
    1.21 +const SurfaceDescriptorType SURFACEDESCRIPTOR_UNKNOWN = 0;
    1.22 +
    1.23 +/**
    1.24 + * Flags used by texture clients and texture hosts. These are passed from client
    1.25 + * side to host side when textures and compositables are created. Usually set
    1.26 + * by the compositableCient, they may be modified by either the compositable or
    1.27 + * texture clients.
    1.28 + *
    1.29 + * XXX - switch to all caps constant names which seems to be the standard in gecko
    1.30 + */
    1.31 +typedef uint32_t TextureFlags;
    1.32 +// Use nearest-neighbour texture filtering (as opposed to linear filtering).
    1.33 +const TextureFlags TEXTURE_USE_NEAREST_FILTER = 1 << 0;
    1.34 +// The texture should be flipped around the y-axis when composited.
    1.35 +const TextureFlags TEXTURE_NEEDS_Y_FLIP       = 1 << 1;
    1.36 +// Force the texture to be represented using a single tile (note that this means
    1.37 +// tiled textures, not tiled layers).
    1.38 +const TextureFlags TEXTURE_DISALLOW_BIGIMAGE  = 1 << 2;
    1.39 +// Allow using 'repeat' mode for wrapping.
    1.40 +const TextureFlags TEXTURE_ALLOW_REPEAT       = 1 << 3;
    1.41 +// The texture represents a tile which is newly created.
    1.42 +const TextureFlags TEXTURE_NEW_TILE           = 1 << 4;
    1.43 +// The texture is part of a component-alpha pair
    1.44 +const TextureFlags TEXTURE_COMPONENT_ALPHA    = 1 << 5;
    1.45 +// The buffer will be treated as if the RB bytes are swapped.
    1.46 +// This is useful for rendering using Cairo/Thebes, because there is no
    1.47 +// BGRX Android pixel format, and so we have to do byte swapping.
    1.48 +//
    1.49 +// For example, if the GraphicBuffer has an Android pixel format of
    1.50 +// PIXEL_FORMAT_RGBA_8888 and isRBSwapped is true, when it is sampled
    1.51 +// (for example, with GL), a BGRA shader should be used.
    1.52 +const TextureFlags TEXTURE_RB_SWAPPED         = 1 << 6;
    1.53 +
    1.54 +const TextureFlags TEXTURE_FRONT              = 1 << 12;
    1.55 +// A texture host on white for component alpha
    1.56 +const TextureFlags TEXTURE_ON_WHITE           = 1 << 13;
    1.57 + // A texture host on black for component alpha
    1.58 +const TextureFlags TEXTURE_ON_BLACK           = 1 << 14;
    1.59 +// A texture host that supports tiling
    1.60 +const TextureFlags TEXTURE_TILE               = 1 << 15;
    1.61 +// A texture should be recycled when no longer in used
    1.62 +const TextureFlags TEXTURE_RECYCLE            = 1 << 16;
    1.63 +// Texture contents should be initialized
    1.64 +// from the previous texture.
    1.65 +const TextureFlags TEXTURE_COPY_PREVIOUS      = 1 << 24;
    1.66 +// Who is responsible for deallocating the shared data.
    1.67 +// if TEXTURE_DEALLOCATE_CLIENT is set, the shared data is deallocated on the
    1.68 +// client side and requires some extra synchronizaion to ensure race-free
    1.69 +// deallocation.
    1.70 +// The default behaviour is to deallocate on the host side.
    1.71 +const TextureFlags TEXTURE_DEALLOCATE_CLIENT  = 1 << 25;
    1.72 +// After being shared ith the compositor side, an immutable texture is never
    1.73 +// modified, it can only be read. It is safe to not Lock/Unlock immutable
    1.74 +// textures.
    1.75 +const TextureFlags TEXTURE_IMMUTABLE          = 1 << 27;
    1.76 +// The contents of the texture must be uploaded or copied immediately
    1.77 +// during the transaction, because the producer may want to write
    1.78 +// to it again.
    1.79 +const TextureFlags TEXTURE_IMMEDIATE_UPLOAD   = 1 << 28;
    1.80 +// The texture is going to be used as part of a double
    1.81 +// buffered pair, and so we can guarantee that the producer/consumer
    1.82 +// won't be racing to access its contents.
    1.83 +const TextureFlags TEXTURE_DOUBLE_BUFFERED    = 1 << 29;
    1.84 +// We've previously tried a texture and it didn't work for some reason. If there
    1.85 +// is a fallback available, try that.
    1.86 +const TextureFlags TEXTURE_ALLOC_FALLBACK     = 1 << 31;
    1.87 +
    1.88 +// the default flags
    1.89 +const TextureFlags TEXTURE_FLAGS_DEFAULT = TEXTURE_FRONT;
    1.90 +
    1.91 +static inline bool
    1.92 +TextureRequiresLocking(TextureFlags aFlags)
    1.93 +{
    1.94 +  // If we're not double buffered, or uploading
    1.95 +  // within a transaction, then we need to support
    1.96 +  // locking correctly.
    1.97 +  return !(aFlags & (TEXTURE_IMMEDIATE_UPLOAD |
    1.98 +                     TEXTURE_DOUBLE_BUFFERED |
    1.99 +                     TEXTURE_IMMUTABLE));
   1.100 +}
   1.101 +
   1.102 +/**
   1.103 + * The type of debug diagnostic to enable.
   1.104 + */
   1.105 +typedef uint32_t DiagnosticTypes;
   1.106 +const DiagnosticTypes DIAGNOSTIC_NONE             = 0;
   1.107 +const DiagnosticTypes DIAGNOSTIC_TILE_BORDERS     = 1 << 0;
   1.108 +const DiagnosticTypes DIAGNOSTIC_LAYER_BORDERS    = 1 << 1;
   1.109 +const DiagnosticTypes DIAGNOSTIC_BIGIMAGE_BORDERS = 1 << 2;
   1.110 +const DiagnosticTypes DIAGNOSTIC_FLASH_BORDERS    = 1 << 3;
   1.111 +
   1.112 +#define DIAGNOSTIC_FLASH_COUNTER_MAX 100
   1.113 +
   1.114 +/**
   1.115 + * Information about the object that is being diagnosed.
   1.116 + */
   1.117 +typedef uint32_t DiagnosticFlags;
   1.118 +const DiagnosticFlags DIAGNOSTIC_IMAGE      = 1 << 0;
   1.119 +const DiagnosticFlags DIAGNOSTIC_CONTENT    = 1 << 1;
   1.120 +const DiagnosticFlags DIAGNOSTIC_CANVAS     = 1 << 2;
   1.121 +const DiagnosticFlags DIAGNOSTIC_COLOR      = 1 << 3;
   1.122 +const DiagnosticFlags DIAGNOSTIC_CONTAINER  = 1 << 4;
   1.123 +const DiagnosticFlags DIAGNOSTIC_TILE       = 1 << 5;
   1.124 +const DiagnosticFlags DIAGNOSTIC_BIGIMAGE   = 1 << 6;
   1.125 +const DiagnosticFlags DIAGNOSTIC_COMPONENT_ALPHA = 1 << 7;
   1.126 +const DiagnosticFlags DIAGNOSTIC_REGION_RECT = 1 << 8;
   1.127 +
   1.128 +/**
   1.129 + * See gfx/layers/Effects.h
   1.130 + */
   1.131 +enum EffectTypes
   1.132 +{
   1.133 +  EFFECT_MASK,
   1.134 +  EFFECT_MAX_SECONDARY, // sentinel for the count of secondary effect types
   1.135 +  EFFECT_RGB,
   1.136 +  EFFECT_YCBCR,
   1.137 +  EFFECT_COMPONENT_ALPHA,
   1.138 +  EFFECT_SOLID_COLOR,
   1.139 +  EFFECT_RENDER_TARGET,
   1.140 +  EFFECT_MAX  //sentinel for the count of all effect types
   1.141 +};
   1.142 +
   1.143 +/**
   1.144 + * How the Compositable should manage textures.
   1.145 + */
   1.146 +enum CompositableType
   1.147 +{
   1.148 +  BUFFER_UNKNOWN,
   1.149 +  // the deprecated compositable types
   1.150 +  BUFFER_IMAGE_SINGLE,    // image/canvas with a single texture, single buffered
   1.151 +  BUFFER_IMAGE_BUFFERED,  // canvas, double buffered
   1.152 +  BUFFER_BRIDGE,          // image bridge protocol
   1.153 +  BUFFER_CONTENT_INC,     // thebes layer interface, only sends incremental
   1.154 +                          // updates to a texture on the compositor side.
   1.155 +  // somewhere in the middle
   1.156 +  BUFFER_TILED,           // tiled thebes layer
   1.157 +  BUFFER_SIMPLE_TILED,
   1.158 +  // the new compositable types
   1.159 +  COMPOSITABLE_IMAGE,     // image with single buffering
   1.160 +  COMPOSITABLE_CONTENT_SINGLE,  // thebes layer interface, single buffering
   1.161 +  COMPOSITABLE_CONTENT_DOUBLE,  // thebes layer interface, double buffering
   1.162 +  BUFFER_COUNT
   1.163 +};
   1.164 +
   1.165 +/**
   1.166 + * How the texture host is used for composition,
   1.167 + */
   1.168 +enum DeprecatedTextureHostFlags
   1.169 +{
   1.170 +  TEXTURE_HOST_DEFAULT = 0,       // The default texture host for the given
   1.171 +                                  // SurfaceDescriptor
   1.172 +  TEXTURE_HOST_TILED = 1 << 0,    // A texture host that supports tiling
   1.173 +  TEXTURE_HOST_COPY_PREVIOUS = 1 << 1 // Texture contents should be initialized
   1.174 +                                      // from the previous texture.
   1.175 +};
   1.176 +
   1.177 +/**
   1.178 + * Sent from the compositor to the content-side LayerManager, includes properties
   1.179 + * of the compositor and should (in the future) include information about what
   1.180 + * kinds of buffer and texture clients to create.
   1.181 + */
   1.182 +struct TextureFactoryIdentifier
   1.183 +{
   1.184 +  LayersBackend mParentBackend;
   1.185 +  GeckoProcessType mParentProcessId;
   1.186 +  int32_t mMaxTextureSize;
   1.187 +  bool mSupportsTextureBlitting;
   1.188 +  bool mSupportsPartialUploads;
   1.189 +
   1.190 +  TextureFactoryIdentifier(LayersBackend aLayersBackend = LayersBackend::LAYERS_NONE,
   1.191 +                           GeckoProcessType aParentProcessId = GeckoProcessType_Default,
   1.192 +                           int32_t aMaxTextureSize = 0,
   1.193 +                           bool aSupportsTextureBlitting = false,
   1.194 +                           bool aSupportsPartialUploads = false)
   1.195 +    : mParentBackend(aLayersBackend)
   1.196 +    , mParentProcessId(aParentProcessId)
   1.197 +    , mMaxTextureSize(aMaxTextureSize)
   1.198 +    , mSupportsTextureBlitting(aSupportsTextureBlitting)
   1.199 +    , mSupportsPartialUploads(aSupportsPartialUploads)
   1.200 +  {}
   1.201 +};
   1.202 +
   1.203 +/**
   1.204 + * Identify a texture to a compositable. Many textures can have the same id, but
   1.205 + * the id is unique for any texture owned by a particular compositable.
   1.206 + * XXX - This is now redundant with TextureFlags. it ill be removed along with
   1.207 + * deprecated texture classes.
   1.208 + */
   1.209 +typedef uint32_t TextureIdentifier;
   1.210 +const TextureIdentifier TextureFront = 1;
   1.211 +const TextureIdentifier TextureBack = 2;
   1.212 +const TextureIdentifier TextureOnWhiteFront = 3;
   1.213 +const TextureIdentifier TextureOnWhiteBack = 4;
   1.214 +
   1.215 +/**
   1.216 + * Information required by the compositor from the content-side for creating or
   1.217 + * using compositables and textures.
   1.218 + * XXX - TextureInfo is a bad name: this information is useful for the compositable,
   1.219 + * not the Texture. And ith new Textures, only the compositable type is really
   1.220 + * useful. This may (should) be removed in the near future.
   1.221 + */
   1.222 +struct TextureInfo
   1.223 +{
   1.224 +  CompositableType mCompositableType;
   1.225 +  uint32_t mDeprecatedTextureHostFlags;
   1.226 +  uint32_t mTextureFlags;
   1.227 +
   1.228 +  TextureInfo()
   1.229 +    : mCompositableType(BUFFER_UNKNOWN)
   1.230 +    , mDeprecatedTextureHostFlags(0)
   1.231 +    , mTextureFlags(0)
   1.232 +  {}
   1.233 +
   1.234 +  TextureInfo(CompositableType aType)
   1.235 +    : mCompositableType(aType)
   1.236 +    , mDeprecatedTextureHostFlags(0)
   1.237 +    , mTextureFlags(0)
   1.238 +  {}
   1.239 +
   1.240 +  bool operator==(const TextureInfo& aOther) const
   1.241 +  {
   1.242 +    return mCompositableType == aOther.mCompositableType &&
   1.243 +           mDeprecatedTextureHostFlags == aOther.mDeprecatedTextureHostFlags &&
   1.244 +           mTextureFlags == aOther.mTextureFlags;
   1.245 +  }
   1.246 +};
   1.247 +
   1.248 +/**
   1.249 + * How a SurfaceDescriptor will be opened.
   1.250 + *
   1.251 + * See ShadowLayerForwarder::OpenDescriptor for example.
   1.252 + */
   1.253 +typedef uint32_t OpenMode;
   1.254 +const OpenMode OPEN_READ        = 0x1;
   1.255 +const OpenMode OPEN_WRITE       = 0x2;
   1.256 +const OpenMode OPEN_READ_WRITE  = OPEN_READ|OPEN_WRITE;
   1.257 +const OpenMode OPEN_READ_ONLY   = OPEN_READ;
   1.258 +const OpenMode OPEN_WRITE_ONLY  = OPEN_WRITE;
   1.259 +
   1.260 +// The kinds of mask texture a shader can support
   1.261 +// We rely on the items in this enum being sequential
   1.262 +enum MaskType {
   1.263 +  MaskNone = 0,   // no mask layer
   1.264 +  Mask2d,         // mask layer for layers with 2D transforms
   1.265 +  Mask3d,         // mask layer for layers with 3D transforms
   1.266 +  NumMaskTypes
   1.267 +};
   1.268 +
   1.269 +} // namespace layers
   1.270 +} // namespace mozilla
   1.271 +
   1.272 +#endif

mercurial