diff src/video/SDL_surface.c @ 1672:8e754b82cecc SDL-1.3

Updated SDL_Surface code for software-only access, fixed some build errors
author Sam Lantinga <slouken@libsdl.org>
date Fri, 09 Jun 2006 07:06:12 +0000
parents eef792d31de8
children 90bf530ced8e
line wrap: on
line diff
--- a/src/video/SDL_surface.c	Fri Jun 09 06:42:42 2006 +0000
+++ b/src/video/SDL_surface.c	Fri Jun 09 07:06:12 2006 +0000
@@ -22,8 +22,8 @@
 #include "SDL_config.h"
 
 #include "SDL_video.h"
+#include "SDL_compat.h"
 #include "SDL_sysvideo.h"
-#include "SDL_cursor_c.h"
 #include "SDL_blit.h"
 #include "SDL_RLEaccel_c.h"
 #include "SDL_pixels_c.h"
@@ -70,7 +70,6 @@
     surface->h = height;
     surface->pitch = SDL_CalculatePitch(surface);
     surface->pixels = NULL;
-    surface->hwdata = NULL;
     surface->locked = 0;
     surface->map = NULL;
     SDL_SetClipRect(surface, NULL);
@@ -114,8 +113,8 @@
 {
     SDL_Surface *surface;
 
-    surface = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, depth,
-                                   Rmask, Gmask, Bmask, Amask);
+    surface =
+        SDL_CreateRGBSurface(0, 0, 0, depth, Rmask, Gmask, Bmask, Amask);
     if (surface != NULL) {
         surface->flags |= SDL_PREALLOC;
         surface->pixels = pixels;
@@ -146,12 +145,12 @@
         return NULL;
     }
 
-    surface = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, bpp,
-                                   Rmask, Gmask, Bmask, Amask);
+    surface = SDL_CreateRGBSurface(0, 0, 0, bpp, Rmask, Gmask, Bmask, Amask);
     if (surface != NULL) {
         surface->flags |= (SDL_HWSURFACE | SDL_PREALLOC);
-        surface->w = width;
-        surface->h = height;
+        surface->w = w;
+        surface->h = h;
+        surface->lock_data = (void *) textureID;
         SDL_SetClipRect(surface, NULL);
     }
     return surface;
