From f3f6d830cdc55b9c63dc766db73e7666dfd96f63 Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Tue, 29 Jan 2013 20:27:47 -0500 Subject: [PATCH] WinRT: Windows Phone fixes. SDL can now display images, and respond to input, on Microsoft's Windows Phone 8 emulator. --- src/video/windowsrt/SDL_WinRTApp.cpp | 5 ++++- src/video/windowsrt/SDL_winrtmouse.cpp | 2 ++ src/video/windowsrt/SDL_winrtrenderer.cpp | 23 ++++++++++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/video/windowsrt/SDL_WinRTApp.cpp b/src/video/windowsrt/SDL_WinRTApp.cpp index 9cdf0969f..d74ad087a 100644 --- a/src/video/windowsrt/SDL_WinRTApp.cpp +++ b/src/video/windowsrt/SDL_WinRTApp.cpp @@ -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; @@ -77,7 +76,9 @@ void SDL_WinRTApp::SetWindow(CoreWindow^ window) window->Closed += ref new TypedEventHandler(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(this, &SDL_WinRTApp::OnPointerPressed); @@ -88,9 +89,11 @@ void SDL_WinRTApp::SetWindow(CoreWindow^ window) window->PointerMoved += ref new TypedEventHandler(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(this, &SDL_WinRTApp::OnMouseMoved); +#endif window->KeyDown += ref new TypedEventHandler(this, &SDL_WinRTApp::OnKeyDown); diff --git a/src/video/windowsrt/SDL_winrtmouse.cpp b/src/video/windowsrt/SDL_winrtmouse.cpp index 2b44400e7..5d6bcc607 100644 --- a/src/video/windowsrt/SDL_winrtmouse.cpp +++ b/src/video/windowsrt/SDL_winrtmouse.cpp @@ -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; @@ -134,6 +135,7 @@ WINRT_InitMouse(_THIS) mouse->SetRelativeMouseMode = WINRT_SetRelativeMouseMode; SDL_SetDefaultCursor(WINRT_CreateDefaultCursor()); +#endif } void diff --git a/src/video/windowsrt/SDL_winrtrenderer.cpp b/src/video/windowsrt/SDL_winrtrenderer.cpp index 43564fe61..030aeacb4 100644 --- a/src/video/windowsrt/SDL_winrtrenderer.cpp +++ b/src/video/windowsrt/SDL_winrtrenderer.cpp @@ -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^ fileData) { DX::ThrowIfFailed( @@ -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; @@ -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 dxgiDevice; @@ -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 backBuffer; @@ -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; @@ -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, ¶meters); +#endif // Discard the contents of the render target. // This is a valid operation only when the existing contents will be entirely