changeset 1666:6e7ec5cb83c3 SDL-1.3

The dummy video driver compiles. :)
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 21:56:07 +0000
parents 28193f833b2b
children 1fddae038bc8
files src/events/SDL_events.c src/video/SDL_surface.c src/video/SDL_sysvideo.h src/video/SDL_video.c src/video/dummy/SDL_nullvideo.c test/testsprite.c
diffstat 6 files changed, 35 insertions(+), 130 deletions(-) [+]
line wrap: on
line diff
--- a/src/events/SDL_events.c	Sun May 28 18:18:30 2006 +0000
+++ b/src/events/SDL_events.c	Sun May 28 21:56:07 2006 +0000
@@ -219,7 +219,6 @@
     SDL_StopEventThread ();
 
     /* Shutdown event handlers */
-    SDL_AppActiveQuit ();
     SDL_KeyboardQuit ();
     SDL_MouseQuit ();
     SDL_QuitQuit ();
@@ -251,7 +250,6 @@
 
     /* Initialize event handlers */
     retcode = 0;
-    retcode += SDL_AppActiveInit ();
     retcode += SDL_KeyboardInit ();
     retcode += SDL_MouseInit ();
     retcode += SDL_QuitInit ();
--- a/src/video/SDL_surface.c	Sun May 28 18:18:30 2006 +0000
+++ b/src/video/SDL_surface.c	Sun May 28 21:56:07 2006 +0000
@@ -896,12 +896,7 @@
 void
 SDL_FreeSurface (SDL_Surface * surface)
 {
-    SDL_VideoDevice *_this = SDL_GetVideoDevice ();
-
-    /* Free anything that's not NULL, and not the screen surface */
-    if ((surface == NULL) ||
-        (_this &&
-         ((surface == SDL_ShadowSurface) || (surface == SDL_VideoSurface)))) {
+    if (surface == NULL) {
         return;
     }
     if (--surface->refcount > 0) {
--- a/src/video/SDL_sysvideo.h	Sun May 28 18:18:30 2006 +0000
+++ b/src/video/SDL_sysvideo.h	Sun May 28 21:56:07 2006 +0000
@@ -122,7 +122,7 @@
     void (*SetWindowGrab) (_THIS, SDL_Window * window);
     void (*DestroyWindow) (_THIS, SDL_Window * window);
 
-    SDL_Surface *(*CreateWindowSurface) (_THIS, SDL_Window * window);
+    void (*CreateWindowSurface) (_THIS, SDL_Window * window, Uint32 flags);
     void (*UpdateWindowSurface) (_THIS, SDL_Window * window, int numrects,
                                  SDL_Rect * rects);
     void (*FlipWindowSurface) (_THIS, SDL_Window * window);
--- a/src/video/SDL_video.c	Sun May 28 18:18:30 2006 +0000
+++ b/src/video/SDL_video.c	Sun May 28 21:56:07 2006 +0000
@@ -997,10 +997,8 @@
 SDL_CreateWindowSurface (SDL_WindowID windowID, Uint32 format, Uint32 flags)
 {
     SDL_Window *window = SDL_GetWindowFromID (windowID);
+    Uint32 black;
     SDL_Surface *surface;
-    SDL_Surface *shadow;
-    Uint32 surface_format;
-    Uint32 black;
 
     if (!window) {
         return NULL;
@@ -1011,54 +1009,50 @@
     }
 
     if (!window->surface) {
-        window->surface = _this->CreateWindowSurface (_this, window);
+        _this->CreateWindowSurface (_this, window, flags);
         if (!window->surface) {
             return NULL;
         }
+        window->surface->flags |= SDL_SCREEN_SURFACE;
     }
+    surface = window->surface;
 
     if (window->shadow) {
         SDL_FreeSurface (window->shadow);
         window->shadow = NULL;
     }
 
-    surface = window->surface;
-    surface_format =
-        SDL_MasksToPixelFormatEnum (surface->format->BitsPerPixel,
-                                    surface->format->Rmask,
-                                    surface->format->Gmask,
-                                    surface->format->Bmask,
-                                    surface->format->Amask);
-
     /* Create a shadow surface if necessary */
-    if ((!(flags & SDL_ANYFORMAT) && (surface_format != format)) ||
-        ((flags & SDL_HWPALETTE)
-         && !(window->surface->flags & SDL_HWPALETTE))) {
+    if ((!(flags & SDL_ANYFORMAT)
+         && (format != SDL_GetCurrentDisplayMode ()->format))
+        || ((flags & SDL_HWPALETTE)
+            && !(window->surface->flags & SDL_HWPALETTE))) {
         int bpp;
         Uint32 Rmask, Gmask, Bmask, Amask;
 
-        SDL_PixelFormatEnumToMasks (format, &bpp, &Rmask, &Gmask, &Bmask,
+        SDL_PixelFormatEnumToMasks (format, &bpp, &Amask, &Gmask, &Bmask,
                                     &Amask);
-        shadow =
-            SDL_CreateRGBSurface (SDL_SWSURFACE, surface->w, surface->h,
-                                  bpp, Rmask, Gmask, Bmask, Amask);
-        if (shadow == NULL) {
+        window->shadow =
+            SDL_CreateRGBSurface (SDL_SWSURFACE, surface->w, surface->h, bpp,
+                                  Rmask, Gmask, Bmask, Amask);
+        if (window->shadow == NULL) {
             return NULL;
         }
+        window->shadow->flags |= SDL_SHADOW_SURFACE;
+        surface = window->shadow;
 
         /* 8-bit shadow surfaces report that they have exclusive palette */
-        if (shadow->format->palette) {
-            shadow->flags |= SDL_HWPALETTE;
-            if (format == surface_format) {
-                SDL_memcpy (shadow->format->palette->colors,
-                            surface->format->palette->colors,
-                            surface->format->palette->ncolors *
+        if (surface->format->palette) {
+            surface->flags |= SDL_HWPALETTE;
+            if (format == SDL_GetCurrentDisplayMode ()->format) {
+                SDL_memcpy (surface->format->palette->colors,
+                            window->surface->format->palette->colors,
+                            window->surface->format->palette->ncolors *
                             sizeof (SDL_Color));
             } else {
-                SDL_DitherColors (shadow->format->palette->colors, bpp);
+                SDL_DitherColors (surface->format->palette->colors, bpp);
             }
         }
-        surface = window->shadow = shadow;
     }
 
     /* Clear the surface for display */
--- a/src/video/dummy/SDL_nullvideo.c	Sun May 28 18:18:30 2006 +0000
+++ b/src/video/dummy/SDL_nullvideo.c	Sun May 28 21:56:07 2006 +0000
@@ -51,7 +51,8 @@
 /* Initialization/Query functions */
 static int DUMMY_VideoInit (_THIS);
 static int DUMMY_SetDisplayMode (_THIS, const SDL_DisplayMode * mode);
-static SDL_Surface *DUMMY_CreateWindowSurface (_THIS, SDL_Window * window);
+static void DUMMY_CreateWindowSurface (_THIS, SDL_Window * window,
+                                       Uint32 flags);
 static void DUMMY_VideoQuit (_THIS);
 
 /* DUMMY driver bootstrap functions */
@@ -98,6 +99,7 @@
     /* Set the function pointers */
     device->VideoInit = DUMMY_VideoInit;
     device->SetDisplayMode = DUMMY_SetDisplayMode;
+    device->CreateWindowSurface = DUMMY_CreateWindowSurface;
     device->VideoQuit = DUMMY_VideoQuit;
     device->InitOSKeymap = DUMMY_InitOSKeymap;
     device->PumpEvents = DUMMY_PumpEvents;
@@ -128,93 +130,17 @@
     return 0;
 }
 
-static SDL_Surface *
-DUMMY_CreateWindowSurface (_THIS, SDL_Window * window)
+static void
+DUMMY_CreateWindowSurface (_THIS, SDL_Window * window, Uint32 flags)
 {
     int bpp;
     Uint32 Rmask, Gmask, Bmask, Amask;
 
-    if (_this->hidden->buffer) {
-        SDL_free (_this->hidden->buffer);
-    }
-
-    _this->hidden->buffer =
-        SDL_malloc (mode->w * mode->h * SDL_BYTESPERPIXEL (mode->format));
-    if (!_this->hidden->buffer) {
-        SDL_SetError ("Couldn't allocate buffer for requested mode");
-        return (NULL);
-    }
-
-/* 	printf("Setting mode %dx%d\n", width, height); */
-
-    SDL_memset (_this->hidden->buffer, 0,
-                mode->w * mode->h * SDL_BYTESPERPIXEL (mode->format));
-
-    /* Allocate the new pixel format for the screen */
-    SDL_PixelFormatEnumToMasks (mode->format, &bpp, &Rmask, &Gmask, &Bmask,
-                                &Amask);
-    if (!SDL_ReallocFormat (current, bpp, Rmask, Gmask, Bmask, Amask)) {
-        SDL_free (_this->hidden->buffer);
-        _this->hidden->buffer = NULL;
-        SDL_SetError
-            ("Couldn't allocate new pixel format for requested mode");
-        return (NULL);
-    }
-
-    /* Set up the new mode framebuffer */
-    current->flags = flags & SDL_FULLSCREEN;
-    _this->hidden->w = current->w = mode->w;
-    _this->hidden->h = current->h = mode->h;
-    current->pitch = current->w * SDL_BYTESPERPIXEL (mode->format);
-    current->pixels = _this->hidden->buffer;
-
-    /* We're done */
-    return (current);
-}
-
-SDL_Surface *
-DUMMY_SetVideoMode (_THIS, SDL_Surface * current,
-                    const SDL_DisplayMode * mode, Uint32 flags)
-{
-    int bpp;
-    Uint32 Rmask, Gmask, Bmask, Amask;
-
-    if (_this->hidden->buffer) {
-        SDL_free (_this->hidden->buffer);
-    }
-
-    _this->hidden->buffer =
-        SDL_malloc (mode->w * mode->h * SDL_BYTESPERPIXEL (mode->format));
-    if (!_this->hidden->buffer) {
-        SDL_SetError ("Couldn't allocate buffer for requested mode");
-        return (NULL);
-    }
-
-/* 	printf("Setting mode %dx%d\n", width, height); */
-
-    SDL_memset (_this->hidden->buffer, 0,
-                mode->w * mode->h * SDL_BYTESPERPIXEL (mode->format));
-
-    /* Allocate the new pixel format for the screen */
-    SDL_PixelFormatEnumToMasks (mode->format, &bpp, &Rmask, &Gmask, &Bmask,
-                                &Amask);
-    if (!SDL_ReallocFormat (current, bpp, Rmask, Gmask, Bmask, Amask)) {
-        SDL_free (_this->hidden->buffer);
-        _this->hidden->buffer = NULL;
-        SDL_SetError
-            ("Couldn't allocate new pixel format for requested mode");
-        return (NULL);
-    }
-
-    /* Set up the new mode framebuffer */
-    current->flags = flags & SDL_FULLSCREEN;
-    _this->hidden->w = current->w = mode->w;
-    _this->hidden->h = current->h = mode->h;
-    current->pitch = current->w * SDL_BYTESPERPIXEL (mode->format);
-    current->pixels = _this->hidden->buffer;
-
-    /* We're done */
-    return (current);
+    SDL_PixelFormatEnumToMasks (SDL_GetCurrentDisplayMode ()->format, &bpp,
+                                &Rmask, &Gmask, &Bmask, &Amask);
+    window->surface =
+        SDL_CreateRGBSurface (flags, window->w, window->h, bpp, Rmask, Gmask,
+                              Bmask, Amask);
 }
 
 /* Note:  If we are terminated, this could be called in the middle of
@@ -223,9 +149,6 @@
 void
 DUMMY_VideoQuit (_THIS)
 {
-    if (_this->hidden->buffer) {
-        SDL_free (_this->hidden->buffer);
-    }
 }
 
 /* vi: set ts=4 sw=4 expandtab: */
--- a/test/testsprite.c	Sun May 28 18:18:30 2006 +0000
+++ b/test/testsprite.c	Sun May 28 21:56:07 2006 +0000
@@ -156,7 +156,6 @@
 int
 main (int argc, char *argv[])
 {
-    SDL_DisplayMode mode;
     SDL_Surface *screen;
     Uint8 *mem;
     int width, height;
@@ -212,11 +211,7 @@
     }
 
     /* Set video mode */
-    mode.format = 0;            /* FIXME */
-    mode.w = width;
-    mode.h = height;
-    mode.refresh_rate = 0;
-    screen = SDL_SetDisplayMode (&mode, videoflags);
+    screen = SDL_SetVideoMode (width, height, video_bpp, videoflags);
     if (!screen) {
         fprintf (stderr, "Couldn't set %dx%d video mode: %s\n",
                  width, height, SDL_GetError ());