WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
authorDavid Ludwig
Sat, 27 Oct 2012 22:48:04 -0400
changeset 8327bc51589f33dc
parent 8326 22db28fb8099
child 8328 88b08ad81bf7
WinRT: created a skeleton for a video driver, using a copy of the dummy driver for a base
VisualC/SDL/SDL_VS2012_WinRT.vcxproj
include/SDL_config_windowsrt.h
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/windowsrt/SDL_winrtevents.c
src/video/windowsrt/SDL_winrtevents_c.h
src/video/windowsrt/SDL_winrtframebuffer.c
src/video/windowsrt/SDL_winrtframebuffer_c.h
src/video/windowsrt/SDL_winrtvideo.c
src/video/windowsrt/SDL_winrtvideo.h
     1.1 --- a/VisualC/SDL/SDL_VS2012_WinRT.vcxproj	Sat Oct 27 22:27:51 2012 -0400
     1.2 +++ b/VisualC/SDL/SDL_VS2012_WinRT.vcxproj	Sat Oct 27 22:48:04 2012 -0400
     1.3 @@ -125,6 +125,9 @@
     1.4        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
     1.5        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
     1.6      </ClCompile>
     1.7 +    <ClCompile Include="..\..\src\video\windowsrt\SDL_winrtevents.c" />
     1.8 +    <ClCompile Include="..\..\src\video\windowsrt\SDL_winrtframebuffer.c" />
     1.9 +    <ClCompile Include="..\..\src\video\windowsrt\SDL_winrtvideo.c" />
    1.10    </ItemGroup>
    1.11    <ItemGroup>
    1.12      <ClInclude Include="..\..\include\begin_code.h" />
    1.13 @@ -234,6 +237,9 @@
    1.14      <ClInclude Include="..\..\src\video\windowsrt\DirectXHelper.h" />
    1.15      <ClInclude Include="..\..\src\video\windowsrt\SDLmain_WinRT_common.h" />
    1.16      <ClInclude Include="..\..\src\video\windowsrt\SDL_WinRTApp.h" />
    1.17 +    <ClInclude Include="..\..\src\video\windowsrt\SDL_winrtevents_c.h" />
    1.18 +    <ClInclude Include="..\..\src\video\windowsrt\SDL_winrtframebuffer_c.h" />
    1.19 +    <ClInclude Include="..\..\src\video\windowsrt\SDL_winrtvideo.h" />
    1.20    </ItemGroup>
    1.21    <PropertyGroup Label="Globals">
    1.22      <ProjectGuid>{aeaea3a2-d4e6-45b1-8ec6-53d84287fc14}</ProjectGuid>
     2.1 --- a/include/SDL_config_windowsrt.h	Sat Oct 27 22:27:51 2012 -0400
     2.2 +++ b/include/SDL_config_windowsrt.h	Sat Oct 27 22:48:04 2012 -0400
     2.3 @@ -169,7 +169,8 @@
     2.4  #define SDL_TIMERS_DISABLED	1
     2.5  
     2.6  /* Enable various video drivers */
     2.7 -#define SDL_VIDEO_DRIVER_DUMMY	1
     2.8 +#define SDL_VIDEO_DRIVER_WINRT	1
     2.9 +#define SDL_VIDEO_DRIVER_DUMMY  1
    2.10  
    2.11  // TODO, WinRT: Get a Direct3D 11 based renderer working in SDL.
    2.12  
     3.1 --- a/src/video/SDL_sysvideo.h	Sat Oct 27 22:27:51 2012 -0400
     3.2 +++ b/src/video/SDL_sysvideo.h	Sat Oct 27 22:48:04 2012 -0400
     3.3 @@ -327,6 +327,9 @@
     3.4  #if SDL_VIDEO_DRIVER_WINDOWS
     3.5  extern VideoBootStrap WINDOWS_bootstrap;
     3.6  #endif
     3.7 +#if SDL_VIDEO_DRIVER_WINRT
     3.8 +extern VideoBootStrap WINRT_bootstrap;
     3.9 +#endif
    3.10  #if SDL_VIDEO_DRIVER_BWINDOW
    3.11  extern VideoBootStrap BWINDOW_bootstrap;
    3.12  #endif
     4.1 --- a/src/video/SDL_video.c	Sat Oct 27 22:27:51 2012 -0400
     4.2 +++ b/src/video/SDL_video.c	Sat Oct 27 22:48:04 2012 -0400
     4.3 @@ -63,6 +63,9 @@
     4.4  #if SDL_VIDEO_DRIVER_WINDOWS
     4.5      &WINDOWS_bootstrap,
     4.6  #endif
     4.7 +#if SDL_VIDEO_DRIVER_WINRT
     4.8 +    &WINRT_bootstrap,
     4.9 +#endif
    4.10  #if SDL_VIDEO_DRIVER_BWINDOW
    4.11      &BWINDOW_bootstrap,
    4.12  #endif
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/video/windowsrt/SDL_winrtevents.c	Sat Oct 27 22:48:04 2012 -0400
     5.3 @@ -0,0 +1,41 @@
     5.4 +/*
     5.5 +  Simple DirectMedia Layer
     5.6 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     5.7 +
     5.8 +  This software is provided 'as-is', without any express or implied
     5.9 +  warranty.  In no event will the authors be held liable for any damages
    5.10 +  arising from the use of this software.
    5.11 +
    5.12 +  Permission is granted to anyone to use this software for any purpose,
    5.13 +  including commercial applications, and to alter it and redistribute it
    5.14 +  freely, subject to the following restrictions:
    5.15 +
    5.16 +  1. The origin of this software must not be misrepresented; you must not
    5.17 +     claim that you wrote the original software. If you use this software
    5.18 +     in a product, an acknowledgment in the product documentation would be
    5.19 +     appreciated but is not required.
    5.20 +  2. Altered source versions must be plainly marked as such, and must not be
    5.21 +     misrepresented as being the original software.
    5.22 +  3. This notice may not be removed or altered from any source distribution.
    5.23 +*/
    5.24 +#include "SDL_config.h"
    5.25 +
    5.26 +#if SDL_VIDEO_DRIVER_WINRT
    5.27 +
    5.28 +/* Being a null driver, there's no event stream. We just define stubs for
    5.29 +   most of the API. */
    5.30 +
    5.31 +#include "../../events/SDL_events_c.h"
    5.32 +
    5.33 +#include "SDL_winrtvideo.h"
    5.34 +#include "SDL_winrtevents_c.h"
    5.35 +
    5.36 +void
    5.37 +WINRT_PumpEvents(_THIS)
    5.38 +{
    5.39 +    /* do nothing. */
    5.40 +}
    5.41 +
    5.42 +#endif /* SDL_VIDEO_DRIVER_WINRT */
    5.43 +
    5.44 +/* vi: set ts=4 sw=4 expandtab: */
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/video/windowsrt/SDL_winrtevents_c.h	Sat Oct 27 22:48:04 2012 -0400
     6.3 @@ -0,0 +1,27 @@
     6.4 +/*
     6.5 +  Simple DirectMedia Layer
     6.6 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     6.7 +
     6.8 +  This software is provided 'as-is', without any express or implied
     6.9 +  warranty.  In no event will the authors be held liable for any damages
    6.10 +  arising from the use of this software.
    6.11 +
    6.12 +  Permission is granted to anyone to use this software for any purpose,
    6.13 +  including commercial applications, and to alter it and redistribute it
    6.14 +  freely, subject to the following restrictions:
    6.15 +
    6.16 +  1. The origin of this software must not be misrepresented; you must not
    6.17 +     claim that you wrote the original software. If you use this software
    6.18 +     in a product, an acknowledgment in the product documentation would be
    6.19 +     appreciated but is not required.
    6.20 +  2. Altered source versions must be plainly marked as such, and must not be
    6.21 +     misrepresented as being the original software.
    6.22 +  3. This notice may not be removed or altered from any source distribution.
    6.23 +*/
    6.24 +#include "SDL_config.h"
    6.25 +
    6.26 +#include "SDL_winrtvideo.h"
    6.27 +
    6.28 +extern void WINRT_PumpEvents(_THIS);
    6.29 +
    6.30 +/* vi: set ts=4 sw=4 expandtab: */
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/video/windowsrt/SDL_winrtframebuffer.c	Sat Oct 27 22:48:04 2012 -0400
     7.3 @@ -0,0 +1,94 @@
     7.4 +/*
     7.5 +  Simple DirectMedia Layer
     7.6 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     7.7 +
     7.8 +  This software is provided 'as-is', without any express or implied
     7.9 +  warranty.  In no event will the authors be held liable for any damages
    7.10 +  arising from the use of this software.
    7.11 +
    7.12 +  Permission is granted to anyone to use this software for any purpose,
    7.13 +  including commercial applications, and to alter it and redistribute it
    7.14 +  freely, subject to the following restrictions:
    7.15 +
    7.16 +  1. The origin of this software must not be misrepresented; you must not
    7.17 +     claim that you wrote the original software. If you use this software
    7.18 +     in a product, an acknowledgment in the product documentation would be
    7.19 +     appreciated but is not required.
    7.20 +  2. Altered source versions must be plainly marked as such, and must not be
    7.21 +     misrepresented as being the original software.
    7.22 +  3. This notice may not be removed or altered from any source distribution.
    7.23 +*/
    7.24 +#include "SDL_config.h"
    7.25 +
    7.26 +#if SDL_VIDEO_DRIVER_WINRT
    7.27 +
    7.28 +#include "../SDL_sysvideo.h"
    7.29 +#include "SDL_winrtframebuffer_c.h"
    7.30 +
    7.31 +
    7.32 +#define WINRT_SURFACE   "_SDL_WinRTSurface"
    7.33 +
    7.34 +int SDL_WINRT_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
    7.35 +{
    7.36 +    SDL_Surface *surface;
    7.37 +    const Uint32 surface_format = SDL_PIXELFORMAT_RGB888;
    7.38 +    int w, h;
    7.39 +    int bpp;
    7.40 +    Uint32 Rmask, Gmask, Bmask, Amask;
    7.41 +
    7.42 +    /* Free the old framebuffer surface */
    7.43 +    surface = (SDL_Surface *) SDL_GetWindowData(window, WINRT_SURFACE);
    7.44 +    if (surface) {
    7.45 +        SDL_FreeSurface(surface);
    7.46 +    }
    7.47 +
    7.48 +    /* Create a new one */
    7.49 +    SDL_PixelFormatEnumToMasks(surface_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
    7.50 +    SDL_GetWindowSize(window, &w, &h);
    7.51 +    surface = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask);
    7.52 +    if (!surface) {
    7.53 +        return -1;
    7.54 +    }
    7.55 +
    7.56 +    /* Save the info and return! */
    7.57 +    SDL_SetWindowData(window, WINRT_SURFACE, surface);
    7.58 +    *format = surface_format;
    7.59 +    *pixels = surface->pixels;
    7.60 +    *pitch = surface->pitch;
    7.61 +    return 0;
    7.62 +}
    7.63 +
    7.64 +int SDL_WINRT_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects)
    7.65 +{
    7.66 +    static int frame_number;
    7.67 +    SDL_Surface *surface;
    7.68 +
    7.69 +    surface = (SDL_Surface *) SDL_GetWindowData(window, WINRT_SURFACE);
    7.70 +    if (!surface) {
    7.71 +        SDL_SetError("Couldn't find WinRT surface for window");
    7.72 +        return -1;
    7.73 +    }
    7.74 +
    7.75 +    /* Send the data to the display */
    7.76 +    if (SDL_getenv("SDL_VIDEO_WINRT_SAVE_FRAMES")) {
    7.77 +        char file[128];
    7.78 +        SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp",
    7.79 +                     SDL_GetWindowID(window), ++frame_number);
    7.80 +        SDL_SaveBMP(surface, file);
    7.81 +    }
    7.82 +    return 0;
    7.83 +}
    7.84 +
    7.85 +void SDL_WINRT_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
    7.86 +{
    7.87 +    SDL_Surface *surface;
    7.88 +
    7.89 +    surface = (SDL_Surface *) SDL_SetWindowData(window, WINRT_SURFACE, NULL);
    7.90 +    if (surface) {
    7.91 +        SDL_FreeSurface(surface);
    7.92 +    }
    7.93 +}
    7.94 +
    7.95 +#endif /* SDL_VIDEO_DRIVER_WINRT */
    7.96 +
    7.97 +/* vi: set ts=4 sw=4 expandtab: */
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/video/windowsrt/SDL_winrtframebuffer_c.h	Sat Oct 27 22:48:04 2012 -0400
     8.3 @@ -0,0 +1,27 @@
     8.4 +/*
     8.5 +  Simple DirectMedia Layer
     8.6 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     8.7 +
     8.8 +  This software is provided 'as-is', without any express or implied
     8.9 +  warranty.  In no event will the authors be held liable for any damages
    8.10 +  arising from the use of this software.
    8.11 +
    8.12 +  Permission is granted to anyone to use this software for any purpose,
    8.13 +  including commercial applications, and to alter it and redistribute it
    8.14 +  freely, subject to the following restrictions:
    8.15 +
    8.16 +  1. The origin of this software must not be misrepresented; you must not
    8.17 +     claim that you wrote the original software. If you use this software
    8.18 +     in a product, an acknowledgment in the product documentation would be
    8.19 +     appreciated but is not required.
    8.20 +  2. Altered source versions must be plainly marked as such, and must not be
    8.21 +     misrepresented as being the original software.
    8.22 +  3. This notice may not be removed or altered from any source distribution.
    8.23 +*/
    8.24 +#include "SDL_config.h"
    8.25 +
    8.26 +extern int SDL_WINRT_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
    8.27 +extern int SDL_WINRT_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects);
    8.28 +extern void SDL_WINRT_DestroyWindowFramebuffer(_THIS, SDL_Window * window);
    8.29 +
    8.30 +/* vi: set ts=4 sw=4 expandtab: */
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/video/windowsrt/SDL_winrtvideo.c	Sat Oct 27 22:48:04 2012 -0400
     9.3 @@ -0,0 +1,137 @@
     9.4 +/*
     9.5 +  Simple DirectMedia Layer
     9.6 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     9.7 +
     9.8 +  This software is provided 'as-is', without any express or implied
     9.9 +  warranty.  In no event will the authors be held liable for any damages
    9.10 +  arising from the use of this software.
    9.11 +
    9.12 +  Permission is granted to anyone to use this software for any purpose,
    9.13 +  including commercial applications, and to alter it and redistribute it
    9.14 +  freely, subject to the following restrictions:
    9.15 +
    9.16 +  1. The origin of this software must not be misrepresented; you must not
    9.17 +     claim that you wrote the original software. If you use this software
    9.18 +     in a product, an acknowledgment in the product documentation would be
    9.19 +     appreciated but is not required.
    9.20 +  2. Altered source versions must be plainly marked as such, and must not be
    9.21 +     misrepresented as being the original software.
    9.22 +  3. This notice may not be removed or altered from any source distribution.
    9.23 +*/
    9.24 +#include "SDL_config.h"
    9.25 +
    9.26 +#if SDL_VIDEO_DRIVER_WINRT
    9.27 +
    9.28 +/* WinRT SDL video driver implementation
    9.29 +
    9.30 +   Initial work on this was done by David Ludwig (dludwig@pobox.com), and
    9.31 +   was based off of SDL's "dummy" video driver.
    9.32 + */
    9.33 +
    9.34 +#include "SDL_video.h"
    9.35 +#include "SDL_mouse.h"
    9.36 +#include "../SDL_sysvideo.h"
    9.37 +#include "../SDL_pixels_c.h"
    9.38 +#include "../../events/SDL_events_c.h"
    9.39 +
    9.40 +#include "SDL_winrtvideo.h"
    9.41 +#include "SDL_winrtevents_c.h"
    9.42 +#include "SDL_winrtframebuffer_c.h"
    9.43 +
    9.44 +#define WINRTVID_DRIVER_NAME "dummy"
    9.45 +
    9.46 +/* Initialization/Query functions */
    9.47 +static int WINRT_VideoInit(_THIS);
    9.48 +static int WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
    9.49 +static void WINRT_VideoQuit(_THIS);
    9.50 +
    9.51 +/* WinRT driver bootstrap functions */
    9.52 +
    9.53 +static int
    9.54 +WINRT_Available(void)
    9.55 +{
    9.56 +    const char *envr = SDL_getenv("SDL_VIDEODRIVER");
    9.57 +    if ((envr) && (SDL_strcmp(envr, WINRTVID_DRIVER_NAME) == 0)) {
    9.58 +        return (1);
    9.59 +    }
    9.60 +
    9.61 +    return (0);
    9.62 +}
    9.63 +
    9.64 +static void
    9.65 +WINRT_DeleteDevice(SDL_VideoDevice * device)
    9.66 +{
    9.67 +    SDL_free(device);
    9.68 +}
    9.69 +
    9.70 +static SDL_VideoDevice *
    9.71 +WINRT_CreateDevice(int devindex)
    9.72 +{
    9.73 +    SDL_VideoDevice *device;
    9.74 +
    9.75 +    /* Initialize all variables that we clean on shutdown */
    9.76 +    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
    9.77 +    if (!device) {
    9.78 +        SDL_OutOfMemory();
    9.79 +        if (device) {
    9.80 +            SDL_free(device);
    9.81 +        }
    9.82 +        return (0);
    9.83 +    }
    9.84 +
    9.85 +    /* Set the function pointers */
    9.86 +    device->VideoInit = WINRT_VideoInit;
    9.87 +    device->VideoQuit = WINRT_VideoQuit;
    9.88 +    device->SetDisplayMode = WINRT_SetDisplayMode;
    9.89 +    device->PumpEvents = WINRT_PumpEvents;
    9.90 +    device->CreateWindowFramebuffer = SDL_WINRT_CreateWindowFramebuffer;
    9.91 +    device->UpdateWindowFramebuffer = SDL_WINRT_UpdateWindowFramebuffer;
    9.92 +    device->DestroyWindowFramebuffer = SDL_WINRT_DestroyWindowFramebuffer;
    9.93 +
    9.94 +    device->free = WINRT_DeleteDevice;
    9.95 +
    9.96 +    return device;
    9.97 +}
    9.98 +
    9.99 +VideoBootStrap WINRT_bootstrap = {
   9.100 +    WINRTVID_DRIVER_NAME, "SDL Windows RT video driver",
   9.101 +    WINRT_Available, WINRT_CreateDevice
   9.102 +};
   9.103 +
   9.104 +
   9.105 +int
   9.106 +WINRT_VideoInit(_THIS)
   9.107 +{
   9.108 +    SDL_DisplayMode mode;
   9.109 +
   9.110 +    /* Use a fake 32-bpp desktop mode */
   9.111 +    mode.format = SDL_PIXELFORMAT_RGB888;
   9.112 +    mode.w = 1024;
   9.113 +    mode.h = 768;
   9.114 +    mode.refresh_rate = 0;
   9.115 +    mode.driverdata = NULL;
   9.116 +    if (SDL_AddBasicVideoDisplay(&mode) < 0) {
   9.117 +        return -1;
   9.118 +    }
   9.119 +
   9.120 +    SDL_zero(mode);
   9.121 +    SDL_AddDisplayMode(&_this->displays[0], &mode);
   9.122 +
   9.123 +    /* We're done! */
   9.124 +    return 0;
   9.125 +}
   9.126 +
   9.127 +static int
   9.128 +WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
   9.129 +{
   9.130 +    return 0;
   9.131 +}
   9.132 +
   9.133 +void
   9.134 +WINRT_VideoQuit(_THIS)
   9.135 +{
   9.136 +}
   9.137 +
   9.138 +#endif /* SDL_VIDEO_DRIVER_WINRT */
   9.139 +
   9.140 +/* vi: set ts=4 sw=4 expandtab: */
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/video/windowsrt/SDL_winrtvideo.h	Sat Oct 27 22:48:04 2012 -0400
    10.3 @@ -0,0 +1,30 @@
    10.4 +/*
    10.5 +  Simple DirectMedia Layer
    10.6 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
    10.7 +
    10.8 +  This software is provided 'as-is', without any express or implied
    10.9 +  warranty.  In no event will the authors be held liable for any damages
   10.10 +  arising from the use of this software.
   10.11 +
   10.12 +  Permission is granted to anyone to use this software for any purpose,
   10.13 +  including commercial applications, and to alter it and redistribute it
   10.14 +  freely, subject to the following restrictions:
   10.15 +
   10.16 +  1. The origin of this software must not be misrepresented; you must not
   10.17 +     claim that you wrote the original software. If you use this software
   10.18 +     in a product, an acknowledgment in the product documentation would be
   10.19 +     appreciated but is not required.
   10.20 +  2. Altered source versions must be plainly marked as such, and must not be
   10.21 +     misrepresented as being the original software.
   10.22 +  3. This notice may not be removed or altered from any source distribution.
   10.23 +*/
   10.24 +#include "SDL_config.h"
   10.25 +
   10.26 +#ifndef _SDL_winrtvideo_h
   10.27 +#define _SDL_winrtvideo_h
   10.28 +
   10.29 +#include "../SDL_sysvideo.h"
   10.30 +
   10.31 +#endif /* _SDL_winrtvideo_h */
   10.32 +
   10.33 +/* vi: set ts=4 sw=4 expandtab: */