mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Improve smallwindow detection, code cleanup.
This commit is contained in:
parent
d91f82604d
commit
0be02f6de0
5 changed files with 45 additions and 30 deletions
|
@ -130,22 +130,38 @@ bool Core_GetPowerSaving() {
|
|||
return powerSaving;
|
||||
}
|
||||
|
||||
static int ScreenDPI() {
|
||||
HDC screenDC = GetDC(nullptr);
|
||||
int dotsPerInch = GetDeviceCaps(screenDC, LOGPIXELSY);
|
||||
ReleaseDC(nullptr, screenDC);
|
||||
return dotsPerInch;
|
||||
}
|
||||
|
||||
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);
|
||||
return g_Config.IsPortrait() ? (h < 480 + 80) : (w < 480 + 80);
|
||||
}
|
||||
|
||||
// TODO: Feels like this belongs elsewhere.
|
||||
bool UpdateScreenScale(int width, int height, bool smallWindow) {
|
||||
bool UpdateScreenScale(int width, int height) {
|
||||
bool smallWindow;
|
||||
#ifdef _WIN32
|
||||
// Use legacy DPI handling, because we still compile as XP compatible we don't get the new SDK, unless
|
||||
// we do unholy tricks.
|
||||
HDC screenDC = GetDC(nullptr);
|
||||
double hPixelsPerInch = GetDeviceCaps(screenDC, LOGPIXELSY);
|
||||
ReleaseDC(nullptr, screenDC);
|
||||
|
||||
g_dpi = hPixelsPerInch;
|
||||
g_dpi = ScreenDPI();
|
||||
g_dpi_scale = 96.0f / g_dpi;
|
||||
smallWindow = IsWindowSmall(width, height);
|
||||
#else
|
||||
g_dpi = 96;
|
||||
g_dpi_scale = 1.0f;
|
||||
#endif
|
||||
|
||||
if (smallWindow) {
|
||||
g_dpi /= 2;
|
||||
g_dpi_scale *= 2.0f;
|
||||
}
|
||||
pixel_in_dps = 1.0f / g_dpi_scale;
|
||||
|
||||
int new_dp_xres = width * g_dpi_scale;
|
||||
|
|
|
@ -47,7 +47,7 @@ bool Core_IsInactive();
|
|||
void Core_WaitInactive();
|
||||
void Core_WaitInactive(int milliseconds);
|
||||
|
||||
bool UpdateScreenScale(int width, int height, bool smallWindow);
|
||||
bool UpdateScreenScale(int width, int height);
|
||||
|
||||
// Don't run the core when minimized etc.
|
||||
void Core_NotifyWindowHidden(bool hidden);
|
||||
|
|
|
@ -204,15 +204,6 @@ namespace MainWindow
|
|||
rcOuter.top = g_Config.iWindowY;
|
||||
}
|
||||
|
||||
static bool IsWindowSmall() {
|
||||
// Can't take this from config as it will not be set if windows is maximized.
|
||||
RECT rc;
|
||||
GetWindowRect(hwndMain, &rc);
|
||||
int width = (int)((rc.right - rc.left) * g_dpi_scale);
|
||||
int height = (int)((rc.bottom - rc.top) * g_dpi_scale);
|
||||
return g_Config.IsPortrait() ? (height < 480 + 80) : (width < 480 + 80);
|
||||
}
|
||||
|
||||
void SetWindowSize(int zoom) {
|
||||
AssertCurrentThreadName("Main");
|
||||
RECT rc, rcOuter;
|
||||
|
@ -281,7 +272,7 @@ namespace MainWindow
|
|||
PSP_CoreParameter().pixelHeight = height;
|
||||
}
|
||||
|
||||
if (UpdateScreenScale(width, height, IsWindowSmall())) {
|
||||
if (UpdateScreenScale(width, height)) {
|
||||
NativeMessageReceived("gpu resized", "");
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ TextDrawer::TextDrawer(Draw::DrawContext *thin3d) : thin3d_(thin3d), ctx_(nullpt
|
|||
// These probably shouldn't be state.
|
||||
fontScaleX_ = 1.0f;
|
||||
fontScaleY_ = 1.0f;
|
||||
last_dpi_scale_ = g_dpi_scale;
|
||||
|
||||
ctx_ = new TextDrawerContext();
|
||||
ctx_->hDC = CreateCompatibleDC(NULL);
|
||||
|
@ -75,12 +76,7 @@ TextDrawer::TextDrawer(Draw::DrawContext *thin3d) : thin3d_(thin3d), ctx_(nullpt
|
|||
}
|
||||
|
||||
TextDrawer::~TextDrawer() {
|
||||
for (auto &iter : cache_) {
|
||||
if (iter.second->texture)
|
||||
iter.second->texture->Release();
|
||||
}
|
||||
cache_.clear();
|
||||
sizeCache_.clear();
|
||||
ClearCache();
|
||||
|
||||
for (auto iter = fontMap_.begin(); iter != fontMap_.end(); ++iter) {
|
||||
DeleteObject(iter->second->hFont);
|
||||
|
@ -304,12 +300,7 @@ TextDrawer::TextDrawer(Draw::DrawContext *thin3d) : thin3d_(thin3d), ctx_(NULL)
|
|||
}
|
||||
|
||||
TextDrawer::~TextDrawer() {
|
||||
for (auto &iter : cache_) {
|
||||
if (iter.second->texture)
|
||||
iter.second->texture->Release();
|
||||
}
|
||||
cache_.clear();
|
||||
sizeCache_.clear();
|
||||
ClearCache();
|
||||
}
|
||||
|
||||
uint32_t TextDrawer::SetFont(const char *fontName, int size, int flags) {
|
||||
|
@ -441,6 +432,15 @@ void TextDrawer::DrawString(DrawBuffer &target, const char *str, float x, float
|
|||
|
||||
#endif
|
||||
|
||||
void TextDrawer::ClearCache() {
|
||||
for (auto &iter : cache_) {
|
||||
if (iter.second->texture)
|
||||
iter.second->texture->Release();
|
||||
}
|
||||
cache_.clear();
|
||||
sizeCache_.clear();
|
||||
}
|
||||
|
||||
void TextDrawer::WrapString(std::string &out, const char *str, float maxW) {
|
||||
TextDrawerWordWrapper wrapper(this, str, maxW);
|
||||
out = wrapper.Wrapped();
|
||||
|
@ -476,7 +476,13 @@ void TextDrawer::DrawStringRect(DrawBuffer &target, const char *str, const Bound
|
|||
|
||||
void TextDrawer::OncePerFrame() {
|
||||
frameCount_++;
|
||||
// Use a prime number to reduce clashing with other rhythms
|
||||
// If DPI changed (small-mode, future proper monitor DPI support), drop everything.
|
||||
if (g_dpi_scale != last_dpi_scale_) {
|
||||
last_dpi_scale_ = g_dpi_scale;
|
||||
ClearCache();
|
||||
}
|
||||
|
||||
// Drop old strings. Use a prime number to reduce clashing with other rhythms
|
||||
if (frameCount_ % 23 == 0) {
|
||||
for (auto iter = cache_.begin(); iter != cache_.end();) {
|
||||
if (frameCount_ - iter->second->lastUsedFrame > 100) {
|
||||
|
|
|
@ -68,11 +68,13 @@ public:
|
|||
private:
|
||||
Draw::DrawContext *thin3d_;
|
||||
|
||||
void ClearCache();
|
||||
void WrapString(std::string &out, const char *str, float maxWidth);
|
||||
|
||||
int frameCount_;
|
||||
float fontScaleX_;
|
||||
float fontScaleY_;
|
||||
float last_dpi_scale_;
|
||||
|
||||
TextDrawerContext *ctx_;
|
||||
#ifdef USING_QT_UI
|
||||
|
|
Loading…
Add table
Reference in a new issue