WinRT: unified the two, public, app-init functions

This function, SDL_WinRTRunApp, can be used to help launch either XAML or non-XAML/Direct3D-only based apps.
This commit is contained in:
David Ludwig 2013-09-22 12:26:53 -04:00
parent 2aa11eef54
commit 79f80241a8
12 changed files with 77 additions and 46 deletions

View file

@ -38,6 +38,7 @@ extern "C" {
#include "../../video/winrt/SDL_winrtevents_c.h"
#include "../../video/winrt/SDL_winrtvideo_cpp.h"
#include "SDL_winrtapp_common.h"
#include "SDL_winrtapp_direct3d.h"
@ -48,12 +49,6 @@ extern "C" {
//#define LOG_ORIENTATION_EVENTS 1
// HACK, DLudwig: The C-style main() will get loaded via the app's
// WinRT-styled main(), which is part of SDLmain_for_WinRT.cpp.
// This seems wrong on some level, but does seem to work.
typedef int (*SDL_WinRT_MainFunction)(int, char **);
static SDL_WinRT_MainFunction SDL_WinRT_main = nullptr;
// HACK, DLudwig: record a reference to the global, WinRT 'app'/view.
// SDL/WinRT will use this throughout its code.
//
@ -83,9 +78,9 @@ IFrameworkView^ SDLApplicationSource::CreateView()
return app;
}
__declspec(dllexport) int SDL_WinRT_RunApplication(SDL_WinRT_MainFunction mainFunction)
int SDL_WinRTInitNonXAMLApp(int (*mainFunction)(int, char **))
{
SDL_WinRT_main = mainFunction;
WINRT_SDLAppEntryPoint = mainFunction;
auto direct3DApplicationSource = ref new SDLApplicationSource();
CoreApplication::Run(direct3DApplicationSource);
return 0;
@ -328,13 +323,13 @@ void SDL_WinRTApp::Load(Platform::String^ entryPoint)
void SDL_WinRTApp::Run()
{
SDL_SetMainReady();
if (SDL_WinRT_main)
if (WINRT_SDLAppEntryPoint)
{
// TODO, WinRT: pass the C-style main() a reasonably realistic
// representation of command line arguments.
int argc = 0;
char **argv = NULL;
SDL_WinRT_main(argc, argv);
WINRT_SDLAppEntryPoint(argc, argv);
}
}

View file

@ -1,5 +1,9 @@
#pragma once
#include <Windows.h>
extern int SDL_WinRTInitNonXAMLApp(int (*mainFunction)(int, char **));
ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFrameworkView
{
public:

View file

@ -32,13 +32,13 @@
#include "SDL.h"
#include "../../video/winrt/SDL_winrtevents_c.h"
#include "../../video/winrt/SDL_winrtvideo_cpp.h"
#include "SDL_winrtapp_common.h"
#include "SDL_winrtapp_xaml.h"
/* SDL-internal globals: */
SDL_bool WINRT_XAMLWasEnabled = SDL_FALSE;
int (*WINRT_XAMLAppMainFunction)(int, char **) = NULL;
#if WINAPI_FAMILY == WINAPI_FAMILY_APP
ISwapChainBackgroundPanelNative * WINRT_GlobalSwapChainBackgroundPanelNative = NULL;
@ -96,8 +96,8 @@ WINRT_OnRenderViaXAML(_In_ Platform::Object^ sender, _In_ Platform::Object^ args
* SDL + XAML Initialization
*/
extern "C" int
SDL_WinRTInitXAMLApp(Platform::Object ^backgroundPanel, int (*mainFunction)(int, char **))
int
SDL_WinRTInitXAMLApp(int (*mainFunction)(int, char **), void * backgroundPanelAsIInspectable)
{
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
return SDL_SetError("XAML support is not yet available in Windows Phone.");
@ -112,10 +112,11 @@ SDL_WinRTInitXAMLApp(Platform::Object ^backgroundPanel, int (*mainFunction)(int,
using namespace Windows::UI::Xaml::Media;
// Make sure we have a valid XAML element (to draw onto):
if ( ! backgroundPanel) {
return SDL_SetError("'backgroundPanel' can't be NULL");
if ( ! backgroundPanelAsIInspectable) {
return SDL_SetError("'backgroundPanelAsIInspectable' can't be NULL");
}
Platform::Object ^ backgroundPanel = reinterpret_cast<Object ^>((IInspectable *) backgroundPanelAsIInspectable);
SwapChainBackgroundPanel ^swapChainBackgroundPanel = dynamic_cast<SwapChainBackgroundPanel ^>(backgroundPanel);
if ( ! swapChainBackgroundPanel) {
return SDL_SetError("An unknown or unsupported type of XAML control was specified.");
@ -134,7 +135,7 @@ SDL_WinRTInitXAMLApp(Platform::Object ^backgroundPanel, int (*mainFunction)(int,
WINRT_XAMLAppEventToken = CompositionTarget::Rendering::add(ref new EventHandler<Object^>(WINRT_OnRenderViaXAML));
// Make sure the app is ready to call the SDL-centric main() function:
WINRT_XAMLAppMainFunction = mainFunction;
WINRT_SDLAppEntryPoint = mainFunction;
SDL_SetMainReady();
// Make sure video-init knows that we're initializing XAML:

View file

@ -27,7 +27,7 @@
#ifdef __cplusplus
extern SDL_bool WINRT_XAMLWasEnabled;
extern int (*WINRT_XAMLAppMainFunction)(int, char **);
extern int SDL_WinRTInitXAMLApp(int (*mainFunction)(int, char **), void * backgroundPanelAsIInspectable);
#endif // ifdef __cplusplus
#endif // ifndef _SDL_winrtapp_xaml_h