aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/views/mac
diff options
context:
space:
mode:
authorGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-06-28 16:44:55 +0000
committerGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-06-28 16:44:55 +0000
commitb20a1b56a08d59d44eb8f7d423fccf88375c2c73 (patch)
treefd4bad0e003065a52d802349aa1940badaf1bd1c /src/views/mac
parent572b54dd7afdbe12d874ad9d2a82fc75485fae87 (diff)
Minimal changes for SampleApp to eb HiDPI aware on Mac.
R=caryclark@google.com Review URL: https://codereview.chromium.org/18055009 git-svn-id: http://skia.googlecode.com/svn/trunk@9807 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/views/mac')
-rw-r--r--src/views/mac/SampleApp-Info.plist2
-rw-r--r--src/views/mac/SkNSView.mm78
2 files changed, 76 insertions, 4 deletions
diff --git a/src/views/mac/SampleApp-Info.plist b/src/views/mac/SampleApp-Info.plist
index 64c6d481ff..6b42c2a465 100644
--- a/src/views/mac/SampleApp-Info.plist
+++ b/src/views/mac/SampleApp-Info.plist
@@ -28,5 +28,7 @@
<string>SampleApp</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
+ <key>NSHighResolutionCapable</key>
+ <true/>
</dict>
</plist>
diff --git a/src/views/mac/SkNSView.mm b/src/views/mac/SkNSView.mm
index 2d796e46b6..6a09fa65c1 100644
--- a/src/views/mac/SkNSView.mm
+++ b/src/views/mac/SkNSView.mm
@@ -13,6 +13,9 @@
SK_COMPILE_ASSERT(SK_SUPPORT_GPU, not_implemented_for_non_gpu_build);
//#define FORCE_REDRAW
+// Can be dropped when we no longer support 10.6.
+#define RETINA_API_AVAILABLE (defined(MAC_OS_X_VERSION_10_7) && \
+ MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
@implementation SkNSView
@synthesize fWind, fTitle, fOptionsDelegate, fGLContext;
@@ -33,15 +36,26 @@ SK_COMPILE_ASSERT(SK_SUPPORT_GPU, not_implemented_for_non_gpu_build);
}
- (id)initWithDefaults {
+#if RETINA_API_AVAILABLE
+ [self setWantsBestResolutionOpenGLSurface:YES];
+#endif
fRedrawRequestPending = false;
fWind = NULL;
return self;
}
- (void)setUpWindow {
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(backingPropertiesChanged:)
+ name:@"NSWindowDidChangeBackingPropertiesNotification"
+ object:[self window]];
if (NULL != fWind) {
fWind->setVisibleP(true);
- fWind->resize((int) self.frame.size.width, (int) self.frame.size.height,
+ NSSize size = self.frame.size;
+#if RETINA_API_AVAILABLE
+ size = [self convertSizeToBacking:self.frame.size];
+#endif
+ fWind->resize((int) size.width, (int) size.height,
SkBitmap::kARGB_8888_Config);
}
}
@@ -54,13 +68,49 @@ SK_COMPILE_ASSERT(SK_SUPPORT_GPU, not_implemented_for_non_gpu_build);
return YES;
}
+- (float)scaleFactor {
+ NSWindow *window = [self window];
+#if RETINA_API_AVAILABLE
+ if (window) {
+ return [window backingScaleFactor];
+ }
+ return [[NSScreen mainScreen] backingScaleFactor];
+#else
+ if (window) {
+ return [window userSpaceScaleFactor];
+ }
+ return [[NSScreen mainScreen] userSpaceScaleFactor];
+#endif
+}
+
+- (void)backingPropertiesChanged:(NSNotification *)notification {
+ CGFloat oldBackingScaleFactor = [
+ [notification.userInfo objectForKey:@"NSBackingPropertyOldScaleFactorKey"] doubleValue
+ ];
+ CGFloat newBackingScaleFactor = [self scaleFactor];
+ if (oldBackingScaleFactor == newBackingScaleFactor) {
+ return;
+ }
+
+ // TODO: need a better way to force a refresh (that works).
+ // [fGLContext update] does not appear to update if the point size has not changed,
+ // even if the backing size has changed.
+ [self setFrameSize:NSMakeSize(self.frame.size.width + 1, self.frame.size.height + 1)];
+}
+
- (void)resizeSkView:(NSSize)newSize {
- if (NULL != fWind && (fWind->width() != newSize.width || fWind->height() != newSize.height)) {
+#if RETINA_API_AVAILABLE
+ newSize = [self convertSizeToBacking:newSize];
+#endif
+ if (NULL != fWind &&
+ (fWind->width() != newSize.width ||
+ fWind->height() != newSize.height))
+ {
fWind->resize((int) newSize.width, (int) newSize.height);
if (NULL != fGLContext) {
glClear(GL_STENCIL_BUFFER_BIT);
+ [fGLContext update];
}
- [fGLContext update];
}
}
@@ -219,6 +269,10 @@ static unsigned convertNSModifiersToSk(NSUInteger nsModi) {
if ([self mouse:p inRect:[self bounds]] && NULL != fWind) {
NSPoint loc = [self convertPoint:p fromView:nil];
+#if RETINA_API_AVAILABLE
+ loc = [self convertPointToBacking:loc]; //y-up
+ loc.y = -loc.y;
+#endif
fWind->handleClick((int) loc.x, (int) loc.y,
SkView::Click::kDown_State, self, modi);
}
@@ -230,6 +284,10 @@ static unsigned convertNSModifiersToSk(NSUInteger nsModi) {
if ([self mouse:p inRect:[self bounds]] && NULL != fWind) {
NSPoint loc = [self convertPoint:p fromView:nil];
+#if RETINA_API_AVAILABLE
+ loc = [self convertPointToBacking:loc]; //y-up
+ loc.y = -loc.y;
+#endif
fWind->handleClick((int) loc.x, (int) loc.y,
SkView::Click::kMoved_State, self, modi);
}
@@ -241,6 +299,10 @@ static unsigned convertNSModifiersToSk(NSUInteger nsModi) {
if ([self mouse:p inRect:[self bounds]] && NULL != fWind) {
NSPoint loc = [self convertPoint:p fromView:nil];
+#if RETINA_API_AVAILABLE
+ loc = [self convertPointToBacking:loc]; //y-up
+ loc.y = -loc.y;
+#endif
fWind->handleClick((int) loc.x, (int) loc.y,
SkView::Click::kMoved_State, self, modi);
}
@@ -252,6 +314,10 @@ static unsigned convertNSModifiersToSk(NSUInteger nsModi) {
if ([self mouse:p inRect:[self bounds]] && NULL != fWind) {
NSPoint loc = [self convertPoint:p fromView:nil];
+#if RETINA_API_AVAILABLE
+ loc = [self convertPointToBacking:loc]; //y-up
+ loc.y = -loc.y;
+#endif
fWind->handleClick((int) loc.x, (int) loc.y,
SkView::Click::kUp_State, self, modi);
}
@@ -329,7 +395,11 @@ CGLContextObj createGLContext(int msaaSampleCount) {
CGLPixelFormatObj format = CGLGetPixelFormat((CGLContextObj)[fGLContext CGLContextObj]);
CGLDescribePixelFormat(format, 0, kCGLPFASamples, &info->fSampleCount);
CGLDescribePixelFormat(format, 0, kCGLPFAStencilSize, &info->fStencilBits);
- glViewport(0, 0, (int) self.bounds.size.width, (int) self.bounds.size.width);
+ NSSize size = self.bounds.size;
+#if RETINA_API_AVAILABLE
+ size = [self convertSizeToBacking:size];
+#endif
+ glViewport(0, 0, (int) size.width, (int) size.height);
glClearColor(0, 0, 0, 0);
glClearStencil(0);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);