src/video/dummy/SDL_nullframebuffer.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@5166
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6138
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
slouken@5166
     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@5166
     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@5166
    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@5166
    20
*/
slouken@5166
    21
#include "SDL_config.h"
slouken@5166
    22
slouken@6044
    23
#if SDL_VIDEO_DRIVER_DUMMY
slouken@6044
    24
slouken@5166
    25
#include "../SDL_sysvideo.h"
slouken@6044
    26
#include "SDL_nullframebuffer_c.h"
slouken@5166
    27
slouken@5166
    28
slouken@5166
    29
#define DUMMY_SURFACE   "_SDL_DummySurface"
slouken@5166
    30
slouken@5166
    31
int SDL_DUMMY_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
slouken@5166
    32
{
slouken@5166
    33
    SDL_Surface *surface;
slouken@5166
    34
    const Uint32 surface_format = SDL_PIXELFORMAT_RGB888;
slouken@5166
    35
    int w, h;
slouken@5166
    36
    int bpp;
slouken@5166
    37
    Uint32 Rmask, Gmask, Bmask, Amask;
slouken@5166
    38
slouken@5166
    39
    /* Free the old framebuffer surface */
slouken@5166
    40
    surface = (SDL_Surface *) SDL_GetWindowData(window, DUMMY_SURFACE);
slouken@5166
    41
    if (surface) {
slouken@5166
    42
        SDL_FreeSurface(surface);
slouken@5166
    43
    }
slouken@5166
    44
slouken@5166
    45
    /* Create a new one */
slouken@5166
    46
    SDL_PixelFormatEnumToMasks(surface_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
slouken@5166
    47
    SDL_GetWindowSize(window, &w, &h);
slouken@5166
    48
    surface = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask);
slouken@5166
    49
    if (!surface) {
slouken@5166
    50
        return -1;
slouken@5166
    51
    }
slouken@5166
    52
slouken@5166
    53
    /* Save the info and return! */
slouken@5166
    54
    SDL_SetWindowData(window, DUMMY_SURFACE, surface);
slouken@5166
    55
    *format = surface_format;
slouken@5166
    56
    *pixels = surface->pixels;
slouken@5166
    57
    *pitch = surface->pitch;
slouken@5166
    58
    return 0;
slouken@5166
    59
}
slouken@5166
    60
slouken@5297
    61
int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects)
slouken@5166
    62
{
slouken@5166
    63
    static int frame_number;
slouken@5166
    64
    SDL_Surface *surface;
slouken@5166
    65
slouken@5166
    66
    surface = (SDL_Surface *) SDL_GetWindowData(window, DUMMY_SURFACE);
slouken@5166
    67
    if (!surface) {
slouken@5166
    68
        SDL_SetError("Couldn't find dummy surface for window");
slouken@5166
    69
        return -1;
slouken@5166
    70
    }
slouken@5166
    71
slouken@5166
    72
    /* Send the data to the display */
slouken@5166
    73
    if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) {
slouken@5166
    74
        char file[128];
slouken@5166
    75
        SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp",
slouken@5166
    76
                     SDL_GetWindowID(window), ++frame_number);
slouken@5166
    77
        SDL_SaveBMP(surface, file);
slouken@5166
    78
    }
slouken@5166
    79
    return 0;
slouken@5166
    80
}
slouken@5166
    81
slouken@5166
    82
void SDL_DUMMY_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
slouken@5166
    83
{
slouken@5166
    84
    SDL_Surface *surface;
slouken@5166
    85
slouken@5166
    86
    surface = (SDL_Surface *) SDL_SetWindowData(window, DUMMY_SURFACE, NULL);
slouken@5166
    87
    if (surface) {
slouken@5166
    88
        SDL_FreeSurface(surface);
slouken@5166
    89
    }
slouken@5166
    90
}
slouken@5166
    91
slouken@6044
    92
#endif /* SDL_VIDEO_DRIVER_DUMMY */
slouken@6044
    93
slouken@5166
    94
/* vi: set ts=4 sw=4 expandtab: */