src/video/windowsrt/SDL_winrtframebuffer.c
changeset 8327 bc51589f33dc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/windowsrt/SDL_winrtframebuffer.c	Sat Oct 27 22:48:04 2012 -0400
     1.3 @@ -0,0 +1,94 @@
     1.4 +/*
     1.5 +  Simple DirectMedia Layer
     1.6 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     1.7 +
     1.8 +  This software is provided 'as-is', without any express or implied
     1.9 +  warranty.  In no event will the authors be held liable for any damages
    1.10 +  arising from the use of this software.
    1.11 +
    1.12 +  Permission is granted to anyone to use this software for any purpose,
    1.13 +  including commercial applications, and to alter it and redistribute it
    1.14 +  freely, subject to the following restrictions:
    1.15 +
    1.16 +  1. The origin of this software must not be misrepresented; you must not
    1.17 +     claim that you wrote the original software. If you use this software
    1.18 +     in a product, an acknowledgment in the product documentation would be
    1.19 +     appreciated but is not required.
    1.20 +  2. Altered source versions must be plainly marked as such, and must not be
    1.21 +     misrepresented as being the original software.
    1.22 +  3. This notice may not be removed or altered from any source distribution.
    1.23 +*/
    1.24 +#include "SDL_config.h"
    1.25 +
    1.26 +#if SDL_VIDEO_DRIVER_WINRT
    1.27 +
    1.28 +#include "../SDL_sysvideo.h"
    1.29 +#include "SDL_winrtframebuffer_c.h"
    1.30 +
    1.31 +
    1.32 +#define WINRT_SURFACE   "_SDL_WinRTSurface"
    1.33 +
    1.34 +int SDL_WINRT_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
    1.35 +{
    1.36 +    SDL_Surface *surface;
    1.37 +    const Uint32 surface_format = SDL_PIXELFORMAT_RGB888;
    1.38 +    int w, h;
    1.39 +    int bpp;
    1.40 +    Uint32 Rmask, Gmask, Bmask, Amask;
    1.41 +
    1.42 +    /* Free the old framebuffer surface */
    1.43 +    surface = (SDL_Surface *) SDL_GetWindowData(window, WINRT_SURFACE);
    1.44 +    if (surface) {
    1.45 +        SDL_FreeSurface(surface);
    1.46 +    }
    1.47 +
    1.48 +    /* Create a new one */
    1.49 +    SDL_PixelFormatEnumToMasks(surface_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
    1.50 +    SDL_GetWindowSize(window, &w, &h);
    1.51 +    surface = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask);
    1.52 +    if (!surface) {
    1.53 +        return -1;
    1.54 +    }
    1.55 +
    1.56 +    /* Save the info and return! */
    1.57 +    SDL_SetWindowData(window, WINRT_SURFACE, surface);
    1.58 +    *format = surface_format;
    1.59 +    *pixels = surface->pixels;
    1.60 +    *pitch = surface->pitch;
    1.61 +    return 0;
    1.62 +}
    1.63 +
    1.64 +int SDL_WINRT_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects)
    1.65 +{
    1.66 +    static int frame_number;
    1.67 +    SDL_Surface *surface;
    1.68 +
    1.69 +    surface = (SDL_Surface *) SDL_GetWindowData(window, WINRT_SURFACE);
    1.70 +    if (!surface) {
    1.71 +        SDL_SetError("Couldn't find WinRT surface for window");
    1.72 +        return -1;
    1.73 +    }
    1.74 +
    1.75 +    /* Send the data to the display */
    1.76 +    if (SDL_getenv("SDL_VIDEO_WINRT_SAVE_FRAMES")) {
    1.77 +        char file[128];
    1.78 +        SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp",
    1.79 +                     SDL_GetWindowID(window), ++frame_number);
    1.80 +        SDL_SaveBMP(surface, file);
    1.81 +    }
    1.82 +    return 0;
    1.83 +}
    1.84 +
    1.85 +void SDL_WINRT_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
    1.86 +{
    1.87 +    SDL_Surface *surface;
    1.88 +
    1.89 +    surface = (SDL_Surface *) SDL_SetWindowData(window, WINRT_SURFACE, NULL);
    1.90 +    if (surface) {
    1.91 +        SDL_FreeSurface(surface);
    1.92 +    }
    1.93 +}
    1.94 +
    1.95 +#endif /* SDL_VIDEO_DRIVER_WINRT */
    1.96 +
    1.97 +/* vi: set ts=4 sw=4 expandtab: */