13#import <OpenGLES/EAGL.h>
16#define EAGLCTX ((EAGLContext*)(fEAGLContext))
21 EAGLContext* context = [EAGLContext currentContext];
22 return [context] { [EAGLContext setCurrentContext:context]; };
27 IOSGLTestContext(IOSGLTestContext* shareContext);
28 ~IOSGLTestContext()
override;
31 void destroyGLContext();
33 void onPlatformMakeNotCurrent()
const override;
34 void onPlatformMakeCurrent()
const override;
35 std::function<void()> onPlatformGetAutoContextRestore()
const override;
36 GrGLFuncPtr onPlatformGetProcAddress(
const char*)
const override;
38 sk_cfp<EAGLContext*> fEAGLContext;
42IOSGLTestContext::IOSGLTestContext(IOSGLTestContext* shareContext)
43 : fGLLibrary(RTLD_DEFAULT) {
46 EAGLContext* iosShareContext = shareContext->fEAGLContext.get();
47 fEAGLContext.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3
48 sharegroup:[iosShareContext sharegroup]]);
50 fEAGLContext.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2
51 sharegroup:[iosShareContext sharegroup]]);
54 fEAGLContext.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]);
56 fEAGLContext.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]);
60 [EAGLContext setCurrentContext:fEAGLContext.get()];
63 if (
nullptr ==
gl.get()) {
64 SkDebugf(
"Failed to create gl interface");
65 this->destroyGLContext();
68 if (!
gl->validate()) {
69 SkDebugf(
"Failed to validate gl interface");
70 this->destroyGLContext();
75 "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib",
81IOSGLTestContext::~IOSGLTestContext() {
83 this->destroyGLContext();
86void IOSGLTestContext::destroyGLContext() {
88 if ([EAGLContext currentContext] == fEAGLContext.get()) {
90 [EAGLContext setCurrentContext:nil];
94 if (
nullptr != fGLLibrary) {
99void IOSGLTestContext::onPlatformMakeNotCurrent()
const {
100 if (![EAGLContext setCurrentContext:nil]) {
101 SkDebugf(
"Could not reset the context.\n");
105void IOSGLTestContext::onPlatformMakeCurrent()
const {
106 if (![EAGLContext setCurrentContext:fEAGLContext.get()]) {
107 SkDebugf(
"Could not set the context.\n");
111std::function<void()> IOSGLTestContext::onPlatformGetAutoContextRestore()
const {
112 if ([EAGLContext currentContext] == fEAGLContext.get()) {
115 return context_restorer();
118GrGLFuncPtr IOSGLTestContext::onPlatformGetProcAddress(
const char* procName)
const {
119 void* handle = (
nullptr == fGLLibrary) ? RTLD_DEFAULT : fGLLibrary;
120 return reinterpret_cast<GrGLFuncPtr>(dlsym(handle, procName));
127 GLTestContext *shareContext) {
131 IOSGLTestContext* iosShareContext =
reinterpret_cast<IOSGLTestContext*
>(shareContext);
132 IOSGLTestContext *ctx =
new IOSGLTestContext(iosShareContext);
133 if (!ctx->isValid()) {
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
Dart_NativeFunction function
SK_API sk_sp< const GrGLInterface > MakeIOS()
GLTestContext * CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI, GLTestContext *shareContext)