chromium/third_party/angle/src/common/angleutils.h

//
// Copyright 2002 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.
//

// angleutils.h: Common ANGLE utilities.

#ifndef COMMON_ANGLEUTILS_H_
#define COMMON_ANGLEUTILS_H_

#include "common/platform.h"

#if defined(ANGLE_WITH_LSAN)
#    include <sanitizer/lsan_interface.h>
#endif  // defined(ANGLE_WITH_LSAN)

#if defined(ANGLE_WITH_MSAN)
#    include <sanitizer/msan_interface.h>
#endif  // defined(ANGLE_WITH_MSAN)

#include <climits>
#include <cstdarg>
#include <cstddef>
#include <mutex>
#include <set>
#include <sstream>
#include <string>
#include <thread>
#include <vector>

namespace angle
{

#if defined(ANGLE_ENABLE_D3D9) || defined(ANGLE_ENABLE_D3D11)
using Microsoft::WRL::ComPtr;
#endif  // defined(ANGLE_ENABLE_D3D9) || defined(ANGLE_ENABLE_D3D11)

// Forward declaration. Implementation in system_utils.h
#if defined(ANGLE_PLATFORM_LINUX) || defined(ANGLE_PLATFORM_WINDOWS)
ThreadId;
#else
using ThreadId = std::thread::id;
#endif

// A helper class to disallow copy and assignment operators
class NonCopyable
{};

extern const uintptr_t DirtyPointer;

// AMD_performance_monitor helpers.
constexpr char kPerfMonitorExtensionName[] =;

struct PerfMonitorCounter
{};
PerfMonitorCounters;

struct PerfMonitorCounterGroup
{};
PerfMonitorCounterGroups;

uint32_t GetPerfMonitorCounterIndex(const PerfMonitorCounters &counters, const std::string &name);
const PerfMonitorCounter &GetPerfMonitorCounter(const PerfMonitorCounters &counters,
                                                const std::string &name);
PerfMonitorCounter &GetPerfMonitorCounter(PerfMonitorCounters &counters, const std::string &name);
uint32_t GetPerfMonitorCounterGroupIndex(const PerfMonitorCounterGroups &groups,
                                         const std::string &name);
const PerfMonitorCounterGroup &GetPerfMonitorCounterGroup(const PerfMonitorCounterGroups &groups,
                                                          const std::string &name);
PerfMonitorCounterGroup &GetPerfMonitorCounterGroup(PerfMonitorCounterGroups &groups,
                                                    const std::string &name);

struct PerfMonitorTriplet
{};

#define ANGLE_VK_PERF_COUNTERS_X(FN)

#define ANGLE_DECLARE_PERF_COUNTER

struct VulkanPerfCounters
{};

#undef ANGLE_DECLARE_PERF_COUNTER

}  // namespace angle

template <typename T, size_t N>
constexpr inline size_t ArraySize(T (&)[N])
{}

template <typename T>
class WrappedArray final : angle::NonCopyable
{};

template <typename T, unsigned int N>
void SafeRelease(T (&resourceBlock)[N])
{}

template <typename T>
void SafeRelease(T &resource)
{}

template <typename T>
void SafeDelete(T *&resource)
{}

template <typename T>
void SafeDeleteContainer(T &resource)
{}

template <typename T>
void SafeDeleteArray(T *&resource)
{}

// Provide a less-than function for comparing structs
// Note: struct memory must be initialized to zero, because of packing gaps
template <typename T>
inline bool StructLessThan(const T &a, const T &b)
{}

// Provide a less-than function for comparing structs
// Note: struct memory must be initialized to zero, because of packing gaps
template <typename T>
inline bool StructEquals(const T &a, const T &b)
{}

template <typename T>
inline void StructZero(T *obj)
{}

template <typename T>
inline bool IsMaskFlagSet(T mask, T flag)
{}

inline const char *MakeStaticString(const std::string &str)
{}

std::string ArrayString(unsigned int i);

// Indices are stored in vectors with the outermost index in the back. In the output of the function
// the indices are reversed.
std::string ArrayIndexString(const std::vector<unsigned int> &indices);

inline std::string Str(int i)
{}

template <typename T>
std::string ToString(const T &value)
{}

inline bool IsLittleEndian()
{}

// Helper macro that casts to a bitfield type then verifies no bits were dropped.
#define SetBitField(lhs, rhs)

// snprintf is not defined with MSVC prior to to msvc14
#if defined(_MSC_VER) && _MSC_VER < 1900
#define snprintf
#endif

