From 8aaf4ea0987a361e5d4f7b690544ee9119746660 Mon Sep 17 00:00:00 2001 From: Michael Lutz Date: Sat, 30 Jan 2021 19:13:29 +0100 Subject: Codechange: [OSX] Split Window and back buffer creation in Cocoa video driver. --- src/video/cocoa/cocoa_wnd.mm | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'src/video/cocoa/cocoa_wnd.mm') diff --git a/src/video/cocoa/cocoa_wnd.mm b/src/video/cocoa/cocoa_wnd.mm index ff222ea42..80c2e2e21 100644 --- a/src/video/cocoa/cocoa_wnd.mm +++ b/src/video/cocoa/cocoa_wnd.mm @@ -324,10 +324,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel { [ super setFrame:frameRect display:flag ]; - /* Don't do anything if the window is currently being created */ - if (driver->setup) return; - - if (!driver->WindowResized()) error("Cocoa: Failed to resize window."); + driver->AllocateBackingStore(); } /** * Handle hiding of the application @@ -401,12 +398,13 @@ static const char *Utf8AdvanceByUtf16Units(const char *str, NSUInteger count) } @implementation OTTD_CocoaView -/** - * Initialize the driver - */ -- (void)setDriver:(VideoDriver_Cocoa *)drv + +- (instancetype)initWithFrame:(NSRect)frameRect andDriver:(VideoDriver_Cocoa *)drv { - driver = drv; + if (self = [ super initWithFrame:frameRect ]) { + self->driver = drv; + } + return self; } /** * Define the opaqueness of the window / screen @@ -810,9 +808,12 @@ static const char *Utf8AdvanceByUtf16Units(const char *str, NSUInteger count) @implementation OTTD_CocoaWindowDelegate /** Initialize the video driver */ -- (void)setDriver:(VideoDriver_Cocoa *)drv +- (instancetype)initWithDriver:(VideoDriver_Cocoa *)drv { - driver = drv; + if (self = [ super init ]) { + self->driver = drv; + } + return self; } /** Handle closure requests */ - (BOOL)windowShouldClose:(id)sender @@ -854,10 +855,11 @@ static const char *Utf8AdvanceByUtf16Units(const char *str, NSUInteger count) [ e release ]; } } -/** The colour profile of the screen the window is on changed. */ -- (void)windowDidChangeScreenProfile:(NSNotification *)aNotification +/** Screen the window is on changed. */ +- (void)windowDidChangeBackingProperties:(NSNotification *)notification { - if (!driver->setup) driver->WindowResized(); + /* Reallocate screen buffer if necessary. */ + driver->AllocateBackingStore(); } /** Presentation options to use for fullsreen mode. */ @@ -867,4 +869,5 @@ static const char *Utf8AdvanceByUtf16Units(const char *str, NSUInteger count) } @end + #endif /* WITH_COCOA */ -- cgit v1.2.3-54-g00ecf