tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

entry_points_utils.h (3469B)


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