#define GL_A1RGB5_ANGLEX
#define GL_BGRX8_ANGLEX
#define GL_BGR565_ANGLEX
#define GL_BGRA4_ANGLEX
#define GL_BGR5_A1_ANGLEX
#define GL_INT_64_ANGLEX
#define GL_UINT_64_ANGLEX
#define GL_BGRA8_SRGB_ANGLEX
#define GL_BGR10_A2_ANGLEX
#define GL_BGRX8_SRGB_ANGLEX
// fake format for GL_ANGLE_rgbx_internal_format
#define GL_RGBX8_SRGB_ANGLEX

// These are fake formats used to fit typeless D3D textures that can be bound to EGL pbuffers into
// the format system (for extension EGL_ANGLE_d3d_texture_client_buffer):
#define GL_RGBA8_TYPELESS_ANGLEX
#define GL_RGBA8_TYPELESS_SRGB_ANGLEX
#define GL_BGRA8_TYPELESS_ANGLEX
#define GL_BGRA8_TYPELESS_SRGB_ANGLEX

#define GL_R8_SSCALED_ANGLEX
#define GL_RG8_SSCALED_ANGLEX
#define GL_RGB8_SSCALED_ANGLEX
#define GL_RGBA8_SSCALED_ANGLEX
#define GL_R8_USCALED_ANGLEX
#define GL_RG8_USCALED_ANGLEX
#define GL_RGB8_USCALED_ANGLEX
#define GL_RGBA8_USCALED_ANGLEX

#define GL_R16_SSCALED_ANGLEX
#define GL_RG16_SSCALED_ANGLEX
#define GL_RGB16_SSCALED_ANGLEX
#define GL_RGBA16_SSCALED_ANGLEX
#define GL_R16_USCALED_ANGLEX
#define GL_RG16_USCALED_ANGLEX
#define GL_RGB16_USCALED_ANGLEX
#define GL_RGBA16_USCALED_ANGLEX

#define GL_R32_SSCALED_ANGLEX
#define GL_RG32_SSCALED_ANGLEX
#define GL_RGB32_SSCALED_ANGLEX
#define GL_RGBA32_SSCALED_ANGLEX
#define GL_R32_USCALED_ANGLEX
#define GL_RG32_USCALED_ANGLEX
#define GL_RGB32_USCALED_ANGLEX
#define GL_RGBA32_USCALED_ANGLEX

#define GL_R32_SNORM_ANGLEX
#define GL_RG32_SNORM_ANGLEX
#define GL_RGB32_SNORM_ANGLEX
#define GL_RGBA32_SNORM_ANGLEX
#define GL_R32_UNORM_ANGLEX
#define GL_RG32_UNORM_ANGLEX
#define GL_RGB32_UNORM_ANGLEX
#define GL_RGBA32_UNORM_ANGLEX

#define GL_R32_FIXED_ANGLEX
#define GL_RG32_FIXED_ANGLEX
#define GL_RGB32_FIXED_ANGLEX
#define GL_RGBA32_FIXED_ANGLEX

#define GL_RGB10_A2_SINT_ANGLEX
#define GL_RGB10_A2_SNORM_ANGLEX
#define GL_RGB10_A2_SSCALED_ANGLEX
#define GL_RGB10_A2_USCALED_ANGLEX

// EXT_texture_type_2_10_10_10_REV
#define GL_RGB10_UNORM_ANGLEX

// These are fake formats for OES_vertex_type_10_10_10_2
#define GL_A2_RGB10_UNORM_ANGLEX
#define GL_A2_RGB10_SNORM_ANGLEX
#define GL_A2_RGB10_USCALED_ANGLEX
#define GL_A2_RGB10_SSCALED_ANGLEX
#define GL_X2_RGB10_UINT_ANGLEX
#define GL_X2_RGB10_SINT_ANGLEX
#define GL_X2_RGB10_USCALED_ANGLEX
#define GL_X2_RGB10_SSCALED_ANGLEX
#define GL_X2_RGB10_UNORM_ANGLEX
#define GL_X2_RGB10_SNORM_ANGLEX

#define ANGLE_CHECK_GL_ALLOC(context, result)

#define ANGLE_CHECK_GL_MATH(context, result)

#define ANGLE_GL_UNREACHABLE(context)

#if defined(ANGLE_WITH_LSAN)
#define ANGLE_SCOPED_DISABLE_LSAN
#else
#define ANGLE_SCOPED_DISABLE_LSAN()
#endif

#if defined(ANGLE_WITH_MSAN)
class MsanScopedDisableInterceptorChecks final : angle::NonCopyable
{
  public:
    MsanScopedDisableInterceptorChecks() { __msan_scoped_disable_interceptor_checks(); }
    ~MsanScopedDisableInterceptorChecks() { __msan_scoped_enable_interceptor_checks(); }
};
#define ANGLE_SCOPED_DISABLE_MSAN
#else
#define ANGLE_SCOPED_DISABLE_MSAN()
#endif

