Ok, heres the code after following your directions:
while (SDL_WaitEvent(g_pEventData))
{
//printf("sdl_refresh(): SDL_PollEvent loop. g_pEventData->type=%d eventCount=%u\n", g_pEventData->type, eventCount);
eventCount--;
if(g_pEventData->type == SDL_QUIT)
{
g_pEventData = NULL;
/*
* SDL system shutdown request. Send to event channel.
*/
SDL_QuitSubSystem(SDL_INIT_VIDEO);
return FALSE;
}
//nonblocking notification to outside world of event goes here regardless of event type.
if (ERROR_SUCCESS != dwRetVal)
{
LOG("sdl_refresh: Notify failed with error(%d).\n",
dwRetVal);
}
switch (g_pEventData->type)
{
case SDL_VIDEOEXPOSE:
sdl_update();
break;
case SDL_VIDEORESIZE:
boRetval = sdl_scale(g_pEventData->resize.w, g_pEventData->resize.h);
if (!boRetval)
{
return FALSE;
}
break;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
/*
* Sleep is to allow event handling to sync.
* Without this sleep the Mouse scroll does not work.
* This sleep gives that extra 5 milliseconds to Source
* to process the Mouse Scroll event, before it is overwritten
* by next event, which happens quite fast in case of
* scroll.
*/
Sleep(5);
break;
}
//SDL_Delay(10);
}
Even with the change, I still see the performance issue. Now that I think about it, the behavior matches what wintertime and Kylotan said of a queue getting full. When I move the mouse in circles, I'm generating a lot of MOUSE_MOVEMENT events, and after a few seconds of doing that I see the lagging perf issue, which behaves like a buffer getting full and using high CPU to process all the events. After I stop moving the mouse, it seems like the queue might be getting drained, and the perf goes back to normal again. But we should also keep in mind that I'm using SDL_WaitEvent rather than SDL_PollEvent, and that this loop is on the main thread (called from main).
Heres where I got the recommendation to call SDL_Delay():
http://www.sdltutorials.com/huh-my-pong-clone-uses-100-percent-cpu-and-is-still-slow
https://forums.libsdl.org/viewtopic.php?p=11173