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

// Copyright 2017 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.
//
// PackedGLEnums_autogen.h:
//   Declares ANGLE-specific enums classes for GLEnum and functions operating
//   on them.

#ifndef COMMON_PACKEDGLENUMS_H_
#define COMMON_PACKEDGLENUMS_H_

#include "common/PackedEGLEnums_autogen.h"
#include "common/PackedGLEnums_autogen.h"

#include <array>
#include <bitset>
#include <cstddef>

#include <EGL/egl.h>

#include "common/bitset_utils.h"

namespace angle
{

// Return the number of elements of a packed enum, including the InvalidEnum element.
template <typename E>
constexpr size_t EnumSize()
{}

// Implementation of AllEnums which allows iterating over all the possible values for a packed enums
// like so:
//     for (auto value : AllEnums<MyPackedEnum>()) {
//         // Do something with the enum.
//     }

template <typename E>
class EnumIterator final
{};

template <typename E, size_t MaxSize = EnumSize<E>()>
struct AllEnums
{};

// PackedEnumMap<E, T> is like an std::array<T, E::EnumCount> but is indexed with enum values. It
// implements all of the std::array interface except with enum values instead of indices.
template <typename E, typename T, size_t MaxSize = EnumSize<E>()>
class PackedEnumMap
{};

// PackedEnumBitSetE> is like an std::bitset<E::EnumCount> but is indexed with enum values. It
// implements the std::bitset interface except with enum values instead of indices.
PackedEnumBitSet;

}  // namespace angle

#define ANGLE_DEFINE_ID_TYPE

gl  // namespace gl

egl  // namespace egl

#undef ANGLE_DEFINE_ID_TYPE

namespace egl_gl
{
gl::TextureTarget EGLCubeMapTargetToCubeMapTarget(EGLenum eglTarget);
gl::TextureTarget EGLImageTargetToTextureTarget(EGLenum eglTarget);
gl::TextureType EGLTextureTargetToTextureType(EGLenum eglTarget);
}  // namespace egl_gl

namespace gl
{
// First case: handling packed enums.
template <typename EnumT, typename FromT>
typename std::enable_if<std::is_enum<EnumT>::value, EnumT>::type PackParam(FromT from)
{}

// Second case: handling non-pointer resource ids.
template <typename EnumT, typename FromT>
typename std::enable_if<!std::is_pointer<FromT>::value && !std::is_enum<EnumT>::value, EnumT>::type
PackParam(FromT from)
{}

IsEGLImage;

IsGLSync;

IsEGLSync;

// Third case: handling EGLImage, GLSync and EGLSync pointer resource ids.
template <typename EnumT, typename FromT>
typename std::enable_if<IsEGLImage<EnumT>::value || IsGLSync<EnumT>::value ||
                            IsEGLSync<EnumT>::value,
                        EnumT>::type
PackParam(FromT from)
{}

// Fourth case: handling non-EGLImage non-GLsync resource ids.
template <typename EnumT, typename FromT>
typename std::enable_if<std::is_pointer<FromT>::value && !std::is_enum<EnumT>::value &&
                            !IsEGLImage<EnumT>::value && !IsGLSync<EnumT>::value,
                        EnumT>::type
PackParam(FromT from)
{}
}  // namespace gl

#endif  // COMMON_PACKEDGLENUMS_H_