chromium/third_party/angle/src/libANGLE/angletypes.h

//
// Copyright 2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//

// angletypes.h : Defines a variety of structures and enum types that are used throughout libGLESv2

#ifndef LIBANGLE_ANGLETYPES_H_
#define LIBANGLE_ANGLETYPES_H_

#include <anglebase/sha1.h>
#include "common/Color.h"
#include "common/FixedVector.h"
#include "common/MemoryBuffer.h"
#include "common/PackedEnums.h"
#include "common/bitset_utils.h"
#include "common/hash_utils.h"
#include "common/vector_utils.h"
#include "libANGLE/Constants.h"
#include "libANGLE/Error.h"
#include "libANGLE/RefCountObject.h"

#include <inttypes.h>
#include <stdint.h>

#include <bitset>
#include <functional>
#include <map>
#include <memory>
#include <unordered_map>

namespace gl
{
class Buffer;
class Texture;

enum class Command
{};

enum CommandBlitBuffer
{};

enum class InitState
{};

template <typename T>
struct RectangleImpl
{};

template <typename T>
bool operator==(const RectangleImpl<T> &a, const RectangleImpl<T> &b);
template <typename T>
bool operator!=(const RectangleImpl<T> &a, const RectangleImpl<T> &b);

Rectangle;

// Calculate the intersection of two rectangles.  Returns false if the intersection is empty.
[[nodiscard]] bool ClipRectangle(const Rectangle &source,
                                 const Rectangle &clip,
                                 Rectangle *intersection);
// Calculate the smallest rectangle that covers both rectangles.  This rectangle may cover areas
// not covered by the two rectangles, for example in this situation:
//
//   +--+        +----+
//   | ++-+  ->  |    |
//   +-++ |      |    |
//     +--+      +----+
//
void GetEnclosingRectangle(const Rectangle &rect1, const Rectangle &rect2, Rectangle *rectUnion);
// Extend the source rectangle to cover parts (or all of) the second rectangle, in such a way that
// no area is covered that isn't covered by both rectangles.  For example:
//
//             +--+        +--+
//  source --> |  |        |  |
//            ++--+-+  ->  |  |
//            |+--+ |      |  |
//            +-----+      +--+
//
void ExtendRectangle(const Rectangle &source, const Rectangle &extend, Rectangle *extended);

struct Offset
{};

constexpr Offset kOffsetZero(0, 0, 0);

bool operator==(const Offset &a, const Offset &b);
bool operator!=(const Offset &a, const Offset &b);

struct Extents
{};

bool operator==(const Extents &lhs, const Extents &rhs);
bool operator!=(const Extents &lhs, const Extents &rhs);

struct Box
{};

struct RasterizerState final
{};

bool operator==(const RasterizerState &a, const RasterizerState &b);
bool operator!=(const RasterizerState &a, const RasterizerState &b);

struct BlendState final
{};

bool operator==(const BlendState &a, const BlendState &b);
bool operator!=(const BlendState &a, const BlendState &b);

struct DepthStencilState final
{};

bool operator==(const DepthStencilState &a, const DepthStencilState &b);
bool operator!=(const DepthStencilState &a, const DepthStencilState &b);

// Packs a sampler state for completeness checks:
// * minFilter: 5 values (3 bits)
// * magFilter: 2 values (1 bit)
// * wrapS:     3 values (2 bits)
// * wrapT:     3 values (2 bits)
// * compareMode: 1 bit (for == GL_NONE).
// This makes a total of 9 bits. We can pack this easily into 32 bits:
// * minFilter: 8 bits
// * magFilter: 8 bits
// * wrapS:     8 bits
// * wrapT:     4 bits
// * compareMode: 4 bits

struct PackedSamplerCompleteness
{};

static_assert;

// State from Table 6.10 (state per sampler object)
class SamplerState final
{};

bool operator==(const SamplerState &a, const SamplerState &b);
bool operator!=(const SamplerState &a, const SamplerState &b);

struct DrawArraysIndirectCommand
{};
static_assert;

struct DrawElementsIndirectCommand
{};
static_assert;

struct ImageUnit
{};

ImageUnitTextureTypeMap;

struct PixelStoreStateBase
{};

struct PixelUnpackState : PixelStoreStateBase
{};

struct PixelPackState : PixelStoreStateBase
{};

// Used in VertexArray.
VertexArrayBufferBindingMask;

// Used in Program and VertexArray.
AttributesMask;

// Used in Program
ProgramUniformBlockMask;
ProgramUniformBlockArray;
UniformBufferBindingArray;

// Used in Framebuffer / Program
DrawBufferMask;

class BlendStateExt final
{};

static_assert;

// Used in StateCache
StorageBuffersMask;

SampleMaskArray;

TexLevelArray;

TexLevelMask;

enum class ComponentType
{};

constexpr ComponentType GLenumToComponentType(GLenum componentType)
{}

constexpr angle::PackedEnumMap<ComponentType, uint32_t> kComponentMasks =;

constexpr size_t kMaxComponentTypeMaskIndex =;
ComponentTypeMask;

ANGLE_INLINE void SetComponentTypeMask(ComponentType type, size_t index, ComponentTypeMask *mask)
{}

ANGLE_INLINE ComponentType GetComponentTypeMask(ComponentTypeMask mask, size_t index)
{}

ANGLE_INLINE ComponentTypeMask GetActiveComponentTypeMask(gl::AttributesMask activeAttribLocations)
{}

ANGLE_INLINE DrawBufferMask GetComponentTypeMaskDiff(ComponentTypeMask mask1,
                                                     ComponentTypeMask mask2)
{}

bool ValidateComponentTypeMasks(unsigned long outputTypes,
                                unsigned long inputTypes,
                                unsigned long outputMask,
                                unsigned long inputMask);

// Helpers for performing WebGL 2.0 clear validation
// Extracted component type has always one of these four values:
// * 0x10001 - float or normalized
// * 0x00001 - int
// * 0x10000 - unsigned int
// * 0x00000 - unused or disabled

// The following functions rely on these.
static_assert;
static_assert;
static_assert;

// Used for clearBufferuiv
ANGLE_INLINE bool IsComponentTypeFloatOrInt(ComponentTypeMask mask, size_t index)
{}

// Used for clearBufferiv
ANGLE_INLINE bool IsComponentTypeFloatOrUnsignedInt(ComponentTypeMask mask, size_t index)
{}

// Used for clearBufferfv
ANGLE_INLINE bool IsComponentTypeIntOrUnsignedInt(ComponentTypeMask mask, size_t index)
{}

// Used for clear
ANGLE_INLINE DrawBufferMask GetIntOrUnsignedIntDrawBufferMask(ComponentTypeMask mask)
{}

enum class RenderToTextureImageIndex
{};

RenderToTextureImageMap;

constexpr size_t kCubeFaceCount =;

CubeFaceArray;

TextureTypeMap;
TextureMap;

// ShaderVector can contain one item per shader.  It differs from ShaderMap in that the values are
// not indexed by ShaderType.
ShaderVector;

AttachmentArray;

AttachmentVector;

AttachmentsMask;

DrawBuffersArray;

DrawBuffersVector;

AttribArray;

AttribVector;

ActiveTextureMask;

ActiveTextureArray;

ActiveTextureTypeArray;

ImageUnitMask;

SupportedSampleSet;

TransformFeedbackBuffersArray;

ClipDistanceEnableBits;

QueryTypeMap;

constexpr size_t kBarrierVectorDefaultSize =;

BarrierVector;

BufferBarrierVector;

SamplerBindingVector;
BufferVector;

struct TextureAndLayout
{};
TextureBarrierVector;

// OffsetBindingPointer.getSize() returns the size specified by the user, which may be larger than
// the size of the bound buffer. This function reduces the returned size to fit the bound buffer if
// necessary. Returns 0 if no buffer is bound or if integer overflow occurs.
GLsizeiptr GetBoundBufferAvailableSize(const OffsetBindingPointer<Buffer> &binding);

// A texture level index.
template <typename T>
class LevelIndexWrapper
{};

// A GL texture level index.
LevelIndex;

enum class MultisamplingMode
{};
}  // namespace gl

