Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the red flashing during live resize #1418

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/macosx/osxgl.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/


#define GL_SILENCE_DEPRECATION
#include "allegro5/allegro.h"
#include "allegro5/allegro_opengl.h"
#include "allegro5/internal/aintern.h"
Expand Down Expand Up @@ -211,6 +212,8 @@ @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;
Expand Down Expand Up @@ -238,11 +241,13 @@ -(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;
-(void) finishExitingFullScreenWindowMode;
-(void) maximize;
-(void) setFrameSize: (NSSize) newSize;
-(NSRect) windowWillUseStandardFrame:
(NSWindow *) window
defaultFrame: (NSRect) newFrame;
Expand Down Expand Up @@ -561,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;
Expand Down Expand Up @@ -640,6 +650,28 @@ -(void) maximize
[dpy->win performZoom: nil];
}

-(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 resize 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
{
[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
Expand Down Expand Up @@ -2028,6 +2060,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;
}
Expand Down