changeset 1669:9857d21967bb SDL-1.3

The test programs compile again. The dummy video driver is partially functional now.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 05:08:33 +0000
parents 4da1ee79c9af
children eef792d31de8
files include/SDL_compat.h include/SDL_events.h include/SDL_video.h src/SDL_compat.c src/video/SDL_sysvideo.h src/video/SDL_video.c src/video/dummy/SDL_nullvideo.c
diffstat 7 files changed, 165 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/include/SDL_compat.h	Mon May 29 04:04:35 2006 +0000
+++ b/include/SDL_compat.h	Mon May 29 05:08:33 2006 +0000
@@ -25,6 +25,7 @@
 #ifndef _SDL_compat_h
 #define _SDL_compat_h
 
+#include "SDL_video.h"
 #include "SDL_syswm.h"
 
 #include "begin_code.h"
@@ -59,6 +60,10 @@
 #define SDL_LOGPAL 0x01
 #define SDL_PHYSPAL 0x02
 
+#define SDL_ACTIVEEVENT	SDL_EVENT_RESERVED1
+#define SDL_VIDEORESIZE	SDL_EVENT_RESERVED2
+#define SDL_VIDEOEXPOSE	SDL_EVENT_RESERVED3
+
 typedef enum
 {
     SDL_GRAB_QUERY = -1,
--- a/include/SDL_events.h	Mon May 29 04:04:35 2006 +0000
+++ b/include/SDL_events.h	Mon May 29 05:08:33 2006 +0000
@@ -269,6 +269,20 @@
     SDL_SysWMmsg *msg;  /**< driver dependent data, defined in SDL_syswm.h */
 } SDL_SysWMEvent;
 
+/* Typedefs for backwards compatibility */
+typedef struct SDL_ActiveEvent
+{
+    Uint8 type;
+    Uint8 gain;
+    Uint8 state;
+} SDL_ActiveEvent;
+typedef struct SDL_ResizeEvent
+{
+    Uint8 type;
+    int w;
+    int h;
+} SDL_ResizeEvent;
+
 /**
  * \union SDL_Event
  *
@@ -288,6 +302,10 @@
     SDL_QuitEvent quit;             /**< Quit request event data */
     SDL_UserEvent user;             /**< Custom event data */
     SDL_SysWMEvent syswm;           /**< System dependent window event data */
+
+    /* Temporarily here for backwards compatibility */
+    SDL_ActiveEvent active;
+    SDL_ResizeEvent resize;
 } SDL_Event;
 
 
--- a/include/SDL_video.h	Mon May 29 04:04:35 2006 +0000
+++ b/include/SDL_video.h	Mon May 29 05:08:33 2006 +0000
@@ -126,22 +126,29 @@
                          struct SDL_Surface * dst, SDL_Rect * dstrect);
 
 
