src/video/SDL_surface.c
branchSDL-1.3
changeset 1672 8e754b82cecc
parent 1670 eef792d31de8
child 1678 90bf530ced8e
     1.1 --- a/src/video/SDL_surface.c	Fri Jun 09 06:42:42 2006 +0000
     1.2 +++ b/src/video/SDL_surface.c	Fri Jun 09 07:06:12 2006 +0000
     1.3 @@ -22,8 +22,8 @@
     1.4  #include "SDL_config.h"
     1.5  
     1.6  #include "SDL_video.h"
     1.7 +#include "SDL_compat.h"
     1.8  #include "SDL_sysvideo.h"
     1.9 -#include "SDL_cursor_c.h"
    1.10  #include "SDL_blit.h"
    1.11  #include "SDL_RLEaccel_c.h"
    1.12  #include "SDL_pixels_c.h"
    1.13 @@ -70,7 +70,6 @@
    1.14      surface->h = height;
    1.15      surface->pitch = SDL_CalculatePitch(surface);
    1.16      surface->pixels = NULL;
    1.17 -    surface->hwdata = NULL;
    1.18      surface->locked = 0;
    1.19      surface->map = NULL;
    1.20      SDL_SetClipRect(surface, NULL);
    1.21 @@ -114,8 +113,8 @@
    1.22  {
    1.23      SDL_Surface *surface;
    1.24  
    1.25 -    surface = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, depth,
    1.26 -                                   Rmask, Gmask, Bmask, Amask);
    1.27 +    surface =
    1.28 +        SDL_CreateRGBSurface(0, 0, 0, depth, Rmask, Gmask, Bmask, Amask);
    1.29      if (surface != NULL) {
    1.30          surface->flags |= SDL_PREALLOC;
    1.31          surface->pixels = pixels;
    1.32 @@ -146,12 +145,12 @@
    1.33          return NULL;
    1.34      }
    1.35  
    1.36 -    surface = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, bpp,
    1.37 -                                   Rmask, Gmask, Bmask, Amask);
    1.38 +    surface = SDL_CreateRGBSurface(0, 0, 0, bpp, Rmask, Gmask, Bmask, Amask);
    1.39      if (surface != NULL) {
    1.40          surface->flags |= (SDL_HWSURFACE | SDL_PREALLOC);
    1.41 -        surface->w = width;
    1.42 -        surface->h = height;
    1.43 +        surface->w = w;
    1.44 +        surface->h = h;
    1.45 +        surface->lock_data = (void *) textureID;
    1.46          SDL_SetClipRect(surface, NULL);
    1.47      }
    1.48      return surface;
    1.49 @@ -221,16 +220,8 @@
    1.50      }
    1.51  
    1.52      if (flag) {
    1.53 -        SDL_VideoDevice *_this = SDL_GetVideoDevice();
    1.54 -
    1.55          surface->flags |= SDL_SRCCOLORKEY;
    1.56          surface->format->colorkey = key;
    1.57 -        if ((surface->flags & SDL_HWACCEL) == SDL_HWACCEL) {
    1.58 -            if ((_this->SetHWColorKey == NULL) ||
    1.59 -                (_this->SetHWColorKey(_this, surface, key) < 0)) {
    1.60 -                surface->flags &= ~SDL_HWACCEL;
    1.61 -            }
    1.62 -        }
    1.63          if (flag & SDL_RLEACCELOK) {
    1.64              surface->flags |= SDL_RLEACCELOK;
    1.65          } else {
    1.66 @@ -272,16 +263,8 @@
    1.67          SDL_UnRLESurface(surface, 1);
    1.68  
    1.69      if (flag) {
    1.70 -        SDL_VideoDevice *_this = SDL_GetVideoDevice();
    1.71 -
    1.72          surface->flags |= SDL_SRCALPHA;
    1.73          surface->format->alpha = value;
    1.74 -        if ((surface->flags & SDL_HWACCEL) == SDL_HWACCEL) {
    1.75 -            if ((_this->SetHWAlpha == NULL) ||
    1.76 -                (_this->SetHWAlpha(_this, surface, value) < 0)) {
    1.77 -                surface->flags &= ~SDL_HWACCEL;
    1.78 -            }
    1.79 -        }
    1.80          if (flag & SDL_RLEACCELOK) {
    1.81              surface->flags |= SDL_RLEACCELOK;
    1.82          } else {
    1.83 @@ -297,10 +280,10 @@
    1.84       * if just the alpha value was changed. (If either is 255, we still
    1.85       * need to invalidate.)
    1.86       */
    1.87 -    if ((surface->flags & SDL_HWACCEL) == SDL_HWACCEL
    1.88 -        || oldflags != surface->flags
    1.89 -        || (((oldalpha + 1) ^ (value + 1)) & 0x100))
    1.90 +    if (oldflags != surface->flags
    1.91 +        || (((oldalpha + 1) ^ (value + 1)) & 0x100)) {
    1.92          SDL_InvalidateMap(surface->map);
    1.93 +    }
    1.94      return (0);
    1.95  }
    1.96  
    1.97 @@ -438,8 +421,6 @@
    1.98  SDL_LowerBlit(SDL_Surface * src, SDL_Rect * srcrect,
    1.99                SDL_Surface * dst, SDL_Rect * dstrect)
   1.100  {
   1.101 -    SDL_blit do_blit;
   1.102 -
   1.103      /* Check to make sure the blit mapping is valid */
   1.104      if ((src->map->dst != dst) ||
   1.105          (src->map->dst->format_version != src->map->format_version)) {
   1.106 @@ -447,14 +428,7 @@
   1.107              return (-1);
   1.108          }
   1.109      }
   1.110 -
   1.111 -    /* Figure out which blitter to use */
   1.112 -    if ((src->flags & SDL_HWACCEL) == SDL_HWACCEL) {
   1.113 -        do_blit = src->map->hw_blit;
   1.114 -    } else {
   1.115 -        do_blit = src->map->sw_blit;
   1.116 -    }
   1.117 -    return (do_blit(src, srcrect, dst, dstrect));
   1.118 +    return (src->map->sw_blit(src, srcrect, dst, dstrect));
   1.119  }
   1.120  
   1.121  
   1.122 @@ -603,12 +577,6 @@
   1.123          dstrect = &dst->clip_rect;
   1.124      }
   1.125  
   1.126 -    /* Check for hardware acceleration */
   1.127 -    if (((dst->flags & SDL_HWSURFACE) == SDL_HWSURFACE) &&
   1.128 -        _this->info.blit_fill) {
   1.129 -        return (_this->FillHWRect(_this, dst, dstrect, color));
   1.130 -    }
   1.131 -
   1.132      /* Perform software fill */
   1.133      if (SDL_LockSurface(dst) != 0) {
   1.134          return (-1);
   1.135 @@ -632,7 +600,7 @@
   1.136               * causes an alignment exception if the destination is
   1.137               * uncachable, so only use it on software surfaces
   1.138               */
   1.139 -            if ((dst->flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
   1.140 +            if (dst->flags & SDL_HWSURFACE) {
   1.141                  if (dstrect->w >= 8) {
   1.142                      /*
   1.143                       * 64-bit stores are probably most
   1.144 @@ -752,8 +720,9 @@
   1.145      if (!surface->locked) {
   1.146          /* Perform the lock */
   1.147          if (surface->flags & SDL_HWSURFACE) {
   1.148 -            SDL_VideoDevice *_this = SDL_GetVideoDevice();
   1.149 -            if (_this->LockHWSurface(_this, surface) < 0) {
   1.150 +            if (SDL_LockTexture
   1.151 +                ((SDL_TextureID) surface->lock_data, NULL, 1,
   1.152 +                 &surface->pixels, &surface->pitch) < 0) {
   1.153                  return (-1);
   1.154              }
   1.155          }
   1.156 @@ -761,8 +730,6 @@
   1.157              SDL_UnRLESurface(surface, 1);
   1.158              surface->flags |= SDL_RLEACCEL;     /* save accel'd state */
   1.159          }
   1.160 -        /* This needs to be done here in case pixels changes value */
   1.161 -        surface->pixels = (Uint8 *) surface->pixels + surface->offset;
   1.162      }
   1.163  
   1.164      /* Increment the surface lock count, for recursive locks */
   1.165 @@ -783,13 +750,9 @@
   1.166          return;
   1.167      }
   1.168  
   1.169 -    /* Perform the unlock */
   1.170 -    surface->pixels = (Uint8 *) surface->pixels - surface->offset;
   1.171 -
   1.172      /* Unlock hardware or accelerated surfaces */
   1.173      if (surface->flags & SDL_HWSURFACE) {
   1.174 -        SDL_VideoDevice *_this = SDL_GetVideoDevice();
   1.175 -        _this->UnlockHWSurface(_this, surface);
   1.176 +        SDL_UnlockTexture((SDL_TextureID) surface->lock_data);
   1.177      } else {
   1.178          /* Update RLE encoded surface with new data */
   1.179          if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
   1.180 @@ -827,14 +790,6 @@
   1.181          }
   1.182      }
   1.183  
   1.184 -    /* Only create hw surfaces with alpha channel if hw alpha blits
   1.185 -       are supported */
   1.186 -    if (format->Amask != 0 && (flags & SDL_HWSURFACE)) {
   1.187 -        const SDL_VideoInfo *vi = SDL_GetVideoInfo();
   1.188 -        if (!vi || !vi->blit_hw_A)
   1.189 -            flags &= ~SDL_HWSURFACE;
   1.190 -    }
   1.191 -
   1.192      /* Create a new surface with the desired format */
   1.193      convert = SDL_CreateRGBSurface(flags,
   1.194                                     surface->w, surface->h,
   1.195 @@ -927,7 +882,7 @@
   1.196      while (surface->locked > 0) {
   1.197          SDL_UnlockSurface(surface);
   1.198      }
   1.199 -    if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
   1.200 +    if (surface->flags & SDL_RLEACCEL) {
   1.201          SDL_UnRLESurface(surface, 0);
   1.202      }
   1.203      if (surface->format) {
   1.204 @@ -938,10 +893,11 @@
   1.205          SDL_FreeBlitMap(surface->map);
   1.206          surface->map = NULL;
   1.207      }
   1.208 -    if (surface->hwdata) {
   1.209 -        SDL_VideoDevice *_this = SDL_GetVideoDevice();
   1.210 -        _this->FreeHWSurface(_this, surface);
   1.211 -    }
   1.212 +    /* Should we destroy the texture too?
   1.213 +       if (surface->flags & SDL_HWSURFACE) {
   1.214 +       SDL_DestroyTexture((SDL_TextureID)surface->lock_data);
   1.215 +       }
   1.216 +     */
   1.217      if (surface->pixels && ((surface->flags & SDL_PREALLOC) != SDL_PREALLOC)) {
   1.218          SDL_free(surface->pixels);
   1.219      }