WinRT: added SDL_WINDOWEVENT_RESIZED support, and moved window-resize-handling code from WinRT rendering code to D3D 11.1 code
authorDavid Ludwig <dludwig@pobox.com>
Sat, 09 Feb 2013 16:00:55 -0500
changeset 841591977f5b2135
parent 8414 25a7605097a2
child 8416 17040ce2693d
WinRT: added SDL_WINDOWEVENT_RESIZED support, and moved window-resize-handling code from WinRT rendering code to D3D 11.1 code
src/render/direct3d11/SDL_render_d3d11.cpp
src/video/windowsrt/SDL_WinRTApp.cpp
src/video/windowsrt/SDL_winrtrenderer.cpp
src/video/windowsrt/SDL_winrtrenderer.h
     1.1 --- a/src/render/direct3d11/SDL_render_d3d11.cpp	Sat Feb 09 15:43:13 2013 -0500
     1.2 +++ b/src/render/direct3d11/SDL_render_d3d11.cpp	Sat Feb 09 16:00:55 2013 -0500
     1.3 @@ -51,8 +51,8 @@
     1.4  /* Direct3D 11.1 renderer implementation */
     1.5  
     1.6  static SDL_Renderer *D3D11_CreateRenderer(SDL_Window * window, Uint32 flags);
     1.7 -//static void D3D11_WindowEvent(SDL_Renderer * renderer,
     1.8 -//                            const SDL_WindowEvent *event);
     1.9 +static void D3D11_WindowEvent(SDL_Renderer * renderer,
    1.10 +                            const SDL_WindowEvent *event);
    1.11  //static int D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    1.12  //static int D3D11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    1.13  //                             const SDL_Rect * rect, const void *pixels,
    1.14 @@ -131,9 +131,7 @@
    1.15      data->windowSizeInDIPs = XMFLOAT2(0, 0);
    1.16      data->renderTargetSize = XMFLOAT2(0, 0);
    1.17  
    1.18 -    // TODO: Create Direct3D Object(s)
    1.19 -
    1.20 -    //renderer->WindowEvent = D3D11_WindowEvent;
    1.21 +    renderer->WindowEvent = D3D11_WindowEvent;
    1.22      //renderer->CreateTexture = D3D11_CreateTexture;
    1.23      //renderer->UpdateTexture = D3D11_UpdateTexture;
    1.24      //renderer->LockTexture = D3D11_LockTexture;
    1.25 @@ -402,7 +400,7 @@
    1.26  
    1.27  #ifdef __WINRT__
    1.28  
    1.29 -CoreWindow ^
    1.30 +static CoreWindow ^
    1.31  D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer)
    1.32  {
    1.33      SDL_Window * sdlWindow = renderer->window;
    1.34 @@ -660,6 +658,7 @@
    1.35      return S_OK;
    1.36  }
    1.37  
    1.38 +// This method is called when the window's size changes.
    1.39  HRESULT
    1.40  D3D11_UpdateForWindowSizeChange(SDL_Renderer * renderer)
    1.41  {
    1.42 @@ -691,7 +690,7 @@
    1.43      D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
    1.44      HRESULT result = S_OK;
    1.45  
    1.46 -    // Reset these member variables to ensure that UpdateForWindowSizeChange recreates all resources.
    1.47 +    // Reset these member variables to ensure that D3D11_UpdateForWindowSizeChange recreates all resources.
    1.48      data->windowSizeInDIPs.x = 0;
    1.49      data->windowSizeInDIPs.y = 0;
    1.50      data->swapChain = nullptr;
    1.51 @@ -711,6 +710,16 @@
    1.52      return S_OK;
    1.53  }
    1.54  
    1.55 +static void
    1.56 +D3D11_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
    1.57 +{
    1.58 +    //D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
    1.59 +
    1.60 +    if (event->event == SDL_WINDOWEVENT_RESIZED) {
    1.61 +        D3D11_UpdateForWindowSizeChange(renderer);
    1.62 +    }
    1.63 +}
    1.64 +
    1.65  static int
    1.66  D3D11_UpdateViewport(SDL_Renderer * renderer)
    1.67  {
     2.1 --- a/src/video/windowsrt/SDL_WinRTApp.cpp	Sat Feb 09 15:43:13 2013 -0500
     2.2 +++ b/src/video/windowsrt/SDL_WinRTApp.cpp	Sat Feb 09 16:00:55 2013 -0500
     2.3 @@ -151,7 +151,11 @@
     2.4  
     2.5  void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args)
     2.6  {
     2.7 -    m_renderer->UpdateForWindowSizeChange();
     2.8 +    SDL_SendWindowEvent(
     2.9 +        m_sdlWindowData->sdlWindow,
    2.10 +        SDL_WINDOWEVENT_RESIZED,
    2.11 +        (int) ceil(args->Size.Width),
    2.12 +        (int) ceil(args->Size.Height));
    2.13  }
    2.14  
    2.15  void SDL_WinRTApp::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
     3.1 --- a/src/video/windowsrt/SDL_winrtrenderer.cpp	Sat Feb 09 15:43:13 2013 -0500
     3.2 +++ b/src/video/windowsrt/SDL_winrtrenderer.cpp	Sat Feb 09 16:00:55 2013 -0500
     3.3 @@ -16,9 +16,6 @@
     3.4  using namespace Windows::Foundation;
     3.5  using namespace Windows::Graphics::Display;
     3.6  
     3.7 -extern CoreWindow ^ D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer);
     3.8 -extern HRESULT D3D11_UpdateForWindowSizeChange(SDL_Renderer * renderer);
     3.9 -
    3.10  // Constructor.
    3.11  SDL_winrtrenderer::SDL_winrtrenderer() :
    3.12      m_mainTextureHelperSurface(NULL),
    3.13 @@ -102,12 +99,6 @@
    3.14          );
    3.15  }
    3.16  
    3.17 -// This method is called in the event handler for the SizeChanged event.
    3.18 -void SDL_winrtrenderer::UpdateForWindowSizeChange()
    3.19 -{
    3.20 -    DX::ThrowIfFailed(D3D11_UpdateForWindowSizeChange(m_sdlRenderer));
    3.21 -}
    3.22 -
    3.23  void SDL_winrtrenderer::Render(SDL_Surface * surface, SDL_Rect * rects, int numrects)
    3.24  {
    3.25      const float blackColor[] = { 0.0f, 0.0f, 0.0f, 0.0f };
     4.1 --- a/src/video/windowsrt/SDL_winrtrenderer.h	Sat Feb 09 15:43:13 2013 -0500
     4.2 +++ b/src/video/windowsrt/SDL_winrtrenderer.h	Sat Feb 09 16:00:55 2013 -0500
     4.3 @@ -16,7 +16,6 @@
     4.4  
     4.5  public:
     4.6      virtual ~SDL_winrtrenderer();
     4.7 -    virtual void UpdateForWindowSizeChange();
     4.8      virtual void Present();
     4.9  
    4.10  internal: