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.mm44
1 files changed, 31 insertions, 13 deletions
diff --git a/src/views/mac/SkNSView.mm b/src/views/mac/SkNSView.mm
index a6aa59cbef..9d52814afa 100644
--- a/src/views/mac/SkNSView.mm
+++ b/src/views/mac/SkNSView.mm
@@ -225,25 +225,36 @@ static SkKey raw2key(UInt32 raw)
///////////////////////////////////////////////////////////////////////////////
#include <OpenGL/OpenGL.h>
-CGLContextObj createGLContext() {
+namespace {
+CGLContextObj createGLContext(int msaaSampleCount) {
GLint major, minor;
CGLGetVersion(&major, &minor);
- const CGLPixelFormatAttribute attributes[] = {
+ static const CGLPixelFormatAttribute attributes[] = {
kCGLPFAStencilSize, (CGLPixelFormatAttribute)8,
-#if USE_MSAA
- kCGLPFASampleBuffers, 1,
- kCGLPFAMultisample,
- kCGLPFASamples, 8,
-#endif
kCGLPFAAccelerated,
kCGLPFADoubleBuffer,
(CGLPixelFormatAttribute)0
};
CGLPixelFormatObj format;
- GLint npix;
- CGLChoosePixelFormat(attributes, &format, &npix);
+ GLint npix = 0;
+ if (msaaSampleCount > 0) {
+ static int kAttributeCount = SK_ARRAY_COUNT(attributes);
+ CGLPixelFormatAttribute msaaAttributes[kAttributeCount + 5];
+ memcpy(msaaAttributes, attributes, sizeof(attributes));
+ SkASSERT(0 == msaaAttributes[kAttributeCount - 1]);
+ msaaAttributes[kAttributeCount - 1] = kCGLPFASampleBuffers;
+ msaaAttributes[kAttributeCount + 0] = (CGLPixelFormatAttribute)1;
+ msaaAttributes[kAttributeCount + 1] = kCGLPFAMultisample;
+ msaaAttributes[kAttributeCount + 2] = kCGLPFASamples;
+ msaaAttributes[kAttributeCount + 3] = (CGLPixelFormatAttribute)msaaSampleCount;
+ msaaAttributes[kAttributeCount + 4] = (CGLPixelFormatAttribute)0;
+ CGLChoosePixelFormat(msaaAttributes, &format, &npix);
+ }
+ if (!npix) {
+ CGLChoosePixelFormat(attributes, &format, &npix);
+ }
CGLContextObj ctx;
CGLCreateContext(format, NULL, &ctx);
@@ -254,6 +265,7 @@ CGLContextObj createGLContext() {
CGLSetCurrentContext(ctx);
return ctx;
}
+}
- (void)viewDidMoveToWindow {
[super viewDidMoveToWindow];
@@ -265,12 +277,15 @@ CGLContextObj createGLContext() {
[fGLContext setView:self];
}
}
-- (bool)attach:(SkOSWindow::SkBackEndTypes)attachType {
+- (bool)attach:(SkOSWindow::SkBackEndTypes)attachType withMSAASampleCount:(int) sampleCount {
if (nil == fGLContext) {
- fGLContext = [[NSOpenGLContext alloc] initWithCGLContextObj:createGLContext()];
+ CGLContextObj ctx = createGLContext(sampleCount);
+ fGLContext = [[NSOpenGLContext alloc] initWithCGLContextObj:ctx];
+ CGLReleaseContext(ctx);
if (NULL == fGLContext) {
return false;
}
+ [fGLContext setView:self];
}
[fGLContext makeCurrentContext];
@@ -283,10 +298,13 @@ CGLContextObj createGLContext() {
}
- (void)detach {
- [fGLContext clearDrawable];
+ [fGLContext release];
+ fGLContext = nil;
}
- (void)present {
- [fGLContext flushBuffer];
+ if (nil != fGLContext) {
+ [fGLContext flushBuffer];
+ }
}
@end