aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/views/mac
diff options
context:
space:
mode:
Diffstat (limited to 'src/views/mac')
-rw-r--r--src/views/mac/SkNSView.h2
-rw-r--r--src/views/mac/SkNSView.mm44
-rw-r--r--src/views/mac/SkOSWindow_Mac.mm4
3 files changed, 34 insertions, 16 deletions
diff --git a/src/views/mac/SkNSView.h b/src/views/mac/SkNSView.h
index 60727eb3e6..bf6e67c71c 100644
--- a/src/views/mac/SkNSView.h
+++ b/src/views/mac/SkNSView.h
@@ -42,7 +42,7 @@ class SkEvent;
- (void)postInvalWithRect:(const SkIRect*)rectOrNil;
- (BOOL)onHandleEvent:(const SkEvent&)event;
-- (bool)attach:(SkOSWindow::SkBackEndTypes)attachType;
+- (bool)attach:(SkOSWindow::SkBackEndTypes)attachType withMSAASampleCount:(int) sampleCount;
- (void)detach;
- (void)present;
@end
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
diff --git a/src/views/mac/SkOSWindow_Mac.mm b/src/views/mac/SkOSWindow_Mac.mm
index 4aa4eb5ff8..a5d3fef706 100644
--- a/src/views/mac/SkOSWindow_Mac.mm
+++ b/src/views/mac/SkOSWindow_Mac.mm
@@ -63,8 +63,8 @@ void SkOSWindow::onUpdateMenu(const SkOSMenu* menu) {
[(SkNSView*)fHWND onUpdateMenu:menu];
}
-bool SkOSWindow::attach(SkBackEndTypes attachType) {
- return [(SkNSView*)fHWND attach:attachType];
+bool SkOSWindow::attach(SkBackEndTypes attachType, int sampleCount) {
+ return [(SkNSView*)fHWND attach:attachType withMSAASampleCount:sampleCount];
}
void SkOSWindow::detach() {