Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
WinRT: made the device's screen size be retrieve-able via SDL_GetDisp…
Browse files Browse the repository at this point in the history
…layMode()
  • Loading branch information
DavidLudwig committed Oct 28, 2012
1 parent a543a25 commit 781340d
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 21 deletions.
13 changes: 10 additions & 3 deletions VisualC/SDL/SDL_VS2012_WinRT.vcxproj
Expand Up @@ -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" />
Expand Down
38 changes: 37 additions & 1 deletion src/video/windowsrt/SDL_WinRTApp.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions src/video/windowsrt/SDL_WinRTApp.h
Expand Up @@ -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
{
Expand All @@ -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);
Expand Down
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}

Expand Down
8 changes: 8 additions & 0 deletions src/video/windowsrt/SDL_winrtvideo.h
Expand Up @@ -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: */
7 changes: 6 additions & 1 deletion src/video/windowsrt/SDLmain_WinRT_common.h
Expand Up @@ -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.