WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
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.
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:
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.
21 #include "SDL_config.h"
23 #if SDL_VIDEO_DRIVER_WINRT
29 using namespace Windows::UI::Core;
30 using Windows::UI::Core::CoreCursor;
35 #include "SDL_winrtevents_c.h"
36 #include "../../core/winrt/SDL_winrtapp_direct3d.h"
37 #include "../../core/winrt/SDL_winrtapp_xaml.h"
38 #include "SDL_assert.h"
39 #include "SDL_system.h"
42 #include "../SDL_sysvideo.h"
43 #include "../../events/SDL_events_c.h"
47 /* Forward declarations */
48 static void WINRT_YieldXAMLThread();
51 /* Global event management */
54 WINRT_PumpEvents(_THIS)
56 if (SDL_WinRTGlobalApp) {
57 SDL_WinRTGlobalApp->PumpEvents();
58 } else if (WINRT_XAMLAppMainFunction) {
59 WINRT_YieldXAMLThread();
64 /* XAML Thread management */
66 enum SDL_XAMLAppThreadState
68 ThreadState_NotLaunched = 0,
73 static SDL_XAMLAppThreadState _threadState = ThreadState_NotLaunched;
74 static SDL_Thread * _XAMLThread = nullptr;
75 static SDL_mutex * _mutex = nullptr;
76 static SDL_cond * _cond = nullptr;
79 WINRT_YieldXAMLThread()
81 SDL_LockMutex(_mutex);
82 SDL_assert(_threadState == ThreadState_Running);
83 _threadState = ThreadState_Yielding;
84 SDL_UnlockMutex(_mutex);
86 SDL_CondSignal(_cond);
88 SDL_LockMutex(_mutex);
89 while (_threadState != ThreadState_Running) {
90 SDL_CondWait(_cond, _mutex);
92 SDL_UnlockMutex(_mutex);
96 WINRT_XAMLThreadMain(void * userdata)
98 return WINRT_XAMLAppMainFunction(0, NULL);
102 WINRT_CycleXAMLThread()
104 switch (_threadState) {
105 case ThreadState_NotLaunched:
107 _cond = SDL_CreateCond();
109 _mutex = SDL_CreateMutex();
110 _threadState = ThreadState_Running;
111 _XAMLThread = SDL_CreateThread(WINRT_XAMLThreadMain, "SDL/XAML App Thread", nullptr);
113 SDL_LockMutex(_mutex);
114 while (_threadState != ThreadState_Yielding) {
115 SDL_CondWait(_cond, _mutex);
117 SDL_UnlockMutex(_mutex);
122 case ThreadState_Running:
128 case ThreadState_Yielding:
130 SDL_LockMutex(_mutex);
131 SDL_assert(_threadState == ThreadState_Yielding);
132 _threadState = ThreadState_Running;
133 SDL_UnlockMutex(_mutex);
135 SDL_CondSignal(_cond);
137 SDL_LockMutex(_mutex);
138 while (_threadState != ThreadState_Yielding) {
139 SDL_CondWait(_cond, _mutex);
141 SDL_UnlockMutex(_mutex);
146 #endif /* SDL_VIDEO_DRIVER_WINRT */
148 /* vi: set ts=4 sw=4 expandtab: */