Skip to content

Commit

Permalink
SDL: Add Suspend/Resume handlers for GDK
Browse files Browse the repository at this point in the history
  • Loading branch information
flibitijibibo committed Dec 20, 2024
1 parent ebfa3c6 commit b288d4d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/FNA3D_Driver_SDL.c
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,23 @@ static void SDLGPU_SwapBuffers(
SDL_UnlockMutex(renderer->copyPassMutex);
}

/* GDK Support */

#if SDL_PLATFORM_GDK
static bool SDLCALL SDLGPU_INTERNAL_GDKEventFilter(void* userdata, SDL_Event* event)
{
if (event->type == SDL_EVENT_DID_ENTER_BACKGROUND)
{
SDL_GDKSuspendGPU((SDL_GPUDevice*) userdata);
}
else if (event->type == SDL_EVENT_WILL_ENTER_FOREGROUND)
{
SDL_GDKResumeGPU((SDL_GPUDevice*) userdata);
}
return true;
}
#endif

/* Drawing */

static void SDLGPU_INTERNAL_PrepareRenderPassClear(
Expand Down Expand Up @@ -4120,6 +4137,10 @@ static void SDLGPU_DestroyDevice(FNA3D_Device *device)

MOJOSHADER_sdlDestroyContext(renderer->mojoshaderContext);

#if SDL_PLATFORM_GDK
SDL_RemoveEventWatch(SDLGPU_INTERNAL_GDKEventFilter, renderer->device);
#endif

SDL_DestroyGPUDevice(renderer->device);

SDL_free(renderer);
Expand Down Expand Up @@ -4473,6 +4494,10 @@ static FNA3D_Device* SDLGPU_CreateDevice(
renderer->fenceGroups[i][1] = NULL;
}

#if SDL_PLATFORM_GDK
SDL_AddEventWatch(SDLGPU_INTERNAL_GDKEventFilter, renderer->device);
#endif

return result;
}

Expand Down

0 comments on commit b288d4d

Please sign in to comment.