Skip to content

Commit

Permalink
Fixed automation tests using the dummy video driver
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jul 25, 2023
1 parent a16b241 commit b8d9125
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 23 deletions.
32 changes: 24 additions & 8 deletions src/events/SDL_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ int SDL_InitMouse(void)

mouse->cursor_shown = SDL_TRUE;

if (!mouse->CreateCursor) {
SDL_Surface *surface = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_ARGB8888);
if (surface) {
SDL_memset(surface->pixels, 0, (size_t)surface->h * surface->pitch);
SDL_SetDefaultCursor(SDL_CreateColorCursor(surface, 0, 0));
SDL_DestroySurface(surface);
}
}
return 0;
}

Expand Down Expand Up @@ -846,8 +854,12 @@ void SDL_QuitMouse(void)
mouse->cursors = NULL;
mouse->cur_cursor = NULL;

if (mouse->def_cursor && mouse->FreeCursor) {
mouse->FreeCursor(mouse->def_cursor);
if (mouse->def_cursor) {
if (mouse->FreeCursor) {
mouse->FreeCursor(mouse->def_cursor);
} else {
SDL_free(mouse->def_cursor);
}
mouse->def_cursor = NULL;
}

Expand Down Expand Up @@ -1220,11 +1232,6 @@ SDL_Cursor *SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y)
return NULL;
}

if (!mouse->CreateCursor) {
SDL_SetError("Cursors are not currently supported");
return NULL;
}

/* Sanity check the hot spot */
if ((hot_x < 0) || (hot_y < 0) ||
(hot_x >= surface->w) || (hot_y >= surface->h)) {
Expand All @@ -1240,7 +1247,14 @@ SDL_Cursor *SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y)
surface = temp;
}

cursor = mouse->CreateCursor(surface, hot_x, hot_y);
if (mouse->CreateCursor) {
cursor = mouse->CreateCursor(surface, hot_x, hot_y);
} else {
cursor = SDL_calloc(1, sizeof(*cursor));
if (!cursor) {
SDL_OutOfMemory();
}
}
if (cursor) {
cursor->next = mouse->cursors;
mouse->cursors = cursor;
Expand Down Expand Up @@ -1365,6 +1379,8 @@ void SDL_DestroyCursor(SDL_Cursor *cursor)

if (mouse->FreeCursor) {
mouse->FreeCursor(curr);
} else {
SDL_free(curr);
}
return;
}
Expand Down
32 changes: 24 additions & 8 deletions src/video/SDL_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -1607,9 +1607,18 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
}
if (_this->SetWindowFullscreen) {
_this->SetWindowFullscreen(_this, window, display, SDL_TRUE);
} else {
resized = SDL_TRUE;
}
display->fullscreen_window = window;

if (mode) {
mode_w = mode->w;
mode_h = mode->h;
} else {
mode_w = display->desktop_mode.w;
mode_h = display->desktop_mode.h;
}
#ifdef __ANDROID__
/* Android may not resize the window to exactly what our fullscreen mode is,
* especially on windowed Android environments like the Chromebook or Samsung DeX.
Expand All @@ -1621,13 +1630,6 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
* WM_WINDOWPOSCHANGED will send SDL_EVENT_WINDOW_RESIZED).
*/
#else
if (mode) {
mode_w = mode->w;
mode_h = mode->h;
} else {
mode_w = display->desktop_mode.w;
mode_h = display->desktop_mode.h;
}
if (window->w != mode_w || window->h != mode_h) {
resized = SDL_TRUE;
}
Expand All @@ -1642,14 +1644,22 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
SDL_RestoreMousePosition(window);

} else {
SDL_bool resized = SDL_FALSE;

/* Restore the desktop mode */
SDL_SetDisplayModeForDisplay(display, NULL);
if (_this->SetWindowFullscreen) {
_this->SetWindowFullscreen(_this, window, display, SDL_FALSE);
} else {
resized = SDL_TRUE;
}
display->fullscreen_window = NULL;

SDL_OnWindowResized(window);
if (resized) {
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, window->windowed.w, window->windowed.h);
} else {
SDL_OnWindowResized(window);
}

/* Restore the cursor position */
SDL_RestoreMousePosition(window);
Expand Down Expand Up @@ -2804,6 +2814,9 @@ int SDL_ShowWindow(SDL_Window *window)

if (_this->ShowWindow) {
_this->ShowWindow(_this, window);
} else {
SDL_SetMouseFocus(window);
SDL_SetKeyboardFocus(window);
}
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_SHOWN, 0, 0);

Expand Down Expand Up @@ -2847,6 +2860,9 @@ int SDL_HideWindow(SDL_Window *window)
window->is_hiding = SDL_TRUE;
if (_this->HideWindow) {
_this->HideWindow(_this, window);
} else {
SDL_SetMouseFocus(NULL);
SDL_SetKeyboardFocus(NULL);
}
window->is_hiding = SDL_FALSE;
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_HIDDEN, 0, 0);
Expand Down
7 changes: 0 additions & 7 deletions src/video/dummy/SDL_nullvideo.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@

/* Initialization/Query functions */
static int DUMMY_VideoInit(SDL_VideoDevice *_this);
static int DUMMY_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
static void DUMMY_VideoQuit(SDL_VideoDevice *_this);

/* DUMMY driver bootstrap functions */
Expand Down Expand Up @@ -93,7 +92,6 @@ static SDL_VideoDevice *DUMMY_InternalCreateDevice(const char *enable_hint)
/* Set the function pointers */
device->VideoInit = DUMMY_VideoInit;
device->VideoQuit = DUMMY_VideoQuit;
device->SetDisplayMode = DUMMY_SetDisplayMode;
device->PumpEvents = DUMMY_PumpEvents;
device->CreateWindowFramebuffer = SDL_DUMMY_CreateWindowFramebuffer;
device->UpdateWindowFramebuffer = SDL_DUMMY_UpdateWindowFramebuffer;
Expand Down Expand Up @@ -158,11 +156,6 @@ int DUMMY_VideoInit(SDL_VideoDevice *_this)
return 0;
}

static int DUMMY_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
{
return 0;
}

void DUMMY_VideoQuit(SDL_VideoDevice *_this)
{
#ifdef SDL_INPUT_LINUXEV
Expand Down
2 changes: 2 additions & 0 deletions test/testautomation_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ static int video_createWindowVariousFlags(void *arg)
break;
case 2:
flags = SDL_WINDOW_OPENGL;
/* Skip - not every video driver supports OpenGL; comment out next line to run test */
continue;
break;
case 3:
flags = 0;
Expand Down

0 comments on commit b8d9125

Please sign in to comment.