src/video/dummy/SDL_nullvideo.c
author Ryan C. Gordon <icculus@icculus.org>
Mon, 09 Apr 2012 23:55:43 -0400
changeset 6305 601b0e251822
parent 6138 4c64952a58fb
child 6885 700f1b25f77f
permissions -rwxr-xr-x
SDL_ExitProcess() was ignoring exit code parameter.
slouken@1
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6138
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
slouken@1
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@1
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@1
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@1
    20
*/
slouken@1402
    21
#include "SDL_config.h"
slouken@1
    22
slouken@6044
    23
#if SDL_VIDEO_DRIVER_DUMMY
slouken@6044
    24
slouken@1
    25
/* Dummy SDL video driver implementation; this is just enough to make an
slouken@1
    26
 *  SDL-based application THINK it's got a working video driver, for
slouken@1
    27
 *  applications that call SDL_Init(SDL_INIT_VIDEO) when they don't need it,
slouken@1
    28
 *  and also for use as a collection of stubs when porting SDL to a new
slouken@1
    29
 *  platform for which you haven't yet written a valid video driver.
slouken@1
    30
 *
slouken@1
    31
 * This is also a great way to determine bottlenecks: if you think that SDL
slouken@1
    32
 *  is a performance problem for a given platform, enable this driver, and
slouken@1
    33
 *  then see if your application runs faster without video overhead.
slouken@1
    34
 *
icculus@1594
    35
 * Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion
slouken@1
    36
 *  of this was cut-and-pasted from Stephane Peter's work in the AAlib
slouken@1
    37
 *  SDL video driver.  Renamed to "DUMMY" by Sam Lantinga.
slouken@1
    38
 */
slouken@1
    39
slouken@1
    40
#include "SDL_video.h"
slouken@1
    41
#include "SDL_mouse.h"
slouken@1361
    42
#include "../SDL_sysvideo.h"
slouken@1361
    43
#include "../SDL_pixels_c.h"
slouken@1361
    44
#include "../../events/SDL_events_c.h"
slouken@1
    45
slouken@1
    46
#include "SDL_nullvideo.h"
slouken@1
    47
#include "SDL_nullevents_c.h"
slouken@5166
    48
#include "SDL_nullframebuffer_c.h"
slouken@1
    49
slouken@86
    50
#define DUMMYVID_DRIVER_NAME "dummy"
slouken@86
    51
slouken@1
    52
/* Initialization/Query functions */
slouken@1895
    53
static int DUMMY_VideoInit(_THIS);
slouken@3520
    54
static int DUMMY_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
slouken@1
    55
static void DUMMY_VideoQuit(_THIS);
slouken@1
    56
slouken@1
    57
/* DUMMY driver bootstrap functions */
slouken@1
    58
slouken@1895
    59
static int
slouken@1895
    60
DUMMY_Available(void)
slouken@1
    61
{
slouken@1895
    62
    const char *envr = SDL_getenv("SDL_VIDEODRIVER");
slouken@1895
    63
    if ((envr) && (SDL_strcmp(envr, DUMMYVID_DRIVER_NAME) == 0)) {
slouken@1895
    64
        return (1);
slouken@1895
    65
    }
slouken@86
    66
slouken@1895
    67
    return (0);
slouken@1
    68
}
slouken@1
    69
slouken@1895
    70
static void
slouken@1895
    71
DUMMY_DeleteDevice(SDL_VideoDevice * device)
slouken@1
    72
{
slouken@1895
    73
    SDL_free(device);
slouken@1
    74
}
slouken@1
    75
slouken@1895
    76
static SDL_VideoDevice *
slouken@1895
    77
DUMMY_CreateDevice(int devindex)
slouken@1
    78
{
slouken@1895
    79
    SDL_VideoDevice *device;
slouken@1
    80
slouken@1895
    81
    /* Initialize all variables that we clean on shutdown */
slouken@1895
    82
    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
slouken@1895
    83
    if (!device) {
slouken@1895
    84
        SDL_OutOfMemory();
slouken@1895
    85
        if (device) {
slouken@1895
    86
            SDL_free(device);
slouken@1895
    87
        }
slouken@1895
    88
        return (0);
slouken@1895
    89
    }
slouken@1
    90
slouken@1895
    91
    /* Set the function pointers */
slouken@1895
    92
    device->VideoInit = DUMMY_VideoInit;
slouken@1913
    93
    device->VideoQuit = DUMMY_VideoQuit;
slouken@1895
    94
    device->SetDisplayMode = DUMMY_SetDisplayMode;
slouken@1895
    95
    device->PumpEvents = DUMMY_PumpEvents;
slouken@5166
    96
    device->CreateWindowFramebuffer = SDL_DUMMY_CreateWindowFramebuffer;
slouken@5166
    97
    device->UpdateWindowFramebuffer = SDL_DUMMY_UpdateWindowFramebuffer;
slouken@5166
    98
    device->DestroyWindowFramebuffer = SDL_DUMMY_DestroyWindowFramebuffer;
slouken@1
    99
slouken@1895
   100
    device->free = DUMMY_DeleteDevice;
slouken@1
   101
slouken@1895
   102
    return device;
slouken@1
   103
}
slouken@1
   104
slouken@1
   105
VideoBootStrap DUMMY_bootstrap = {
slouken@1895
   106
    DUMMYVID_DRIVER_NAME, "SDL dummy video driver",
slouken@1895
   107
    DUMMY_Available, DUMMY_CreateDevice
slouken@1
   108
};
slouken@1
   109
slouken@1
   110
slouken@1895
   111
int
slouken@1895
   112
DUMMY_VideoInit(_THIS)
slouken@1
   113
{
slouken@1895
   114
    SDL_DisplayMode mode;
slouken@1
   115
slouken@1911
   116
    /* Use a fake 32-bpp desktop mode */
slouken@1965
   117
    mode.format = SDL_PIXELFORMAT_RGB888;
slouken@1911
   118
    mode.w = 1024;
slouken@1911
   119
    mode.h = 768;
slouken@1911
   120
    mode.refresh_rate = 0;
slouken@2227
   121
    mode.driverdata = NULL;
slouken@3520
   122
    if (SDL_AddBasicVideoDisplay(&mode) < 0) {
slouken@3520
   123
        return -1;
slouken@3520
   124
    }
slouken@1
   125
slouken@1895
   126
    SDL_zero(mode);
slouken@3532
   127
    SDL_AddDisplayMode(&_this->displays[0], &mode);
slouken@1895
   128
slouken@1895
   129
    /* We're done! */
slouken@1895
   130
    return 0;
slouken@1
   131
}
slouken@1
   132
slouken@1895
   133
static int
slouken@3520
   134
DUMMY_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
slouken@1
   135
{
slouken@1895
   136
    return 0;
slouken@1
   137
}
slouken@1
   138
slouken@1895
   139
void
slouken@1895
   140
DUMMY_VideoQuit(_THIS)
slouken@1
   141
{
slouken@1
   142
}
slouken@1
   143
slouken@6044
   144
#endif /* SDL_VIDEO_DRIVER_DUMMY */
slouken@6044
   145
slouken@1895
   146
/* vi: set ts=4 sw=4 expandtab: */