From e7c42621af12aa525b937b663ad9518ebbba56d7 Mon Sep 17 00:00:00 2001 From: scooterpsu <3433982+scooterpsu@users.noreply.github.com> Date: Wed, 16 Oct 2019 22:26:25 -0400 Subject: [PATCH 1/2] Add IPU check, use software scaling if not present --- SourceX/dx.cpp | 38 ++++++++++++++++++++++++++++---------- SourceX/miniwin/misc.cpp | 8 +++++++- SourceX/storm/storm.cpp | 18 ++++++++++++++++-- SourceX/utils.cpp | 10 ++++++++++ SourceX/utils.h | 1 + 5 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 SourceX/utils.cpp create mode 100644 SourceX/utils.h diff --git a/SourceX/dx.cpp b/SourceX/dx.cpp index 8ca8903e61c..0ef9c5c1a5f 100644 --- a/SourceX/dx.cpp +++ b/SourceX/dx.cpp @@ -4,6 +4,8 @@ #include "miniwin/com_macro.h" #include +#include "utils.h" + namespace dvl { int sgdwLockCount; @@ -182,17 +184,33 @@ void BltFast(DWORD dwX, DWORD dwY, LPRECT lpSrcRect) static_cast(lpSrcRect->top), w, h }; - SDL_Rect dst_rect = { - static_cast(dwX), - static_cast(dwY), - w, h - }; - - // Convert from 8-bit to 32-bit - if (SDL_BlitSurface(pal_surface, &src_rect, GetOutputSurface(), &dst_rect) <= -1) { - ErrSdl(); + + if (GFX_IsRetroFW20()) { + SDL_Rect dst_rect = { + static_cast(dwX), + static_cast(dwY), + w, h + }; + + // Convert from 8-bit to 32-bit + if (SDL_BlitSurface(pal_surface, &src_rect, GetOutputSurface(), &dst_rect) <= -1) { + ErrSdl(); + } + + } else { + SDL_Rect dst_rect = { + static_cast(dwX) / 2, + static_cast(dwY), + w / 2, h + }; + // Convert from 8-bit to 32-bit + SDL_Surface *tmp = SDL_ConvertSurface(pal_surface, GetOutputSurface()->format, 0); + if (SDL_BlitScaled(tmp, &src_rect, GetOutputSurface(), &dst_rect) <= -1) { + SDL_FreeSurface(tmp); + ErrSdl(); + } + SDL_FreeSurface(tmp); } - bufferUpdated = true; } diff --git a/SourceX/miniwin/misc.cpp b/SourceX/miniwin/misc.cpp index 4f38b720471..7cab8b2ef5a 100644 --- a/SourceX/miniwin/misc.cpp +++ b/SourceX/miniwin/misc.cpp @@ -12,6 +12,8 @@ #define strncasecmp _strnicmp #endif +#include "utils.h" + namespace dvl { DWORD last_error; @@ -149,7 +151,11 @@ bool SpawnWindow(LPCSTR lpWindowName, int nWidth, int nHeight) if (fullscreen) flags |= SDL_FULLSCREEN; SDL_WM_SetCaption(lpWindowName, WINDOW_ICON_NAME); - SDL_SetVideoMode(nWidth, nHeight, /*bpp=*/0, flags); + if (GFX_IsRetroFW20()) { + SDL_SetVideoMode(nWidth, nHeight, /*bpp=*/0, flags); + } else { + SDL_SetVideoMode(320, 480, /*bpp=*/0, flags); // LDK Hack + } window = SDL_GetVideoSurface(); if (grabInput) SDL_WM_GrabInput(SDL_GRAB_ON); diff --git a/SourceX/storm/storm.cpp b/SourceX/storm/storm.cpp index 4099a2a0800..7e75dfc2047 100644 --- a/SourceX/storm/storm.cpp +++ b/SourceX/storm/storm.cpp @@ -14,6 +14,8 @@ #include "DiabloUI/diabloui.h" +#include "utils.h" + namespace dvl { DWORD nLastError = 0; @@ -706,13 +708,25 @@ BOOL SVidPlayContinue(void) } const int scaledW = SVidWidth * factor; const int scaledH = SVidHeight * factor; + + int newX; + int newW; + + if (GFX_IsRetroFW20()) { + newX = (SCREEN_WIDTH - scaledW) / 2; + newW = scaledW; + } else { + newX = (SCREEN_WIDTH - scaledW) / 2 / 2; + newW = scaledW / 2; + } SDL_Rect pal_surface_offset = { - static_cast((SCREEN_WIDTH - scaledW) / 2), + static_cast(newX), static_cast((SCREEN_HEIGHT - scaledH) / 2), - static_cast(scaledW), + static_cast(newW), static_cast(scaledH) }; + #ifdef USE_SDL1 SDL_Surface *tmp = SDL_ConvertSurface(SVidSurface, window->format, 0); // NOTE: Consider resolution switching instead if video doesn't play diff --git a/SourceX/utils.cpp b/SourceX/utils.cpp new file mode 100644 index 00000000000..12e9fd8d741 --- /dev/null +++ b/SourceX/utils.cpp @@ -0,0 +1,10 @@ +#include +#include +#include + +bool GFX_IsRetroFW20(void) +{ + struct stat buffer; + + return (stat("/proc/jz/ipu_ratio", &buffer) == 0); +} diff --git a/SourceX/utils.h b/SourceX/utils.h new file mode 100644 index 00000000000..08f4ef53f49 --- /dev/null +++ b/SourceX/utils.h @@ -0,0 +1 @@ +bool GFX_IsRetroFW20(void); From 7fb5993af6193dd33c28eb89326f454d7f228388 Mon Sep 17 00:00:00 2001 From: scooterpsu <3433982+scooterpsu@users.noreply.github.com> Date: Wed, 16 Oct 2019 22:39:14 -0400 Subject: [PATCH 2/2] Forgot to update CMakeLists.txt --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65d2f65ce37..094ed9733c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -219,6 +219,7 @@ add_library(devilution STATIC Source/wave.cpp) set(devilutionx_SRCS + SourceX/utils.cpp SourceX/dx.cpp SourceX/miniwin/ddraw.cpp SourceX/miniwin/misc.cpp