diff options
author | 2012-04-06 20:13:38 +0000 | |
---|---|---|
committer | 2012-04-06 20:13:38 +0000 | |
commit | 1195925b05ee9d666ea8a8f68fde5d8ca7e49b04 (patch) | |
tree | ac396c0182d7a933aa23f35d7f29e3a6dce10265 /src/views/mac/SkNSView.mm | |
parent | 09042b80d22837c760bb530124aaa67469b19b8f (diff) |
Add MSAA option to SampleApp
Review URL: http://codereview.appspot.com/5969049
git-svn-id: http://skia.googlecode.com/svn/trunk@3627 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/views/mac/SkNSView.mm')
-rw-r--r-- | src/views/mac/SkNSView.mm | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/views/mac/SkNSView.mm b/src/views/mac/SkNSView.mm index 30488abb3d..1e7be69cab 100644 --- a/src/views/mac/SkNSView.mm +++ b/src/views/mac/SkNSView.mm @@ -226,25 +226,36 @@ static SkKey raw2key(UInt32 raw) #include <OpenGL/OpenGL.h> namespace { -CGLContextObj createGLContext() { +CGLContextObj createGLContext(int msaaSampleCount) { GLint major, minor; CGLGetVersion(&major, &minor); - const CGLPixelFormatAttribute attributes[] = { - kCGLPFAStencilSize, (CGLPixelFormatAttribute)8, -#if USE_MSAA - kCGLPFASampleBuffers, 1, - kCGLPFAMultisample, - kCGLPFASamples, 8, -#endif + static const CGLPixelFormatAttribute attributes[] = { + kCGLPFAStencilSize, (CGLPixelFormatAttribute) 8, 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); @@ -267,9 +278,10 @@ CGLContextObj createGLContext() { [fGLContext setView:self]; } } -- (bool)attach:(SkOSWindow::SkBackEndTypes)attachType { +- (bool)attach:(SkOSWindow::SkBackEndTypes)attachType + withMSAASampleCount:(int) sampleCount { if (nil == fGLContext) { - CGLContextObj ctx = createGLContext(); + CGLContextObj ctx = createGLContext(sampleCount); fGLContext = [[NSOpenGLContext alloc] initWithCGLContextObj:ctx]; CGLReleaseContext(ctx); if (NULL == fGLContext) { |