src/video/dummy/SDL_nullframebuffer.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 03 Jan 2018 10:03:25 -0800
changeset 11811 5d94cb6b24d3
parent 10737 3406a0f8b041
child 12503 806492103856
permissions -rw-r--r--
Updated copyright for 2018
slouken@5166
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@11811
     3
  Copyright (C) 1997-2018 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
*/
icculus@8093
    21
#include "../../SDL_internal.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@7720
    41
    SDL_FreeSurface(surface);
slouken@5166
    42
slouken@5166
    43
    /* Create a new one */
slouken@5166
    44
    SDL_PixelFormatEnumToMasks(surface_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
slouken@5166
    45
    SDL_GetWindowSize(window, &w, &h);
slouken@5166
    46
    surface = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask);
slouken@5166
    47
    if (!surface) {
slouken@5166
    48
        return -1;
slouken@5166
    49
    }
slouken@5166
    50
slouken@5166
    51
    /* Save the info and return! */
slouken@5166
    52
    SDL_SetWindowData(window, DUMMY_SURFACE, surface);
slouken@5166
    53
    *format = surface_format;
slouken@5166
    54
    *pixels = surface->pixels;
slouken@5166
    55
    *pitch = surface->pitch;
slouken@5166
    56
    return 0;
slouken@5166
    57
}
slouken@5166
    58
slouken@7014
    59
int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects)
slouken@5166
    60
{
slouken@5166
    61
    static int frame_number;
slouken@5166
    62
    SDL_Surface *surface;
slouken@5166
    63
slouken@5166
    64
    surface = (SDL_Surface *) SDL_GetWindowData(window, DUMMY_SURFACE);
slouken@5166
    65
    if (!surface) {
icculus@7037
    66
        return SDL_SetError("Couldn't find dummy surface for window");
slouken@5166
    67
    }
slouken@5166
    68
slouken@5166
    69
    /* Send the data to the display */
slouken@5166
    70
    if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) {
slouken@5166
    71
        char file[128];
slouken@5166
    72
        SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp",
slouken@5166
    73
                     SDL_GetWindowID(window), ++frame_number);
slouken@5166
    74
        SDL_SaveBMP(surface, file);
slouken@5166
    75
    }
slouken@5166
    76
    return 0;
slouken@5166
    77
}
slouken@5166
    78
slouken@5166
    79
void SDL_DUMMY_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
slouken@5166
    80
{
slouken@5166
    81
    SDL_Surface *surface;
slouken@5166
    82
slouken@5166
    83
    surface = (SDL_Surface *) SDL_SetWindowData(window, DUMMY_SURFACE, NULL);
slouken@7720
    84
    SDL_FreeSurface(surface);
slouken@5166
    85
}
slouken@5166
    86
slouken@6044
    87
#endif /* SDL_VIDEO_DRIVER_DUMMY */
slouken@6044
    88
slouken@5166
    89
/* vi: set ts=4 sw=4 expandtab: */