redraw during live resize operations

This commit is contained in:
Martin Fouilleul 2022-08-15 23:11:13 +02:00
parent e22893e9ea
commit beffc60634
2 changed files with 55 additions and 1 deletions

View File

@ -342,6 +342,9 @@ void mp_set_target_fps(u32 fps); // or use wait vblank?
void mp_pump_events(f64 timeout);
bool mp_next_event(mp_event* event);
typedef void(*mp_live_resize_callback)(mp_event event, void* data);
void mp_set_live_resize_callback(mp_live_resize_callback callback, void* data);
//--------------------------------------------------------------------
// Input state polling
//--------------------------------------------------------------------

View File

@ -171,6 +171,11 @@ struct mp_app_data
mp_input_state inputState;
ringbuffer eventQueue;
mp_live_resize_callback liveResizeCallback;
void* liveResizeData;
CVDisplayLinkRef displayLink;
mp_frame_stats frameStats;
NSTimer* frameTimer;
@ -181,7 +186,6 @@ struct mp_app_data
mp_view_data viewPool[MP_APP_MAX_VIEWS];
list_info viewFreeList;
TISInputSourceRef kbLayoutInputSource;
void* kbLayoutUnicodeData;
id kbLayoutListener;
@ -839,9 +843,26 @@ static void mp_queue_event(mp_event* event)
mp_rect viewFrame = {0, 0, contentRect.size.width, contentRect.size.height};
mp_view_set_frame(mpWindow->mainView, viewFrame);
if(__mpAppData.liveResizeCallback)
{
__mpAppData.liveResizeCallback(event, __mpAppData.liveResizeData);
}
//TODO: also ensure we don't overflow the queue during live resize...
mp_queue_event(&event);
}
-(void)windowWillStartLiveResize:(NSNotification *)notification
{
CVDisplayLinkStart(__mpAppData.displayLink);
}
-(void)windowDidEndLiveResize:(NSNotification *)notification
{
CVDisplayLinkStop(__mpAppData.displayLink);
}
- (void)windowWillClose:(NSNotification *)notification
{
mpWindow->nsWindow = nil;
@ -1297,6 +1318,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
{
}
@end //@implementation MPNativeView
/*
@ -1326,6 +1348,25 @@ f64 mp_get_elapsed_seconds()
}
*/
CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink,
const CVTimeStamp *inNow,
const CVTimeStamp *inOutputTime,
CVOptionFlags flagsIn,
CVOptionFlags *flagsOut,
void *displayLinkContext)
{
if(__mpAppData.liveResizeCallback)
{
mp_event event = {};
event.type = MP_EVENT_FRAME;
__mpAppData.liveResizeCallback(event, __mpAppData.liveResizeData);
}
return(0);
}
//***************************************************************
// public API
//***************************************************************
@ -1367,6 +1408,10 @@ void mp_init()
LOG_MESSAGE("run application\n");
[NSApp run];
CGDirectDisplayID displayID = CGMainDisplayID();
CVDisplayLinkCreateWithCGDisplay(displayID, &__mpAppData.displayLink);
CVDisplayLinkSetOutputCallback(__mpAppData.displayLink, DisplayLinkCallback, 0);
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
[NSApp activateIgnoringOtherApps:YES];
@ -1993,6 +2038,12 @@ void mp_end_frame()
// Events handling
//--------------------------------------------------------------------
void mp_set_live_resize_callback(mp_live_resize_callback callback, void* data)
{
__mpAppData.liveResizeCallback = callback;
__mpAppData.liveResizeData = data;
}
void mp_pump_events(f64 timeout)
{
__mpAppData.inputState.frameCounter++;