src/video/dummy/SDL_nullvideo.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 02 Jan 2016 10:10:34 -0800
changeset 9998 f67cf37e9cd4
parent 9619 b94b6d0bff0f
child 10699 5b918dee0872
permissions -rw-r--r--
Updated copyright to 2016
slouken@1
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@9998
     3
  Copyright (C) 1997-2016 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
*/
icculus@8093
    21
#include "../../SDL_internal.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
        return (0);
slouken@1895
    86
    }
slouken@1
    87
slouken@1895
    88
    /* Set the function pointers */
slouken@1895
    89
    device->VideoInit = DUMMY_VideoInit;
slouken@1913
    90
    device->VideoQuit = DUMMY_VideoQuit;
slouken@1895
    91
    device->SetDisplayMode = DUMMY_SetDisplayMode;
slouken@1895
    92
    device->PumpEvents = DUMMY_PumpEvents;
slouken@5166
    93
    device->CreateWindowFramebuffer = SDL_DUMMY_CreateWindowFramebuffer;
slouken@5166
    94
    device->UpdateWindowFramebuffer = SDL_DUMMY_UpdateWindowFramebuffer;
slouken@5166
    95
    device->DestroyWindowFramebuffer = SDL_DUMMY_DestroyWindowFramebuffer;
slouken@1
    96
slouken@1895
    97
    device->free = DUMMY_DeleteDevice;
slouken@1
    98
slouken@1895
    99
    return device;
slouken@1
   100
}
slouken@1
   101
slouken@1
   102
VideoBootStrap DUMMY_bootstrap = {
slouken@1895
   103
    DUMMYVID_DRIVER_NAME, "SDL dummy video driver",
slouken@1895
   104
    DUMMY_Available, DUMMY_CreateDevice
slouken@1
   105
};
slouken@1
   106
slouken@1
   107
slouken@1895
   108
int
slouken@1895
   109
DUMMY_VideoInit(_THIS)
slouken@1
   110
{
slouken@1895
   111
    SDL_DisplayMode mode;
slouken@1
   112
slouken@1911
   113
    /* Use a fake 32-bpp desktop mode */
slouken@1965
   114
    mode.format = SDL_PIXELFORMAT_RGB888;
slouken@1911
   115
    mode.w = 1024;
slouken@1911
   116
    mode.h = 768;
slouken@1911
   117
    mode.refresh_rate = 0;
slouken@2227
   118
    mode.driverdata = NULL;
slouken@3520
   119
    if (SDL_AddBasicVideoDisplay(&mode) < 0) {
slouken@3520
   120
        return -1;
slouken@3520
   121
    }
slouken@1
   122
slouken@1895
   123
    SDL_zero(mode);
slouken@3532
   124
    SDL_AddDisplayMode(&_this->displays[0], &mode);
slouken@1895
   125
slouken@1895
   126
    /* We're done! */
slouken@1895
   127
    return 0;
slouken@1
   128
}
slouken@1
   129
slouken@1895
   130
static int
slouken@3520
   131
DUMMY_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
slouken@1
   132
{
slouken@1895
   133
    return 0;
slouken@1
   134
}
slouken@1
   135
slouken@1895
   136
void
slouken@1895
   137
DUMMY_VideoQuit(_THIS)
slouken@1
   138
{
slouken@1
   139
}
slouken@1
   140
slouken@6044
   141
#endif /* SDL_VIDEO_DRIVER_DUMMY */
slouken@6044
   142
slouken@1895
   143
/* vi: set ts=4 sw=4 expandtab: */