WinRT: Windows Phone fixes. SDL can now display images, and respond to input, on Microsoft's Windows Phone 8 emulator.
authorDavid Ludwig <dludwig@pobox.com>
Tue, 29 Jan 2013 20:27:47 -0500
changeset 83991fa9dcfbeac5
parent 8398 454efbee8341
child 8400 1315402d9028
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
src/video/windowsrt/SDL_winrtmouse.cpp
src/video/windowsrt/SDL_winrtrenderer.cpp
     1.1 --- a/src/video/windowsrt/SDL_WinRTApp.cpp	Mon Jan 28 23:19:13 2013 -0500
     1.2 +++ b/src/video/windowsrt/SDL_WinRTApp.cpp	Tue Jan 29 20:27:47 2013 -0500
     1.3 @@ -33,7 +33,6 @@
     1.4  // SDL_CreateWindow().
     1.5  SDL_WinRTApp ^ SDL_WinRTGlobalApp = nullptr;
     1.6  
     1.7 -
     1.8  using namespace Windows::ApplicationModel;
     1.9  using namespace Windows::ApplicationModel::Core;
    1.10  using namespace Windows::ApplicationModel::Activation;
    1.11 @@ -77,7 +76,9 @@
    1.12      window->Closed += 
    1.13          ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &SDL_WinRTApp::OnWindowClosed);
    1.14  
    1.15 +#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
    1.16      window->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
    1.17 +#endif
    1.18  
    1.19      window->PointerPressed +=
    1.20          ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerPressed);
    1.21 @@ -88,9 +89,11 @@
    1.22      window->PointerMoved +=
    1.23          ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerMoved);
    1.24  
    1.25 +#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
    1.26      // Retrieves relative-only mouse movements:
    1.27      Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved +=
    1.28          ref new TypedEventHandler<MouseDevice^, MouseEventArgs^>(this, &SDL_WinRTApp::OnMouseMoved);
    1.29 +#endif
    1.30  
    1.31      window->KeyDown +=
    1.32          ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyDown);
     2.1 --- a/src/video/windowsrt/SDL_winrtmouse.cpp	Mon Jan 28 23:19:13 2013 -0500
     2.2 +++ b/src/video/windowsrt/SDL_winrtmouse.cpp	Tue Jan 29 20:27:47 2013 -0500
     2.3 @@ -126,6 +126,7 @@
     2.4          - programmatically moveable cursors
     2.5      */
     2.6  
     2.7 +#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
     2.8      //mouse->CreateCursor = WINRT_CreateCursor;
     2.9      mouse->CreateSystemCursor = WINRT_CreateSystemCursor;
    2.10      mouse->ShowCursor = WINRT_ShowCursor;
    2.11 @@ -134,6 +135,7 @@
    2.12      mouse->SetRelativeMouseMode = WINRT_SetRelativeMouseMode;
    2.13  
    2.14      SDL_SetDefaultCursor(WINRT_CreateDefaultCursor());
    2.15 +#endif
    2.16  }
    2.17  
    2.18  void
     3.1 --- a/src/video/windowsrt/SDL_winrtrenderer.cpp	Mon Jan 28 23:19:13 2013 -0500
     3.2 +++ b/src/video/windowsrt/SDL_winrtrenderer.cpp	Tue Jan 29 20:27:47 2013 -0500
     3.3 @@ -98,8 +98,13 @@
     3.4          context.As(&m_d3dContext)
     3.5          );
     3.6  
     3.7 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
     3.8 +    auto loadVSTask = DX::ReadDataAsync("SimpleVertexShader.cso");
     3.9 +    auto loadPSTask = DX::ReadDataAsync("SimplePixelShader.cso");
    3.10 +#else
    3.11      auto loadVSTask = DX::ReadDataAsync("SDL_VS2012_WinRT\\SimpleVertexShader.cso");
    3.12      auto loadPSTask = DX::ReadDataAsync("SDL_VS2012_WinRT\\SimplePixelShader.cso");
    3.13 +#endif
    3.14  
    3.15      auto createVSTask = loadVSTask.then([this](Platform::Array<byte>^ fileData) {
    3.16          DX::ThrowIfFailed(
    3.17 @@ -194,7 +199,7 @@
    3.18  
    3.19  // Allocate all memory resources that change on a window SizeChanged event.
    3.20  void SDL_winrtrenderer::CreateWindowSizeDependentResources()
    3.21 -{ 
    3.22 +{
    3.23      // Store the window bounds so the next time we get a SizeChanged event we can
    3.24      // avoid rebuilding everything if the size is identical.
    3.25      m_windowBounds = m_window->Bounds;
    3.26 @@ -238,8 +243,13 @@
    3.27          swapChainDesc.SampleDesc.Quality = 0;
    3.28          swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    3.29          swapChainDesc.BufferCount = 2; // Use double-buffering to minimize latency.
    3.30 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    3.31 +        swapChainDesc.Scaling = DXGI_SCALING_STRETCH; // On phone, only stretch and aspect-ratio stretch scaling are allowed.
    3.32 +        swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; // On phone, no swap effects are supported.
    3.33 +#else
    3.34          swapChainDesc.Scaling = DXGI_SCALING_NONE;
    3.35          swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // All Windows Store apps must use this SwapEffect.
    3.36 +#endif
    3.37          swapChainDesc.Flags = 0;
    3.38  
    3.39          ComPtr<IDXGIDevice1>  dxgiDevice;
    3.40 @@ -327,9 +337,12 @@
    3.41              throw ref new Platform::FailureException();
    3.42      }
    3.43  
    3.44 +#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
    3.45 +    // TODO, WinRT: Windows Phone does not have the IDXGISwapChain1::SetRotation method.  Check if an alternative is available, or needed.
    3.46      DX::ThrowIfFailed(
    3.47          m_swapChain->SetRotation(rotation)
    3.48          );
    3.49 +#endif
    3.50  
    3.51      // Create a render target view of the swap chain back buffer.
    3.52      ComPtr<ID3D11Texture2D> backBuffer;
    3.53 @@ -546,8 +559,15 @@
    3.54  // Method to deliver the final image to the display.
    3.55  void SDL_winrtrenderer::Present()
    3.56  {
    3.57 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    3.58 +    // The first argument instructs DXGI to block until VSync, putting the application
    3.59 +	// to sleep until the next VSync. This ensures we don't waste any cycles rendering
    3.60 +	// frames that will never be displayed to the screen.
    3.61 +	HRESULT hr = m_swapChain->Present(1, 0);
    3.62 +#else
    3.63      // The application may optionally specify "dirty" or "scroll"
    3.64      // rects to improve efficiency in certain scenarios.
    3.65 +    // This option is not available on Windows Phone 8, to note.
    3.66      DXGI_PRESENT_PARAMETERS parameters = {0};
    3.67      parameters.DirtyRectsCount = 0;
    3.68      parameters.pDirtyRects = nullptr;
    3.69 @@ -558,6 +578,7 @@
    3.70      // to sleep until the next VSync. This ensures we don't waste any cycles rendering
    3.71      // frames that will never be displayed to the screen.
    3.72      HRESULT hr = m_swapChain->Present1(1, 0, &parameters);
    3.73 +#endif
    3.74  
    3.75      // Discard the contents of the render target.
    3.76      // This is a valid operation only when the existing contents will be entirely