13#include <OpenGL/OpenGL.h>
19 auto context = CGLGetCurrentContext();
20 return [context] { CGLSetCurrentContext(context); };
25 MacGLTestContext(MacGLTestContext* shareContext);
26 ~MacGLTestContext()
override;
29 void destroyGLContext();
31 void onPlatformMakeNotCurrent()
const override;
32 void onPlatformMakeCurrent()
const override;
33 std::function<void()> onPlatformGetAutoContextRestore()
const override;
34 GrGLFuncPtr onPlatformGetProcAddress(
const char*)
const override;
40MacGLTestContext::MacGLTestContext(MacGLTestContext* shareContext)
42 , fGLLibrary(RTLD_DEFAULT) {
46 CGLPixelFormatAttribute attributes[] = {
49 (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core,
53 kCGLPFAAllowOfflineRenderers,
55 kCGLPFARendererID, (CGLPixelFormatAttribute)kCGLRendererATIRadeonX4000ID,
56 (CGLPixelFormatAttribute)NULL
58 static const int kFirstEGPUParameter = 3;
59 SkASSERT(kCGLPFAAllowOfflineRenderers == attributes[kFirstEGPUParameter]);
61 CGLPixelFormatObj pixFormat;
63 CGLChoosePixelFormat(attributes, &pixFormat, &npix);
65 if (
nullptr == pixFormat) {
67 attributes[kFirstEGPUParameter] = (CGLPixelFormatAttribute)NULL;
68 CGLChoosePixelFormat(attributes, &pixFormat, &npix);
70 if (
nullptr == pixFormat) {
71 SkDebugf(
"CGLChoosePixelFormat failed.");
75 CGLCreateContext(pixFormat, shareContext ? shareContext->fContext :
nullptr, &
fContext);
76 CGLReleasePixelFormat(pixFormat);
79 SkDebugf(
"CGLCreateContext failed.");
88 SkDebugf(
"Context could not create GL interface.\n");
89 this->destroyGLContext();
92 if (!
gl->validate()) {
93 SkDebugf(
"Context could not validate GL interface.\n");
94 this->destroyGLContext();
99 "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib",
102 this->
init(std::move(
gl));
105MacGLTestContext::~MacGLTestContext() {
107 this->destroyGLContext();
110void MacGLTestContext::destroyGLContext() {
112 if (CGLGetCurrentContext() ==
fContext) {
114 CGLSetCurrentContext(
nullptr);
119 if (
nullptr != fGLLibrary) {
124void MacGLTestContext::onPlatformMakeNotCurrent()
const {
125 CGLSetCurrentContext(
nullptr);
128void MacGLTestContext::onPlatformMakeCurrent()
const {
132std::function<void()> MacGLTestContext::onPlatformGetAutoContextRestore()
const {
133 if (CGLGetCurrentContext() ==
fContext) {
136 return context_restorer();
139GrGLFuncPtr MacGLTestContext::onPlatformGetProcAddress(
const char* procName)
const {
140 void* handle = (
nullptr == fGLLibrary) ? RTLD_DEFAULT : fGLLibrary;
141 return reinterpret_cast<GrGLFuncPtr>(dlsym(handle, procName));
148 GLTestContext* shareContext) {
152 MacGLTestContext* macShareContext =
reinterpret_cast<MacGLTestContext*
>(shareContext);
153 MacGLTestContext* ctx =
new MacGLTestContext(macShareContext);
154 if (!ctx->isValid()) {
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
Dart_NativeFunction function
SK_API sk_sp< const GrGLInterface > MakeMac()
GLTestContext * CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI, GLTestContext *shareContext)