From 73440f61079e00cf5c59879dbf124d648753a68f Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Sat, 9 Feb 2013 19:39:42 -0500 Subject: [PATCH] WinRT: made use of SDL's framebuffer emulation code, instead of the custom stuff; then removed SDL_winrtrenderer --- .../SDL/SDL_VS2012-WinPhone.vcxproj | 14 --- .../SDL/SDL_VS2012-WinPhone.vcxproj.filters | 12 -- VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj | 18 --- .../SDL/SDL_VS2012-WinRT.vcxproj.filters | 12 -- src/video/windowsrt/SDL_WinRTApp.cpp | 20 +--- src/video/windowsrt/SDL_WinRTApp.h | 6 - src/video/windowsrt/SDL_winrtframebuffer.cpp | 104 ------------------ src/video/windowsrt/SDL_winrtframebuffer_c.h | 27 ----- src/video/windowsrt/SDL_winrtrenderer.cpp | 87 --------------- src/video/windowsrt/SDL_winrtrenderer.h | 33 ------ src/video/windowsrt/SDL_winrtvideo.cpp | 29 +---- 11 files changed, 6 insertions(+), 356 deletions(-) delete mode 100644 src/video/windowsrt/SDL_winrtframebuffer.cpp delete mode 100644 src/video/windowsrt/SDL_winrtframebuffer_c.h delete mode 100644 src/video/windowsrt/SDL_winrtrenderer.cpp delete mode 100644 src/video/windowsrt/SDL_winrtrenderer.h diff --git a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj index 4ddc0a112..06bef404f 100644 --- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj +++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj @@ -248,9 +248,7 @@ - - @@ -366,24 +364,12 @@ true true - - true - true - true - true - true true true true - - true - true - true - true - true true diff --git a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters index ec1edad74..4735718d2 100644 --- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters +++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters @@ -333,15 +333,9 @@ Source Files - - Source Files - Source Files - - Source Files - Source Files @@ -593,15 +587,9 @@ Source Files - - Source Files - Source Files - - Source Files - Source Files diff --git a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj index c5a803fbc..925f5c8a3 100644 --- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj +++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj @@ -151,14 +151,6 @@ true true - - true - true - true - true - true - true - true true @@ -167,14 +159,6 @@ true true - - true - true - true - true - true - true - true true @@ -293,9 +277,7 @@ - - diff --git a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters index fec688350..2119bc170 100644 --- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters +++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters @@ -234,15 +234,9 @@ Source Files - - Source Files - Source Files - - Source Files - Source Files @@ -356,9 +350,6 @@ Source Files - - Source Files - Source Files @@ -578,9 +569,6 @@ Source Files - - Source Files - Source Files diff --git a/src/video/windowsrt/SDL_WinRTApp.cpp b/src/video/windowsrt/SDL_WinRTApp.cpp index d9f433163..03283e639 100644 --- a/src/video/windowsrt/SDL_WinRTApp.cpp +++ b/src/video/windowsrt/SDL_WinRTApp.cpp @@ -1,5 +1,6 @@ #include "SDLmain_WinRT_common.h" #include "SDL_WinRTApp.h" +#include "ppltasks.h" extern "C" { #include "SDL_assert.h" @@ -47,8 +48,7 @@ SDL_WinRTApp::SDL_WinRTApp() : m_windowClosed(false), m_windowVisible(true), m_sdlWindowData(NULL), - m_useRelativeMouseMode(false), - m_renderer(nullptr) + m_useRelativeMouseMode(false) { } @@ -62,8 +62,6 @@ void SDL_WinRTApp::Initialize(CoreApplicationView^ applicationView) CoreApplication::Resuming += ref new EventHandler(this, &SDL_WinRTApp::OnResuming); - - m_renderer = ref new SDL_winrtrenderer(); } void SDL_WinRTApp::SetWindow(CoreWindow^ window) @@ -136,15 +134,6 @@ void SDL_WinRTApp::PumpEvents() } } -void SDL_WinRTApp::UpdateWindowFramebuffer(SDL_Surface * surface, SDL_Rect * rects, int numrects) -{ - if (!m_windowClosed && m_windowVisible) - { - m_renderer->Render(surface, rects, numrects); - m_renderer->Present(); // This call is synchronized to the display frame rate. - } -} - void SDL_WinRTApp::Uninitialize() { } @@ -649,11 +638,6 @@ void SDL_WinRTApp::SetSDLWindowData(const SDL_WindowData* windowData) m_sdlWindowData = windowData; } -void SDL_WinRTApp::ResizeMainTexture(int w, int h) -{ - m_renderer->ResizeMainTexture(w, h); -} - IFrameworkView^ Direct3DApplicationSource::CreateView() { // TODO, WinRT: see if this function (CreateView) can ever get called diff --git a/src/video/windowsrt/SDL_WinRTApp.h b/src/video/windowsrt/SDL_WinRTApp.h index b6dd25749..7c03ecafe 100644 --- a/src/video/windowsrt/SDL_WinRTApp.h +++ b/src/video/windowsrt/SDL_WinRTApp.h @@ -2,7 +2,6 @@ #include "SDLmain_WinRT_common.h" #include "SDL_winrtvideo.h" -#include "SDL_winrtrenderer.h" #include using namespace Windows::UI::Core; @@ -27,8 +26,6 @@ ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFramewo bool HasSDLWindowData() const; void SetRelativeMouseMode(bool enable); void SetSDLWindowData(const SDL_WindowData * windowData); - void UpdateWindowFramebuffer(SDL_Surface * surface, SDL_Rect * rects, int numrects); - void ResizeMainTexture(int w, int h); Windows::Foundation::Point TransformCursor(Windows::Foundation::Point rawPosition); protected: @@ -47,9 +44,6 @@ ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFramewo void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args); void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args); -internal: - SDL_winrtrenderer^ m_renderer; - private: bool m_windowClosed; bool m_windowVisible; diff --git a/src/video/windowsrt/SDL_winrtframebuffer.cpp b/src/video/windowsrt/SDL_winrtframebuffer.cpp deleted file mode 100644 index a30990e19..000000000 --- a/src/video/windowsrt/SDL_winrtframebuffer.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -#if SDL_VIDEO_DRIVER_WINRT - -#include "../SDL_sysvideo.h" -#include "SDL_winrtframebuffer_c.h" -#include "SDL_WinRTApp.h" - -extern SDL_WinRTApp ^ SDL_WinRTGlobalApp; - - -#define WINRT_SURFACE "_SDL_WinRTSurface" - -int SDL_WINRT_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch) -{ - SDL_Surface *surface; - const Uint32 surface_format = SDL_PIXELFORMAT_RGB888; - int w, h; - int bpp; - Uint32 Rmask, Gmask, Bmask, Amask; - - /* Free the old framebuffer surface */ - surface = (SDL_Surface *) SDL_GetWindowData(window, WINRT_SURFACE); - if (surface) { - SDL_FreeSurface(surface); - } - - /* Create a new one */ - SDL_PixelFormatEnumToMasks(surface_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask); - SDL_GetWindowSize(window, &w, &h); - surface = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask); - if (!surface) { - return -1; - } - - /* Save info on the surface */ - SDL_SetWindowData(window, WINRT_SURFACE, surface); - *format = surface_format; - *pixels = surface->pixels; - *pitch = surface->pitch; - - /* Make sure a Direct3D texture exists to draw the surface onto */ - SDL_WinRTGlobalApp->ResizeMainTexture(surface->w, surface->h); - - return 0; -} - -int SDL_WINRT_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects) -{ - static int frame_number; - SDL_Surface *surface; - - surface = (SDL_Surface *) SDL_GetWindowData(window, WINRT_SURFACE); - if (!surface) { - SDL_SetError("Couldn't find WinRT surface for window"); - return -1; - } - - /* Send the data to the display */ - if (SDL_getenv("SDL_VIDEO_WINRT_SAVE_FRAMES")) { - char file[128]; - SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp", - SDL_GetWindowID(window), ++frame_number); - SDL_SaveBMP(surface, file); - } - - SDL_WinRTGlobalApp->UpdateWindowFramebuffer(surface, rects, numrects); - - return 0; -} - -void SDL_WINRT_DestroyWindowFramebuffer(_THIS, SDL_Window * window) -{ - SDL_Surface *surface; - - surface = (SDL_Surface *) SDL_SetWindowData(window, WINRT_SURFACE, NULL); - if (surface) { - SDL_FreeSurface(surface); - } -} - -#endif /* SDL_VIDEO_DRIVER_WINRT */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/windowsrt/SDL_winrtframebuffer_c.h b/src/video/windowsrt/SDL_winrtframebuffer_c.h deleted file mode 100644 index d6531cfd0..000000000 --- a/src/video/windowsrt/SDL_winrtframebuffer_c.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -extern int SDL_WINRT_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch); -extern int SDL_WINRT_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects); -extern void SDL_WINRT_DestroyWindowFramebuffer(_THIS, SDL_Window * window); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/windowsrt/SDL_winrtrenderer.cpp b/src/video/windowsrt/SDL_winrtrenderer.cpp deleted file mode 100644 index a84fa7b2e..000000000 --- a/src/video/windowsrt/SDL_winrtrenderer.cpp +++ /dev/null @@ -1,87 +0,0 @@ - -#include -#include -#include -#include "SDLmain_WinRT_common.h" -#include "SDL_winrtrenderer.h" - -extern "C" { -#include "SDL_syswm.h" -#include "../../core/windows/SDL_windows.h" -} - -using namespace DirectX; -using namespace Microsoft::WRL; -using namespace std; -using namespace Windows::UI::Core; -using namespace Windows::Foundation; -using namespace Windows::Graphics::Display; - -// Constructor. -SDL_winrtrenderer::SDL_winrtrenderer() : - m_sdlRenderer(NULL), - m_sdlRendererData(NULL), - m_mainTexture(NULL) -{ -} - -SDL_winrtrenderer::~SDL_winrtrenderer() -{ - if (m_mainTexture) { - SDL_DestroyTexture(m_mainTexture); - m_mainTexture = NULL; - } -} - -void SDL_winrtrenderer::ResizeMainTexture(int w, int h) -{ - if (m_mainTexture) { - SDL_DestroyTexture(m_mainTexture); - m_mainTexture = NULL; - } - - m_mainTexture = SDL_CreateTexture(m_sdlRenderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_TARGET, w, h); -} - -static inline Platform::Exception ^ -WINRT_CreateExceptionWithSDLError() -{ - wchar_t * sdlErrorMessage = WIN_UTF8ToString(SDL_GetError()); - Platform::String ^ errorMessage = ref new Platform::String(sdlErrorMessage); - SDL_free(sdlErrorMessage); - throw ref new Platform::FailureException(errorMessage); -} - -void SDL_winrtrenderer::Render(SDL_Surface * surface, SDL_Rect * rects, int numrects) -{ - D3D11_TextureData * textureData = (D3D11_TextureData *)m_mainTexture->driverdata; - - SDL_SetRenderDrawColor(m_sdlRenderer, 0, 0, 0, 0); - if (SDL_RenderClear(m_sdlRenderer) != 0) { - throw WINRT_CreateExceptionWithSDLError(); - } - - // Only draw the screen once it is loaded (some loading is asynchronous). - if (!m_sdlRendererData->loadingComplete) { - return; - } - if (!textureData->mainTextureResourceView) { - return; - } - - // Update the main texture (for SDL usage). - // TODO, WinRT: only update the requested rects (passed to SDL_UpdateWindowSurface), rather than everything - if (SDL_UpdateTexture(m_mainTexture, NULL, surface->pixels, surface->pitch) != 0) { - throw WINRT_CreateExceptionWithSDLError(); - } - - if (SDL_RenderCopy(m_sdlRenderer, m_mainTexture, NULL, NULL) != 0) { - throw WINRT_CreateExceptionWithSDLError(); - } -} - -// Method to deliver the final image to the display. -void SDL_winrtrenderer::Present() -{ - SDL_RenderPresent(m_sdlRenderer); -} diff --git a/src/video/windowsrt/SDL_winrtrenderer.h b/src/video/windowsrt/SDL_winrtrenderer.h deleted file mode 100644 index f99d67c36..000000000 --- a/src/video/windowsrt/SDL_winrtrenderer.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include "DirectXHelper.h" -#include "../../render/direct3d11/SDL_render_d3d11_cpp.h" - -extern "C" { -#include "SDL.h" -#include "../../render/SDL_sysrender.h" -} - -// Helper class that initializes DirectX APIs for 3D rendering. -ref class SDL_winrtrenderer -{ -internal: - SDL_winrtrenderer(); - -public: - virtual ~SDL_winrtrenderer(); - virtual void Present(); - -internal: - virtual void Render(SDL_Surface * surface, SDL_Rect * rects, int numrects); - void ResizeMainTexture(int w, int h); - -internal: - // Internal SDL renderer (likely a temporary addition, for refactoring purposes): - SDL_Renderer * m_sdlRenderer; - D3D11_RenderData * m_sdlRendererData; - -protected private: - // UpdateWindowSurface helper objects - SDL_Texture * m_mainTexture; -}; diff --git a/src/video/windowsrt/SDL_winrtvideo.cpp b/src/video/windowsrt/SDL_winrtvideo.cpp index 38c30415f..682ea386e 100644 --- a/src/video/windowsrt/SDL_winrtvideo.cpp +++ b/src/video/windowsrt/SDL_winrtvideo.cpp @@ -41,7 +41,6 @@ extern "C" { #include "SDL_WinRTApp.h" #include "SDL_winrtvideo.h" #include "SDL_winrtevents_c.h" -#include "SDL_winrtframebuffer_c.h" #include "SDL_winrtmouse.h" /* On Windows, windows.h defines CreateWindow */ @@ -100,9 +99,9 @@ WINRT_CreateDevice(int devindex) device->DestroyWindow = WINRT_DestroyWindow; device->SetDisplayMode = WINRT_SetDisplayMode; device->PumpEvents = WINRT_PumpEvents; - device->CreateWindowFramebuffer = SDL_WINRT_CreateWindowFramebuffer; - device->UpdateWindowFramebuffer = SDL_WINRT_UpdateWindowFramebuffer; - device->DestroyWindowFramebuffer = SDL_WINRT_DestroyWindowFramebuffer; + //device->CreateWindowFramebuffer = SDL_WINRT_CreateWindowFramebuffer; + //device->UpdateWindowFramebuffer = SDL_WINRT_UpdateWindowFramebuffer; + //device->DestroyWindowFramebuffer = SDL_WINRT_DestroyWindowFramebuffer; device->GetWindowWMInfo = WINRT_GetWindowWMInfo; device->free = WINRT_DeleteDevice; @@ -167,6 +166,7 @@ WINRT_CreateWindow(_THIS, SDL_Window * window) SDL_OutOfMemory(); return -1; } + window->driverdata = data; data->sdlWindow = window; data->coreWindow = new CoreWindow^(CoreWindow::GetForCurrentThread()); @@ -213,27 +213,6 @@ WINRT_CreateWindow(_THIS, SDL_Window * window) */ SDL_WinRTGlobalApp->SetSDLWindowData(data); - /* For now, create a Direct3D 11 renderer up-front. Eventually, this - won't be done in WINRT_CreateWindow, although it may get done in - SDL_WINRT_CreateWindowFramebuffer. - */ - - // Link SDL_winrtrenderer to the SDL_Renderer temporarily, - // for refactoring purposes. Initialize the SDL_Renderer - // first in order to give it the opportunity to create key - // resources first. - // - // TODO, WinRT: either make WINRT_CreateWindow not call SDL_CreateRenderer, or have it do error checking if it does call it - - // HACK: make sure the SDL window references SDL_WindowData data now, in - // order to allow the SDL_Renderer to be created in WINRT_CreateWindow - window->driverdata = data; - - SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE); - SDL_WinRTGlobalApp->m_renderer->m_sdlRenderer = renderer; - SDL_WinRTGlobalApp->m_renderer->m_sdlRendererData = (D3D11_RenderData *) renderer->driverdata; - //SDL_WinRTGlobalApp->m_renderer->Initialize(); - /* All done! */ return 0; }