SDL_UpperBlit / LowerBlit + ValidateRect?

The code in UpperBlit performs rectangle validation. This is a great piece of
code, even if – and because, like many gemms in SDL – it looks simple.

Changing a very few lines would allow gurus to use it – but it should still
stay semi-private and undocumented.

Here is my patch (really: 5 lines added.) Will Sam take it?

— SDL_surface.c Tue Mar 16 11:07:32 2004
+++ SDL_surface_new.c Sun Aug 01 07:40:53 2004
@@ -432,8 +432,9 @@
}

-int SDL_UpperBlit (SDL_Surface *src, SDL_Rect *srcrect,

  •      SDL_Surface *dst, SDL_Rect *dstrect)
    

+int SDL_ValidateRect (SDL_Surface *src, SDL_Rect *srcrect,

  •      SDL_Surface *dst, SDL_Rect *dstrect,
    
  •     SDL_Rect *srcvalidrect)
    

{
SDL_Rect fulldst;
int srcx, srcy, w, h;
@@ -513,16 +514,22 @@
}

if(w > 0 && h > 0) {
  •       SDL_Rect sr;
    
  •       sr.x = srcx;
    
  •   sr.y = srcy;
    
  •   sr.w = dstrect->w = w;
    
  •   sr.h = dstrect->h = h;
    
  •   return SDL_LowerBlit(src, &sr, dst, dstrect);
    
  •   srcvalidrect->x = srcx;
    
  •   srcvalidrect->y = srcy;
    
  •   srcvalidrect->w = dstrect->w = w;
    
  •   srcvalidrect->h = dstrect->h = h;
    
  •   return 1;
    
    }
    dstrect->w = dstrect->h = 0;
    return 0;
    }+
    +int SDL_UpperBlit (SDL_Surface *src, SDL_Rect *srcrect,
  •      SDL_Surface *dst, SDL_Rect *dstrect)
    

+{

  • SDL_Rect srcvalidrect;
  • if (SDL_ValidateRect(src, srcrect, dst, dstrect, &srcvalidrect))
  •  return SDL_LowerBlit(src, &srcvalidrect, dst, dstrect);
    
  • return 0;
    +}

static int SDL_FillRect1(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color)
{

The code in UpperBlit performs rectangle validation. This is a great piece of
code, even if – and because, like many gemms in SDL – it looks simple.

Changing a very few lines would allow gurus to use it – but it should still
stay semi-private and undocumented.

I took a quick look at this, and there are lots of problems with the patch.
Go ahead and just write a separate rect validation routine for your needs. :slight_smile:

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Sam Lantinga <slouken devolution.com> writes:

I took a quick look at this, and there are lots of problems with the patch.
Go ahead and just write a separate rect validation routine for your needs. :slight_smile:

If you have a minute, could you drop just two lines to explain what’s wrong?
Thanks. Pierre.