From e05df70ce6d9ee6b25be28579126457820a9302c Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 16 Jun 2006 06:00:31 +0000 Subject: [PATCH] Default palette entries to white, instead of black. More palettized video mode support... --- include/SDL_compat.h | 8 +++---- include/SDL_pixels.h | 2 +- include/SDL_video.h | 4 ++-- src/SDL_compat.c | 40 +++++++++++++++++++++++++++++--- src/video/SDL_pixels.c | 7 +++--- src/video/SDL_surface.c | 10 ++++---- src/video/SDL_sysvideo.h | 2 ++ src/video/SDL_video.c | 1 + src/video/dummy/SDL_nullrender.c | 37 ++++++++++++++++++----------- 9 files changed, 79 insertions(+), 32 deletions(-) diff --git a/include/SDL_compat.h b/include/SDL_compat.h index 32e632d04..6418220f7 100644 --- a/include/SDL_compat.h +++ b/include/SDL_compat.h @@ -44,8 +44,8 @@ extern "C" { #define SDL_RESIZABLE 0x01000000 #define SDL_NOFRAME 0x02000000 #define SDL_OPENGL 0x04000000 -#define SDL_ASYNCBLIT 0x00000000 -#define SDL_HWACCEL 0x00000000 +#define SDL_ASYNCBLIT 0x08000000 /* Not used */ +#define SDL_HWACCEL 0x08000000 /* Not used */ #define SDL_SCREEN_SURFACE 0x10000000 /* Surface is a window screen surface */ #define SDL_SHADOW_SURFACE 0x20000000 /* Surface is a window shadow surface */ @@ -146,10 +146,10 @@ extern DECLSPEC int SDLCALL SDL_WM_IconifyWindow(void); extern DECLSPEC int SDLCALL SDL_WM_ToggleFullScreen(SDL_Surface * surface); extern DECLSPEC SDL_GrabMode SDLCALL SDL_WM_GrabInput(SDL_GrabMode mode); extern DECLSPEC int SDLCALL SDL_SetPalette(SDL_Surface * surface, int flags, - SDL_Color * colors, + const SDL_Color * colors, int firstcolor, int ncolors); extern DECLSPEC int SDLCALL SDL_SetScreenColors(SDL_Surface * screen, - SDL_Color * colors, + const SDL_Color * colors, int firstcolor, int ncolors); extern DECLSPEC int SDLCALL SDL_GetWMInfo(SDL_SysWMinfo * info); extern DECLSPEC Uint8 SDLCALL SDL_GetAppState(void); diff --git a/include/SDL_pixels.h b/include/SDL_pixels.h index 210e2969b..d4af56960 100644 --- a/include/SDL_pixels.h +++ b/include/SDL_pixels.h @@ -114,7 +114,7 @@ enum (SDL_PIXELTYPE(format) == SDL_PixelType_Index8)) #define SDL_ISPIXELFORMAT_FOURCC(format) \ - ((format) && !((format) & 0x8000000)) + ((format) && !((format) & 0x80000000)) enum { diff --git a/include/SDL_video.h b/include/SDL_video.h index 5642b3921..cf9d880fd 100644 --- a/include/SDL_video.h +++ b/include/SDL_video.h @@ -1082,8 +1082,8 @@ extern DECLSPEC int SDLCALL SDL_GetGammaRamp(Uint16 * red, Uint16 * green, * emulation. */ extern DECLSPEC int SDLCALL SDL_SetColors(SDL_Surface * surface, - SDL_Color * colors, int firstcolor, - int ncolors); + const SDL_Color * colors, + int firstcolor, int ncolors); /* * Maps an RGB triple to an opaque pixel value for a given pixel format diff --git a/src/SDL_compat.c b/src/SDL_compat.c index 94b7d79d7..a6164c624 100644 --- a/src/SDL_compat.c +++ b/src/SDL_compat.c @@ -218,6 +218,7 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) Uint32 desktop_format; Uint32 desired_format; Uint32 texture_format; + Uint32 surface_flags; if (!SDL_GetVideoDevice()) { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) { @@ -264,6 +265,21 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) return NULL; } + window_flags = SDL_GetWindowFlags(SDL_VideoWindow); + surface_flags = SDL_SCREEN_SURFACE; + if (window_flags & SDL_WINDOW_FULLSCREEN) { + surface_flags |= SDL_FULLSCREEN; + } + if (window_flags & SDL_WINDOW_OPENGL) { + surface_flags |= SDL_OPENGL; + } + if (window_flags & SDL_WINDOW_RESIZABLE) { + surface_flags |= SDL_RESIZABLE; + } + if (window_flags & SDL_WINDOW_BORDERLESS) { + surface_flags |= SDL_NOFRAME; + } + /* Set up the desired display mode */ desktop_mode = SDL_GetDesktopDisplayMode(); desktop_format = desktop_mode->format; @@ -323,6 +339,18 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) return NULL; } + /* If we're in OpenGL mode, just create a stub surface and we're done! */ + if (flags & SDL_OPENGL) { + SDL_VideoSurface = + SDL_CreateRGBSurfaceFrom(NULL, width, height, bpp, 0, 0, 0, 0, 0); + if (!SDL_VideoSurface) { + return NULL; + } + SDL_VideoSurface->flags |= surface_flags; + SDL_PublicSurface = SDL_VideoSurface; + return SDL_PublicSurface; + } + /* Create a renderer for the window */ if (SDL_CreateRenderer(SDL_VideoWindow, -1, 0) < 0) { return NULL; @@ -345,6 +373,7 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) if (!SDL_VideoSurface) { return NULL; } + SDL_VideoSurface->flags |= surface_flags; /* Set a default screen palette */ if (SDL_VideoSurface->format->palette) { @@ -354,6 +383,8 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) SDL_SetTexturePalette(SDL_VideoTexture, SDL_VideoSurface->format->palette->colors, 0, SDL_VideoSurface->format->palette->ncolors); + SDL_SetDisplayPalette(SDL_VideoSurface->format->palette->colors, 0, + SDL_VideoSurface->format->palette->ncolors); } /* Create a shadow surface if necessary */ @@ -377,6 +408,9 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) if (!SDL_ShadowSurface) { return NULL; } + surface_flags &= ~SDL_SCREEN_SURFACE; + surface_flags |= SDL_SHADOW_SURFACE; + SDL_ShadowSurface->flags |= surface_flags; /* 8-bit SDL_ShadowSurface surfaces report that they have exclusive palette */ if (SDL_ShadowSurface->format->palette) { @@ -615,15 +649,15 @@ SDL_Linked_Version(void) } int -SDL_SetPalette(SDL_Surface * surface, int flags, SDL_Color * colors, +SDL_SetPalette(SDL_Surface * surface, int flags, const SDL_Color * colors, int firstcolor, int ncolors) { SDL_SetColors(surface, colors, firstcolor, ncolors); } int -SDL_SetScreenColors(SDL_Surface * screen, SDL_Color * colors, int firstcolor, - int ncolors) +SDL_SetScreenColors(SDL_Surface * screen, const SDL_Color * colors, + int firstcolor, int ncolors) { SDL_Palette *pal; int gotall; diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c index 6d673d7e7..ba50924e6 100644 --- a/src/video/SDL_pixels.c +++ b/src/video/SDL_pixels.c @@ -386,7 +386,7 @@ SDL_AllocFormat(int bpp, a = (a << format->Aloss) | ((a * Am) >> Aw); format->palette->colors[i].unused = a; #else - format->palette->colors[i].unused = 0; + format->palette->colors[i].unused = SDL_ALPHA_OPAQUE; #endif } } else if (ncolors == 2) { @@ -399,7 +399,7 @@ SDL_AllocFormat(int bpp, format->palette->colors[1].b = 0x00; } else { /* Create an empty palette */ - SDL_memset((format->palette)->colors, 0, + SDL_memset((format->palette)->colors, 0xFF, (format->palette)->ncolors * sizeof(SDL_Color)); } } @@ -474,6 +474,7 @@ SDL_DitherColors(SDL_Color * colors, int bpp) b |= b << 2; b |= b << 4; colors[i].b = b; + colors[i].unused = SDL_ALPHA_OPAQUE; } } @@ -696,7 +697,7 @@ MapNto1(SDL_PixelFormat * src, SDL_PixelFormat * dst, int *identical) /* SDL_DitherColors does not initialize the 'unused' component of colors, but Map1to1 compares it against pal, so we should initialize it. */ - SDL_memset(colors, 0, sizeof(colors)); + SDL_memset(colors, 0xFF, sizeof(colors)); dithered.ncolors = 256; SDL_DitherColors(colors, 8); diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index c9ec72a62..191de5f77 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -39,7 +39,6 @@ SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) { - SDL_VideoDevice *_this = SDL_GetVideoDevice(); SDL_Surface *screen; SDL_Surface *surface; @@ -170,7 +169,7 @@ SDL_CreateRGBSurfaceFromTexture(SDL_TextureID textureID) * Set the palette in a blittable surface */ int -SDL_SetColors(SDL_Surface * surface, SDL_Color * colors, int firstcolor, +SDL_SetColors(SDL_Surface * surface, const SDL_Color * colors, int firstcolor, int ncolors) { SDL_Palette *pal; @@ -557,7 +556,6 @@ SDL_FillRect4(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color) int SDL_FillRect(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color) { - SDL_VideoDevice *_this = SDL_GetVideoDevice(); int x, y; Uint8 *row; @@ -789,9 +787,9 @@ SDL_ConvertSurface(SDL_Surface * surface, if (format->palette != NULL) { int i; for (i = 0; i < format->palette->ncolors; ++i) { - if ((format->palette->colors[i].r != 0) || - (format->palette->colors[i].g != 0) || - (format->palette->colors[i].b != 0)) + if ((format->palette->colors[i].r != 0xFF) || + (format->palette->colors[i].g != 0xFF) || + (format->palette->colors[i].b != 0xFF)) break; } if (i == format->palette->ncolors) { diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index bc3ac7cc5..39167fdec 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -159,6 +159,8 @@ struct SDL_VideoDisplay /* The hash list of textures */ SDL_Texture *textures[64]; + SDL_VideoDevice *device; + void *driverdata; }; diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 73046fb4a..fb16e673b 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -333,6 +333,7 @@ SDL_AddVideoDisplay(const SDL_VideoDisplay * display) if (displays) { index = _this->num_displays++; displays[index] = *display; + displays[index].device = _this; _this->displays = displays; } else { SDL_OutOfMemory(); diff --git a/src/video/dummy/SDL_nullrender.c b/src/video/dummy/SDL_nullrender.c index 8390d37f4..e0c17a9af 100644 --- a/src/video/dummy/SDL_nullrender.c +++ b/src/video/dummy/SDL_nullrender.c @@ -32,11 +32,11 @@ static SDL_Renderer *SDL_DUMMY_CreateRenderer(SDL_Window * window, static int SDL_DUMMY_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); static int SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, - SDL_Rect * rect, void *pixels, + const SDL_Rect * rect, void *pixels, int pitch); static int SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer, - SDL_Rect * rect, const void *pixels, - int pitch); + const SDL_Rect * rect, + const void *pixels, int pitch); static void SDL_DUMMY_RenderPresent(SDL_Renderer * renderer); static void SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer); @@ -57,7 +57,7 @@ SDL_RenderDriver SDL_DUMMY_RenderDriver = { typedef struct { - SDL_Surface *screen; + SDL_Surface *surface; } SDL_DUMMY_RenderData; SDL_Renderer * @@ -99,24 +99,34 @@ SDL_DUMMY_CreateRenderer(SDL_Window * window, Uint32 flags) renderer->window = window; renderer->driverdata = data; - data->screen = + data->surface = SDL_CreateRGBSurface(0, window->w, window->h, bpp, Rmask, Gmask, Bmask, Amask); - if (!data->screen) { + if (!data->surface) { SDL_DUMMY_DestroyRenderer(renderer); return NULL; } + /* If the display has a palette, use it for the window surfaces */ + if (window->display->palette.ncolors) { + SDL_PixelFormat *format = data->surface->format; + if (format->palette->colors) { + SDL_free(format->palette->colors); + } + SDL_free(format->palette); + format->palette = &window->display->palette; + } + return renderer; } int -SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, SDL_Rect * rect, +SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, void *pixels, int pitch) { SDL_DUMMY_RenderData *data = (SDL_DUMMY_RenderData *) renderer->driverdata; - SDL_Surface *surface = data->screen; + SDL_Surface *surface = data->surface; Uint8 *src, *dst; int row; size_t length; @@ -135,12 +145,12 @@ SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, SDL_Rect * rect, } int -SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer, SDL_Rect * rect, +SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, const void *pixels, int pitch) { SDL_DUMMY_RenderData *data = (SDL_DUMMY_RenderData *) renderer->driverdata; - SDL_Surface *surface = data->screen; + SDL_Surface *surface = data->surface; Uint8 *src, *dst; int row; size_t length; @@ -164,7 +174,7 @@ SDL_DUMMY_RenderPresent(SDL_Renderer * renderer) static int frame_number; SDL_DUMMY_RenderData *data = (SDL_DUMMY_RenderData *) renderer->driverdata; - SDL_Surface *surface = data->screen; + SDL_Surface *surface = data->surface; if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) { char file[128]; @@ -181,8 +191,9 @@ SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer) (SDL_DUMMY_RenderData *) renderer->driverdata; if (data) { - if (data->screen) { - SDL_FreeSurface(data->screen); + if (data->surface) { + data->surface->format->palette = NULL; + SDL_FreeSurface(data->surface); } SDL_free(data); }