Allow sparse rendering while resizing/moving application on Windows

This commit is contained in:
Joshua Granick
2020-03-10 13:04:58 -07:00
parent 17aa0bfd32
commit c873ff2f2e
2 changed files with 54 additions and 0 deletions

View File

@@ -7,6 +7,11 @@
#include <CoreFoundation/CoreFoundation.h>
#endif
#ifdef HX_WINDOWS
#include <windows.h>
#include <SDL_syswm.h>
#endif
#ifdef EMSCRIPTEN
#include "emscripten.h"
#endif
@@ -21,6 +26,8 @@ namespace lime {
const int analogAxisDeadZone = 1000;
std::map<int, std::map<int, int> > gamepadsAxisMap;
bool inBackground = false;
bool winTimerActive = false;
int winTimerID = 1;
SDLApplication::SDLApplication () {
@@ -325,6 +332,11 @@ namespace lime {
lastUpdate = SDL_GetTicks ();
nextUpdate = lastUpdate;
#ifdef HX_WINDOWS
SDL_AddEventWatch (SDLApplication::WatchEvent, nullptr);
SDL_EventState (SDL_SYSWMEVENT, SDL_ENABLE);
#endif
}
@@ -875,6 +887,15 @@ namespace lime {
while (SDL_PollEvent (&event)) {
#ifdef HX_WINDOWS
if (winTimerActive) {
KillTimer (GetActiveWindow (), winTimerID);
winTimerActive = false;
}
#endif
HandleEvent (&event);
event.type = -1;
if (!active)
@@ -982,6 +1003,38 @@ namespace lime {
}
int SDLApplication::WatchEvent (void* userData, SDL_Event* event) {
#ifdef HX_WINDOWS
if (event->type == SDL_SYSWMEVENT) {
const auto& message = event->syswm.msg->msg.win;
if (message.msg == WM_ENTERSIZEMOVE) {
winTimerActive = SetTimer (GetActiveWindow (), winTimerID, currentApplication->framePeriod, nullptr);
// TODO: Are we thread-safe to call GL here?
RenderEvent::Dispatch (&currentApplication->renderEvent);
} else if (message.msg == WM_TIMER) {
if (message.wParam == winTimerID) {
RenderEvent::Dispatch (&currentApplication->renderEvent);
}
}
}
#endif
return 0;
}
Application* CreateApplication () {
return new SDLApplication ();

View File

@@ -54,6 +54,7 @@ namespace lime {
static void UpdateFrame ();
static void UpdateFrame (void*);
static int WatchEvent (void* userData, SDL_Event* event);
static SDLApplication* currentApplication;