Fixed bug 5171 - PollEvent impacts performance in 2.0.12 On some systems, GetClipCursor() impacts performance when called frequently, so only call it every once in a while to make sure we haven't lost our capture.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index 52e4603..4ee1b07 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -497,6 +497,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
SDL_SendMouseMotion(data->window, 0, 0, cursorPos.x, cursorPos.y);
WIN_CheckAsyncMouseRelease(data);
+ WIN_UpdateClipCursor(data->window);
/*
* FIXME: Update keyboard state
@@ -1117,11 +1118,19 @@ static void WIN_UpdateClipCursorForWindows()
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
SDL_Window *window;
+ Uint32 now = SDL_GetTicks();
+ const Uint32 CLIPCURSOR_UPDATE_INTERVAL_MS = 3000;
if (_this) {
for (window = _this->windows; window; window = window->next) {
- if (window->driverdata) {
- WIN_UpdateClipCursor(window);
+ SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+ if (data) {
+ if (data->skip_update_clipcursor) {
+ data->skip_update_clipcursor = SDL_FALSE;
+ WIN_UpdateClipCursor(window);
+ } else if ((now - data->last_updated_clipcursor) >= CLIPCURSOR_UPDATE_INTERVAL_MS) {
+ WIN_UpdateClipCursor(window);
+ }
}
}
}
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index ef73142..825680e 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -34,6 +34,7 @@
#include "SDL_windowsvideo.h"
#include "SDL_windowswindow.h"
#include "SDL_hints.h"
+#include "SDL_timer.h"
/* Dropfile support */
#include <shellapi.h>
@@ -926,7 +927,6 @@ WIN_UpdateClipCursor(SDL_Window *window)
return;
}
if (data->skip_update_clipcursor) {
- data->skip_update_clipcursor = SDL_FALSE;
return;
}
if (!GetClipCursor(&clipped_rect)) {
@@ -969,6 +969,7 @@ WIN_UpdateClipCursor(SDL_Window *window)
ClipCursor(NULL);
SDL_zero(data->cursor_clipped_rect);
}
+ data->last_updated_clipcursor = SDL_GetTicks();
}
int
diff --git a/src/video/windows/SDL_windowswindow.h b/src/video/windows/SDL_windowswindow.h
index 574a452..cfbf120 100644
--- a/src/video/windows/SDL_windowswindow.h
+++ b/src/video/windows/SDL_windowswindow.h
@@ -46,6 +46,7 @@ typedef struct
SDL_bool in_title_click;
Uint8 focus_click_pending;
SDL_bool skip_update_clipcursor;
+ Uint32 last_updated_clipcursor;
SDL_bool windowed_mode_was_maximized;
SDL_bool in_window_deactivation;
RECT cursor_clipped_rect;