зеркало из https://github.com/mozilla/moz-skia.git
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
This commit is contained in:
Родитель
572b54dd7a
Коммит
b20a1b56a0
|
@ -28,5 +28,7 @@
|
||||||
<string>SampleApp</string>
|
<string>SampleApp</string>
|
||||||
<key>NSPrincipalClass</key>
|
<key>NSPrincipalClass</key>
|
||||||
<string>NSApplication</string>
|
<string>NSApplication</string>
|
||||||
|
<key>NSHighResolutionCapable</key>
|
||||||
|
<true/>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|
|
@ -13,6 +13,9 @@
|
||||||
SK_COMPILE_ASSERT(SK_SUPPORT_GPU, not_implemented_for_non_gpu_build);
|
SK_COMPILE_ASSERT(SK_SUPPORT_GPU, not_implemented_for_non_gpu_build);
|
||||||
|
|
||||||
//#define FORCE_REDRAW
|
//#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
|
@implementation SkNSView
|
||||||
@synthesize fWind, fTitle, fOptionsDelegate, fGLContext;
|
@synthesize fWind, fTitle, fOptionsDelegate, fGLContext;
|
||||||
|
|
||||||
|
@ -33,15 +36,26 @@ SK_COMPILE_ASSERT(SK_SUPPORT_GPU, not_implemented_for_non_gpu_build);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithDefaults {
|
- (id)initWithDefaults {
|
||||||
|
#if RETINA_API_AVAILABLE
|
||||||
|
[self setWantsBestResolutionOpenGLSurface:YES];
|
||||||
|
#endif
|
||||||
fRedrawRequestPending = false;
|
fRedrawRequestPending = false;
|
||||||
fWind = NULL;
|
fWind = NULL;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setUpWindow {
|
- (void)setUpWindow {
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(backingPropertiesChanged:)
|
||||||
|
name:@"NSWindowDidChangeBackingPropertiesNotification"
|
||||||
|
object:[self window]];
|
||||||
if (NULL != fWind) {
|
if (NULL != fWind) {
|
||||||
fWind->setVisibleP(true);
|
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);
|
SkBitmap::kARGB_8888_Config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,13 +68,49 @@ SK_COMPILE_ASSERT(SK_SUPPORT_GPU, not_implemented_for_non_gpu_build);
|
||||||
return YES;
|
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 {
|
- (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);
|
fWind->resize((int) newSize.width, (int) newSize.height);
|
||||||
if (NULL != fGLContext) {
|
if (NULL != fGLContext) {
|
||||||
glClear(GL_STENCIL_BUFFER_BIT);
|
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) {
|
if ([self mouse:p inRect:[self bounds]] && NULL != fWind) {
|
||||||
NSPoint loc = [self convertPoint:p fromView:nil];
|
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,
|
fWind->handleClick((int) loc.x, (int) loc.y,
|
||||||
SkView::Click::kDown_State, self, modi);
|
SkView::Click::kDown_State, self, modi);
|
||||||
}
|
}
|
||||||
|
@ -230,6 +284,10 @@ static unsigned convertNSModifiersToSk(NSUInteger nsModi) {
|
||||||
|
|
||||||
if ([self mouse:p inRect:[self bounds]] && NULL != fWind) {
|
if ([self mouse:p inRect:[self bounds]] && NULL != fWind) {
|
||||||
NSPoint loc = [self convertPoint:p fromView:nil];
|
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,
|
fWind->handleClick((int) loc.x, (int) loc.y,
|
||||||
SkView::Click::kMoved_State, self, modi);
|
SkView::Click::kMoved_State, self, modi);
|
||||||
}
|
}
|
||||||
|
@ -241,6 +299,10 @@ static unsigned convertNSModifiersToSk(NSUInteger nsModi) {
|
||||||
|
|
||||||
if ([self mouse:p inRect:[self bounds]] && NULL != fWind) {
|
if ([self mouse:p inRect:[self bounds]] && NULL != fWind) {
|
||||||
NSPoint loc = [self convertPoint:p fromView:nil];
|
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,
|
fWind->handleClick((int) loc.x, (int) loc.y,
|
||||||
SkView::Click::kMoved_State, self, modi);
|
SkView::Click::kMoved_State, self, modi);
|
||||||
}
|
}
|
||||||
|
@ -252,6 +314,10 @@ static unsigned convertNSModifiersToSk(NSUInteger nsModi) {
|
||||||
|
|
||||||
if ([self mouse:p inRect:[self bounds]] && NULL != fWind) {
|
if ([self mouse:p inRect:[self bounds]] && NULL != fWind) {
|
||||||
NSPoint loc = [self convertPoint:p fromView:nil];
|
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,
|
fWind->handleClick((int) loc.x, (int) loc.y,
|
||||||
SkView::Click::kUp_State, self, modi);
|
SkView::Click::kUp_State, self, modi);
|
||||||
}
|
}
|
||||||
|
@ -329,7 +395,11 @@ CGLContextObj createGLContext(int msaaSampleCount) {
|
||||||
CGLPixelFormatObj format = CGLGetPixelFormat((CGLContextObj)[fGLContext CGLContextObj]);
|
CGLPixelFormatObj format = CGLGetPixelFormat((CGLContextObj)[fGLContext CGLContextObj]);
|
||||||
CGLDescribePixelFormat(format, 0, kCGLPFASamples, &info->fSampleCount);
|
CGLDescribePixelFormat(format, 0, kCGLPFASamples, &info->fSampleCount);
|
||||||
CGLDescribePixelFormat(format, 0, kCGLPFAStencilSize, &info->fStencilBits);
|
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);
|
glClearColor(0, 0, 0, 0);
|
||||||
glClearStencil(0);
|
glClearStencil(0);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче