diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-04-03 18:06:20 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-04-03 18:06:20 +0000 |
commit | ed164836f3268e4cd7cea916b4876f6e1c81849a (patch) | |
tree | b013d2bc81eea203b045f321df4bc850cd2ba6a8 | |
parent | 3c4d032aeb2831a64fd6eff570667d590e3ed209 (diff) |
Fix GL attach/detach in Mac SampleApp
Review URL: http://codereview.appspot.com/5984043/
git-svn-id: http://skia.googlecode.com/svn/trunk@3589 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | src/views/mac/SkNSView.mm | 14 |
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 |