15#include <Cocoa/Cocoa.h>
27 ~GLWindowContext_mac()
override;
35 void teardownContext();
39 NSOpenGLContext* fGLContext;
40 NSOpenGLPixelFormat* fPixelFormat;
45 , fMainView(
info.fMainView)
50 this->initializeContext();
53GLWindowContext_mac::~GLWindowContext_mac() {
57void GLWindowContext_mac::teardownContext() {
58 [NSOpenGLContext clearCurrentContext];
59 [fPixelFormat release];
69 fPixelFormat = skwindow::GetGLPixelFormat(fDisplayParams.fMSAASampleCount);
70 if (nil == fPixelFormat) {
75 fGLContext = [[NSOpenGLContext alloc] initWithFormat:fPixelFormat shareContext:nil];
76 if (nil == fGLContext) {
77 [fPixelFormat release];
82 [fMainView setWantsBestResolutionOpenGLSurface:YES];
83 [fGLContext setView:fMainView];
86 GLint swapInterval = fDisplayParams.fDisableVsync ? 0 : 1;
87 [fGLContext setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
90 [fGLContext makeCurrentContext];
93 glClearColor(0, 0, 0, 255);
94 glStencilMask(0xffffffff);
95 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
98 [fPixelFormat getValues:&stencilBits forAttribute:NSOpenGLPFAStencilSize forVirtualScreen:0];
99 fStencilBits = stencilBits;
101 [fPixelFormat getValues:&sampleCount forAttribute:NSOpenGLPFASamples forVirtualScreen:0];
102 fSampleCount = sampleCount;
103 fSampleCount =
std::max(fSampleCount, 1);
106 fWidth = fMainView.bounds.size.width * backingScaleFactor;
107 fHeight = fMainView.bounds.size.height * backingScaleFactor;
108 glViewport(0, 0, fWidth, fHeight);
113void GLWindowContext_mac::onDestroyContext() {
115 if (fGLContext && fSampleCount != fDisplayParams.fMSAASampleCount) {
120void GLWindowContext_mac::onSwapBuffers() {
121 [fGLContext flushBuffer];
124void GLWindowContext_mac::resize(
int w,
int h) {
128 GLWindowContext::resize(0, 0);
138 std::unique_ptr<WindowContext> ctx(
new GLWindowContext_mac(
info,
params));
139 if (!ctx->isValid()) {
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
virtual void onSwapBuffers()=0
void resize(int w, int h) override
virtual sk_sp< const GrGLInterface > onInitializeContext()=0
virtual void onDestroyContext()=0
const EmbeddedViewParams * params
static float max(float r, float g, float b)
SK_API sk_sp< const GrGLInterface > MakeMac()
std::unique_ptr< WindowContext > MakeGLForMac(const MacWindowInfo &info, const DisplayParams ¶ms)
static CGFloat GetBackingScaleFactor(NSView *view)