src/video/windowsrt/SDL_winrtvideo.cpp
changeset 8411 aca0591bc58f
parent 8401 29ecd2eca4af
child 8412 59f1191a5cca
equal deleted inserted replaced
8410:ba725b3a0c87 8411:aca0591bc58f
    33 #include "SDL_mouse.h"
    33 #include "SDL_mouse.h"
    34 #include "../SDL_sysvideo.h"
    34 #include "../SDL_sysvideo.h"
    35 #include "../SDL_pixels_c.h"
    35 #include "../SDL_pixels_c.h"
    36 #include "../../events/SDL_events_c.h"
    36 #include "../../events/SDL_events_c.h"
    37 #include "../../render/SDL_sysrender.h"
    37 #include "../../render/SDL_sysrender.h"
       
    38 #include "SDL_syswm.h"
    38 }
    39 }
    39 
    40 
    40 #include "SDL_WinRTApp.h"
    41 #include "SDL_WinRTApp.h"
    41 #include "SDL_winrtvideo.h"
    42 #include "SDL_winrtvideo.h"
    42 #include "SDL_winrtevents_c.h"
    43 #include "SDL_winrtevents_c.h"
    59 static void WINRT_VideoQuit(_THIS);
    60 static void WINRT_VideoQuit(_THIS);
    60 
    61 
    61 /* Window functions */
    62 /* Window functions */
    62 static int WINRT_CreateWindow(_THIS, SDL_Window * window);
    63 static int WINRT_CreateWindow(_THIS, SDL_Window * window);
    63 static void WINRT_DestroyWindow(_THIS, SDL_Window * window);
    64 static void WINRT_DestroyWindow(_THIS, SDL_Window * window);
       
    65 static SDL_bool WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info);
    64 
    66 
    65 /* WinRT driver bootstrap functions */
    67 /* WinRT driver bootstrap functions */
    66 
    68 
    67 static int
    69 static int
    68 WINRT_Available(void)
    70 WINRT_Available(void)
    99     device->SetDisplayMode = WINRT_SetDisplayMode;
   101     device->SetDisplayMode = WINRT_SetDisplayMode;
   100     device->PumpEvents = WINRT_PumpEvents;
   102     device->PumpEvents = WINRT_PumpEvents;
   101     device->CreateWindowFramebuffer = SDL_WINRT_CreateWindowFramebuffer;
   103     device->CreateWindowFramebuffer = SDL_WINRT_CreateWindowFramebuffer;
   102     device->UpdateWindowFramebuffer = SDL_WINRT_UpdateWindowFramebuffer;
   104     device->UpdateWindowFramebuffer = SDL_WINRT_UpdateWindowFramebuffer;
   103     device->DestroyWindowFramebuffer = SDL_WINRT_DestroyWindowFramebuffer;
   105     device->DestroyWindowFramebuffer = SDL_WINRT_DestroyWindowFramebuffer;
       
   106     device->GetWindowWMInfo = WINRT_GetWindowWMInfo;
   104 
   107 
   105     device->free = WINRT_DeleteDevice;
   108     device->free = WINRT_DeleteDevice;
   106 
   109 
   107     return device;
   110     return device;
   108 }
   111 }
   157     {
   160     {
   158         SDL_SetError("WinRT only supports one window");
   161         SDL_SetError("WinRT only supports one window");
   159         return -1;
   162         return -1;
   160     }
   163     }
   161 
   164 
   162     SDL_WindowData *data;
   165     SDL_WindowData *data = new SDL_WindowData;
   163     data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
       
   164     if (!data) {
   166     if (!data) {
   165         SDL_OutOfMemory();
   167         SDL_OutOfMemory();
   166         return -1;
   168         return -1;
   167     }
   169     }
   168     SDL_zerop(data);
       
   169     data->sdlWindow = window;
   170     data->sdlWindow = window;
       
   171     data->coreWindow = new CoreWindow^(CoreWindow::GetForCurrentThread());
   170 
   172 
   171     /* Make sure the window is considered to be positioned at {0,0},
   173     /* Make sure the window is considered to be positioned at {0,0},
   172        and is considered fullscreen, shown, and the like.
   174        and is considered fullscreen, shown, and the like.
   173     */
   175     */
   174     window->x = 0;
   176     window->x = 0;
   220     // for refactoring purposes.  Initialize the SDL_Renderer
   222     // for refactoring purposes.  Initialize the SDL_Renderer
   221     // first in order to give it the opportunity to create key
   223     // first in order to give it the opportunity to create key
   222     // resources first.
   224     // resources first.
   223     //
   225     //
   224     // TODO, WinRT: either make WINRT_CreateWindow not call SDL_CreateRenderer, or have it do error checking if it does call it
   226     // TODO, WinRT: either make WINRT_CreateWindow not call SDL_CreateRenderer, or have it do error checking if it does call it
       
   227 
       
   228     // HACK: make sure the SDL window references SDL_WindowData data now, in
       
   229     // order to allow the SDL_Renderer to be created in WINRT_CreateWindow
       
   230     window->driverdata = data;
       
   231 
   225     SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE);
   232     SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE);
   226     SDL_WinRTGlobalApp->m_renderer->m_sdlRenderer = renderer;
   233     SDL_WinRTGlobalApp->m_renderer->m_sdlRenderer = renderer;
   227     SDL_WinRTGlobalApp->m_renderer->m_sdlRendererData = (D3D11_RenderData *) renderer->driverdata;
   234     SDL_WinRTGlobalApp->m_renderer->m_sdlRendererData = (D3D11_RenderData *) renderer->driverdata;
   228     SDL_WinRTGlobalApp->m_renderer->Initialize(CoreWindow::GetForCurrentThread());
   235     SDL_WinRTGlobalApp->m_renderer->Initialize(CoreWindow::GetForCurrentThread());
   229 
   236 
   232 }
   239 }
   233 
   240 
   234 void
   241 void
   235 WINRT_DestroyWindow(_THIS, SDL_Window * window)
   242 WINRT_DestroyWindow(_THIS, SDL_Window * window)
   236 {
   243 {
       
   244     SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
       
   245 
       
   246     if (data) {
       
   247         // Delete the reference to the WinRT CoreWindow:
       
   248         CoreWindow ^* windowPointer = ((SDL_WindowData *) window->driverdata)->coreWindow;
       
   249         if (windowPointer) {
       
   250             *windowPointer = nullptr;   // Clear the C++/CX reference to the CoreWindow
       
   251             delete windowPointer;       // Delete the C++/CX reference itself
       
   252         }
       
   253 
       
   254         // Delete the internal window data:
       
   255         delete data;
       
   256         data = NULL;
       
   257     }
       
   258 
   237     if (SDL_WinRTGlobalApp->HasSDLWindowData() &&
   259     if (SDL_WinRTGlobalApp->HasSDLWindowData() &&
   238         SDL_WinRTGlobalApp->GetSDLWindowData()->sdlWindow == window)
   260         SDL_WinRTGlobalApp->GetSDLWindowData()->sdlWindow == window)
   239     {
   261     {
   240         SDL_WinRTGlobalApp->SetSDLWindowData(NULL);
   262         SDL_WinRTGlobalApp->SetSDLWindowData(NULL);
   241     }
   263     }
   242 }
   264 }
   243 
   265 
       
   266 SDL_bool
       
   267 WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
       
   268 {
       
   269     SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
       
   270     CoreWindow ^* windowPointer = data->coreWindow;
       
   271 
       
   272     if (info->version.major <= SDL_MAJOR_VERSION) {
       
   273         info->subsystem = SDL_SYSWM_WINDOWSRT;
       
   274         info->info.winrt.window = windowPointer;
       
   275         return SDL_TRUE;
       
   276     } else {
       
   277         SDL_SetError("Application not compiled with SDL %d.%d\n",
       
   278                      SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
       
   279         return SDL_FALSE;
       
   280     }
       
   281     return SDL_FALSE;
       
   282 }
   244 
   283 
   245 #endif /* SDL_VIDEO_DRIVER_WINRT */
   284 #endif /* SDL_VIDEO_DRIVER_WINRT */
   246 
   285 
   247 /* vi: set ts=4 sw=4 expandtab: */
   286 /* vi: set ts=4 sw=4 expandtab: */