@@ -221,16 +220,8 @@
     }
 
     if (flag) {
-        SDL_VideoDevice *_this = SDL_GetVideoDevice();
-
         surface->flags |= SDL_SRCCOLORKEY;
         surface->format->colorkey = key;
-        if ((surface->flags & SDL_HWACCEL) == SDL_HWACCEL) {
-            if ((_this->SetHWColorKey == NULL) ||
-                (_this->SetHWColorKey(_this, surface, key) < 0)) {
-                surface->flags &= ~SDL_HWACCEL;
-            }
-        }
         if (flag & SDL_RLEACCELOK) {
             surface->flags |= SDL_RLEACCELOK;
         } else {
@@ -272,16 +263,8 @@
         SDL_UnRLESurface(surface, 1);
 
     if (flag) {
-        SDL_VideoDevice *_this = SDL_GetVideoDevice();
-
         surface->flags |= SDL_SRCALPHA;
         surface->format->alpha = value;
-        if ((surface->flags & SDL_HWACCEL) == SDL_HWACCEL) {
-            if ((_this->SetHWAlpha == NULL) ||
-                (_this->SetHWAlpha(_this, surface, value) < 0)) {
-                surface->flags &= ~SDL_HWACCEL;
-            }
-        }
         if (flag & SDL_RLEACCELOK) {
             surface->flags |= SDL_RLEACCELOK;
         } else {
@@ -297,10 +280,10 @@
      * if just the alpha value was changed. (If either is 255, we still
      * need to invalidate.)
      */
-    if ((surface->flags & SDL_HWACCEL) == SDL_HWACCEL
-        || oldflags != surface->flags
-        || (((oldalpha + 1) ^ (value + 1)) & 0x100))
+    if (oldflags != surface->flags
+        || (((oldalpha + 1) ^ (value + 1)) & 0x100)) {
         SDL_InvalidateMap(surface->map);
+    }
     return (0);
 }
 
@@ -438,8 +421,6 @@
 SDL_LowerBlit(SDL_Surface * src, SDL_Rect * srcrect,
               SDL_Surface * dst, SDL_Rect * dstrect)
 {
-    SDL_blit do_blit;
-
     /* Check to make sure the blit mapping is valid */
     if ((src->map->dst != dst) ||
         (src->map->dst->format_version != src->map->format_version)) {
@@ -447,14 +428,7 @@
             return (-1);
         }
     }
-
-    /* Figure out which blitter to use */
-    if ((src->flags & SDL_HWACCEL) == SDL_HWACCEL) {
-        do_blit = src->map->hw_blit;
-    } else {
-        do_blit = src->map->sw_blit;
-    }
-    return (do_blit(src, srcrect, dst, dstrect));
+    return (src->map->sw_blit(src, srcrect, dst, dstrect));
 }
 
 
@@ -603,12 +577,6 @@
         dstrect = &dst->clip_rect;
     }
 
-    /* Check for hardware acceleration */
-    if (((dst->flags & SDL_HWSURFACE) == SDL_HWSURFACE) &&
-        _this->info.blit_fill) {
-        return (_this->FillHWRect(_this, dst, dstrect, color));
-    }
-
     /* Perform software fill */
     if (SDL_LockSurface(dst) != 0) {
         return (-1);
@@ -632,7 +600,7 @@
              * causes an alignment exception if the destination is
              * uncachable, so only use it on software surfaces
              */
-            if ((dst->flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
+            if (dst->flags & SDL_HWSURFACE) {
                 if (dstrect->w >= 8) {
                     /*
                      * 64-bit stores are probably most
@@ -752,8 +720,9 @@
     if (!surface->locked) {
         /* Perform the lock */
         if (surface->flags & SDL_HWSURFACE) {
-            SDL_VideoDevice *_this = SDL_GetVideoDevice();
-            if (_this->LockHWSurface(_this, surface) < 0) {
+            if (SDL_LockTexture
+                ((SDL_TextureID) surface->lock_data, NULL, 1,
+                 &surface->pixels, &surface->pitch) < 0) {
                 return (-1);
             }
         }
@@ -761,8 +730,6 @@
             SDL_UnRLESurface(surface, 1);
             surface->flags |= SDL_RLEACCEL;     /* save accel'd state */
         }
-        /* This needs to be done here in case pixels changes value */
-        surface->pixels = (Uint8 *) surface->pixels + surface->offset;
     }
 
     /* Increment the surface lock count, for recursive locks */
@@ -783,13 +750,9 @@
         return;
     }
 
-    /* Perform the unlock */
-    surface->pixels = (Uint8 *) surface->pixels - surface->offset;
-
     /* Unlock hardware or accelerated surfaces */
     if (surface->flags & SDL_HWSURFACE) {
-        SDL_VideoDevice *_this = SDL_GetVideoDevice();
-        _this->UnlockHWSurface(_this, surface);
+        SDL_UnlockTexture((SDL_TextureID) surface->lock_data);
     } else {
         /* Update RLE encoded surface with new data */
         if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
@@ -827,14 +790,6 @@
         }
     }
 
-    /* Only create hw surfaces with alpha channel if hw alpha blits
-       are supported */
-    if (format->Amask != 0 && (flags & SDL_HWSURFACE)) {
-        const SDL_VideoInfo *vi = SDL_GetVideoInfo();
-        if (!vi || !vi->blit_hw_A)
-            flags &= ~SDL_HWSURFACE;
-    }
-
     /* Create a new surface with the desired format */
     convert = SDL_CreateRGBSurface(flags,
                                    surface->w, surface->h,
@@ -927,7 +882,7 @@
     while (surface->locked > 0) {
         SDL_UnlockSurface(surface);
     }
-    if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
+    if (surface->flags & SDL_RLEACCEL) {
         SDL_UnRLESurface(surface, 0);
     }
     if (surface->format) {
@@ -938,10 +893,11 @@
         SDL_FreeBlitMap(surface->map);
         surface->map = NULL;
     }
-    if (surface->hwdata) {
-        SDL_VideoDevice *_this = SDL_GetVideoDevice();
-        _this->FreeHWSurface(_this, surface);
-    }
+    /* Should we destroy the texture too?
+       if (surface->flags & SDL_HWSURFACE) {
+       SDL_DestroyTexture((SDL_TextureID)surface->lock_data);
+       }
+     */
     if (surface->pixels && ((surface->flags & SDL_PREALLOC) != SDL_PREALLOC)) {
         SDL_free(surface->pixels);
     }