-/* Useful for determining the video hardware capabilities */
+/**
+ * \struct SDL_VideoInfo
+ *
+ * \brief Useful for determining the video hardware capabilities
+ */
 typedef struct SDL_VideoInfo
 {
-    Uint32 hw_available:1;      /* Flag: Can you create hardware surfaces? */
-    Uint32 wm_available:1;      /* Flag: Can you talk to a window manager? */
+    Uint32 hw_available:1;  /**< Flag: Can you create hardware surfaces? */
+    Uint32 wm_available:1;  /**< Flag: Can you talk to a window manager? */
     Uint32 UnusedBits1:6;
     Uint32 UnusedBits2:1;
-    Uint32 blit_hw:1;           /* Flag: Accelerated blits HW --> HW */
-    Uint32 blit_hw_CC:1;        /* Flag: Accelerated blits with Colorkey */
-    Uint32 blit_hw_A:1;         /* Flag: Accelerated blits with Alpha */
-    Uint32 blit_sw:1;           /* Flag: Accelerated blits SW --> HW */
-    Uint32 blit_sw_CC:1;        /* Flag: Accelerated blits with Colorkey */
-    Uint32 blit_sw_A:1;         /* Flag: Accelerated blits with Alpha */
-    Uint32 blit_fill:1;         /* Flag: Accelerated color fill */
+    Uint32 blit_hw:1;       /**< Flag: Accelerated blits HW --> HW */
+    Uint32 blit_hw_CC:1;    /**< Flag: Accelerated blits with Colorkey */
+    Uint32 blit_hw_A:1;     /**< Flag: Accelerated blits with Alpha */
+    Uint32 blit_sw:1;       /**< Flag: Accelerated blits SW --> HW */
+    Uint32 blit_sw_CC:1;    /**< Flag: Accelerated blits with Colorkey */
+    Uint32 blit_sw_A:1;     /**< Flag: Accelerated blits with Alpha */
+    Uint32 blit_fill:1;     /**< Flag: Accelerated color fill */
     Uint32 UnusedBits3:16;
     Uint32 video_mem;           /* The total amount of video memory (in K) */
+
+    /* Here for backwards compatibility */
+    SDL_PixelFormat *vfmt;
 } SDL_VideoInfo;
 
 /**
--- a/src/SDL_compat.c	Mon May 29 04:04:35 2006 +0000
+++ b/src/SDL_compat.c	Mon May 29 05:08:33 2006 +0000
@@ -129,9 +129,68 @@
     return modes;
 }
 
+static int (*orig_eventfilter) (const SDL_Event * event);
+
+static int
+SDL_CompatEventFilter(const SDL_Event * event)
+{
+    SDL_Event fake;
+
+    switch (event->type) {
+    case SDL_WINDOWEVENT:
+        switch (event->window.event) {
+        case SDL_WINDOWEVENT_RESIZED:
+            fake.type = SDL_VIDEORESIZE;
+            fake.resize.w = event->window.data1;
+            fake.resize.h = event->window.data2;
+            SDL_PushEvent(&fake);
+            break;
+        case SDL_WINDOWEVENT_MINIMIZED:
+            fake.type = SDL_ACTIVEEVENT;
+            fake.active.gain = 0;
+            fake.active.state = SDL_APPACTIVE;
+            SDL_PushEvent(&fake);
+            break;
+        case SDL_WINDOWEVENT_RESTORED:
+            fake.type = SDL_ACTIVEEVENT;
+            fake.active.gain = 1;
+            fake.active.state = SDL_APPACTIVE;
+            SDL_PushEvent(&fake);
+            break;
+        case SDL_WINDOWEVENT_ENTER:
+            fake.type = SDL_ACTIVEEVENT;
+            fake.active.gain = 1;
+            fake.active.state = SDL_APPMOUSEFOCUS;
+            SDL_PushEvent(&fake);
+            break;
+        case SDL_WINDOWEVENT_LEAVE:
+            fake.type = SDL_ACTIVEEVENT;
+            fake.active.gain = 0;
+            fake.active.state = SDL_APPMOUSEFOCUS;
+            SDL_PushEvent(&fake);
+            break;
+        case SDL_WINDOWEVENT_FOCUS_GAINED:
+            fake.type = SDL_ACTIVEEVENT;
+            fake.active.gain = 1;
+            fake.active.state = SDL_APPINPUTFOCUS;
+            SDL_PushEvent(&fake);
+            break;
+        case SDL_WINDOWEVENT_FOCUS_LOST:
+            fake.type = SDL_ACTIVEEVENT;
+            fake.active.gain = 1;
+            fake.active.state = SDL_APPINPUTFOCUS;
+            SDL_PushEvent(&fake);
+            break;
+        }
+    }
+    return orig_eventfilter(event);
+}
+
 SDL_Surface *
 SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
 {
+    int (*filter) (const SDL_Event * event);
+    const SDL_DisplayMode *desktop_mode;
     SDL_DisplayMode mode;
     int i;
     Uint32 window_flags;
@@ -147,6 +206,13 @@
     /* Destroy existing window */
     SDL_DestroyWindow(window);
 
+    /* Set up the event filter */
+    filter = SDL_GetEventFilter();
+    if (filter != SDL_CompatEventFilter) {
+        orig_eventfilter = filter;
+    }
+    SDL_SetEventFilter(SDL_CompatEventFilter);
+
     /* Create a new window */
     window_flags = SDL_WINDOW_SHOWN;
     if (flags & SDL_FULLSCREEN) {
@@ -167,12 +233,20 @@
     }
 
     /* Set up the desired display mode */
