|
@@ -247,13 +247,13 @@ class FullscreenSubdriver: public CocoaS
|
|
|
double adjustment = (target - position) / linesPerSecond;
|
|
|
|
|
|
CSleep((uint32)(adjustment * 1000));
|
|
|
}
|
|
|
|
|
|
|
|
|
bool SetVideoMode(int w, int h)
|
|
|
bool SetVideoMode(int w, int h, int bpp)
|
|
|
{
|
|
|
/* Define this variables at the top (against coding style) because
|
|
|
* otherwise GCC 4.2 barfs at the goto's jumping over variable initialization. */
|
|
|
NSRect screen_rect;
|
|
|
int gamma_error;
|
|
|
NSPoint mouseLocation;
|
|
@@ -263,20 +263,20 @@ class FullscreenSubdriver: public CocoaS
|
|
|
free(this->pixel_buffer);
|
|
|
this->pixel_buffer = NULL;
|
|
|
}
|
|
|
|
|
|
/* See if requested mode exists */
|
|
|
boolean_t exact_match;
|
|
|
this->cur_mode = CGDisplayBestModeForParameters(this->display_id, this->device_depth, w, h, &exact_match);
|
|
|
this->cur_mode = CGDisplayBestModeForParameters(this->display_id, bpp, w, h, &exact_match);
|
|
|
|
|
|
/* If the mode wasn't an exact match, check if it has the right bpp, and update width and height */
|
|
|
if (!exact_match) {
|
|
|
int bpp;
|
|
|
int act_bpp;
|
|
|
CFNumberRef number = (const __CFNumber*) CFDictionaryGetValue(this->cur_mode, kCGDisplayBitsPerPixel);
|
|
|
CFNumberGetValue(number, kCFNumberSInt32Type, &bpp);
|
|
|
if (bpp != this->device_depth) {
|
|
|
CFNumberGetValue(number, kCFNumberSInt32Type, &act_bpp);
|
|
|
if (act_bpp != bpp) {
|
|
|
DEBUG(driver, 0, "Failed to find display resolution");
|
|
|
goto ERR_NO_MATCH;
|
|
|
}
|
|
|
|
|
|
number = (const __CFNumber*)CFDictionaryGetValue(this->cur_mode, kCGDisplayWidth);
|
|
|
CFNumberGetValue(number, kCFNumberSInt32Type, &w);
|
|
@@ -320,12 +320,13 @@ class FullscreenSubdriver: public CocoaS
|
|
|
this->window_pitch = CGDisplayBytesPerRow(this->display_id);
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
this->device_width = CGDisplayPixelsWide(this->display_id);
|
|
|
this->device_height = CGDisplayPixelsHigh(this->display_id);
|
|
|
this->device_depth = bpp;
|
|
|
|
|
|
/* Setup double-buffer emulation */
|
|
|
this->pixel_buffer = malloc(this->device_width * this->device_height * this->device_depth / 8);
|
|
|
if (this->pixel_buffer == NULL) {
|
|
|
DEBUG(driver, 0, "Failed to allocate memory for double buffering");
|
|
|
goto ERR_DOUBLEBUF;
|
|
@@ -415,28 +416,24 @@ ERR_NO_MATCH:
|
|
|
|
|
|
this->device_width = CGDisplayPixelsWide(this->display_id);
|
|
|
this->device_height = CGDisplayPixelsHigh(this->display_id);
|
|
|
}
|
|
|
|
|
|
public:
|
|
|
FullscreenSubdriver(int bpp)
|
|
|
FullscreenSubdriver()
|
|
|
{
|
|
|
if (bpp != 8 && bpp != 32) {
|
|
|
error("Cocoa: This video driver only supports 8 and 32 bpp blitters.");
|
|
|
}
|
|
|
|
|
|
/* Initialize the video settings; this data persists between mode switches */
|
|
|
this->display_id = kCGDirectMainDisplay;
|
|
|
this->save_mode = CGDisplayCurrentMode(this->display_id);
|
|
|
|
|
|
if (bpp == 8) this->palette = CGPaletteCreateDefaultColorPalette();
|
|
|
this->palette = CGPaletteCreateDefaultColorPalette();
|
|
|
|
|
|
this->device_width = CGDisplayPixelsWide(this->display_id);
|
|
|
this->device_height = CGDisplayPixelsHigh(this->display_id);
|
|
|
this->device_depth = bpp;
|
|
|
this->pixel_buffer = NULL;
|
|
|
this->device_depth = 0;
|
|
|
this->pixel_buffer = NULL;
|
|
|
|
|
|
this->num_dirty_rects = MAX_DIRTY_RECTS;
|
|
|
}
|
|
|
|
|
|
virtual ~FullscreenSubdriver()
|
|
|
{
|
|
@@ -509,20 +506,22 @@ public:
|
|
|
|
|
|
virtual uint ListModes(OTTD_Point *modes, uint max_modes)
|
|
|
{
|
|
|
return QZ_ListModes(modes, max_modes, this->display_id, this->device_depth);
|
|
|
}
|
|
|
|
|
|
virtual bool ChangeResolution(int w, int h)
|
|
|
virtual bool ChangeResolution(int w, int h, int bpp)
|
|
|
{
|
|
|
int old_width = this->device_width;
|
|
|
int old_height = this->device_height;
|
|
|
int old_bpp = this->device_depth;
|
|
|
|
|
|
if (SetVideoMode(w, h)) return true;
|
|
|
if (bpp != 8 && bpp != 32) error("Cocoa: This video driver only supports 8 and 32 bpp blitters.");
|
|
|
|
|
|
if (old_width != 0 && old_height != 0) SetVideoMode(old_width, old_height);
|
|
|
if (SetVideoMode(w, h, bpp)) return true;
|
|
|
if (old_width != 0 && old_height != 0) SetVideoMode(old_width, old_height, old_bpp);
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
virtual bool IsFullscreen()
|
|
|
{
|
|
@@ -580,15 +579,15 @@ CocoaSubdriver *QZ_CreateFullscreenSubdr
|
|
|
* been removed from the API.
|
|
|
*/
|
|
|
if (MacOSVersionIsAtLeast(10, 7, 0)) {
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
FullscreenSubdriver *ret = new FullscreenSubdriver(bpp);
|
|
|
FullscreenSubdriver *ret = new FullscreenSubdriver();
|
|
|
|
|
|
if (!ret->ChangeResolution(width, height)) {
|
|
|
if (!ret->ChangeResolution(width, height, bpp)) {
|
|
|
delete ret;
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
|
}
|