namespace rx
{
// A macro that determines whether an object has a given runtime type.
#if defined(__clang__)
#    if __has_feature(cxx_rtti)
#define ANGLE_HAS_DYNAMIC_CAST
#    endif
#elif !defined(NDEBUG) && (!defined(_MSC_VER) || defined(_CPPRTTI)) &&              \
    (!defined(__GNUC__) || __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3) || \
     defined(__GXX_RTTI))
#define ANGLE_HAS_DYNAMIC_CAST
#endif

#ifdef ANGLE_HAS_DYNAMIC_CAST
#define ANGLE_HAS_DYNAMIC_TYPE
#    undef ANGLE_HAS_DYNAMIC_CAST
#else
#define ANGLE_HAS_DYNAMIC_TYPE
#endif

// Downcast a base implementation object (EG TextureImpl to TextureD3D)
template <typename DestT, typename SrcT>
inline DestT *GetAs(SrcT *src)
{}

template <typename DestT, typename SrcT>
inline const DestT *GetAs(const SrcT *src)
{}

#undef ANGLE_HAS_DYNAMIC_TYPE

// Downcast a GL object to an Impl (EG gl::Texture to rx::TextureD3D)
template <typename DestT, typename SrcT>
inline DestT *GetImplAs(SrcT *src)
{}

