Permalink
Browse files

Separate X and Y dpi_scale

  • Loading branch information...
hrydgard committed Aug 7, 2017
1 parent 11c7547 commit f4cf501cf614516132eaabe0ba77ed099984b03b
View
@@ -132,8 +132,8 @@ bool Core_GetPowerSaving() {
static bool IsWindowSmall(int pixelWidth, int pixelHeight) {
// Can't take this from config as it will not be set if windows is maximized.
int w = (int)(pixelWidth * g_dpi_scale);
int h = (int)(pixelHeight * g_dpi_scale);
int w = (int)(pixelWidth * g_dpi_scale_x);
int h = (int)(pixelHeight * g_dpi_scale_y);
return g_Config.IsPortrait() ? (h < 480 + 80) : (w < 480 + 80);
}
@@ -142,22 +142,27 @@ bool UpdateScreenScale(int width, int height) {
bool smallWindow;
#ifdef _WIN32
g_dpi = (float)System_GetPropertyInt(SYSPROP_DISPLAY_DPI);
g_dpi_scale = 96.0f / g_dpi;
g_dpi_scale_x = 96.0f / g_dpi;
g_dpi_scale_y = 96.0f / g_dpi;
#else
g_dpi = 96.0f;
g_dpi_scale = 1.0f;
g_dpi_scale_x = 1.0f;
g_dpi_scale_y = 1.0f;
#endif
g_dpi_scale_real = g_dpi_scale;
g_dpi_scale_real_x = g_dpi_scale_x;
g_dpi_scale_real_y = g_dpi_scale_y;
smallWindow = IsWindowSmall(width, height);
if (smallWindow) {
g_dpi /= 2.0f;
g_dpi_scale *= 2.0f;
g_dpi_scale_x *= 2.0f;
g_dpi_scale_y *= 2.0f;
}
pixel_in_dps = 1.0f / g_dpi_scale;
pixel_in_dps_x = 1.0f / g_dpi_scale_x;
pixel_in_dps_y = 1.0f / g_dpi_scale_y;
int new_dp_xres = width * g_dpi_scale;
int new_dp_yres = height * g_dpi_scale;
int new_dp_xres = width * g_dpi_scale_x;
int new_dp_yres = height * g_dpi_scale_y;
bool dp_changed = new_dp_xres != dp_xres || new_dp_yres != dp_yres;
bool px_changed = pixel_xres != width || pixel_yres != height;
View
@@ -248,7 +248,7 @@ void ReportScreen::CreateViews() {
screenshotFilename_ = path + ".reporting.jpg";
int shotWidth = 0, shotHeight = 0;
if (TakeGameScreenshot(screenshotFilename_.c_str(), SCREENSHOT_JPG, SCREENSHOT_DISPLAY, &shotWidth, &shotHeight, 4)) {
float scale = 340.0f * (1.0f / g_dpi_scale) * (1.0f / shotHeight);
float scale = 340.0f * (1.0f / g_dpi_scale_y) * (1.0f / shotHeight);
leftColumnItems->Add(new CheckBox(&includeScreenshot_, rp->T("FeedbackIncludeScreen", "Include a screenshot")))->SetEnabledPtr(&enableReporting_);
screenshot_ = leftColumnItems->Add(new AsyncImageFileView(screenshotFilename_, IS_DEFAULT, nullptr, new LinearLayoutParams(shotWidth * scale, shotHeight * scale, Margins(12, 0))));
} else {
View
@@ -203,12 +203,14 @@ bool PPSSPP_UWPMain::Render() {
// Boost DPI a bit to look better.
g_dpi *= 96.0f / 136.0f;
}
g_dpi_scale = 96.0f / g_dpi;
g_dpi_scale_x = 96.0f / g_dpi;
g_dpi_scale_y = 96.0f / g_dpi;
pixel_in_dps = 1.0f / g_dpi_scale;
pixel_in_dps_x = 1.0f / g_dpi_scale_x;
pixel_in_dps_y = 1.0f / g_dpi_scale_y;
dp_xres = pixel_xres * g_dpi_scale;
dp_yres = pixel_yres * g_dpi_scale;
dp_xres = pixel_xres * g_dpi_scale_x;
dp_yres = pixel_yres * g_dpi_scale_y;
context->RSSetViewports(1, &viewport);
@@ -281,13 +283,15 @@ bool PPSSPP_UWPMain::OnHardwareButton(HardwareButton button) {
void PPSSPP_UWPMain::OnTouchEvent(int touchEvent, int touchId, float x, float y, double timestamp) {
// We get the coordinate in Windows' device independent pixels already. So let's undo that,
// and then apply our own "dpi".
float dpiFactor = m_deviceResources->GetActualDpi() / 96.0f;
dpiFactor /= pixel_in_dps;
float dpiFactor_x = m_deviceResources->GetActualDpi() / 96.0f;
float dpiFactor_y = dpiFactor_x;
dpiFactor_x /= pixel_in_dps_x;
dpiFactor_y /= pixel_in_dps_y;
TouchInput input{};
input.id = touchId;
input.x = x * dpiFactor;
input.y = y * dpiFactor;
input.x = x * dpiFactor_x;
input.y = y * dpiFactor_y;
input.flags = touchEvent;
input.timestamp = timestamp;
NativeTouch(input);
@@ -46,7 +46,7 @@ CtrlDisplayListView::CtrlDisplayListView(HWND _wnd)
instructionSize = 4;
// In small window mode, g_dpi_scal may have been adjusted.
const float fontScale = 1.0f / g_dpi_scale_real;
const float fontScale = 1.0f / g_dpi_scale_real_y;
int fontHeight = g_Config.iFontHeight * fontScale;
int charWidth = g_Config.iFontWidth * fontScale;
View
@@ -574,8 +574,8 @@ namespace MainWindow
// Hack: Take the opportunity to show the cursor.
mouseButtonDown = true;
float x = GET_X_LPARAM(lParam) * g_dpi_scale;
float y = GET_Y_LPARAM(lParam) * g_dpi_scale;
float x = GET_X_LPARAM(lParam) * g_dpi_scale_x;
float y = GET_Y_LPARAM(lParam) * g_dpi_scale_y;
WindowsRawInput::SetMousePos(x, y);
TouchInput touch;
@@ -615,8 +615,8 @@ namespace MainWindow
prevCursorX = cursorX;
prevCursorY = cursorY;
float x = GET_X_LPARAM(lParam) * g_dpi_scale;
float y = GET_Y_LPARAM(lParam) * g_dpi_scale;
float x = (float)cursorX * g_dpi_scale_x;
float y = (float)cursorY * g_dpi_scale_y;
WindowsRawInput::SetMousePos(x, y);
if (wParam & MK_LBUTTON) {
@@ -637,8 +637,8 @@ namespace MainWindow
// Hack: Take the opportunity to hide the cursor.
mouseButtonDown = false;
float x = GET_X_LPARAM(lParam) * g_dpi_scale;
float y = GET_Y_LPARAM(lParam) * g_dpi_scale;
float x = (float)GET_X_LPARAM(lParam) * g_dpi_scale_x;
float y = (float)GET_Y_LPARAM(lParam) * g_dpi_scale_y;
WindowsRawInput::SetMousePos(x, y);
TouchInput touch;
@@ -10,20 +10,13 @@
#include "base/NativeApp.h"
#include "Windows/MainWindow.h"
TouchInputHandler::TouchInputHandler() :
touchInfo(nullptr),
closeTouch(nullptr),
registerTouch(nullptr)
{
TouchInputHandler::TouchInputHandler() {
touchInfo = (getTouchInputProc) GetProcAddress(
GetModuleHandle(TEXT("User32.dll")),
"GetTouchInputInfo");
closeTouch = (closeTouchInputProc) GetProcAddress(
GetModuleHandle(TEXT("User32.dll")),
"CloseTouchInputHandle");
registerTouch = (registerTouchProc) GetProcAddress(
GetModuleHandle(TEXT("User32.dll")),
"RegisterTouchWindow");
@@ -65,8 +58,8 @@ bool TouchInputHandler::GetTouchPoint(HWND hWnd, const TOUCHINPUT &input, float
point.x = (LONG)(TOUCH_COORD_TO_PIXEL(input.x));
point.y = (LONG)(TOUCH_COORD_TO_PIXEL(input.y));
if (ScreenToClient(hWnd, &point)) {
x = point.x * g_dpi_scale;
y = point.y * g_dpi_scale;
x = point.x * g_dpi_scale_x;
y = point.y * g_dpi_scale_y;
return true;
}
@@ -34,7 +34,7 @@ class TouchInputHandler
void touchDown(int id, float x, float y);
void touchMove(int id, float x, float y);
int touchIds[10];
int touchIds[10]{};
getTouchInputProc touchInfo;
closeTouchInputProc closeTouch;
registerTouchProc registerTouch;
View
@@ -211,10 +211,11 @@ void WindowsHost::PollControllers() {
doPad = false;
}
float scaleFactor = g_dpi_scale * 0.1 * g_Config.fMouseSensitivity;
float scaleFactor_x = g_dpi_scale_x * 0.1 * g_Config.fMouseSensitivity;
float scaleFactor_y = g_dpi_scale_y * 0.1 * g_Config.fMouseSensitivity;
float mx = std::max(-1.0f, std::min(1.0f, g_mouseDeltaX * scaleFactor));
float my = std::max(-1.0f, std::min(1.0f, g_mouseDeltaY * scaleFactor));
float mx = std::max(-1.0f, std::min(1.0f, g_mouseDeltaX * scaleFactor_x));
float my = std::max(-1.0f, std::min(1.0f, g_mouseDeltaY * scaleFactor_y));
AxisInput axisX, axisY;
axisX.axisId = JOYSTICK_AXIS_MOUSE_REL_X;
axisX.deviceId = DEVICE_ID_MOUSE;
@@ -705,21 +705,58 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeRenderer_displayResize(JNIEnv *, jo
pixel_yres = h;
g_dpi = display_dpi;
g_dpi_scale = 240.0f / g_dpi;
g_dpi_scale_real = g_dpi_scale;
g_dpi_scale_x = 240.0f / g_dpi;
g_dpi_scale_y = 240.0f / g_dpi;
g_dpi_scale_real_x = g_dpi_scale_x;
g_dpi_scale_real_y = g_dpi_scale_y;
dp_xres = display_xres * g_dpi_scale;
dp_yres = display_yres * g_dpi_scale;
dp_xres = display_xres * g_dpi_scale_x;
dp_yres = display_yres * g_dpi_scale_y;
// Touch scaling is from display pixels to dp pixels.
dp_xscale = (float)dp_xres / (float)display_xres;
dp_yscale = (float)dp_yres / (float)display_yres;
pixel_in_dps = (float)pixel_xres / dp_xres;
pixel_in_dps_x = (float)pixel_xres / dp_xres;
pixel_in_dps_y = (float)pixel_yres / dp_yres;
NativeResized();
}
extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_backbufferResize(JNIEnv *, jclass, jint bufw, jint bufh, jint format) {
ILOG("NativeApp.backbufferResize(%d x %d)", bufw, bufh);
// pixel_*res is the backbuffer resolution.
pixel_xres = bufw;
pixel_yres = bufh;
backbuffer_format = format;
g_dpi = display_dpi;
g_dpi_scale_x = 240.0f / g_dpi;
g_dpi_scale_y = 240.0f / g_dpi;
g_dpi_scale_real_x = g_dpi_scale_x;
g_dpi_scale_real_y = g_dpi_scale_y;
dp_xres = display_xres * g_dpi_scale_x;
dp_yres = display_yres * g_dpi_scale_y;
// Touch scaling is from display pixels to dp pixels.
dp_xscale = (float)dp_xres / (float)display_xres;
dp_yscale = (float)dp_yres / (float)display_yres;
pixel_in_dps_x = (float)pixel_xres / dp_xres;
pixel_in_dps_y = (float)pixel_yres / dp_yres;
ILOG("dp_xscale=%f dp_yscale=%f", dp_xscale, dp_yscale);
ILOG("dp_xres=%d dp_yres=%d", dp_xres, dp_yres);
ILOG("pixel_xres=%d pixel_yres=%d", pixel_xres, pixel_yres);
ILOG("g_dpi=%d g_dpi_scale_x=%f g_dpi_scale_y", g_dpi, g_dpi_scale_x, g_dpi_scale_y);
NativeResized();
}
// JavaEGL
extern "C" void Java_org_ppsspp_ppsspp_NativeRenderer_displayRender(JNIEnv *env, jobject obj) {
static bool hasSetThreadName = false;
@@ -965,35 +1002,6 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_setDisplayParameters(JN
display_hz = refreshRate;
}
extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_backbufferResize(JNIEnv *, jclass, jint bufw, jint bufh, jint format) {
ILOG("NativeApp.backbufferResize(%d x %d)", bufw, bufh);
// pixel_*res is the backbuffer resolution.
pixel_xres = bufw;
pixel_yres = bufh;
backbuffer_format = format;
g_dpi = (float)display_dpi;
g_dpi_scale = 240.0f / g_dpi;
g_dpi_scale_real = g_dpi_scale;
dp_xres = display_xres * g_dpi_scale;
dp_yres = display_yres * g_dpi_scale;
// Touch scaling is from display pixels to dp pixels.
dp_xscale = (float)dp_xres / (float)display_xres;
dp_yscale = (float)dp_yres / (float)display_yres;
pixel_in_dps = (float)pixel_xres / dp_xres;
ILOG("dp_xscale=%f dp_yscale=%f", dp_xscale, dp_yscale);
ILOG("dp_xres=%d dp_yres=%d", dp_xres, dp_yres);
ILOG("pixel_xres=%d pixel_yres=%d", pixel_xres, pixel_yres);
ILOG("g_dpi=%d g_dpi_scale=%f", g_dpi, g_dpi_scale);
NativeResized();
}
extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_computeDesiredBackbufferDimensions() {
getDesiredBackbufferSize(desiredBackbufferSizeX, desiredBackbufferSizeY);
}
@@ -631,9 +631,12 @@ int main(int argc, char *argv[]) {
NativeInit(remain_argc, (const char **)remain_argv, path, "/tmp", nullptr);
#endif
pixel_in_dps = (float)pixel_xres / dp_xres;
g_dpi_scale = dp_xres / (float)pixel_xres;
g_dpi_scale_real = g_dpi_scale;
pixel_in_dps_x = (float)pixel_xres / dp_xres;
pixel_in_dps_y = (float)pixel_yres / dp_yres;
g_dpi_scale_x = dp_xres / (float)pixel_xres;
g_dpi_scale_y = dp_yres / (float)pixel_yres;
g_dpi_scale_real_x = g_dpi_scale_x;
g_dpi_scale_real_y = g_dpi_scale_y;
printf("Pixels: %i x %i\n", pixel_xres, pixel_yres);
printf("Virtual pixels: %i x %i\n", dp_xres, dp_yres);
View
@@ -263,15 +263,15 @@ bool MainUI::event(QEvent *e)
break;
case Qt::TouchPointPressed:
case Qt::TouchPointReleased:
input.x = touchPoint.pos().x() * g_dpi_scale * xscale;
input.y = touchPoint.pos().y() * g_dpi_scale * yscale;
input.x = touchPoint.pos().x() * g_dpi_scale_x * xscale;
input.y = touchPoint.pos().y() * g_dpi_scale_y * yscale;
input.flags = (touchPoint.state() == Qt::TouchPointPressed) ? TOUCH_DOWN : TOUCH_UP;
input.id = touchPoint.id();
NativeTouch(input);
break;
case Qt::TouchPointMoved:
input.x = touchPoint.pos().x() * g_dpi_scale * xscale;
input.y = touchPoint.pos().y() * g_dpi_scale * yscale;
input.x = touchPoint.pos().x() * g_dpi_scale_x * xscale;
input.y = touchPoint.pos().y() * g_dpi_scale_y * yscale;
input.flags = TOUCH_MOVE;
input.id = touchPoint.id();
NativeTouch(input);
@@ -287,15 +287,15 @@ bool MainUI::event(QEvent *e)
break;
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
input.x = ((QMouseEvent*)e)->pos().x() * g_dpi_scale * xscale;
input.y = ((QMouseEvent*)e)->pos().y() * g_dpi_scale * yscale;
input.x = ((QMouseEvent*)e)->pos().x() * g_dpi_scale_x * xscale;
input.y = ((QMouseEvent*)e)->pos().y() * g_dpi_scale_y * yscale;
input.flags = (e->type() == QEvent::MouseButtonPress) ? TOUCH_DOWN : TOUCH_UP;
input.id = 0;
NativeTouch(input);
break;
case QEvent::MouseMove:
input.x = ((QMouseEvent*)e)->pos().x() * g_dpi_scale * xscale;
input.y = ((QMouseEvent*)e)->pos().y() * g_dpi_scale * yscale;
input.x = ((QMouseEvent*)e)->pos().x() * g_dpi_scale_x * xscale;
input.y = ((QMouseEvent*)e)->pos().y() * g_dpi_scale_y * yscale;
input.flags = TOUCH_MOVE;
input.id = 0;
NativeTouch(input);
@@ -437,8 +437,10 @@ int main(int argc, char *argv[])
res.transpose();
pixel_xres = res.width();
pixel_yres = res.height();
g_dpi_scale = CalculateDPIScale();
g_dpi_scale_real = g_dpi_scale;
g_dpi_scale_x = CalculateDPIScale();
g_dpi_scale_y = CalculateDPIScale();
g_dpi_scale_real_x = g_dpi_scale_x;
g_dpi_scale_real_y = g_dpi_scale_y;
dp_xres = (int)(pixel_xres * g_dpi_scale); dp_yres = (int)(pixel_yres * g_dpi_scale);
std::string savegame_dir = ".";
std::string external_dir = ".";
@@ -7,9 +7,12 @@ int pixel_xres;
int pixel_yres;
float g_dpi = 1.0f; // will be overwritten with a value that makes sense.
float g_dpi_scale = 1.0f;
float g_dpi_scale_real = 1.0f;
float pixel_in_dps = 1.0f;
float g_dpi_scale_x = 1.0f;
float g_dpi_scale_y = 1.0f;
float g_dpi_scale_real_x = 1.0f;
float g_dpi_scale_real_y = 1.0f;
float pixel_in_dps_x = 1.0f;
float pixel_in_dps_y = 1.0f;
float display_hz = 60.0f;
DisplayRotation g_display_rotation;
@@ -11,9 +11,12 @@ extern int pixel_xres;
extern int pixel_yres;
extern float g_dpi;
extern float g_dpi_scale;
extern float g_dpi_scale_real;
extern float pixel_in_dps;
extern float g_dpi_scale_x;
extern float g_dpi_scale_y;
extern float g_dpi_scale_real_x;
extern float g_dpi_scale_real_y;
extern float pixel_in_dps_x;
extern float pixel_in_dps_y;
extern float display_hz;
// On some platforms (currently only Windows UWP) we need to manually rotate
Oops, something went wrong.

0 comments on commit f4cf501

Please sign in to comment.