Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
The dummy video driver compiles. :)
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed May 28, 2006
1 parent 41d0c2c commit 555fee5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 130 deletions.
2 changes: 0 additions & 2 deletions src/events/SDL_events.c
Expand Up @@ -219,7 +219,6 @@ SDL_StopEventLoop (void)
SDL_StopEventThread ();

/* Shutdown event handlers */
SDL_AppActiveQuit ();
SDL_KeyboardQuit ();
SDL_MouseQuit ();
SDL_QuitQuit ();
Expand Down Expand Up @@ -251,7 +250,6 @@ SDL_StartEventLoop (Uint32 flags)

/* Initialize event handlers */
retcode = 0;
retcode += SDL_AppActiveInit ();
retcode += SDL_KeyboardInit ();
retcode += SDL_MouseInit ();
retcode += SDL_QuitInit ();
Expand Down
7 changes: 1 addition & 6 deletions src/video/SDL_surface.c
Expand Up @@ -896,12 +896,7 @@ SDL_ConvertSurface (SDL_Surface * surface,
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) {
Expand Down
2 changes: 1 addition & 1 deletion src/video/SDL_sysvideo.h
Expand Up @@ -122,7 +122,7 @@ struct SDL_VideoDevice
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);
Expand Down
50 changes: 22 additions & 28 deletions src/video/SDL_video.c
Expand Up @@ -997,10 +997,8 @@ SDL_Surface *
SDL_CreateWindowSurface (SDL_WindowID windowID, Uint32 format, Uint32 flags)
{
SDL_Window *window = SDL_GetWindowFromID (windowID);
SDL_Surface *surface;
SDL_Surface *shadow;
Uint32 surface_format;
Uint32 black;
SDL_Surface *surface;

if (!window) {
return NULL;
Expand All @@ -1011,54 +1009,50 @@ SDL_CreateWindowSurface (SDL_WindowID windowID, Uint32 format, Uint32 flags)
}

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 */
Expand Down
97 changes: 10 additions & 87 deletions src/video/dummy/SDL_nullvideo.c
Expand Up @@ -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 */
Expand Down Expand Up @@ -98,6 +99,7 @@ DUMMY_CreateDevice (int devindex)
/* 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;
Expand Down Expand Up @@ -128,93 +130,17 @@ DUMMY_SetDisplayMode (_THIS, const SDL_DisplayMode * mode)
return 0;
}

static SDL_Surface *
DUMMY_CreateWindowSurface (_THIS, SDL_Window * window)
{
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)
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_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
Expand All @@ -223,9 +149,6 @@ DUMMY_SetVideoMode (_THIS, SDL_Surface * current,
void
DUMMY_VideoQuit (_THIS)
{
if (_this->hidden->buffer) {
SDL_free (_this->hidden->buffer);
}
}

/* vi: set ts=4 sw=4 expandtab: */
7 changes: 1 addition & 6 deletions test/testsprite.c
Expand Up @@ -156,7 +156,6 @@ FastestFlags (Uint32 flags, int width, int height, int bpp)
int
main (int argc, char *argv[])
{
SDL_DisplayMode mode;
SDL_Surface *screen;
Uint8 *mem;
int width, height;
Expand Down Expand Up @@ -212,11 +211,7 @@ main (int argc, char *argv[])
}

/* 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 ());
Expand Down

0 comments on commit 555fee5

Please sign in to comment.