Commit e53efb18 by James Darpinian Committed by Commit Bot

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: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org>
parent fbaae6ce
......@@ -194,6 +194,7 @@ IGNORED_INCLUDES = {
b'libANGLE/renderer/d3d/DeviceD3D.h',
b'libANGLE/renderer/d3d/DisplayD3D.h',
b'libANGLE/renderer/d3d/RenderTargetD3D.h',
b'libANGLE/renderer/gl/apple/DisplayApple_api.h',
b'libANGLE/renderer/gl/cgl/DisplayCGL.h',
b'libANGLE/renderer/gl/eagl/DisplayEAGL.h',
b'libANGLE/renderer/gl/egl/android/DisplayAndroid.h',
......
//
// 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_
//
// 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.
//
// FunctionsCGL.cpp: Exposing the soft-linked CGL interface.
#include "common/gl/cgl/FunctionsCGL.h"
#include "common/platform.h"
#if defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST)
SOFT_LINK_FRAMEWORK_SOURCE(OpenGL)
SOFT_LINK_FUNCTION_SOURCE(OpenGL,
CGLChoosePixelFormat,
CGLError,
(const CGLPixelFormatAttribute *attribs,
CGLPixelFormatObj *pix,
GLint *npix),
(attribs, pix, npix))
SOFT_LINK_FUNCTION_SOURCE(OpenGL,
CGLCreateContext,
CGLError,
(CGLPixelFormatObj pix, CGLContextObj share, CGLContextObj *ctx),
(pix, share, ctx))
SOFT_LINK_FUNCTION_SOURCE(
OpenGL,
CGLDescribePixelFormat,
CGLError,
(CGLPixelFormatObj pix, GLint pix_num, CGLPixelFormatAttribute attrib, GLint *value),
(pix, pix_num, attrib, value))
SOFT_LINK_FUNCTION_SOURCE(OpenGL, CGLDestroyContext, CGLError, (CGLContextObj ctx), (ctx))
SOFT_LINK_FUNCTION_SOURCE(OpenGL, CGLDestroyPixelFormat, CGLError, (CGLPixelFormatObj pix), (pix))
SOFT_LINK_FUNCTION_SOURCE(OpenGL, CGLErrorString, const char *, (CGLError error), (error))
SOFT_LINK_FUNCTION_SOURCE(OpenGL, CGLReleaseContext, void, (CGLContextObj ctx), (ctx))
SOFT_LINK_FUNCTION_SOURCE(OpenGL, CGLSetCurrentContext, CGLError, (CGLContextObj ctx), (ctx))
SOFT_LINK_FUNCTION_SOURCE(OpenGL,
CGLSetVirtualScreen,
CGLError,
(CGLContextObj ctx, GLint screen),
(ctx, screen))
SOFT_LINK_FUNCTION_SOURCE(
OpenGL,
CGLTexImageIOSurface2D,
CGLError,
(CGLContextObj ctx,
GLenum target,
GLenum internal_format,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
IOSurfaceRef ioSurface,
GLuint plane),
(ctx, target, internal_format, width, height, format, type, ioSurface, plane))
SOFT_LINK_FUNCTION_SOURCE(OpenGL, CGLUpdateContext, CGLError, (CGLContextObj ctx), (ctx))
SOFT_LINK_FUNCTION_SOURCE(
OpenGL,
CGLDescribeRenderer,
CGLError,
(CGLRendererInfoObj rend, GLint rend_num, CGLRendererProperty prop, GLint *value),
(rend, rend_num, prop, value))
SOFT_LINK_FUNCTION_SOURCE(OpenGL,
CGLDestroyRendererInfo,
CGLError,
(CGLRendererInfoObj rend),
(rend))
SOFT_LINK_FUNCTION_SOURCE(OpenGL,
CGLQueryRendererInfo,
CGLError,
(GLuint display_mask, CGLRendererInfoObj *rend, GLint *nrend),
(display_mask, rend, nrend))
#endif // defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST)
//
// 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.
//
// CGLFunctions.h: Exposing the soft-linked CGL interface.
#ifndef CGL_FUNCTIONS_H_
#define CGL_FUNCTIONS_H_
#include "common/platform.h"
#if defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST)
# include <OpenGL/OpenGL.h>
# include "common/apple/SoftLinking.h"
SOFT_LINK_FRAMEWORK_HEADER(OpenGL)
SOFT_LINK_FUNCTION_HEADER(OpenGL,
CGLChoosePixelFormat,
CGLError,
(const CGLPixelFormatAttribute *attribs,
CGLPixelFormatObj *pix,
GLint *npix),
(attribs, pix, npix))
SOFT_LINK_FUNCTION_HEADER(OpenGL,
CGLCreateContext,
CGLError,
(CGLPixelFormatObj pix, CGLContextObj share, CGLContextObj *ctx),
(pix, share, ctx))
SOFT_LINK_FUNCTION_HEADER(
OpenGL,
CGLDescribePixelFormat,
CGLError,
(CGLPixelFormatObj pix, GLint pix_num, CGLPixelFormatAttribute attrib, GLint *value),
(pix, pix_num, attrib, value))
SOFT_LINK_FUNCTION_HEADER(
OpenGL,
CGLDescribeRenderer,
CGLError,
(CGLRendererInfoObj rend, GLint rend_num, CGLRendererProperty prop, GLint *value),
(rend, rend_num, prop, value))
SOFT_LINK_FUNCTION_HEADER(OpenGL, CGLDestroyContext, CGLError, (CGLContextObj ctx), (ctx))
SOFT_LINK_FUNCTION_HEADER(OpenGL, CGLDestroyPixelFormat, CGLError, (CGLPixelFormatObj pix), (pix))
SOFT_LINK_FUNCTION_HEADER(OpenGL,
CGLDestroyRendererInfo,
CGLError,
(CGLRendererInfoObj rend),
(rend))
SOFT_LINK_FUNCTION_HEADER(OpenGL, CGLErrorString, const char *, (CGLError error), (error))
SOFT_LINK_FUNCTION_HEADER(OpenGL,
CGLQueryRendererInfo,
CGLError,
(GLuint display_mask, CGLRendererInfoObj *rend, GLint *nrend),
(display_mask, rend, nrend))
SOFT_LINK_FUNCTION_HEADER(OpenGL, CGLReleaseContext, void, (CGLContextObj ctx), (ctx))
SOFT_LINK_FUNCTION_HEADER(OpenGL, CGLSetCurrentContext, CGLError, (CGLContextObj ctx), (ctx))
SOFT_LINK_FUNCTION_HEADER(OpenGL,
CGLSetVirtualScreen,
CGLError,
(CGLContextObj ctx, GLint screen),
(ctx, screen))
SOFT_LINK_FUNCTION_HEADER(
OpenGL,
CGLTexImageIOSurface2D,
CGLError,
(CGLContextObj ctx,
GLenum target,
GLenum internal_format,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
IOSurfaceRef ioSurface,
GLuint plane),
(ctx, target, internal_format, width, height, format, type, ioSurface, plane))
SOFT_LINK_FUNCTION_HEADER(OpenGL, CGLUpdateContext, CGLError, (CGLContextObj ctx), (ctx))
#endif // defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST)
#endif // CGL_FUNCTIONS_H_
......@@ -120,14 +120,23 @@
# define ANGLE_PLATFORM_MACOS 1
# elif TARGET_OS_IPHONE
# define ANGLE_PLATFORM_IOS 1
# define GLES_SILENCE_DEPRECATION
# if TARGET_OS_SIMULATOR
# define ANGLE_PLATFORM_IOS_SIMULATOR 1
# endif
# if TARGET_OS_MACCATALYST
# define ANGLE_PLATFORM_MACCATALYST
# define ANGLE_PLATFORM_MACCATALYST 1
# endif
# endif
# // This might be useful globally. At the moment it is used
# // to differentiate MacCatalyst on Intel and Apple Silicon.
# if defined(__arm64__) || defined(__aarch64__)
# define ANGLE_CPU_ARM64 1
# endif
// EAGL should be enabled on iOS, but not Mac Catalyst unless it is running on Apple Silicon.
# if (defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)) || \
(defined(ANGLE_PLATFORM_MACCATALYST) && defined(ANGLE_CPU_ARM64))
# define ANGLE_ENABLE_EAGL
# endif
#endif
// Define ANGLE_WITH_ASAN macro.
......
......@@ -67,6 +67,9 @@ struct SystemInfo
bool isAMDSwitchable = false;
// Only true on dual-GPU Mac laptops.
bool isMacSwitchable = false;
// Only true on Apple Silicon Macs when running iOS binaries.
// See https://developer.apple.com/documentation/foundation/nsprocessinfo/3608556-iosapponmac
bool isiOSAppOnMac = false;
// Only available on Android
std::string machineManufacturer;
......
//
// 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.
//
// SystemInfo_apple.cpp: implementation of the Apple-specific parts of SystemInfo.h
#import "common/platform.h"
#if defined(ANGLE_PLATFORM_APPLE)
# import <Foundation/Foundation.h>
# import <dispatch/dispatch.h>
# import "gpu_info_util/SystemInfo_internal.h"
namespace angle
{
bool GetSystemInfo(SystemInfo *info)
{
# if defined(ANGLE_PLATFORM_MACCATALYST) && defined(ANGLE_CPU_ARM64)
static bool isiOSAppOnMac = false;
static dispatch_once_t once;
dispatch_once(&once, ^{
isiOSAppOnMac = [[NSProcessInfo processInfo] isiOSAppOnMac];
});
if (isiOSAppOnMac)
{
GetSystemInfo_ios(info);
if (info)
{
info->isiOSAppOnMac = true;
}
return info;
}
return GetSystemInfo_mac(info);
# elif defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST)
return GetSystemInfo_mac(info);
# else
return GetSystemInfo_ios(info);
# endif
}
} // namespace angle
#endif // defined(ANGLE_PLATFORM_APPLE)
......@@ -29,6 +29,14 @@ bool ParseMacMachineModel(const std::string &identifier,
int32_t *minor);
bool CMDeviceIDToDeviceAndVendorID(const std::string &id, uint32_t *vendorId, uint32_t *deviceId);
#if defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST)
bool GetSystemInfo_mac(SystemInfo *info);
#endif
#if defined(ANGLE_PLATFORM_IOS) || (defined(ANGLE_PLATFORM_MACCATALYST) && defined(ANGLE_CPU_ARM64))
bool GetSystemInfo_ios(SystemInfo *info);
#endif
} // namespace angle
#endif // GPU_INFO_UTIL_SYSTEM_INFO_INTERNAL_H_
......@@ -8,14 +8,14 @@
#include "common/platform.h"
#if defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)
#if defined(ANGLE_PLATFORM_IOS) || (defined(ANGLE_PLATFORM_MACCATALYST) && defined(ANGLE_CPU_ARM64))
# include "gpu_info_util/SystemInfo_internal.h"
namespace angle
{
bool GetSystemInfo(SystemInfo *info)
bool GetSystemInfo_ios(SystemInfo *info)
{
{
// TODO(anglebug.com/4275): Get the actual system version.
......@@ -27,4 +27,5 @@ bool GetSystemInfo(SystemInfo *info)
} // namespace angle
#endif // defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)
#endif // defined(ANGLE_PLATFORM_IOS) || (defined(ANGLE_PLATFORM_MACCATALYST) &&
// defined(ANGLE_CPU_ARM64))
......@@ -15,6 +15,8 @@
# import <Cocoa/Cocoa.h>
# import <IOKit/IOKitLib.h>
# include "common/gl/cgl/FunctionsCGL.h"
namespace angle
{
......@@ -281,7 +283,7 @@ VendorID GetVendorIDFromMetalDeviceRegistryID(uint64_t registryID)
return 0;
}
bool GetSystemInfo(SystemInfo *info)
bool GetSystemInfo_mac(SystemInfo *info)
{
{
int32_t major = 0;
......
......@@ -28,6 +28,7 @@
#include "common/system_utils.h"
#include "common/tls.h"
#include "common/utilities.h"
#include "gpu_info_util/SystemInfo.h"
#include "libANGLE/Context.h"
#include "libANGLE/Device.h"
#include "libANGLE/EGLSync.h"
......@@ -52,10 +53,8 @@
#if defined(ANGLE_ENABLE_OPENGL)
# if defined(ANGLE_PLATFORM_WINDOWS)
# include "libANGLE/renderer/gl/wgl/DisplayWGL.h"
# elif defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST)
# include "libANGLE/renderer/gl/cgl/DisplayCGL.h"
# elif defined(ANGLE_PLATFORM_IOS)
# include "libANGLE/renderer/gl/eagl/DisplayEAGL.h"
# elif defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_IOS)
# include "libANGLE/renderer/gl/apple/DisplayApple_api.h"
# elif defined(ANGLE_PLATFORM_LINUX)
# include "libANGLE/renderer/gl/egl/DisplayEGL.h"
# if defined(ANGLE_USE_GBM)
......@@ -267,10 +266,12 @@ rx::DisplayImpl *CreateDisplayFromAttribs(EGLAttrib displayType,
#if defined(ANGLE_ENABLE_OPENGL)
# if defined(ANGLE_PLATFORM_WINDOWS)
impl = new rx::DisplayWGL(state);
# elif defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST)
impl = new rx::DisplayCGL(state);
# elif defined(ANGLE_PLATFORM_IOS)
impl = new rx::DisplayEAGL(state);
break;
# elif defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_IOS)
impl = rx::CreateDisplayCGLOrEAGL(state);
break;
# elif defined(ANGLE_PLATFORM_LINUX)
# if defined(ANGLE_USE_GBM)
if (platformType == 0)
......
......@@ -10,6 +10,7 @@
#include "anglebase/no_destructor.h"
#include "common/mathutil.h"
#include "gpu_info_util/SystemInfo.h"
#include "libANGLE/Context.h"
#include "libANGLE/Framebuffer.h"
......@@ -1029,8 +1030,21 @@ static InternalFormatInfoMap BuildInternalFormatInfoMap()
AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
AddRGBAFormat(&map, GL_SRGB, false, 8, 8, 8, 0, 0, GL_SRGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireExt<&Extensions::sRGB>, AlwaysSupported, NeverSupported, NeverSupported, NeverSupported);
AddRGBAFormat(&map, GL_SRGB_ALPHA_EXT, false, 8, 8, 8, 8, 0, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireExt<&Extensions::sRGB>, AlwaysSupported, RequireExt<&Extensions::sRGB>, NeverSupported, NeverSupported);
#if defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)
AddRGBAFormat(&map, GL_BGRA_EXT, false, 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, AlwaysSupported, RequireES<2, 0>, NeverSupported, NeverSupported);
#if (defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)) || (defined(ANGLE_PLATFORM_MACCATALYST) && defined(ANGLE_CPU_ARM64))
angle::SystemInfo info;
if (angle::GetSystemInfo(&info))
{
if (info.isiOSAppOnMac)
{
// Using OpenGLES.framework.
AddRGBAFormat(&map, GL_BGRA_EXT, false, 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, AlwaysSupported, RequireES<2, 0>, NeverSupported, NeverSupported);
}
else
{
// Using OpenGL.framework.
AddRGBAFormat(&map, GL_BGRA_EXT, false, 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported, RequireExt<&Extensions::textureFormatBGRA8888>, NeverSupported, NeverSupported);
}
}
#else
AddRGBAFormat(&map, GL_BGRA_EXT, false, 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported, RequireExt<&Extensions::textureFormatBGRA8888>, NeverSupported, NeverSupported);
#endif
......
//
// 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.
//
// DisplayApple_api.cpp:
// Chooses CGL or EAGL either at compile time or runtime based on the platform.
//
#ifndef LIBANGLE_RENDERER_GL_APPLE_DISPLAYAPPLE_API_H_
#define LIBANGLE_RENDERER_GL_APPLE_DISPLAYAPPLE_API_H_
#include "libANGLE/renderer/DisplayImpl.h"
#if defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST)
# include "libANGLE/renderer/gl/cgl/DisplayCGL.h"
# if defined(ANGLE_PLATFORM_MACCATALYST) && defined(ANGLE_CPU_ARM64)
# include "libANGLE/renderer/gl/eagl/DisplayEAGL.h"
# endif
#elif defined(ANGLE_PLATFORM_IOS)
# include "libANGLE/renderer/gl/eagl/DisplayEAGL.h"
#endif
namespace rx
{
DisplayImpl *CreateDisplayCGLOrEAGL(const egl::DisplayState &state)
{
#if defined(ANGLE_PLATFORM_MACOS)
return new rx::DisplayCGL(state);
#elif defined(ANGLE_PLATFORM_MACCATALYST)
# if defined(ANGLE_CPU_ARM64)
angle::SystemInfo info;
if (!angle::GetSystemInfo(&info))
{
impl = nullptr;
break;
}
if (info.isiOSAppOnMac)
{
return new rx::DisplayEAGL(state);
}
else
{
return new rx::DisplayCGL(state);
}
# else
return new rx::DisplayCGL(state);
# endif
#elif defined(ANGLE_PLATFORM_IOS)
return new rx::DisplayEAGL(state);
#endif
}
} // namespace rx
#endif /* LIBANGLE_RENDERER_GL_APPLE_DISPLAYAPPLE_API_H_ */
//
// 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.
//
// DisplayApple_api.h:
// Chooses CGL or EAGL either at compile time or runtime based on the platform.
//
#ifndef LIBANGLE_RENDERER_GL_APPLE_DISPLAYAPPLE_API_H_
#define LIBANGLE_RENDERER_GL_APPLE_DISPLAYAPPLE_API_H_
#include "libANGLE/renderer/DisplayImpl.h"
namespace rx
{
DisplayImpl *CreateDisplayCGLOrEAGL(const egl::DisplayState &state);
} // namespace rx
#endif /* LIBANGLE_RENDERER_GL_APPLE_DISPLAYAPPLE_API_H_ */
......@@ -17,6 +17,7 @@
# include <dlfcn.h>
# include "common/debug.h"
# include "common/gl/cgl/FunctionsCGL.h"
# include "gpu_info_util/SystemInfo.h"
# include "libANGLE/Display.h"
# include "libANGLE/Error.h"
......
......@@ -18,6 +18,7 @@
# include <OpenGL/OpenGL.h>
# include "common/debug.h"
# include "common/gl/cgl/FunctionsCGL.h"
# include "libANGLE/AttributeMap.h"
# include "libANGLE/renderer/gl/BlitGL.h"
# include "libANGLE/renderer/gl/FramebufferGL.h"
......
......@@ -18,7 +18,7 @@ struct __IOSurface;
typedef __IOSurface *IOSurfaceRef;
// WebKit's build process requires that every Objective-C class name has the prefix "Web".
@class WebSwapLayer;
@class WebSwapLayerCGL;
namespace rx
{
......@@ -87,7 +87,7 @@ class WindowSurfaceCGL : public SurfaceGL
const gl::FramebufferState &state) override;
private:
WebSwapLayer *mSwapLayer;
WebSwapLayerCGL *mSwapLayer;
SharedSwapState mSwapState;
uint64_t mCurrentSwapId;
......
......@@ -17,13 +17,14 @@
# import <QuartzCore/QuartzCore.h>
# include "common/debug.h"
# include "common/gl/cgl/FunctionsCGL.h"
# include "libANGLE/Context.h"
# include "libANGLE/renderer/gl/FramebufferGL.h"
# include "libANGLE/renderer/gl/RendererGL.h"
# include "libANGLE/renderer/gl/StateManagerGL.h"
# include "libANGLE/renderer/gl/cgl/DisplayCGL.h"
@interface WebSwapLayer : CAOpenGLLayer {
@interface WebSwapLayerCGL : CAOpenGLLayer {
CGLContextObj mDisplayContext;
bool initialized;
......@@ -37,7 +38,7 @@
withFunctions:(const rx::FunctionsGL *)functions;
@end
@implementation WebSwapLayer
@implementation WebSwapLayerCGL
- (id)initWithSharedState:(rx::SharedSwapState *)swapState
withContext:(CGLContextObj)displayContext
withFunctions:(const rx::FunctionsGL *)functions
......@@ -212,9 +213,9 @@ egl::Error WindowSurfaceCGL::initialize(const egl::Display *display)
mSwapState.lastRendered = &mSwapState.textures[1];
mSwapState.beingPresented = &mSwapState.textures[2];
mSwapLayer = [[WebSwapLayer alloc] initWithSharedState:&mSwapState
withContext:mContext
withFunctions:mFunctions];
mSwapLayer = [[WebSwapLayerCGL alloc] initWithSharedState:&mSwapState
withContext:mContext
withFunctions:mFunctions];
[mLayer addSublayer:mSwapLayer];
[mSwapLayer setContentsScale:[mLayer contentsScale]];
......
......@@ -8,7 +8,7 @@
#import "common/platform.h"
#if defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)
#if defined(ANGLE_ENABLE_EAGL)
# include "libANGLE/renderer/gl/eagl/DeviceEAGL.h"
......@@ -56,4 +56,4 @@ void DeviceEAGL::generateExtensions(egl::DeviceExtensions *outExtensions) const
} // namespace rx
#endif // defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)
#endif // defined(ANGLE_ENABLE_EAGL)
\ No newline at end of file
......@@ -11,7 +11,7 @@
#import "common/platform.h"
#if defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)
#if defined(ANGLE_ENABLE_EAGL)
# include "libANGLE/Device.h"
# include "libANGLE/renderer/DeviceImpl.h"
......@@ -34,6 +34,6 @@ class DeviceEAGL : public DeviceImpl
} // namespace rx
#endif // defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)
#endif // defined(ANGLE_ENABLE_EAGL)
#endif // LIBANGLE_RENDERER_GL_EAGL_DEVICEEAGL_H_
......@@ -14,7 +14,7 @@
#import "common/platform.h"
#if defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)
#if defined(ANGLE_ENABLE_EAGL)
# include "libANGLE/renderer/gl/DisplayGL.h"
......@@ -104,6 +104,6 @@ class DisplayEAGL : public DisplayGL
} // namespace rx
#endif // defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)
#endif // defined(ANGLE_ENABLE_EAGL)
#endif // LIBANGLE_RENDERER_GL_EAGL_DISPLAYEAGL_H_
......@@ -8,7 +8,7 @@
#import "common/platform.h"
#if defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)
#if defined(ANGLE_ENABLE_EAGL)
# import "libANGLE/renderer/gl/eagl/DisplayEAGL.h"
......@@ -17,18 +17,16 @@
# import "libANGLE/Display.h"
# import "libANGLE/renderer/gl/eagl/ContextEAGL.h"
# import "libANGLE/renderer/gl/eagl/DeviceEAGL.h"
# import "libANGLE/renderer/gl/eagl/FunctionsEAGL.h"
# import "libANGLE/renderer/gl/eagl/IOSurfaceSurfaceEAGL.h"
# import "libANGLE/renderer/gl/eagl/PbufferSurfaceEAGL.h"
# import "libANGLE/renderer/gl/eagl/RendererEAGL.h"
# import "libANGLE/renderer/gl/eagl/WindowSurfaceEAGL.h"
# import <Foundation/Foundation.h>
# import <OpenGLES/EAGL.h>
# import <QuartzCore/QuartzCore.h>
# import <dlfcn.h>
# define GLES_SILENCE_DEPRECATION
namespace
{
......@@ -70,13 +68,13 @@ egl::Error DisplayEAGL::initialize(egl::Display *display)
// contain incomplete information.
(void)angle::GetSystemInfo(&info);
mContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
mContext = [allocEAGLContextInstance() initWithAPI:kEAGLRenderingAPIOpenGLES3];
if (mContext == nullptr)
{
return egl::EglNotInitialized() << "Could not create the EAGL context.";
}
if (![EAGLContext setCurrentContext:mContext])
if (![getEAGLContextClass() setCurrentContext:mContext])
{
return egl::EglNotInitialized() << "Could set the EAGL context current.";
}
......@@ -114,7 +112,7 @@ void DisplayEAGL::terminate()
mRenderer.reset();
if (mContext != nullptr)
{
[EAGLContext setCurrentContext:nil];
[getEAGLContextClass() setCurrentContext:nil];
mContext = nullptr;
mThreadsWithContextCurrent.clear();
}
......@@ -368,13 +366,13 @@ WorkerContextEAGL::WorkerContextEAGL(EAGLContextObj context) : mContext(context)
WorkerContextEAGL::~WorkerContextEAGL()
{
[EAGLContext setCurrentContext:nil];
[getEAGLContextClass() setCurrentContext:nil];
mContext = nullptr;
}
bool WorkerContextEAGL::makeCurrent()
{
if (![EAGLContext setCurrentContext:static_cast<EAGLContext *>(mContext)])
if (![getEAGLContextClass() setCurrentContext:static_cast<EAGLContext *>(mContext)])
{
ERR() << "Unable to make gl context current.";
return false;
......@@ -384,13 +382,13 @@ bool WorkerContextEAGL::makeCurrent()
void WorkerContextEAGL::unmakeCurrent()
{
[EAGLContext setCurrentContext:nil];
[getEAGLContextClass() setCurrentContext:nil];
}
WorkerContext *DisplayEAGL::createWorkerContext(std::string *infoLog)
{
EAGLContextObj context = nullptr;
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
context = [allocEAGLContextInstance() initWithAPI:kEAGLRenderingAPIOpenGLES3];
if (!context)
{
*infoLog += "Could not create the EAGL context.";
......@@ -411,4 +409,4 @@ void DisplayEAGL::populateFeatureList(angle::FeatureList *features)
}
}
#endif // defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)
#endif // defined(ANGLE_ENABLE_EAGL)
//
// 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.
//
// EAGLFunctions.h: Exposing the soft-linked EAGL interface.
#ifndef EAGL_FUNCTIONS_H_
#define EAGL_FUNCTIONS_H_
#include "common/platform.h"
#if defined(ANGLE_ENABLE_EAGL)
# import <OpenGLES/EAGL.h>
# import <OpenGLES/EAGLDrawable.h>
# import <OpenGLES/EAGLIOSurface.h>
# include "libANGLE/renderer/gl/apple/SoftLinking.h"
SOFT_LINK_FRAMEWORK_HEADER(OpenGLES)
SOFT_LINK_CLASS_HEADER(EAGLContext)
#endif // defined(ANGLE_ENABLE_EAGL)
#endif // CGL_FUNCTIONS_H_
//
// 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.
//
// EAGLFunctions.cpp: Exposing the soft-linked EAGL interface.
#include "common/platform.h"
#if defined(ANGLE_ENABLE_EAGL)
# import <OpenGLES/EAGL.h>
# import <OpenGLES/EAGLDrawable.h>
# import <OpenGLES/EAGLIOSurface.h>
# include "libANGLE/renderer/gl/apple/SoftLinking.h"
SOFT_LINK_FRAMEWORK_SOURCE(OpenGLES)
SOFT_LINK_CLASS(OpenGLES, EAGLContext)
#endif // defined(ANGLE_ENABLE_EAGL)
\ No newline at end of file
......@@ -9,7 +9,7 @@
#import "common/platform.h"
#if defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)
#if defined(ANGLE_ENABLE_EAGL)
# import "libANGLE/renderer/gl/eagl/IOSurfaceSurfaceEAGL.h"
......@@ -427,4 +427,4 @@ IOSurfaceLockOptions IOSurfaceSurfaceEAGL::getIOSurfaceLockOptions() const
} // namespace rx
#endif // defined(ANGLE_PLATFORM_IOS)
#endif // defined(ANGLE_ENABLE_EAGL)
......@@ -9,7 +9,7 @@
#import "common/platform.h"
#if defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)
#if defined(ANGLE_ENABLE_EAGL)
# include "libANGLE/renderer/gl/eagl/PbufferSurfaceEAGL.h"
......@@ -144,4 +144,4 @@ FramebufferImpl *PbufferSurfaceEAGL::createDefaultFramebuffer(const gl::Context
} // namespace rx
#endif // defined(ANGLE_PLATFORM_IOS)
#endif // defined(ANGLE_ENABLE_EAGL)
......@@ -8,7 +8,7 @@
#import "common/platform.h"
#if defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)
#if defined(ANGLE_ENABLE_EAGL)
# include "libANGLE/renderer/gl/eagl/DisplayEAGL.h"
# include "libANGLE/renderer/gl/eagl/RendererEAGL.h"
......@@ -31,4 +31,4 @@ WorkerContext *RendererEAGL::createWorkerContext(std::string *infoLog)
} // namespace rx
#endif // defined(ANGLE_PLATFORM_IOS)
#endif // defined(ANGLE_ENABLE_EAGL)
......@@ -22,7 +22,7 @@ struct __IOSurface;
typedef __IOSurface *IOSurfaceRef;
// WebKit's build process requires that every Objective-C class name has the prefix "Web".
@class WebSwapLayer;
@class WebSwapLayerEAGL;
namespace rx
{
......@@ -91,7 +91,7 @@ class WindowSurfaceEAGL : public SurfaceGL
const gl::FramebufferState &state) override;
private:
WebSwapLayer *mSwapLayer;
WebSwapLayerEAGL *mSwapLayer;
SharedSwapState mSwapState;
uint64_t mCurrentSwapId;
......
......@@ -8,7 +8,7 @@
#import "common/platform.h"
#if defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)
#if defined(ANGLE_ENABLE_EAGL)
# import "libANGLE/renderer/gl/eagl/WindowSurfaceEAGL.h"
......@@ -18,13 +18,22 @@
# import "libANGLE/renderer/gl/RendererGL.h"
# import "libANGLE/renderer/gl/StateManagerGL.h"
# import "libANGLE/renderer/gl/eagl/DisplayEAGL.h"
# import "libANGLE/renderer/gl/eagl/FunctionsEAGL.h"
# import <OpenGLES/EAGL.h>
# import <QuartzCore/QuartzCore.h>
// TODO(anglebug.com/4275): It's not clear why this needs to be an EAGLLayer.
# if defined(ANGLE_PLATFORM_MACCATALYST) && defined(ANGLE_CPU_ARM64)
@interface WebSwapLayer : CAEAGLLayer {
// TODO(dino): Necessary because CAEAGLLayer is not in the public QuartzCore headers in this
// configuration.
// TODO(dino): Check that this won't cause an application using ANGLE directly to be flagged
// for non-public API use on Apple's App Store.
@interface CAEAGLLayer : CALayer
@end
# endif
@interface WebSwapLayerEAGL : CAEAGLLayer {
EAGLContextObj mDisplayContext;
bool initialized;
......@@ -38,7 +47,7 @@
withFunctions:(const rx::FunctionsGL *)functions;
@end
@implementation WebSwapLayer
@implementation WebSwapLayerEAGL
- (id)initWithSharedState:(rx::SharedSwapState *)swapState
withContext:(EAGLContextObj)displayContext
withFunctions:(const rx::FunctionsGL *)functions
......@@ -69,7 +78,7 @@
}
pthread_mutex_unlock(&mSwapState->mutex);
[EAGLContext setCurrentContext:mDisplayContext];
[getEAGLContextClass() setCurrentContext:mDisplayContext];
if (!initialized)
{
......@@ -105,7 +114,7 @@
mFunctions->bindRenderbuffer(GL_RENDERBUFFER, texture.texture);
[mDisplayContext presentRenderbuffer:GL_RENDERBUFFER];
[EAGLContext setCurrentContext:nil];
[getEAGLContextClass() setCurrentContext:nil];
}
@end
......@@ -173,9 +182,9 @@ egl::Error WindowSurfaceEAGL::initialize(const egl::Display *display)
mSwapState.lastRendered = &mSwapState.textures[1];
mSwapState.beingPresented = &mSwapState.textures[2];
mSwapLayer = [[WebSwapLayer alloc] initWithSharedState:&mSwapState
withContext:mContext
withFunctions:mFunctions];
mSwapLayer = [[WebSwapLayerEAGL alloc] initWithSharedState:&mSwapState
withContext:mContext
withFunctions:mFunctions];
[mLayer addSublayer:mSwapLayer];
[mSwapLayer setContentsScale:[mLayer contentsScale]];
......@@ -305,4 +314,4 @@ FramebufferImpl *WindowSurfaceEAGL::createDefaultFramebuffer(const gl::Context *
} // namespace rx
#endif // defined(ANGLE_PLATFORM_IOS)
#endif // defined(ANGLE_ENABLE_EAGL)
......@@ -1357,12 +1357,17 @@ void GenerateCaps(const FunctionsGL *functions,
functions->hasGLESExtension("GL_EXT_compressed_ETC1_RGB8_sub_texture");
#if defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST)
VendorID vendor = GetVendorID(functions);
if ((IsAMD(vendor) || IsIntel(vendor)) && *maxSupportedESVersion >= gl::Version(3, 0))
angle::SystemInfo info;
if (angle::GetSystemInfo(&info) && !info.isiOSAppOnMac)
{
// Apple Intel/AMD drivers do not correctly use the TEXTURE_SRGB_DECODE property of sampler
// states. Disable this extension when we would advertise any ES version that has samplers.
extensions->textureSRGBDecode = false;
VendorID vendor = GetVendorID(functions);
if ((IsAMD(vendor) || IsIntel(vendor)) && *maxSupportedESVersion >= gl::Version(3, 0))
{
// Apple Intel/AMD drivers do not correctly use the TEXTURE_SRGB_DECODE property of
// sampler states. Disable this extension when we would advertise any ES version
// that has samplers.
extensions->textureSRGBDecode = false;
}
}
#endif
......
......@@ -71,6 +71,7 @@ xxhash_sources = [
angle_system_utils_sources = [
"src/common/Optional.h",
"src/common/angleutils.h",
"src/common/debug.h",
"src/common/platform.h",
"src/common/system_utils.cpp",
"src/common/system_utils.h",
......@@ -85,6 +86,9 @@ if (is_linux || is_chromeos || is_android || is_fuchsia) {
if (is_mac) {
angle_system_utils_sources += [
"src/common/apple/SoftLinking.h",
"src/common/gl/cgl/FunctionsCGL.cpp",
"src/common/gl/cgl/FunctionsCGL.h",
"src/common/system_utils_mac.cpp",
"src/common/system_utils_posix.cpp",
]
......@@ -143,7 +147,10 @@ libangle_gpu_info_util_libpci_sources =
libangle_gpu_info_util_x11_sources = [ "src/gpu_info_util/SystemInfo_x11.cpp" ]
libangle_gpu_info_util_mac_sources = [ "src/gpu_info_util/SystemInfo_macos.mm" ]
libangle_gpu_info_util_mac_sources = [
"src/gpu_info_util/SystemInfo_apple.mm",
"src/gpu_info_util/SystemInfo_macos.mm",
]
libangle_includes = [
"include/angle_gl.h",
......@@ -458,7 +465,11 @@ libangle_sources = [
"src/libANGLE/validationGL46.cpp",
]
libangle_mac_sources = [ "src/libANGLE/renderer/driver_utils_mac.mm" ]
libangle_mac_sources = [
"src/libANGLE/renderer/driver_utils_mac.mm",
"src/libANGLE/renderer/gl/apple/DisplayApple_api.cpp",
"src/libANGLE/renderer/gl/apple/DisplayApple_api.h",
]
# The frame capture headers are always visible to libANGLE.
libangle_sources += [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment