aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/views/mac/SkNSView.mm
diff options
context:
space:
mode:
Diffstat (limited to 'src/views/mac/SkNSView.mm')
-rw-r--r--src/views/mac/SkNSView.mm14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/views/mac/SkNSView.mm b/src/views/mac/SkNSView.mm
index a6aa59cbef..30488abb3d 100644
--- a/src/views/mac/SkNSView.mm
+++ b/src/views/mac/SkNSView.mm
@@ -225,6 +225,7 @@ static SkKey raw2key(UInt32 raw)
///////////////////////////////////////////////////////////////////////////////
#include <OpenGL/OpenGL.h>
+namespace {
CGLContextObj createGLContext() {
GLint major, minor;
CGLGetVersion(&major, &minor);
@@ -254,6 +255,7 @@ CGLContextObj createGLContext() {
CGLSetCurrentContext(ctx);
return ctx;
}
+}
- (void)viewDidMoveToWindow {
[super viewDidMoveToWindow];
@@ -267,10 +269,13 @@ CGLContextObj createGLContext() {
}
- (bool)attach:(SkOSWindow::SkBackEndTypes)attachType {
if (nil == fGLContext) {
- fGLContext = [[NSOpenGLContext alloc] initWithCGLContextObj:createGLContext()];
+ CGLContextObj ctx = createGLContext();
+ fGLContext = [[NSOpenGLContext alloc] initWithCGLContextObj:ctx];
+ CGLReleaseContext(ctx);
if (NULL == fGLContext) {
return false;
}
+ [fGLContext setView:self];
}
[fGLContext makeCurrentContext];
@@ -283,10 +288,13 @@ CGLContextObj createGLContext() {
}
- (void)detach {
- [fGLContext clearDrawable];
+ [fGLContext release];
+ fGLContext = nil;
}
- (void)present {
- [fGLContext flushBuffer];
+ if (nil != fGLContext) {
+ [fGLContext flushBuffer];
+ }
}
@end