src/video/windowsrt/SDL_winrtframebuffer.cpp
author David Ludwig <dludwig@pobox.com>
Sun, 28 Oct 2012 18:45:33 -0400
changeset 8329 c3047b88e35b
parent 8327 src/video/windowsrt/SDL_winrtframebuffer.c@bc51589f33dc
child 8342 05d7aa70928e
permissions -rw-r--r--
WinRT: made the device's screen size be retrieve-able via SDL_GetDisplayMode()
dludwig@8327
     1
/*
dludwig@8327
     2
  Simple DirectMedia Layer
dludwig@8327
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
dludwig@8327
     4
dludwig@8327
     5
  This software is provided 'as-is', without any express or implied
dludwig@8327
     6
  warranty.  In no event will the authors be held liable for any damages
dludwig@8327
     7
  arising from the use of this software.
dludwig@8327
     8
dludwig@8327
     9
  Permission is granted to anyone to use this software for any purpose,
dludwig@8327
    10
  including commercial applications, and to alter it and redistribute it
dludwig@8327
    11
  freely, subject to the following restrictions:
dludwig@8327
    12
dludwig@8327
    13
  1. The origin of this software must not be misrepresented; you must not
dludwig@8327
    14
     claim that you wrote the original software. If you use this software
dludwig@8327
    15
     in a product, an acknowledgment in the product documentation would be
dludwig@8327
    16
     appreciated but is not required.
dludwig@8327
    17
  2. Altered source versions must be plainly marked as such, and must not be
dludwig@8327
    18
     misrepresented as being the original software.
dludwig@8327
    19
  3. This notice may not be removed or altered from any source distribution.
dludwig@8327
    20
*/
dludwig@8327
    21
#include "SDL_config.h"
dludwig@8327
    22
dludwig@8327
    23
#if SDL_VIDEO_DRIVER_WINRT
dludwig@8327
    24
dludwig@8327
    25
#include "../SDL_sysvideo.h"
dludwig@8327
    26
#include "SDL_winrtframebuffer_c.h"
dludwig@8327
    27
dludwig@8327
    28
dludwig@8327
    29
#define WINRT_SURFACE   "_SDL_WinRTSurface"
dludwig@8327
    30
dludwig@8327
    31
int SDL_WINRT_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
dludwig@8327
    32
{
dludwig@8327
    33
    SDL_Surface *surface;
dludwig@8327
    34
    const Uint32 surface_format = SDL_PIXELFORMAT_RGB888;
dludwig@8327
    35
    int w, h;
dludwig@8327
    36
    int bpp;
dludwig@8327
    37
    Uint32 Rmask, Gmask, Bmask, Amask;
dludwig@8327
    38
dludwig@8327
    39
    /* Free the old framebuffer surface */
dludwig@8327
    40
    surface = (SDL_Surface *) SDL_GetWindowData(window, WINRT_SURFACE);
dludwig@8327
    41
    if (surface) {
dludwig@8327
    42
        SDL_FreeSurface(surface);
dludwig@8327
    43
    }
dludwig@8327
    44
dludwig@8327
    45
    /* Create a new one */
dludwig@8327
    46
    SDL_PixelFormatEnumToMasks(surface_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
dludwig@8327
    47
    SDL_GetWindowSize(window, &w, &h);
dludwig@8327
    48
    surface = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask);
dludwig@8327
    49
    if (!surface) {
dludwig@8327
    50
        return -1;
dludwig@8327
    51
    }
dludwig@8327
    52
dludwig@8327
    53
    /* Save the info and return! */
dludwig@8327
    54
    SDL_SetWindowData(window, WINRT_SURFACE, surface);
dludwig@8327
    55
    *format = surface_format;
dludwig@8327
    56
    *pixels = surface->pixels;
dludwig@8327
    57
    *pitch = surface->pitch;
dludwig@8327
    58
    return 0;
dludwig@8327
    59
}
dludwig@8327
    60
dludwig@8327
    61
int SDL_WINRT_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects)
dludwig@8327
    62
{
dludwig@8327
    63
    static int frame_number;
dludwig@8327
    64
    SDL_Surface *surface;
dludwig@8327
    65
dludwig@8327
    66
    surface = (SDL_Surface *) SDL_GetWindowData(window, WINRT_SURFACE);
dludwig@8327
    67
    if (!surface) {
dludwig@8327
    68
        SDL_SetError("Couldn't find WinRT surface for window");
dludwig@8327
    69
        return -1;
dludwig@8327
    70
    }
dludwig@8327
    71
dludwig@8327
    72
    /* Send the data to the display */
dludwig@8327
    73
    if (SDL_getenv("SDL_VIDEO_WINRT_SAVE_FRAMES")) {
dludwig@8327
    74
        char file[128];
dludwig@8327
    75
        SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp",
dludwig@8327
    76
                     SDL_GetWindowID(window), ++frame_number);
dludwig@8327
    77
        SDL_SaveBMP(surface, file);
dludwig@8327
    78
    }
dludwig@8327
    79
    return 0;
dludwig@8327
    80
}
dludwig@8327
    81
dludwig@8327
    82
void SDL_WINRT_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
dludwig@8327
    83
{
dludwig@8327
    84
    SDL_Surface *surface;
dludwig@8327
    85
dludwig@8327
    86
    surface = (SDL_Surface *) SDL_SetWindowData(window, WINRT_SURFACE, NULL);
dludwig@8327
    87
    if (surface) {
dludwig@8327
    88
        SDL_FreeSurface(surface);
dludwig@8327
    89
    }
dludwig@8327
    90
}
dludwig@8327
    91
dludwig@8327
    92
#endif /* SDL_VIDEO_DRIVER_WINRT */
dludwig@8327
    93
dludwig@8327
    94
/* vi: set ts=4 sw=4 expandtab: */