From 39dff1e1bd5fc60023e3f31a4c1bae8a1c793dfe Mon Sep 17 00:00:00 2001 From: elias Date: Wed, 8 Mar 2023 00:24:05 -0500 Subject: [PATCH 1/3] [WIP] proof of concept to fix the red flashing during live resize --- src/macosx/osxgl.m | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/macosx/osxgl.m b/src/macosx/osxgl.m index fc77b9ad51..45781aee76 100644 --- a/src/macosx/osxgl.m +++ b/src/macosx/osxgl.m @@ -211,6 +211,7 @@ @interface ALOpenGLView : NSOpenGLView { /* This is passed onto the event functions so we know where the event came from */ ALLEGRO_DISPLAY* dpy_ptr; + NSSize frame_size; } -(void)setAllegroDisplay: (ALLEGRO_DISPLAY*) ptr; -(ALLEGRO_DISPLAY*) allegroDisplay; @@ -243,6 +244,7 @@ -(void) enterFullScreenWindowMode; -(void) exitFullScreenWindowMode; -(void) finishExitingFullScreenWindowMode; -(void) maximize; +-(void) setFrameSize: (NSSize) newSize; -(NSRect) windowWillUseStandardFrame: (NSWindow *) window defaultFrame: (NSRect) newFrame; @@ -640,6 +642,17 @@ -(void) maximize [dpy->win performZoom: nil]; } +-(void) setFrameSize: (NSSize) newSize; +{ + frame_size = newSize; +} + +-(void) setRealFrameSize; +{ + [super setFrameSize:frame_size]; +} + + /* Called by NSWindow's zoom: method while determining the frame * a window may be zoomed to. * We use it to update max. constraints values when the window changes @@ -2028,6 +2041,8 @@ static bool acknowledge_resize_display_win_main_thread(ALLEGRO_DISPLAY *d) d->w = NSWidth(content); d->h = NSHeight(content); + ALOpenGLView *view = window.contentView; + [view setRealFrameSize]; return true; } From d576600afa81c100357fc7c9c189c21e68b5fbf7 Mon Sep 17 00:00:00 2001 From: elias Date: Wed, 8 Mar 2023 21:55:31 -0500 Subject: [PATCH 2/3] only defer setFrameSize for a resize, silence macosx.m GL deprecation warnings --- src/macosx/osxgl.m | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/macosx/osxgl.m b/src/macosx/osxgl.m index 45781aee76..3f964d6b65 100644 --- a/src/macosx/osxgl.m +++ b/src/macosx/osxgl.m @@ -16,6 +16,7 @@ */ +#define GL_SILENCE_DEPRECATION #include "allegro5/allegro.h" #include "allegro5/allegro_opengl.h" #include "allegro5/internal/aintern.h" @@ -212,6 +213,7 @@ @interface ALOpenGLView : NSOpenGLView /* This is passed onto the event functions so we know where the event came from */ ALLEGRO_DISPLAY* dpy_ptr; NSSize frame_size; + bool will_resize; } -(void)setAllegroDisplay: (ALLEGRO_DISPLAY*) ptr; -(ALLEGRO_DISPLAY*) allegroDisplay; @@ -239,6 +241,7 @@ -(void) viewDidEndLiveResize; /* Window delegate methods */ -(void) windowDidBecomeMain:(NSNotification*) notification; -(void) windowDidResignMain:(NSNotification*) notification; +-(NSSize) windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize; -(void) windowDidResize:(NSNotification*) notification; -(void) enterFullScreenWindowMode; -(void) exitFullScreenWindowMode; @@ -563,6 +566,11 @@ -(void) windowDidResignMain:(NSNotification*) notification _al_osx_switch_keyboard_focus(dpy_ptr, false); _al_event_source_unlock(src); } +-(NSSize) windowWillResize: (NSWindow*)sender toSize: (NSSize)frameSize +{ + will_resize = true; + return frameSize; +} -(void) windowDidResize:(NSNotification*) notification { (void)notification; @@ -642,14 +650,25 @@ -(void) maximize [dpy->win performZoom: nil]; } --(void) setFrameSize: (NSSize) newSize; +-(void) setFrameSize: (NSSize) newSize { - frame_size = newSize; + // This is called by MacOS to resize the window - and it will call + // glViewport as part of the resize, which will mess up any client + // drawing that is going on in the user thread at the same time. + // So if this was the result of a redraw we defer the call to when + // al_acknowledge_resize is called. + frame_size = newSize; + if (will_resize) { + will_resize = false; + } + else { + [self setRealFrameSize]; + } } --(void) setRealFrameSize; +-(void) setRealFrameSize { - [super setFrameSize:frame_size]; + [super setFrameSize:frame_size]; } From 586a8ec9a0f70dab37b3fd1f8f607c354674aba0 Mon Sep 17 00:00:00 2001 From: elias Date: Wed, 8 Mar 2023 23:46:07 -0500 Subject: [PATCH 3/3] typo --- src/macosx/osxgl.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/macosx/osxgl.m b/src/macosx/osxgl.m index 3f964d6b65..82b23b2248 100644 --- a/src/macosx/osxgl.m +++ b/src/macosx/osxgl.m @@ -655,7 +655,7 @@ -(void) setFrameSize: (NSSize) newSize // This is called by MacOS to resize the window - and it will call // glViewport as part of the resize, which will mess up any client // drawing that is going on in the user thread at the same time. - // So if this was the result of a redraw we defer the call to when + // So if this was the result of a resize we defer the call to when // al_acknowledge_resize is called. frame_size = newSize; if (will_resize) {