michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef MOZILLA_LAYERS_COMPOSITORTYPES_H michael@0: #define MOZILLA_LAYERS_COMPOSITORTYPES_H michael@0: michael@0: #include // for uint32_t michael@0: #include // for int32_t michael@0: #include "LayersTypes.h" // for LayersBackend, etc michael@0: #include "nsXULAppAPI.h" // for GeckoProcessType, etc michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: typedef int32_t SurfaceDescriptorType; michael@0: const SurfaceDescriptorType SURFACEDESCRIPTOR_UNKNOWN = 0; michael@0: michael@0: /** michael@0: * Flags used by texture clients and texture hosts. These are passed from client michael@0: * side to host side when textures and compositables are created. Usually set michael@0: * by the compositableCient, they may be modified by either the compositable or michael@0: * texture clients. michael@0: * michael@0: * XXX - switch to all caps constant names which seems to be the standard in gecko michael@0: */ michael@0: typedef uint32_t TextureFlags; michael@0: // Use nearest-neighbour texture filtering (as opposed to linear filtering). michael@0: const TextureFlags TEXTURE_USE_NEAREST_FILTER = 1 << 0; michael@0: // The texture should be flipped around the y-axis when composited. michael@0: const TextureFlags TEXTURE_NEEDS_Y_FLIP = 1 << 1; michael@0: // Force the texture to be represented using a single tile (note that this means michael@0: // tiled textures, not tiled layers). michael@0: const TextureFlags TEXTURE_DISALLOW_BIGIMAGE = 1 << 2; michael@0: // Allow using 'repeat' mode for wrapping. michael@0: const TextureFlags TEXTURE_ALLOW_REPEAT = 1 << 3; michael@0: // The texture represents a tile which is newly created. michael@0: const TextureFlags TEXTURE_NEW_TILE = 1 << 4; michael@0: // The texture is part of a component-alpha pair michael@0: const TextureFlags TEXTURE_COMPONENT_ALPHA = 1 << 5; michael@0: // The buffer will be treated as if the RB bytes are swapped. michael@0: // This is useful for rendering using Cairo/Thebes, because there is no michael@0: // BGRX Android pixel format, and so we have to do byte swapping. michael@0: // michael@0: // For example, if the GraphicBuffer has an Android pixel format of michael@0: // PIXEL_FORMAT_RGBA_8888 and isRBSwapped is true, when it is sampled michael@0: // (for example, with GL), a BGRA shader should be used. michael@0: const TextureFlags TEXTURE_RB_SWAPPED = 1 << 6; michael@0: michael@0: const TextureFlags TEXTURE_FRONT = 1 << 12; michael@0: // A texture host on white for component alpha michael@0: const TextureFlags TEXTURE_ON_WHITE = 1 << 13; michael@0: // A texture host on black for component alpha michael@0: const TextureFlags TEXTURE_ON_BLACK = 1 << 14; michael@0: // A texture host that supports tiling michael@0: const TextureFlags TEXTURE_TILE = 1 << 15; michael@0: // A texture should be recycled when no longer in used michael@0: const TextureFlags TEXTURE_RECYCLE = 1 << 16; michael@0: // Texture contents should be initialized michael@0: // from the previous texture. michael@0: const TextureFlags TEXTURE_COPY_PREVIOUS = 1 << 24; michael@0: // Who is responsible for deallocating the shared data. michael@0: // if TEXTURE_DEALLOCATE_CLIENT is set, the shared data is deallocated on the michael@0: // client side and requires some extra synchronizaion to ensure race-free michael@0: // deallocation. michael@0: // The default behaviour is to deallocate on the host side. michael@0: const TextureFlags TEXTURE_DEALLOCATE_CLIENT = 1 << 25; michael@0: // After being shared ith the compositor side, an immutable texture is never michael@0: // modified, it can only be read. It is safe to not Lock/Unlock immutable michael@0: // textures. michael@0: const TextureFlags TEXTURE_IMMUTABLE = 1 << 27; michael@0: // The contents of the texture must be uploaded or copied immediately michael@0: // during the transaction, because the producer may want to write michael@0: // to it again. michael@0: const TextureFlags TEXTURE_IMMEDIATE_UPLOAD = 1 << 28; michael@0: // The texture is going to be used as part of a double michael@0: // buffered pair, and so we can guarantee that the producer/consumer michael@0: // won't be racing to access its contents. michael@0: const TextureFlags TEXTURE_DOUBLE_BUFFERED = 1 << 29; michael@0: // We've previously tried a texture and it didn't work for some reason. If there michael@0: // is a fallback available, try that. michael@0: const TextureFlags TEXTURE_ALLOC_FALLBACK = 1 << 31; michael@0: michael@0: // the default flags michael@0: const TextureFlags TEXTURE_FLAGS_DEFAULT = TEXTURE_FRONT; michael@0: michael@0: static inline bool michael@0: TextureRequiresLocking(TextureFlags aFlags) michael@0: { michael@0: // If we're not double buffered, or uploading michael@0: // within a transaction, then we need to support michael@0: // locking correctly. michael@0: return !(aFlags & (TEXTURE_IMMEDIATE_UPLOAD | michael@0: TEXTURE_DOUBLE_BUFFERED | michael@0: TEXTURE_IMMUTABLE)); michael@0: } michael@0: michael@0: /** michael@0: * The type of debug diagnostic to enable. michael@0: */ michael@0: typedef uint32_t DiagnosticTypes; michael@0: const DiagnosticTypes DIAGNOSTIC_NONE = 0; michael@0: const DiagnosticTypes DIAGNOSTIC_TILE_BORDERS = 1 << 0; michael@0: const DiagnosticTypes DIAGNOSTIC_LAYER_BORDERS = 1 << 1; michael@0: const DiagnosticTypes DIAGNOSTIC_BIGIMAGE_BORDERS = 1 << 2; michael@0: const DiagnosticTypes DIAGNOSTIC_FLASH_BORDERS = 1 << 3; michael@0: michael@0: #define DIAGNOSTIC_FLASH_COUNTER_MAX 100 michael@0: michael@0: /** michael@0: * Information about the object that is being diagnosed. michael@0: */ michael@0: typedef uint32_t DiagnosticFlags; michael@0: const DiagnosticFlags DIAGNOSTIC_IMAGE = 1 << 0; michael@0: const DiagnosticFlags DIAGNOSTIC_CONTENT = 1 << 1; michael@0: const DiagnosticFlags DIAGNOSTIC_CANVAS = 1 << 2; michael@0: const DiagnosticFlags DIAGNOSTIC_COLOR = 1 << 3; michael@0: const DiagnosticFlags DIAGNOSTIC_CONTAINER = 1 << 4; michael@0: const DiagnosticFlags DIAGNOSTIC_TILE = 1 << 5; michael@0: const DiagnosticFlags DIAGNOSTIC_BIGIMAGE = 1 << 6; michael@0: const DiagnosticFlags DIAGNOSTIC_COMPONENT_ALPHA = 1 << 7; michael@0: const DiagnosticFlags DIAGNOSTIC_REGION_RECT = 1 << 8; michael@0: michael@0: /** michael@0: * See gfx/layers/Effects.h michael@0: */ michael@0: enum EffectTypes michael@0: { michael@0: EFFECT_MASK, michael@0: EFFECT_MAX_SECONDARY, // sentinel for the count of secondary effect types michael@0: EFFECT_RGB, michael@0: EFFECT_YCBCR, michael@0: EFFECT_COMPONENT_ALPHA, michael@0: EFFECT_SOLID_COLOR, michael@0: EFFECT_RENDER_TARGET, michael@0: EFFECT_MAX //sentinel for the count of all effect types michael@0: }; michael@0: michael@0: /** michael@0: * How the Compositable should manage textures. michael@0: */ michael@0: enum CompositableType michael@0: { michael@0: BUFFER_UNKNOWN, michael@0: // the deprecated compositable types michael@0: BUFFER_IMAGE_SINGLE, // image/canvas with a single texture, single buffered michael@0: BUFFER_IMAGE_BUFFERED, // canvas, double buffered michael@0: BUFFER_BRIDGE, // image bridge protocol michael@0: BUFFER_CONTENT_INC, // thebes layer interface, only sends incremental michael@0: // updates to a texture on the compositor side. michael@0: // somewhere in the middle michael@0: BUFFER_TILED, // tiled thebes layer michael@0: BUFFER_SIMPLE_TILED, michael@0: // the new compositable types michael@0: COMPOSITABLE_IMAGE, // image with single buffering michael@0: COMPOSITABLE_CONTENT_SINGLE, // thebes layer interface, single buffering michael@0: COMPOSITABLE_CONTENT_DOUBLE, // thebes layer interface, double buffering michael@0: BUFFER_COUNT michael@0: }; michael@0: michael@0: /** michael@0: * How the texture host is used for composition, michael@0: */ michael@0: enum DeprecatedTextureHostFlags michael@0: { michael@0: TEXTURE_HOST_DEFAULT = 0, // The default texture host for the given michael@0: // SurfaceDescriptor michael@0: TEXTURE_HOST_TILED = 1 << 0, // A texture host that supports tiling michael@0: TEXTURE_HOST_COPY_PREVIOUS = 1 << 1 // Texture contents should be initialized michael@0: // from the previous texture. michael@0: }; michael@0: michael@0: /** michael@0: * Sent from the compositor to the content-side LayerManager, includes properties michael@0: * of the compositor and should (in the future) include information about what michael@0: * kinds of buffer and texture clients to create. michael@0: */ michael@0: struct TextureFactoryIdentifier michael@0: { michael@0: LayersBackend mParentBackend; michael@0: GeckoProcessType mParentProcessId; michael@0: int32_t mMaxTextureSize; michael@0: bool mSupportsTextureBlitting; michael@0: bool mSupportsPartialUploads; michael@0: michael@0: TextureFactoryIdentifier(LayersBackend aLayersBackend = LayersBackend::LAYERS_NONE, michael@0: GeckoProcessType aParentProcessId = GeckoProcessType_Default, michael@0: int32_t aMaxTextureSize = 0, michael@0: bool aSupportsTextureBlitting = false, michael@0: bool aSupportsPartialUploads = false) michael@0: : mParentBackend(aLayersBackend) michael@0: , mParentProcessId(aParentProcessId) michael@0: , mMaxTextureSize(aMaxTextureSize) michael@0: , mSupportsTextureBlitting(aSupportsTextureBlitting) michael@0: , mSupportsPartialUploads(aSupportsPartialUploads) michael@0: {} michael@0: }; michael@0: michael@0: /** michael@0: * Identify a texture to a compositable. Many textures can have the same id, but michael@0: * the id is unique for any texture owned by a particular compositable. michael@0: * XXX - This is now redundant with TextureFlags. it ill be removed along with michael@0: * deprecated texture classes. michael@0: */ michael@0: typedef uint32_t TextureIdentifier; michael@0: const TextureIdentifier TextureFront = 1; michael@0: const TextureIdentifier TextureBack = 2; michael@0: const TextureIdentifier TextureOnWhiteFront = 3; michael@0: const TextureIdentifier TextureOnWhiteBack = 4; michael@0: michael@0: /** michael@0: * Information required by the compositor from the content-side for creating or michael@0: * using compositables and textures. michael@0: * XXX - TextureInfo is a bad name: this information is useful for the compositable, michael@0: * not the Texture. And ith new Textures, only the compositable type is really michael@0: * useful. This may (should) be removed in the near future. michael@0: */ michael@0: struct TextureInfo michael@0: { michael@0: CompositableType mCompositableType; michael@0: uint32_t mDeprecatedTextureHostFlags; michael@0: uint32_t mTextureFlags; michael@0: michael@0: TextureInfo() michael@0: : mCompositableType(BUFFER_UNKNOWN) michael@0: , mDeprecatedTextureHostFlags(0) michael@0: , mTextureFlags(0) michael@0: {} michael@0: michael@0: TextureInfo(CompositableType aType) michael@0: : mCompositableType(aType) michael@0: , mDeprecatedTextureHostFlags(0) michael@0: , mTextureFlags(0) michael@0: {} michael@0: michael@0: bool operator==(const TextureInfo& aOther) const michael@0: { michael@0: return mCompositableType == aOther.mCompositableType && michael@0: mDeprecatedTextureHostFlags == aOther.mDeprecatedTextureHostFlags && michael@0: mTextureFlags == aOther.mTextureFlags; michael@0: } michael@0: }; michael@0: michael@0: /** michael@0: * How a SurfaceDescriptor will be opened. michael@0: * michael@0: * See ShadowLayerForwarder::OpenDescriptor for example. michael@0: */ michael@0: typedef uint32_t OpenMode; michael@0: const OpenMode OPEN_READ = 0x1; michael@0: const OpenMode OPEN_WRITE = 0x2; michael@0: const OpenMode OPEN_READ_WRITE = OPEN_READ|OPEN_WRITE; michael@0: const OpenMode OPEN_READ_ONLY = OPEN_READ; michael@0: const OpenMode OPEN_WRITE_ONLY = OPEN_WRITE; michael@0: michael@0: // The kinds of mask texture a shader can support michael@0: // We rely on the items in this enum being sequential michael@0: enum MaskType { michael@0: MaskNone = 0, // no mask layer michael@0: Mask2d, // mask layer for layers with 2D transforms michael@0: Mask3d, // mask layer for layers with 3D transforms michael@0: NumMaskTypes michael@0: }; michael@0: michael@0: } // namespace layers michael@0: } // namespace mozilla michael@0: michael@0: #endif