Skip to content

Commit ac9ef17

Browse files
authored
Avoid RLE for software render alpha subrect copies (#15982)
1 parent df7b937 commit ac9ef17

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/render/software/SDL_render_sw.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ static bool SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL
664664
return true;
665665
}
666666

667-
static void PrepTextureForCopy(const SDL_RenderCommand *cmd, SW_DrawStateCache *drawstate)
667+
static void PrepTextureForCopy(const SDL_RenderCommand *cmd, SW_DrawStateCache *drawstate, const SDL_Rect *srcrect)
668668
{
669669
const Uint8 r = drawstate->color.r;
670670
const Uint8 g = drawstate->color.g;
@@ -674,6 +674,14 @@ static void PrepTextureForCopy(const SDL_RenderCommand *cmd, SW_DrawStateCache *
674674
SDL_Texture *texture = cmd->data.draw.texture;
675675
SDL_Surface *surface = (SDL_Surface *)texture->internal;
676676

677+
if (SDL_SurfaceHasRLE(surface) &&
678+
srcrect &&
679+
texture->access == SDL_TEXTUREACCESS_STATIC &&
680+
SDL_ISPIXELFORMAT_ALPHA(surface->format) &&
681+
(srcrect->x != 0 || srcrect->y != 0 || srcrect->w != surface->w || srcrect->h != surface->h)) {
682+
SDL_SetSurfaceRLE(surface, false);
683+
}
684+
677685
// !!! FIXME: we can probably avoid some of these calls.
678686
SDL_SetSurfaceColorMod(surface, r, g, b);
679687
SDL_SetSurfaceAlphaMod(surface, a);
@@ -857,7 +865,7 @@ static bool SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, v
857865

858866
SetDrawState(surface, &drawstate);
859867

860-
PrepTextureForCopy(cmd, &drawstate);
868+
PrepTextureForCopy(cmd, &drawstate, srcrect);
861869

862870
// Apply viewport
863871
if (drawstate.viewport && (drawstate.viewport->x || drawstate.viewport->y)) {
@@ -912,7 +920,7 @@ static bool SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, v
912920
{
913921
CopyExData *copydata = (CopyExData *)(((Uint8 *)vertices) + cmd->data.draw.first);
914922
SetDrawState(surface, &drawstate);
915-
PrepTextureForCopy(cmd, &drawstate);
923+
PrepTextureForCopy(cmd, &drawstate, &copydata->srcrect);
916924

917925
// Apply viewport
918926
if (drawstate.viewport &&
@@ -943,7 +951,7 @@ static bool SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, v
943951

944952
GeometryCopyData *ptr = (GeometryCopyData *)verts;
945953

946-
PrepTextureForCopy(cmd, &drawstate);
954+
PrepTextureForCopy(cmd, &drawstate, NULL);
947955

948956
// Apply viewport
949957
if (drawstate.viewport && (drawstate.viewport->x || drawstate.viewport->y)) {

0 commit comments

Comments
 (0)