2
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
3
// Use of this source code is governed by a BSD-style license that can be
4
// found in the LICENSE file.
7
// These helpers are used in GL/GLES entry point routines.
9
#ifndef LIBANGLE_ENTRY_POINT_UTILS_H_
10
#define LIBANGLE_ENTRY_POINT_UTILS_H_
13
#include "common/Optional.h"
14
#include "common/PackedEnums.h"
15
#include "common/angleutils.h"
16
#include "common/mathutil.h"
17
#include "libANGLE/Display.h"
18
#include "libANGLE/entry_points_enum_autogen.h"
22
// A template struct for determining the default value to return for each entry point.
23
template <EntryPoint EP, typename ReturnType>
24
struct DefaultReturnValue;
26
// Default return values for each basic return type.
27
template <EntryPoint EP>
28
struct DefaultReturnValue<EP, GLint>
30
static constexpr GLint kValue = -1;
33
// This doubles as the GLenum return value.
34
template <EntryPoint EP>
35
struct DefaultReturnValue<EP, GLuint>
37
static constexpr GLuint kValue = 0;
40
template <EntryPoint EP>
41
struct DefaultReturnValue<EP, GLboolean>
43
static constexpr GLboolean kValue = GL_FALSE;
46
template <EntryPoint EP>
47
struct DefaultReturnValue<EP, ShaderProgramID>
49
static constexpr ShaderProgramID kValue = {0};
52
// Catch-all rules for pointer types.
53
template <EntryPoint EP, typename PointerType>
54
struct DefaultReturnValue<EP, const PointerType *>
56
static constexpr const PointerType *kValue = nullptr;
59
template <EntryPoint EP, typename PointerType>
60
struct DefaultReturnValue<EP, PointerType *>
62
static constexpr PointerType *kValue = nullptr;
65
// Overloaded to return invalid index
67
struct DefaultReturnValue<EntryPoint::GetUniformBlockIndex, GLuint>
69
static constexpr GLuint kValue = GL_INVALID_INDEX;
72
// Specialized enum error value.
74
struct DefaultReturnValue<EntryPoint::ClientWaitSync, GLenum>
76
static constexpr GLenum kValue = GL_WAIT_FAILED;
79
// glTestFenceNV should still return TRUE for an invalid fence.
81
struct DefaultReturnValue<EntryPoint::TestFenceNV, GLboolean>
83
static constexpr GLboolean kValue = GL_TRUE;
86
template <EntryPoint EP, typename ReturnType>
87
constexpr ANGLE_INLINE ReturnType GetDefaultReturnValue()
89
return DefaultReturnValue<EP, ReturnType>::kValue;
92
#if ANGLE_CAPTURE_ENABLED
93
# define ANGLE_CAPTURE(Func, ...) CaptureCallToFrameCapture(Capture##Func, __VA_ARGS__)
95
# define ANGLE_CAPTURE(...)
96
#endif // ANGLE_CAPTURE_ENABLED
98
#define FUNC_EVENT(format, ...) EVENT(__FUNCTION__, format, __VA_ARGS__)
100
inline int CID(const Context *context)
102
return context != nullptr ? context->id() : 0;
108
inline int CID(EGLDisplay display, EGLContext context)
110
auto *displayPtr = reinterpret_cast<const egl::Display *>(display);
111
if (!Display::isValidDisplay(displayPtr))
115
auto *contextPtr = reinterpret_cast<const gl::Context *>(context);
116
if (!displayPtr->isValidContext(contextPtr))
120
return gl::CID(contextPtr);
124
#endif // LIBANGLE_ENTRY_POINT_UTILS_H_