• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
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.
5 //
6 // entry_point_utils:
7 //   These helpers are used in GL/GLES entry point routines.
8 
9 #ifndef LIBANGLE_ENTRY_POINT_UTILS_H_
10 #define LIBANGLE_ENTRY_POINT_UTILS_H_
11 
12 #include "angle_gl.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"
19 
20 namespace gl
21 {
22 // A template struct for determining the default value to return for each entry point.
23 template <EntryPoint EP, typename ReturnType>
24 struct DefaultReturnValue;
25 
26 // Default return values for each basic return type.
27 template <EntryPoint EP>
28 struct DefaultReturnValue<EP, GLint>
29 {
30     static constexpr GLint kValue = -1;
31 };
32 
33 // This doubles as the GLenum return value.
34 template <EntryPoint EP>
35 struct DefaultReturnValue<EP, GLuint>
36 {
37     static constexpr GLuint kValue = 0;
38 };
39 
40 template <EntryPoint EP>
41 struct DefaultReturnValue<EP, GLboolean>
42 {
43     static constexpr GLboolean kValue = GL_FALSE;
44 };
45 
46 template <EntryPoint EP>
47 struct DefaultReturnValue<EP, ShaderProgramID>
48 {
49     static constexpr ShaderProgramID kValue = {0};
50 };
51 
52 // Catch-all rules for pointer types.
53 template <EntryPoint EP, typename PointerType>
54 struct DefaultReturnValue<EP, const PointerType *>
55 {
56     static constexpr const PointerType *kValue = nullptr;
57 };
58 
59 template <EntryPoint EP, typename PointerType>
60 struct DefaultReturnValue<EP, PointerType *>
61 {
62     static constexpr PointerType *kValue = nullptr;
63 };
64 
65 // Overloaded to return invalid index
66 template <>
67 struct DefaultReturnValue<EntryPoint::GetUniformBlockIndex, GLuint>
68 {
69     static constexpr GLuint kValue = GL_INVALID_INDEX;
70 };
71 
72 // Specialized enum error value.
73 template <>
74 struct DefaultReturnValue<EntryPoint::ClientWaitSync, GLenum>
75 {
76     static constexpr GLenum kValue = GL_WAIT_FAILED;
77 };
78 
79 // glTestFenceNV should still return TRUE for an invalid fence.
80 template <>
81 struct DefaultReturnValue<EntryPoint::TestFenceNV, GLboolean>
82 {
83     static constexpr GLboolean kValue = GL_TRUE;
84 };
85 
86 template <EntryPoint EP, typename ReturnType>
87 constexpr ANGLE_INLINE ReturnType GetDefaultReturnValue()
88 {
89     return DefaultReturnValue<EP, ReturnType>::kValue;
90 }
91 
92 #if ANGLE_CAPTURE_ENABLED
93 #    define ANGLE_CAPTURE(Func, ...) CaptureCallToFrameCapture(Capture##Func, __VA_ARGS__)
94 #else
95 #    define ANGLE_CAPTURE(...)
96 #endif  // ANGLE_CAPTURE_ENABLED
97 
98 #define FUNC_EVENT(format, ...) EVENT(__FUNCTION__, format, __VA_ARGS__)
99 
100 inline int CID(const Context *context)
101 {
102     return context != nullptr ? static_cast<int>(context->id()) : 0;
103 }
104 }  // namespace gl
105 
106 namespace egl
107 {
108 inline int CID(EGLDisplay display, EGLContext context)
109 {
110     auto *displayPtr = reinterpret_cast<const egl::Display *>(display);
111     if (!Display::isValidDisplay(displayPtr))
112     {
113         return -1;
114     }
115     auto *contextPtr = reinterpret_cast<const gl::Context *>(context);
116     if (!displayPtr->isValidContext(contextPtr))
117     {
118         return -1;
119     }
120     return gl::CID(contextPtr);
121 }
122 }  // namespace egl
123 
124 #endif  // LIBANGLE_ENTRY_POINT_UTILS_H_
125