src/video/windowsrt/SDL_winrtvideo.c
author David Ludwig <dludwig@pobox.com>
Sat, 27 Oct 2012 22:57:07 -0400
changeset 8328 88b08ad81bf7
parent 8327 bc51589f33dc
permissions -rw-r--r--
WinRT: made the WinRT video driver always be initialize-able
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 #include "SDL_config.h"
    22 
    23 #if SDL_VIDEO_DRIVER_WINRT
    24 
    25 /* WinRT SDL video driver implementation
    26 
    27    Initial work on this was done by David Ludwig (dludwig@pobox.com), and
    28    was based off of SDL's "dummy" video driver.
    29  */
    30 
    31 #include "SDL_video.h"
    32 #include "SDL_mouse.h"
    33 #include "../SDL_sysvideo.h"
    34 #include "../SDL_pixels_c.h"
    35 #include "../../events/SDL_events_c.h"
    36 
    37 #include "SDL_winrtvideo.h"
    38 #include "SDL_winrtevents_c.h"
    39 #include "SDL_winrtframebuffer_c.h"
    40 
    41 #define WINRTVID_DRIVER_NAME "dummy"
    42 
    43 /* Initialization/Query functions */
    44 static int WINRT_VideoInit(_THIS);
    45 static int WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
    46 static void WINRT_VideoQuit(_THIS);
    47 
    48 /* WinRT driver bootstrap functions */
    49 
    50 static int
    51 WINRT_Available(void)
    52 {
    53     return (1);
    54 }
    55 
    56 static void
    57 WINRT_DeleteDevice(SDL_VideoDevice * device)
    58 {
    59     SDL_free(device);
    60 }
    61 
    62 static SDL_VideoDevice *
    63 WINRT_CreateDevice(int devindex)
    64 {
    65     SDL_VideoDevice *device;
    66 
    67     /* Initialize all variables that we clean on shutdown */
    68     device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
    69     if (!device) {
    70         SDL_OutOfMemory();
    71         if (device) {
    72             SDL_free(device);
    73         }
    74         return (0);
    75     }
    76 
    77     /* Set the function pointers */
    78     device->VideoInit = WINRT_VideoInit;
    79     device->VideoQuit = WINRT_VideoQuit;
    80     device->SetDisplayMode = WINRT_SetDisplayMode;
    81     device->PumpEvents = WINRT_PumpEvents;
    82     device->CreateWindowFramebuffer = SDL_WINRT_CreateWindowFramebuffer;
    83     device->UpdateWindowFramebuffer = SDL_WINRT_UpdateWindowFramebuffer;
    84     device->DestroyWindowFramebuffer = SDL_WINRT_DestroyWindowFramebuffer;
    85 
    86     device->free = WINRT_DeleteDevice;
    87 
    88     return device;
    89 }
    90 
    91 VideoBootStrap WINRT_bootstrap = {
    92     WINRTVID_DRIVER_NAME, "SDL Windows RT video driver",
    93     WINRT_Available, WINRT_CreateDevice
    94 };
    95 
    96 
    97 int
    98 WINRT_VideoInit(_THIS)
    99 {
   100     SDL_DisplayMode mode;
   101 
   102     /* Use a fake 32-bpp desktop mode */
   103     mode.format = SDL_PIXELFORMAT_RGB888;
   104     mode.w = 1024;
   105     mode.h = 768;
   106     mode.refresh_rate = 0;
   107     mode.driverdata = NULL;
   108     if (SDL_AddBasicVideoDisplay(&mode) < 0) {
   109         return -1;
   110     }
   111 
   112     SDL_zero(mode);
   113     SDL_AddDisplayMode(&_this->displays[0], &mode);
   114 
   115     /* We're done! */
   116     return 0;
   117 }
   118 
   119 static int
   120 WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
   121 {
   122     return 0;
   123 }
   124 
   125 void
   126 WINRT_VideoQuit(_THIS)
   127 {
   128 }
   129 
   130 #endif /* SDL_VIDEO_DRIVER_WINRT */
   131 
   132 /* vi: set ts=4 sw=4 expandtab: */