Skip to content

Commit

Permalink
Fixed bug 5171 - PollEvent impacts performance in 2.0.12
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
slouken committed Jun 10, 2020
1 parent 511a970 commit 44f50c6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/video/windows/SDL_windowsevents.c
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/video/windows/SDL_windowswindow.c
Expand Up @@ -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>
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -969,6 +969,7 @@ WIN_UpdateClipCursor(SDL_Window *window)
ClipCursor(NULL);
SDL_zero(data->cursor_clipped_rect);
}
data->last_updated_clipcursor = SDL_GetTicks();
}

int
Expand Down
1 change: 1 addition & 0 deletions src/video/windows/SDL_windowswindow.h
Expand Up @@ -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;
Expand Down

0 comments on commit 44f50c6

Please sign in to comment.