Hash :
7ce42b42
Author :
Date :
2024-05-30T16:08:12
Skip Display::prepareForCall calls everywhere except Mac. Display::prepareForCall was added for CGL and EAGL backends which need to know when an EGL call on a new thread is about to happen. Making this virtual call on all EGL calls on all platforms adds overhead which we can avoid so compile out prepareForCall everywhere except Mac. Bug: angleproject:8434 Change-Id: I7b50463ed405a73eb993e18eb4f83434b4a4fd6e Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5582015 Commit-Queue: Geoff Lang <geofflang@chromium.org> Auto-Submit: Geoff Lang <geofflang@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
//
// Copyright 2015 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.
//
// validationEGL.h: Validation functions for generic EGL entry point parameters
#ifndef LIBANGLE_VALIDATIONEGL_H_
#define LIBANGLE_VALIDATIONEGL_H_
#include "common/PackedEnums.h"
#include "libANGLE/Display.h"
#include "libANGLE/Error.h"
#include "libANGLE/Thread.h"
#include <EGL/egl.h>
#include <EGL/eglext.h>
namespace gl
{
class Context;
}
namespace egl
{
constexpr EGLint kEglMajorVersion = 1;
constexpr EGLint kEglMinorVersion = 5;
class AttributeMap;
struct ClientExtensions;
struct Config;
class Device;
class Display;
class Image;
class Stream;
class Surface;
class Sync;
class Thread;
class LabeledObject;
struct ValidationContext
{
ValidationContext(Thread *threadIn, const char *entryPointIn, const LabeledObject *objectIn)
: eglThread(threadIn), entryPoint(entryPointIn), labeledObject(objectIn)
{}
// We should remove the message-less overload once we have messages for all EGL errors.
void setError(EGLint error) const;
ANGLE_FORMAT_PRINTF(3, 4)
void setError(EGLint error, const char *message...) const;
Thread *eglThread;
const char *entryPoint;
const LabeledObject *labeledObject;
};
// Object validation
bool ValidateDisplay(const ValidationContext *val, const Display *display);
bool ValidateSurface(const ValidationContext *val, const Display *display, SurfaceID surfaceID);
bool ValidateConfig(const ValidationContext *val, const Display *display, const Config *config);
bool ValidateContext(const ValidationContext *val, const Display *display, gl::ContextID contextID);
bool ValidateImage(const ValidationContext *val, const Display *display, ImageID imageID);
bool ValidateDevice(const ValidationContext *val, const Device *device);
bool ValidateSync(const ValidationContext *val, const Display *display, SyncID sync);
// Return the requested object only if it is valid (otherwise nullptr)
const Thread *GetThreadIfValid(const Thread *thread);
const Display *GetDisplayIfValid(const Display *display);
const Surface *GetSurfaceIfValid(const Display *display, SurfaceID surfaceID);
const Image *GetImageIfValid(const Display *display, ImageID imageID);
const Stream *GetStreamIfValid(const Display *display, const Stream *stream);
const gl::Context *GetContextIfValid(const Display *display, gl::ContextID contextID);
gl::Context *GetContextIfValid(Display *display, gl::ContextID contextID);
const Device *GetDeviceIfValid(const Device *device);
const Sync *GetSyncIfValid(const Display *display, SyncID sync);
const LabeledObject *GetLabeledObjectIfValid(Thread *thread,
const Display *display,
ObjectType objectType,
EGLObjectKHR object);
LabeledObject *GetLabeledObjectIfValid(Thread *thread,
Display *display,
ObjectType objectType,
EGLObjectKHR object);
// A template struct for determining the default value to return for each entry point.
template <angle::EntryPoint EP, typename ReturnType>
struct DefaultReturnValue
{
static constexpr ReturnType kValue = static_cast<ReturnType>(0);
};
template <angle::EntryPoint EP, typename ReturnType>
ReturnType GetDefaultReturnValue(Thread *thread);
template <>
ANGLE_INLINE EGLint
GetDefaultReturnValue<angle::EntryPoint::EGLLabelObjectKHR, EGLint>(Thread *thread)
{
return thread->getError();
}
template <angle::EntryPoint EP, typename ReturnType>
ANGLE_INLINE ReturnType GetDefaultReturnValue(Thread *thread)
{
return DefaultReturnValue<EP, ReturnType>::kValue;
}
// First case: handling packed enums.
template <typename PackedT, typename FromT>
typename std::enable_if<std::is_enum<PackedT>::value, PackedT>::type PackParam(FromT from)
{
return FromEGLenum<PackedT>(from);
}
// Second case: handling resource ids.
template <typename PackedT,
typename FromT,
typename std::enable_if<IsResourceIDType<PackedT>::value>::type * = nullptr>
PackedT PackParam(FromT from)
{
return {static_cast<GLuint>(reinterpret_cast<uintptr_t>(from))};
}
// This and the next 2 template specializations handle distinguishing between EGLint, EGLAttrib
// and other. This is needed because on some architectures EGLint and EGLAttrib are not the same
// base type. Previously the code conditionally compiled 2 specializations on 64 bit but it turns
// out on WatchOS the assumption about 32/64 bit and if EGLint and ELGAttrib are the same or
// different did not hold.
template <typename PackedT,
typename FromT,
typename std::enable_if<!std::is_enum<PackedT>::value>::type * = nullptr,
typename std::enable_if<std::is_same<FromT, const EGLint *>::value>::type * = nullptr>
typename std::remove_reference<PackedT>::type PackParam(FromT attribs)
{
return AttributeMap::CreateFromIntArray(attribs);
}
template <typename PackedT,
typename FromT,
typename std::enable_if<!std::is_enum<PackedT>::value>::type * = nullptr,
typename std::enable_if<!std::is_same<FromT, const EGLint *>::value>::type * = nullptr,
typename std::enable_if<std::is_same<FromT, const EGLAttrib *>::value>::type * = nullptr>
typename std::remove_reference<PackedT>::type PackParam(FromT attribs)
{
return AttributeMap::CreateFromAttribArray(attribs);
}
template <typename PackedT,
typename FromT,
typename std::enable_if<!std::is_enum<PackedT>::value>::type * = nullptr,
typename std::enable_if<!std::is_same<FromT, const EGLint *>::value>::type * = nullptr,
typename std::enable_if<!std::is_same<FromT, const EGLAttrib *>::value>::type * = nullptr,
typename std::enable_if<!IsResourceIDType<PackedT>::value>::type * = nullptr>
typename std::remove_reference<PackedT>::type PackParam(FromT from)
{
return static_cast<PackedT>(from);
}
} // namespace egl
#define ANGLE_EGL_VALIDATE(THREAD, EP, OBJ, RETURN_TYPE, ...) \
do \
{ \
const char *epname = "egl" #EP; \
ValidationContext vctx(THREAD, epname, OBJ); \
auto ANGLE_LOCAL_VAR = (Validate##EP(&vctx, ##__VA_ARGS__)); \
if (!ANGLE_LOCAL_VAR) \
{ \
return GetDefaultReturnValue<angle::EntryPoint::EGL##EP, RETURN_TYPE>(THREAD); \
} \
} while (0)
#define ANGLE_EGL_VALIDATE_VOID(THREAD, EP, OBJ, ...) \
do \
{ \
const char *epname = "egl" #EP; \
ValidationContext vctx(THREAD, epname, OBJ); \
auto ANGLE_LOCAL_VAR = (Validate##EP(&vctx, ##__VA_ARGS__)); \
if (!ANGLE_LOCAL_VAR) \
{ \
return; \
} \
} while (0)
#define ANGLE_EGL_TRY(THREAD, EXPR, FUNCNAME, LABELOBJECT) \
do \
{ \
auto ANGLE_LOCAL_VAR = (EXPR); \
if (ANGLE_LOCAL_VAR.isError()) \
return THREAD->setError(ANGLE_LOCAL_VAR, FUNCNAME, LABELOBJECT); \
} while (0)
#define ANGLE_EGL_TRY_RETURN(THREAD, EXPR, FUNCNAME, LABELOBJECT, RETVAL) \
do \
{ \
auto ANGLE_LOCAL_VAR = (EXPR); \
if (ANGLE_LOCAL_VAR.isError()) \
{ \
THREAD->setError(ANGLE_LOCAL_VAR, FUNCNAME, LABELOBJECT); \
return RETVAL; \
} \
} while (0)
#if ANGLE_USE_DISPLAY_PREPARE_FOR_CALL
# define ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN ANGLE_EGL_TRY_RETURN
# define ANGLE_EGL_TRY_PREPARE_FOR_CALL ANGLE_EGL_TRY
#else
# define ANGLE_EGL_TRY_PREPARE_FOR_CALL_RETURN(...)
# define ANGLE_EGL_TRY_PREPARE_FOR_CALL(...)
#endif
#define ANGLE_EGLBOOLEAN_TRY(EXPR) \
do \
{ \
EGLBoolean ANGLE_LOCAL_VAR = (EXPR); \
if (ANGLE_LOCAL_VAR != EGL_TRUE) \
{ \
return ANGLE_LOCAL_VAR; \
} \
} while (0)
#endif // LIBANGLE_VALIDATIONEGL_H_