Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

WinRT: made the device's screen size be retrieve-able via SDL_GetDisp…

…layMode()
  • Loading branch information
DavidLudwig committed Oct 28, 2012
1 parent a543a25 commit 781340db636247f189f9a29aeb1caf733992e0ab
@@ -125,9 +125,16 @@
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
</ClCompile>
<ClCompile Include="..\..\src\video\windowsrt\SDL_winrtevents.c" />
<ClCompile Include="..\..\src\video\windowsrt\SDL_winrtframebuffer.c" />
<ClCompile Include="..\..\src\video\windowsrt\SDL_winrtvideo.c" />
<ClCompile Include="..\..\src\video\windowsrt\SDL_winrtevents.cpp" />
<ClCompile Include="..\..\src\video\windowsrt\SDL_winrtframebuffer.cpp" />
<ClCompile Include="..\..\src\video\windowsrt\SDL_winrtvideo.cpp">
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\include\begin_code.h" />
@@ -2,12 +2,27 @@
#include "SDL_WinRTApp.h"
#include "BasicTimer.h"

extern "C" {
#include "SDL_assert.h"
#include "SDL_stdinc.h"
#include "../SDL_sysvideo.h"
}

// 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, Windows RT 'app'/view.
// SDL/WinRT will use this throughout its code.
//
// TODO, WinRT: consider replacing SDL_WinRTGlobalApp with something
// non-global, such as something created inside
// SDL_InitSubSystem(SDL_INIT_VIDEO), or something inside
// SDL_CreateWindow().
SDL_WinRTApp ^ SDL_WinRTGlobalApp = nullptr;


using namespace Windows::ApplicationModel;
using namespace Windows::ApplicationModel::Core;
@@ -151,9 +166,30 @@ void SDL_WinRTApp::OnResuming(Platform::Object^ sender, Platform::Object^ args)
// does not occur if the app was previously terminated.
}

SDL_DisplayMode SDL_WinRTApp::GetMainDisplayMode()
{
SDL_DisplayMode mode;
SDL_zero(mode);
mode.format = SDL_PIXELFORMAT_RGB888;
mode.w = (int) CoreWindow::GetForCurrentThread()->Bounds.Width;
mode.h = (int) CoreWindow::GetForCurrentThread()->Bounds.Height;
mode.refresh_rate = 0; // TODO, WinRT: see if refresh rate data is available, or relevant (for WinRT apps)
mode.driverdata = NULL;
return mode;
}

IFrameworkView^ Direct3DApplicationSource::CreateView()
{
return ref new SDL_WinRTApp();
// TODO, WinRT: see if this function (CreateView) can ever get called
// more than once. For now, just prevent it from ever assigning
// SDL_WinRTGlobalApp more than once.
SDL_assert(!SDL_WinRTGlobalApp);
SDL_WinRTApp ^ app = ref new SDL_WinRTApp();
if (!SDL_WinRTGlobalApp)
{
SDL_WinRTGlobalApp = app;
}
return app;
}

__declspec(dllexport) int SDL_WinRT_RunApplication(SDL_WinRT_MainFunction mainFunction)
@@ -2,6 +2,9 @@

#include "SDLmain_WinRT_common.h"
#include "CubeRenderer.h"
#include <vector>

using namespace Windows::UI::Core;

ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFrameworkView
{
@@ -15,6 +18,10 @@ ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFramewo
virtual void Run();
virtual void Uninitialize();

internal:
// SDL-specific methods
SDL_DisplayMode GetMainDisplayMode();

protected:
// Event Handlers.
void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args);
@@ -28,12 +28,15 @@
was based off of SDL's "dummy" video driver.
*/

extern "C" {
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
}

#include "SDL_WinRTApp.h"
#include "SDL_winrtvideo.h"
#include "SDL_winrtevents_c.h"
#include "SDL_winrtframebuffer_c.h"
@@ -93,26 +96,19 @@ VideoBootStrap WINRT_bootstrap = {
WINRT_Available, WINRT_CreateDevice
};

extern SDL_WinRTApp ^ SDL_WinRTGlobalApp;

int
WINRT_VideoInit(_THIS)
{
SDL_DisplayMode mode;

/* Use a fake 32-bpp desktop mode */
mode.format = SDL_PIXELFORMAT_RGB888;
mode.w = 1024;
mode.h = 768;
mode.refresh_rate = 0;
mode.driverdata = NULL;
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
return -1;
}

SDL_zero(mode);
SDL_AddDisplayMode(&_this->displays[0], &mode);

/* We're done! */
SDL_DisplayMode mode = SDL_WinRTGlobalApp->GetMainDisplayMode();
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
return -1;
}

SDL_AddDisplayMode(&_this->displays[0], &mode);

/* We're done! */
return 0;
}

@@ -23,8 +23,16 @@
#ifndef _SDL_winrtvideo_h
#define _SDL_winrtvideo_h

#ifdef __cplusplus
extern "C" {
#endif

#include "../SDL_sysvideo.h"

#ifdef __cplusplus
}
#endif

#endif /* _SDL_winrtvideo_h */

/* vi: set ts=4 sw=4 expandtab: */
@@ -4,4 +4,9 @@
#include <d3d11_1.h>
#include <DirectXMath.h>
#include <memory>
#include <agile.h>
#include <agile.h>
#include <vector>

extern "C" {
#include "../SDL_sysvideo.h"
}

0 comments on commit 781340d

Please sign in to comment.