Skip to content

Commit

Permalink
DisplayYUVOverlay: Don't update screen surface if clean
Browse files Browse the repository at this point in the history
Currently, if there are multiple SDL_DisplayYUVOverlay() calls in a row,
we force an SDL_Flip() between them, in order to make sure that the
screen is updated. However, this results in the non-YUV video surface
also being updated, even if it otherwise wouldn't be.

Instead, copy the code from all of the other places where we force an
update of the screen, which checks if the surface is dirty, and if not
calls PresentScreen() directly without updating the VideoSurface. (After
checking we're in the correct thread, of course...)

This hopefully fixes video artefacts in Alpha Centauri (bug libsdl-org#279)
  • Loading branch information
sulix committed Nov 27, 2022
1 parent 484c6a8 commit 7322d16
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/SDL12_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -7474,6 +7474,7 @@ SDL_DisplayYUVOverlay(SDL12_Overlay *overlay12, SDL12_Rect *dstrect12)
QueuedOverlayItem *overlay;
SDL12_YUVData *hwdata;
SDL_Renderer *renderer = NULL;
const SDL_bool ThisIsSetVideoModeThread = (SDL20_ThreadID() == SetVideoModeThread) ? SDL_TRUE : SDL_FALSE;

if (!overlay12) {
return SDL20_InvalidParamError("overlay");
Expand All @@ -7485,7 +7486,15 @@ SDL_DisplayYUVOverlay(SDL12_Overlay *overlay12, SDL12_Rect *dstrect12)

for (overlay = QueuedDisplayOverlays.next; overlay != NULL; overlay = overlay->next) {
if (overlay->overlay12 == overlay12) { /* trying to draw the same overlay twice in one frame? Dump the current surface and overlays to the screen now. */
SDL_Flip(VideoSurface12);
/* Force an update of the screen. */
if (ThisIsSetVideoModeThread) {
if (VideoSurfaceUpdatedInBackgroundThread) {
SDL_Flip(VideoSurface12); /* this will update the texture and present. */
} else if (VideoSurfacePresentTicks) {
PresentScreen();
}
}

break;
}
}
Expand Down

0 comments on commit 7322d16

Please sign in to comment.