Fix crash of accessing mainScreen from background thread on 10.11.
This commit is contained in:
parent
2e63d0061d
commit
30c9563511
|
@ -132,7 +132,13 @@
|
|||
#elif SD_UIKIT
|
||||
CGFloat screenScale = [UIScreen mainScreen].scale;
|
||||
#elif SD_MAC
|
||||
CGFloat screenScale = [NSScreen mainScreen].backingScaleFactor;
|
||||
NSScreen *mainScreen = nil;
|
||||
if (@available(macOS 10.12, *)) {
|
||||
mainScreen = [NSScreen mainScreen];
|
||||
} else {
|
||||
mainScreen = [NSScreen screens].firstObject;
|
||||
}
|
||||
CGFloat screenScale = mainScreen.backingScaleFactor ?: 1.0f;
|
||||
#endif
|
||||
self.scale = screenScale;
|
||||
self.opaque = NO;
|
||||
|
@ -166,7 +172,13 @@
|
|||
#elif SD_UIKIT
|
||||
CGFloat screenScale = [UIScreen mainScreen].scale;
|
||||
#elif SD_MAC
|
||||
CGFloat screenScale = [NSScreen mainScreen].backingScaleFactor;
|
||||
NSScreen *mainScreen = nil;
|
||||
if (@available(macOS 10.12, *)) {
|
||||
mainScreen = [NSScreen mainScreen];
|
||||
} else {
|
||||
mainScreen = [NSScreen screens].firstObject;
|
||||
}
|
||||
CGFloat screenScale = mainScreen.backingScaleFactor ?: 1.0f;
|
||||
#endif
|
||||
self.scale = screenScale;
|
||||
self.opaque = NO;
|
||||
|
|
|
@ -17,7 +17,13 @@ static void *kNSGraphicsContextScaleFactorKey;
|
|||
static CGContextRef SDCGContextCreateBitmapContext(CGSize size, BOOL opaque, CGFloat scale) {
|
||||
if (scale == 0) {
|
||||
// Match `UIGraphicsBeginImageContextWithOptions`, reset to the scale factor of the device’s main screen if scale is 0.
|
||||
scale = [NSScreen mainScreen].backingScaleFactor;
|
||||
NSScreen *mainScreen = nil;
|
||||
if (@available(macOS 10.12, *)) {
|
||||
mainScreen = [NSScreen mainScreen];
|
||||
} else {
|
||||
mainScreen = [NSScreen screens].firstObject;
|
||||
}
|
||||
scale = mainScreen.backingScaleFactor ?: 1.0f;
|
||||
}
|
||||
size_t width = ceil(size.width * scale);
|
||||
size_t height = ceil(size.height * scale);
|
||||
|
@ -106,7 +112,13 @@ UIImage * SDGraphicsGetImageFromCurrentImageContext(void) {
|
|||
}
|
||||
if (!scale) {
|
||||
// reset to the scale factor of the device’s main screen if scale is 0.
|
||||
scale = [NSScreen mainScreen].backingScaleFactor;
|
||||
NSScreen *mainScreen = nil;
|
||||
if (@available(macOS 10.12, *)) {
|
||||
mainScreen = [NSScreen mainScreen];
|
||||
} else {
|
||||
mainScreen = [NSScreen screens].firstObject;
|
||||
}
|
||||
scale = mainScreen.backingScaleFactor ?: 1.0f;
|
||||
}
|
||||
NSImage *image = [[NSImage alloc] initWithCGImage:imageRef scale:scale orientation:kCGImagePropertyOrientationUp];
|
||||
CGImageRelease(imageRef);
|
||||
|
|
|
@ -28,7 +28,13 @@ inline CGFloat SDImageScaleFactorForKey(NSString * _Nullable key) {
|
|||
#elif SD_UIKIT
|
||||
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
|
||||
#elif SD_MAC
|
||||
if ([[NSScreen mainScreen] respondsToSelector:@selector(backingScaleFactor)])
|
||||
NSScreen *mainScreen = nil;
|
||||
if (@available(macOS 10.12, *)) {
|
||||
mainScreen = [NSScreen mainScreen];
|
||||
} else {
|
||||
mainScreen = [NSScreen screens].firstObject;
|
||||
}
|
||||
if ([mainScreen respondsToSelector:@selector(backingScaleFactor)])
|
||||
#endif
|
||||
{
|
||||
// a@2x.png -> 8
|
||||
|
|
|
@ -18,7 +18,13 @@ static NSArray *SDBundlePreferredScales() {
|
|||
#elif SD_UIKIT
|
||||
CGFloat screenScale = [UIScreen mainScreen].scale;
|
||||
#elif SD_MAC
|
||||
CGFloat screenScale = [NSScreen mainScreen].backingScaleFactor;
|
||||
NSScreen *mainScreen = nil;
|
||||
if (@available(macOS 10.12, *)) {
|
||||
mainScreen = [NSScreen mainScreen];
|
||||
} else {
|
||||
mainScreen = [NSScreen screens].firstObject;
|
||||
}
|
||||
CGFloat screenScale = mainScreen.backingScaleFactor ?: 1.0f;
|
||||
#endif
|
||||
if (screenScale <= 1) {
|
||||
scales = @[@1,@2,@3];
|
||||
|
|
Loading…
Reference in New Issue