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

Commit

Permalink
WinRT: Windows Phone fixes. SDL can now display images, and respond t…
Browse files Browse the repository at this point in the history
…o input, on Microsoft's Windows Phone 8 emulator.
  • Loading branch information
DavidLudwig committed Jan 30, 2013
1 parent d049a77 commit f3f6d83
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/video/windowsrt/SDL_WinRTApp.cpp
Expand Up @@ -33,7 +33,6 @@ static SDL_WinRT_MainFunction SDL_WinRT_main = nullptr;
// SDL_CreateWindow().
SDL_WinRTApp ^ SDL_WinRTGlobalApp = nullptr;


using namespace Windows::ApplicationModel;
using namespace Windows::ApplicationModel::Core;
using namespace Windows::ApplicationModel::Activation;
Expand Down Expand Up @@ -77,7 +76,9 @@ void SDL_WinRTApp::SetWindow(CoreWindow^ window)
window->Closed +=
ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &SDL_WinRTApp::OnWindowClosed);

#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
window->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
#endif

window->PointerPressed +=
ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerPressed);
Expand All @@ -88,9 +89,11 @@ void SDL_WinRTApp::SetWindow(CoreWindow^ window)
window->PointerMoved +=
ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerMoved);

#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
// Retrieves relative-only mouse movements:
Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved +=
ref new TypedEventHandler<MouseDevice^, MouseEventArgs^>(this, &SDL_WinRTApp::OnMouseMoved);
#endif

window->KeyDown +=
ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyDown);
Expand Down
2 changes: 2 additions & 0 deletions src/video/windowsrt/SDL_winrtmouse.cpp
Expand Up @@ -126,6 +126,7 @@ WINRT_InitMouse(_THIS)
- programmatically moveable cursors
*/

#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
//mouse->CreateCursor = WINRT_CreateCursor;
mouse->CreateSystemCursor = WINRT_CreateSystemCursor;
mouse->ShowCursor = WINRT_ShowCursor;
Expand All @@ -134,6 +135,7 @@ WINRT_InitMouse(_THIS)
mouse->SetRelativeMouseMode = WINRT_SetRelativeMouseMode;

SDL_SetDefaultCursor(WINRT_CreateDefaultCursor());
#endif
}

void
Expand Down
23 changes: 22 additions & 1 deletion src/video/windowsrt/SDL_winrtrenderer.cpp
Expand Up @@ -98,8 +98,13 @@ void SDL_winrtrenderer::CreateDeviceResources()
context.As(&m_d3dContext)
);

#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
auto loadVSTask = DX::ReadDataAsync("SimpleVertexShader.cso");
auto loadPSTask = DX::ReadDataAsync("SimplePixelShader.cso");
#else
auto loadVSTask = DX::ReadDataAsync("SDL_VS2012_WinRT\\SimpleVertexShader.cso");
auto loadPSTask = DX::ReadDataAsync("SDL_VS2012_WinRT\\SimplePixelShader.cso");
#endif

auto createVSTask = loadVSTask.then([this](Platform::Array<byte>^ fileData) {
DX::ThrowIfFailed(
Expand Down Expand Up @@ -194,7 +199,7 @@ void SDL_winrtrenderer::CreateDeviceResources()

// Allocate all memory resources that change on a window SizeChanged event.
void SDL_winrtrenderer::CreateWindowSizeDependentResources()
{
{
// Store the window bounds so the next time we get a SizeChanged event we can
// avoid rebuilding everything if the size is identical.
m_windowBounds = m_window->Bounds;
Expand Down Expand Up @@ -238,8 +243,13 @@ void SDL_winrtrenderer::CreateWindowSizeDependentResources()
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferCount = 2; // Use double-buffering to minimize latency.
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
swapChainDesc.Scaling = DXGI_SCALING_STRETCH; // On phone, only stretch and aspect-ratio stretch scaling are allowed.
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; // On phone, no swap effects are supported.
#else
swapChainDesc.Scaling = DXGI_SCALING_NONE;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // All Windows Store apps must use this SwapEffect.
#endif
swapChainDesc.Flags = 0;

ComPtr<IDXGIDevice1> dxgiDevice;
Expand Down Expand Up @@ -327,9 +337,12 @@ void SDL_winrtrenderer::CreateWindowSizeDependentResources()
throw ref new Platform::FailureException();
}

#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
// TODO, WinRT: Windows Phone does not have the IDXGISwapChain1::SetRotation method. Check if an alternative is available, or needed.
DX::ThrowIfFailed(
m_swapChain->SetRotation(rotation)
);
#endif

// Create a render target view of the swap chain back buffer.
ComPtr<ID3D11Texture2D> backBuffer;
Expand Down Expand Up @@ -546,8 +559,15 @@ void SDL_winrtrenderer::Render(SDL_Surface * surface, SDL_Rect * rects, int numr
// Method to deliver the final image to the display.
void SDL_winrtrenderer::Present()
{
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
// The first argument instructs DXGI to block until VSync, putting the application
// to sleep until the next VSync. This ensures we don't waste any cycles rendering
// frames that will never be displayed to the screen.
HRESULT hr = m_swapChain->Present(1, 0);
#else
// The application may optionally specify "dirty" or "scroll"
// rects to improve efficiency in certain scenarios.
// This option is not available on Windows Phone 8, to note.
DXGI_PRESENT_PARAMETERS parameters = {0};
parameters.DirtyRectsCount = 0;
parameters.pDirtyRects = nullptr;
Expand All @@ -558,6 +578,7 @@ void SDL_winrtrenderer::Present()
// to sleep until the next VSync. This ensures we don't waste any cycles rendering
// frames that will never be displayed to the screen.
HRESULT hr = m_swapChain->Present1(1, 0, &parameters);
#endif

// Discard the contents of the render target.
// This is a valid operation only when the existing contents will be entirely
Expand Down

0 comments on commit f3f6d83

Please sign in to comment.