Hash :
e53efb18
Author :
Date :
2020-11-03T16:22:19
Allow choosing EAGL or CGL at runtime
Dean Jackson made this change downstream in WebKit:
https://bugs.webkit.org/show_bug.cgi?id=216722
Change ANGLE to dynamically load either EAGL (OpenGLES) or CGL (OpenGL)
depending on both compile and runtime configurations.
Intel Mac -> CGL
Intel Mac Catalyst -> CGL
Intel iOS Simulator -> EAGL
iOS Device -> EAGL
Apple Silicon Mac -> CGL
Apple Silicon Mac Catalyst (with Mac app) -> CGL
Apple Silicon Mac Catalyst (with iOS app) -> EAGL
The trickiest bit is Apple Silicon Mac Catalyst, which depends on the
type of the application it is attempting to run. In that case ANGLE must
compile both the CGL and EAGL interfaces and then pick one to use after
launch.
Bug: angleproject:5253
Change-Id: Iba167b3cc3105e457dcfc9bc14147d0fc3e70bac
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2500185
Commit-Queue: James Darpinian <jdarpinian@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Kenneth Russell <kbr@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
//
// Copyright 2020 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.
//
// SoftLinking.h: Macros for soft-linking Frameworks and Functions.
#ifndef SOFT_LINKING_APPLE_H_
#define SOFT_LINKING_APPLE_H_
#include "common/platform.h"
#if defined(ANGLE_PLATFORM_APPLE)
# include "common/debug.h"
# import <dispatch/dispatch.h>
# import <dlfcn.h>
# import <objc/runtime.h>
# define RELEASE_ASSERT(expression, message) \
(expression \
? static_cast<void>(0) \
: (FATAL() << "\t! Assert failed in " << __FUNCTION__ << " (" << __FILE__ << ":" \
<< __LINE__ << "): " << #expression << "\n\t! Message: " << message))
# ifdef __cplusplus
# define EXTERN_C_BEGIN extern "C" {
# define EXTERN_C_END }
# else
# define EXTERN_C_BEGIN
# define EXTERN_C_END
# endif
# define SOFT_LINK_FRAMEWORK_HEADER(framework) extern void *framework##Library();
# define SOFT_LINK_FRAMEWORK_SOURCE(framework) \
void *framework##Library() \
{ \
static dispatch_once_t once = 0; \
static void *frameworkLibrary = NULL; \
dispatch_once(&once, ^{ \
frameworkLibrary = dlopen( \
"/System/Library/Frameworks/" #framework ".framework/" #framework, RTLD_NOW); \
RELEASE_ASSERT(frameworkLibrary, "Unable to load " #framework ".framework"); \
}); \
return frameworkLibrary; \
}
# define SOFT_LINK_FUNCTION_HEADER(framework, functionName, resultType, parameterDeclarations, \
parameterNames) \
EXTERN_C_BEGIN \
resultType functionName parameterDeclarations; \
EXTERN_C_END \
extern resultType init##framework##functionName parameterDeclarations; \
extern resultType(*softLink##framework##functionName) parameterDeclarations; \
inline __attribute__((__always_inline__)) resultType functionName parameterDeclarations \
{ \
return softLink##framework##functionName parameterNames; \
}
# define SOFT_LINK_FUNCTION_SOURCE(framework, functionName, resultType, parameterDeclarations, \
parameterNames) \
resultType(*softLink##framework##functionName) parameterDeclarations = \
init##framework##functionName; \
resultType init##framework##functionName parameterDeclarations \
{ \
static dispatch_once_t once; \
dispatch_once(&once, ^{ \
softLink##framework##functionName = \
(resultType(*) parameterDeclarations)dlsym(framework##Library(), #functionName); \
}); \
return softLink##framework##functionName parameterNames; \
}
# define SOFT_LINK_CLASS_HEADER(className) \
@class className; \
extern Class (*get##className##Class)(); \
className *alloc##className##Instance(); \
inline className *alloc##className##Instance() { return [get##className##Class() alloc]; }
# define SOFT_LINK_CLASS(framework, className) \
@class className; \
static Class init##className(); \
Class (*get##className##Class)() = init##className; \
static Class class##className; \
\
static Class className##Function() { return class##className; } \
\
static Class init##className() \
{ \
static dispatch_once_t once; \
dispatch_once(&once, ^{ \
framework##Library(); \
class##className = objc_getClass(#className); \
RELEASE_ASSERT(class##className, "objc_getClass failed for " #className); \
get##className##Class = className##Function; \
}); \
return class##className; \
} \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wunused-function\"") static className \
*alloc##className##Instance() \
{ \
return [get##className##Class() alloc]; \
} \
_Pragma("clang diagnostic pop")
#endif // defined(ANGLE_PLATFORM_APPLE)
#endif // SOFT_LINKING_APPLE_H_