template <typename DestT, typename SrcT>
inline DestT *SafeGetImplAs(SrcT *src)
{}

}  // namespace rx

#include "angletypes.inc"

namespace angle
{
enum class NativeWindowSystem
{};

struct FeatureOverrides
{};

// 160-bit SHA-1 hash key used for hasing a program.  BlobCache opts in using fixed keys for
// simplicity and efficiency.
static constexpr size_t kBlobCacheKeyLength =;
BlobCacheKey;
class BlobCacheValue  // To be replaced with std::span when C++20 is required
{};

bool CompressBlob(const size_t cacheSize, const uint8_t *cacheData, MemoryBuffer *compressedData);
bool DecompressBlob(const uint8_t *compressedData,
                    const size_t compressedSize,
                    size_t maxUncompressedDataSize,
                    MemoryBuffer *uncompressedData);
uint32_t GenerateCRC32(const uint8_t *data, size_t size);
}  // namespace angle

namespace std
{
template <>
struct hash<angle::BlobCacheKey>
{};
}  // namespace std

namespace angle
{
// Under certain circumstances, such as for increased parallelism, the backend may defer an
// operation to be done at the end of a call after the locks have been unlocked.  The entry point
// function passes an |UnlockedTailCall| through the frontend to the backend.  If it is set, the
// entry point would execute it at the end of the call.
//
// Since the function is called without any locks, care must be taken to minimize the amount of work
// in such calls and ensure thread safety (for example by using fine grained locks inside the call
// itself).
//
// Some entry points pass a void pointer argument to UnlockedTailCall::run method intended to
// contain the return value filled by the backend, the rest of the entry points pass in a
// nullptr.  Regardless, Display::terminate runs pending tail calls passing in a nullptr, so
// the tail calls that return a value in the argument still have to guard against a nullptr
// parameter.
class UnlockedTailCall final : angle::NonCopyable
{};

enum class JobThreadSafety
{};

enum class JobResultExpectancy
{};

// Zero-based for better array indexing
enum FramebufferBinding
{};

inline FramebufferBinding EnumToFramebufferBinding(GLenum enumValue)
{}

inline GLenum FramebufferBindingToEnum(FramebufferBinding binding)
{}

template <typename ObjT, typename ContextT>
class DestroyThenDelete
{};

UniqueObjectPointer;

}  // namespace angle

namespace gl
{
class State;

// Focal Point information for foveated rendering
struct FocalPoint
{};

constexpr FocalPoint kDefaultFocalPoint =;

class FoveationState
{};

}  // namespace gl

#endif  // LIBANGLE_ANGLETYPES_H_