Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IPU check, use software scaling if not present #3

Merged
merged 2 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 28 additions & 10 deletions SourceX/dx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "miniwin/com_macro.h"
#include <SDL.h>

#include "utils.h"

namespace dvl {

int sgdwLockCount;
Expand Down Expand Up @@ -182,17 +184,33 @@ void BltFast(DWORD dwX, DWORD dwY, LPRECT lpSrcRect)
static_cast<decltype(SDL_Rect().y)>(lpSrcRect->top),
w, h
};
SDL_Rect dst_rect = {
static_cast<decltype(SDL_Rect().x)>(dwX),
static_cast<decltype(SDL_Rect().y)>(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<decltype(SDL_Rect().x)>(dwX),
static_cast<decltype(SDL_Rect().y)>(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<decltype(SDL_Rect().x)>(dwX) / 2,
static_cast<decltype(SDL_Rect().y)>(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;
}

Expand Down
8 changes: 7 additions & 1 deletion SourceX/miniwin/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#define strncasecmp _strnicmp
#endif

#include "utils.h"

namespace dvl {

DWORD last_error;
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 16 additions & 2 deletions SourceX/storm/storm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "DiabloUI/diabloui.h"

#include "utils.h"

namespace dvl {

DWORD nLastError = 0;
Expand Down Expand Up @@ -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<decltype(SDL_Rect().x)>((SCREEN_WIDTH - scaledW) / 2),
static_cast<decltype(SDL_Rect().x)>(newX),
static_cast<decltype(SDL_Rect().y)>((SCREEN_HEIGHT - scaledH) / 2),
static_cast<decltype(SDL_Rect().w)>(scaledW),
static_cast<decltype(SDL_Rect().w)>(newW),
static_cast<decltype(SDL_Rect().h)>(scaledH)
};

#ifdef USE_SDL1
SDL_Surface *tmp = SDL_ConvertSurface(SVidSurface, window->format, 0);
// NOTE: Consider resolution switching instead if video doesn't play
Expand Down
10 changes: 10 additions & 0 deletions SourceX/utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

bool GFX_IsRetroFW20(void)
{
struct stat buffer;

return (stat("/proc/jz/ipu_ratio", &buffer) == 0);
}
1 change: 1 addition & 0 deletions SourceX/utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bool GFX_IsRetroFW20(void);