-    desktop_format = SDL_GetDesktopDisplayMode()->format;
-    if ((bpp == SDL_BITSPERPIXEL(desktop_format)) ||
-        (desktop_format && (flags & SDL_ANYFORMAT))) {
+    desktop_mode = SDL_GetDesktopDisplayMode();
+    desktop_format = desktop_mode->format;
+    if (desktop_format && ((flags & SDL_ANYFORMAT)
+                           || (bpp == SDL_BITSPERPIXEL(desktop_format)))) {
         desired_format = desktop_format;
     } else {
         switch (bpp) {
+        case 0:
+            if (desktop_format) {
+                desired_format = desktop_format;
+            } else {
+                desired_format = SDL_PixelFormat_RGB888;
+            }
+            break;
         case 8:
             desired_format = SDL_PixelFormat_Index8;
             break;
@@ -204,7 +278,14 @@
             return NULL;
         }
     } else {
-        mode = *SDL_GetDesktopDisplayMode();
+        if (desktop_format) {
+            mode.format = desktop_format;
+        }
+        if (desktop_mode->w && desktop_mode->h) {
+            mode.w = desktop_mode->w;
+            mode.h = desktop_mode->h;
+        }
+        mode.refresh_rate = desktop_mode->refresh_rate;
     }
     if (SDL_SetDisplayMode(&mode) < 0) {
         return NULL;
--- a/src/video/SDL_sysvideo.h	Mon May 29 04:04:35 2006 +0000
+++ b/src/video/SDL_sysvideo.h	Mon May 29 05:08:33 2006 +0000
@@ -434,7 +434,7 @@
 
 extern SDL_VideoDevice *SDL_GetVideoDevice();
 extern void SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
-extern void SDL_AddVideoDisplay(SDL_VideoDisplay * display);
+extern void SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
 extern void SDL_AddDisplayMode(int display, const SDL_DisplayMode * mode);
 extern SDL_Window *SDL_GetWindowFromSurface(SDL_Surface * surface);
 
--- a/src/video/SDL_video.c	Mon May 29 04:04:35 2006 +0000
+++ b/src/video/SDL_video.c	Mon May 29 05:08:33 2006 +0000
@@ -233,6 +233,7 @@
     _this->name = bootstrap[i]->name;
     _this->next_window_id = 1;
 
+
     /* Set some very sane GL defaults */
     _this->gl_config.driver_loaded = 0;
     _this->gl_config.dll_handle = NULL;
@@ -267,6 +268,16 @@
         return (-1);
     }
 
+    /* Temporarily here for backwards compatibility */
+    {
+        int bpp;
+        Uint32 Rmask, Gmask, Bmask, Amask;
+
+        SDL_PixelFormatEnumToMasks(SDL_GetDesktopDisplayMode()->format, &bpp,
+                                   &Rmask, &Gmask, &Bmask, &Amask);
+        _this->info.vfmt = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
+    }
+
     /* Sort the video modes */
     for (i = 0; i < _this->num_displays; ++i) {
         SDL_qsort(_this->displays[i].display_modes,
@@ -325,7 +336,7 @@
 }
 
 void
-SDL_AddVideoDisplay(SDL_VideoDisplay * display)
+SDL_AddVideoDisplay(const SDL_VideoDisplay * display)
 {
     SDL_VideoDisplay *displays;
 
@@ -1034,6 +1045,14 @@
             return NULL;
         }
         window->surface->flags |= SDL_SCREEN_SURFACE;
+
+        /* If we have a palettized surface, create a default palette */
+        if (window->surface->format->palette) {
+            SDL_Color colors[256];
+            SDL_PixelFormat *vf = window->surface->format;
+            SDL_DitherColors(colors, vf->BitsPerPixel);
+            SDL_SetColors(window->surface, colors, 0, vf->palette->ncolors);
+        }
     }
     surface = window->surface;
 
@@ -1059,6 +1078,7 @@
             return NULL;
         }
         window->shadow->flags |= SDL_SHADOW_SURFACE;
+
         surface = window->shadow;
 
         /* 8-bit shadow surfaces report that they have exclusive palette */
@@ -1401,6 +1421,7 @@
     if (_this->displays) {
         SDL_free(_this->displays);
     }
+    SDL_free(_this->info.vfmt);
     _this->free(_this);
     _this = NULL;
 }
--- a/src/video/dummy/SDL_nullvideo.c	Mon May 29 04:04:35 2006 +0000
+++ b/src/video/dummy/SDL_nullvideo.c	Mon May 29 05:08:33 2006 +0000
@@ -53,6 +53,8 @@
 static int DUMMY_SetDisplayMode(_THIS, const SDL_DisplayMode * mode);
 static void DUMMY_CreateWindowSurface(_THIS, SDL_Window * window,
                                       Uint32 flags);
+static void DUMMY_UpdateWindowSurface(_THIS, SDL_Window * window,
+                                      int numrects, SDL_Rect * rects);
 static void DUMMY_VideoQuit(_THIS);
 
 /* DUMMY driver bootstrap functions */
@@ -100,6 +102,7 @@
     device->VideoInit = DUMMY_VideoInit;
     device->SetDisplayMode = DUMMY_SetDisplayMode;
     device->CreateWindowSurface = DUMMY_CreateWindowSurface;
+    device->UpdateWindowSurface = DUMMY_UpdateWindowSurface;
     device->VideoQuit = DUMMY_VideoQuit;
     device->InitOSKeymap = DUMMY_InitOSKeymap;
     device->PumpEvents = DUMMY_PumpEvents;
@@ -132,6 +135,7 @@
 static int
 DUMMY_SetDisplayMode(_THIS, const SDL_DisplayMode * mode)
 {
+    SDL_CurrentDisplay.current_mode = *mode;
     return 0;
 }
 
@@ -148,6 +152,19 @@
                              Bmask, Amask);
 }
 
+static void
+DUMMY_UpdateWindowSurface(_THIS, SDL_Window * window, int numrects,
+                          SDL_Rect * rects)
+{
+    static int frame_number;
+    if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) {
+        char file[128];
+        SDL_snprintf(file, sizeof(file), "SDL_screen-%8.8d.bmp",
+                     ++frame_number);
+        SDL_SaveBMP(window->surface, file);
+    }
+}
+
 /* Note:  If we are terminated, this could be called in the middle of
    another SDL video routine -- notably UpdateRects.
 */