VITA: Use activeArea rectangle also on Vita

This commit is contained in:
rsn8887 2019-08-13 00:50:59 -05:00
parent e33c80eaba
commit afd360703e
3 changed files with 18 additions and 123 deletions

View File

@ -37,6 +37,9 @@
#include "math.h"
#define TOUCHSCREEN_WIDTH 960
#define TOUCHSCREEN_HEIGHT 544
PSP2EventSource::PSP2EventSource() {
for (int port = 0; port < SCE_TOUCH_PORT_MAX_NUM; port++) {
for (int i = 0; i < MAX_NUM_FINGERS; i++) {
@ -372,48 +375,15 @@ void PSP2EventSource::convertTouchXYToGameXY(float touchX, float touchY, int *ga
int screenH = _km.y_max;
int screenW = _km.x_max;
int windowH = g_system->getHeight();
int windowW = g_system->getWidth();
bool fullscreen = ConfMan.getBool("fullscreen");
bool aspectRatioCorrection = ConfMan.getBool("aspect_ratio");
const int dispW = 960;
const int dispH = 544;
const int dispW = TOUCHSCREEN_WIDTH;
const int dispH = TOUCHSCREEN_HEIGHT;
int x, y, w, h;
float sx, sy;
float ratio = (float)screenW / (float)screenH;
if (aspectRatioCorrection && (windowH == 200 || windowH == 400)) {
ratio = 4.0 / 3.0;
}
if (fullscreen || screenH >= dispH) {
h = dispH;
if (aspectRatioCorrection && (windowH == 200 || windowH == 400)) {
ratio = ratio * 1.1;
}
w = h * ratio;
} else {
if (screenH <= dispH / 2 && screenW <= dispW / 2) {
// Use Vita hardware 2x scaling if the picture is really small
// this uses the current shader and filtering mode
h = screenH * 2;
w = screenW * 2;
} else {
h = screenH;
w = screenW;
}
if (aspectRatioCorrection && (windowH == 200 || windowH == 400)) {
// stretch the height only if it fits, otherwise make the width smaller
if (((float)w * (1.0 / ratio)) <= (float)dispH) {
h = w * (1.0 / ratio);
} else {
w = h * ratio;
}
}
}
h = dispH;
w = h * ratio;
x = (dispW - w) / 2;
y = (dispH - h) / 2;
@ -421,23 +391,12 @@ void PSP2EventSource::convertTouchXYToGameXY(float touchX, float touchY, int *ga
sy = (float)h / (float)screenH;
sx = (float)w / (float)screenW;
// Find touch coordinates in terms of Vita screen pixels
// Find touch coordinates in terms of screen pixels
float dispTouchX = (touchX * (float)dispW);
float dispTouchY = (touchY * (float)dispH);
*gameX = (dispTouchX - x) / sx;
*gameY = (dispTouchY - y) / sy;
if (*gameX < 0) {
*gameX = 0;
} else if (*gameX > _km.x_max) {
*gameX = _km.x_max;
}
if (*gameY < 0) {
*gameY = 0;
} else if (*gameY > _km.y_max) {
*gameY = _km.y_max;
}
*gameX = CLIP((int)((dispTouchX - x) / sx), 0, (int)_km.x_max);
*gameY = CLIP((int)((dispTouchY - y) / sy), 0, (int)_km.y_max);
}
void PSP2EventSource::finishSimulatedMouseClicks() {

View File

@ -79,14 +79,6 @@ PSP2SdlGraphicsManager::PSP2SdlGraphicsManager(SdlEventSource *sdlEventSource, S
_vitatex_hwscreen(nullptr),
_sdlpixels_hwscreen(nullptr) {
// do aspect ratio correction in hardware on the Vita
if (_videoMode.aspectRatioCorrection == true) {
_hardwareAspectRatioCorrection = true;
} else {
_hardwareAspectRatioCorrection = false;
}
_videoMode.aspectRatioCorrection = false;
// shader number 0 is the entry NONE (no shader)
const OSystem::GraphicsMode *p = s_supportedShadersPSP2;
_numShaders = 0;
@ -100,6 +92,9 @@ PSP2SdlGraphicsManager::PSP2SdlGraphicsManager(SdlEventSource *sdlEventSource, S
}
_shaders[0] = NULL;
/* Vita display size is always 960x544 (that's just the hardware) */
handleResize(960, 544);
}
PSP2SdlGraphicsManager::~PSP2SdlGraphicsManager() {
@ -214,27 +209,6 @@ void PSP2SdlGraphicsManager::updateShader() {
}
}
void PSP2SdlGraphicsManager::setAspectRatioCorrection(bool enable) {
Common::StackLock lock(_graphicsMutex);
if (_oldVideoMode.setup && _hardwareAspectRatioCorrection == enable)
return;
if (_transactionMode == kTransactionActive) {
_videoMode.aspectRatioCorrection = false;
_hardwareAspectRatioCorrection = enable;
// erase the screen for both buffers
if (_vitatex_hwscreen) {
for (int i = 0; i <= 10; i++) {
vita2d_start_drawing();
vita2d_clear_screen();
vita2d_end_drawing();
vita2d_swap_buffers();
}
}
}
}
SDL_Surface *PSP2SdlGraphicsManager::SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) {
SDL_Surface *screen = SurfaceSdlGraphicsManager::SDL_SetVideoMode(width, height, bpp, flags);
@ -254,49 +228,13 @@ void PSP2SdlGraphicsManager::SDL_UpdateRects(SDL_Surface *screen, int numrects,
int screenH = screen->h;
int screenW = screen->w;
bool fullscreen = _videoMode.fullscreen;
bool aspectRatioCorrection = _hardwareAspectRatioCorrection;
const int dispW = 960;
const int dispH = 544;
int x, y, w, h;
float sx, sy;
float ratio = (float)screenW / (float)screenH;
if (aspectRatioCorrection && (screenH == 200 || screenH == 400)) {
ratio = 4.0 / 3.0;
}
if (fullscreen || screenH >= dispH) {
h = dispH;
w = h * ratio;
} else {
if (screenH <= dispH / 2 && screenW <= dispW / 2) {
// Use Vita hardware 2x scaling if the picture is really small
// this uses the current shader and filtering mode
h = screenH * 2;
w = screenW * 2;
} else {
h = screenH;
w = screenW;
}
if (aspectRatioCorrection && (screenH == 200 || screenH == 400)) {
// stretch the height only if it fits, otherwise make the width smaller
if (((float)w * (1.0 / ratio)) <= (float)dispH) {
h = w * (1.0 / ratio);
} else {
w = h * ratio;
}
}
}
x = (dispW - w) / 2;
y = (dispH - h) / 2;
sx = (float)w / (float)screenW;
sy = (float)h / (float)screenH;
int x = _activeArea.drawRect.left;
int y = _activeArea.drawRect.top;
float sx = _activeArea.drawRect.width() / (float)screenW;
float sy = _activeArea.drawRect.height() / (float)screenH;
if (_vitatex_hwscreen) {
vita2d_start_drawing();
vita2d_clear_screen();
vita2d_draw_texture_scale(_vitatex_hwscreen, x, y, sx, sy);
vita2d_end_drawing();
vita2d_swap_buffers();

View File

@ -40,12 +40,10 @@ protected:
virtual bool hotswapGFXMode() override;
virtual void updateShader() override;
virtual void setAspectRatioCorrection(bool enable) override;
virtual SDL_Surface *SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) override;
virtual void SDL_UpdateRects(SDL_Surface *screen, int numrects, SDL_Rect *rects) override;
void PSP2_UpdateFiltering();
bool _hardwareAspectRatioCorrection;
vita2d_texture *_vitatex_hwscreen;
void *_sdlpixels_hwscreen;
vita2d_shader *_shaders[6];