// The ANGLE_NO_SANITIZE_MEMORY macro suppresses MemorySanitizer checks for
// use-of-uninitialized-data. It can be used to decorate functions with known
// false positives.
#ifdef __clang__
#define ANGLE_NO_SANITIZE_MEMORY
#else
#define ANGLE_NO_SANITIZE_MEMORY
#endif

// Similar to the above, but for thread sanitization.
#ifdef __clang__
#define ANGLE_NO_SANITIZE_THREAD
#else
#define ANGLE_NO_SANITIZE_THREAD
#endif

// Similar to the above, but for cfi-icall.
#ifdef __clang__
#define ANGLE_NO_SANITIZE_CFI_ICALL
#else
#define ANGLE_NO_SANITIZE_CFI_ICALL
#endif

// The below inlining code lifted from V8.
#if defined(__clang__) || (defined(__GNUC__) && defined(__has_attribute))
#define ANGLE_HAS_ATTRIBUTE_ALWAYS_INLINE
#define ANGLE_HAS___FORCEINLINE
#elif defined(_MSC_VER)
#define ANGLE_HAS_ATTRIBUTE_ALWAYS_INLINE
#define ANGLE_HAS___FORCEINLINE
#else
#define ANGLE_HAS_ATTRIBUTE_ALWAYS_INLINE
#define ANGLE_HAS___FORCEINLINE
#endif

#if defined(NDEBUG) && ANGLE_HAS_ATTRIBUTE_ALWAYS_INLINE
#define ANGLE_INLINE
#elif defined(NDEBUG) && ANGLE_HAS___FORCEINLINE
#define ANGLE_INLINE
#else
#define ANGLE_INLINE
#endif

#if defined(__clang__) || (defined(__GNUC__) && defined(__has_attribute))
#    if __has_attribute(noinline)
#define ANGLE_NOINLINE
#    else
#define ANGLE_NOINLINE
#    endif
#elif defined(_MSC_VER)
#define ANGLE_NOINLINE
#else
#define ANGLE_NOINLINE
#endif

#if defined(__clang__) || (defined(__GNUC__) && defined(__has_attribute))
#    if __has_attribute(format)
#define ANGLE_FORMAT_PRINTF(fmt, args)
#    else
#define ANGLE_FORMAT_PRINTF
#    endif
#else
#define ANGLE_FORMAT_PRINTF
#endif

#if defined(__clang__) || (defined(__GNUC__) && defined(__has_attribute))
#define ANGLE_HAS_ATTRIBUTE_CONSTRUCTOR
#define ANGLE_HAS_ATTRIBUTE_DESTRUCTOR
#else
#define ANGLE_HAS_ATTRIBUTE_CONSTRUCTOR
#define ANGLE_HAS_ATTRIBUTE_DESTRUCTOR
#endif

#if ANGLE_HAS_ATTRIBUTE_CONSTRUCTOR
#define ANGLE_CONSTRUCTOR
#endif

#if ANGLE_HAS_ATTRIBUTE_DESTRUCTOR
#define ANGLE_DESTRUCTOR
#endif

ANGLE_FORMAT_PRINTF(1, 0)
size_t FormatStringIntoVector(const char *fmt, va_list vararg, std::vector<char> &buffer);

// Format messes up the # inside the macro.
// clang-format off
#ifndef ANGLE_STRINGIFY
#define ANGLE_STRINGIFY(x)
#endif
// clang-format on

#ifndef ANGLE_MACRO_STRINGIFY
#define ANGLE_MACRO_STRINGIFY(x)
#endif

// The ANGLE_MAYBE_UNUSED_PRIVATE_FIELD can be used to hint 'unused private field'
// instead of 'maybe_unused' attribute for the compatibility with GCC because
// GCC doesn't have '-Wno-unused-private-field' whereas Clang has.
#if defined(__clang__) || defined(_MSC_VER)
#define ANGLE_MAYBE_UNUSED_PRIVATE_FIELD
#else
#define ANGLE_MAYBE_UNUSED_PRIVATE_FIELD
#endif

#if __has_cpp_attribute(clang::require_constant_initialization)
#define ANGLE_REQUIRE_CONSTANT_INIT
#else
#define ANGLE_REQUIRE_CONSTANT_INIT
#endif  // __has_cpp_attribute(require_constant_initialization)

// Compiler configs.
inline bool IsASan()
{}

inline bool IsMSan()
{}

inline bool IsTSan()
{}

inline bool IsUBSan()
{}
#endif  // COMMON_ANGLEUTILS_H_