diff options
author | Michael Lutz <michi@icosahedron.de> | 2019-09-14 16:31:37 +0200 |
---|---|---|
committer | Charles Pigott <charlespigott@googlemail.com> | 2019-09-16 19:11:08 +0100 |
commit | 994664dec590b7b8f406d3c2ecc153e77630b1db (patch) | |
tree | 602759965e173477d1916ee74f6f39fb2e47400e /src/video | |
parent | d35254139ab6a829e523e76ae902ef8b9ba610f3 (diff) | |
download | openttd-994664dec590b7b8f406d3c2ecc153e77630b1db.tar.xz |
Fix #7644: [OSX] Try to use system colour space to avoid video output performance degradation.
Diffstat (limited to 'src/video')
-rw-r--r-- | src/video/cocoa/wnd_quartz.mm | 53 |
1 files changed, 19 insertions, 34 deletions
diff --git a/src/video/cocoa/wnd_quartz.mm b/src/video/cocoa/wnd_quartz.mm index bd5d8bdaa..4115113cd 100644 --- a/src/video/cocoa/wnd_quartz.mm +++ b/src/video/cocoa/wnd_quartz.mm @@ -106,35 +106,6 @@ public: }; -static CGColorSpaceRef QZ_GetCorrectColorSpace() -{ - static CGColorSpaceRef colorSpace = NULL; - - if (colorSpace == NULL) { -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) - if (MacOSVersionIsAtLeast(10, 5, 0)) { - colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB); - } else -#endif - { -#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) && !defined(HAVE_OSX_1011_SDK) - CMProfileRef sysProfile; - if (CMGetSystemProfile(&sysProfile) == noErr) { - colorSpace = CGColorSpaceCreateWithPlatformColorSpace(sysProfile); - CMCloseProfile(sysProfile); - } -#endif - } - - if (colorSpace == NULL) colorSpace = CGColorSpaceCreateDeviceRGB(); - - if (colorSpace == NULL) error("Could not get system colour space. You might need to recalibrate your monitor."); - } - - return colorSpace; -} - - @implementation OTTD_QuartzView - (void)setDriver:(WindowQuartzSubdriver*)drv @@ -289,9 +260,7 @@ bool WindowQuartzSubdriver::SetVideoMode(int width, int height, int bpp) styleMask:style backing:NSBackingStoreBuffered defer:NO ]; - if ([ this->window respondsToSelector:@selector(setColorSpace:) ]) { - [ this->window setColorSpace:[ [ [ NSColorSpace alloc ] initWithCGColorSpace:QZ_GetCorrectColorSpace() ] autorelease ] ]; - } + if (this->window == nil) { DEBUG(driver, 0, "Could not create the Cocoa window."); this->setup = false; @@ -598,20 +567,36 @@ bool WindowQuartzSubdriver::WindowResized() this->window_width = (int)newframe.size.width; this->window_height = (int)newframe.size.height; + /* Get screen colour space. */ + CGColorSpaceRef color_space = NULL; + +#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6) + if ([ this->window respondsToSelector:@selector(colorSpace) ]) { + color_space = [ [ this->window colorSpace ] CGColorSpace ]; + CGColorSpaceRetain(color_space); + } +#endif +#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) + if (color_space == NULL && MacOSVersionIsAtLeast(10, 5, 0)) color_space = CGColorSpaceCreateWithName(kCGColorSpaceSRGB); +#endif + if (color_space == NULL) color_space = CGColorSpaceCreateDeviceRGB(); + if (color_space == NULL) error("Could not get system colour space. You might need to recalibrate your monitor."); + /* Create Core Graphics Context */ free(this->window_buffer); this->window_buffer = (uint32*)malloc(this->window_width * this->window_height * 4); CGContextRelease(this->cgcontext); this->cgcontext = CGBitmapContextCreate( - this->window_buffer, // data + this->window_buffer, // data this->window_width, // width this->window_height, // height 8, // bits per component this->window_width * 4, // bytes per row - QZ_GetCorrectColorSpace(), // color space + color_space, // color space kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host ); + CGColorSpaceRelease(color_space); assert(this->cgcontext != NULL); CGContextSetShouldAntialias(this->cgcontext, FALSE); |