From 5e501fa9fcfac84dc956e3bf1cbcf769fa9a9b2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 31 Jan 2021 15:49:52 +0100 Subject: [PATCH] Fix minor rendering glitch in PPSSPP's menus on iOS --- Common/Render/DrawBuffer.cpp | 14 ++++++++++++++ Common/Render/DrawBuffer.h | 3 +++ Common/UI/Context.cpp | 2 +- Common/UI/View.cpp | 8 ++++---- Common/UI/ViewGroup.cpp | 4 ++-- UI/DisplayLayoutScreen.cpp | 2 +- UI/GameSettingsScreen.cpp | 2 +- 7 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Common/Render/DrawBuffer.cpp b/Common/Render/DrawBuffer.cpp index 94be1bc385..b29513d725 100644 --- a/Common/Render/DrawBuffer.cpp +++ b/Common/Render/DrawBuffer.cpp @@ -224,6 +224,20 @@ void DrawBuffer::DrawImage(ImageID atlas_image, float x, float y, float scale, C DrawImageStretch(atlas_image, x, y, x + w, y + h, color); } +void DrawBuffer::DrawImageCenterTexel(ImageID atlas_image, float x1, float y1, float x2, float y2, Color color) { + const AtlasImage *image = atlas->getImage(atlas_image); + if (!image) + return; + float centerU = (image->u1 + image->u2) * 0.5f; + float centerV = (image->v1 + image->v2) * 0.5f; + V(x1, y1, color, centerU, centerV); + V(x2, y1, color, centerU, centerV); + V(x2, y2, color, centerU, centerV); + V(x1, y1, color, centerU, centerV); + V(x2, y2, color, centerU, centerV); + V(x1, y2, color, centerU, centerV); +} + void DrawBuffer::DrawImageStretch(ImageID atlas_image, float x1, float y1, float x2, float y2, Color color) { const AtlasImage *image = atlas->getImage(atlas_image); if (!image) diff --git a/Common/Render/DrawBuffer.h b/Common/Render/DrawBuffer.h index 6c3f056f5d..f88308cf97 100644 --- a/Common/Render/DrawBuffer.h +++ b/Common/Render/DrawBuffer.h @@ -107,6 +107,9 @@ public: const Atlas *GetAtlas() const { return atlas; } bool MeasureImage(ImageID atlas_image, float *w, float *h); void DrawImage(ImageID atlas_image, float x, float y, float scale, Color color = COLOR(0xFFFFFF), int align = ALIGN_TOPLEFT); + + // Good for stretching out a white image without edge artifacts that I'm getting on iOS. + void DrawImageCenterTexel(ImageID atlas_image, float x1, float y1, float x2, float y2, Color color = COLOR(0xFFFFFF)); void DrawImageStretch(ImageID atlas_image, float x1, float y1, float x2, float y2, Color color = COLOR(0xFFFFFF)); void DrawImageStretchVGradient(ImageID atlas_image, float x1, float y1, float x2, float y2, Color color1, Color color2); void DrawImageStretch(ImageID atlas_image, const Bounds &bounds, Color color = COLOR(0xFFFFFF)) { diff --git a/Common/UI/Context.cpp b/Common/UI/Context.cpp index 9975281793..365f7ea4eb 100644 --- a/Common/UI/Context.cpp +++ b/Common/UI/Context.cpp @@ -224,7 +224,7 @@ void UIContext::FillRect(const UI::Drawable &drawable, const Bounds &bounds) { switch (drawable.type) { case UI::DRAW_SOLID_COLOR: - uidrawbuffer_->DrawImageStretch(theme->whiteImage, bounds.x, bounds.y, bounds.x2(), bounds.y2(), drawable.color); + uidrawbuffer_->DrawImageCenterTexel(theme->whiteImage, bounds.x, bounds.y, bounds.x2(), bounds.y2(), drawable.color); break; case UI::DRAW_4GRID: uidrawbuffer_->DrawImage4Grid(drawable.image, bounds.x, bounds.y, bounds.x2(), bounds.y2(), drawable.color); diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index 2babf3e4ba..2c25198db2 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -544,7 +544,7 @@ void InfoItem::Draw(UIContext &dc) { dc.SetFontStyle(dc.theme->uiFont); dc.DrawText(text_.c_str(), bounds_.x + paddingX, bounds_.centerY(), style.fgColor, ALIGN_VCENTER); dc.DrawText(rightText_.c_str(), bounds_.x2() - paddingX, bounds_.centerY(), style.fgColor, ALIGN_VCENTER | ALIGN_RIGHT); -// dc.Draw()->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y, bounds_.x2(), bounds_.y + 2, dc.theme->itemDownStyle.bgColor); +// dc.Draw()->DrawImageCenterTexel(dc.theme->whiteImage, bounds_.x, bounds_.y, bounds_.x2(), bounds_.y + 2, dc.theme->itemDownStyle.bgColor); } ItemHeader::ItemHeader(const std::string &text, LayoutParams *layoutParams) @@ -556,7 +556,7 @@ ItemHeader::ItemHeader(const std::string &text, LayoutParams *layoutParams) void ItemHeader::Draw(UIContext &dc) { dc.SetFontStyle(dc.theme->uiFontSmall); dc.DrawText(text_.c_str(), bounds_.x + 4, bounds_.centerY(), dc.theme->headerStyle.fgColor, ALIGN_LEFT | ALIGN_VCENTER); - dc.Draw()->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y2()-2, bounds_.x2(), bounds_.y2(), dc.theme->headerStyle.fgColor); + dc.Draw()->DrawImageCenterTexel(dc.theme->whiteImage, bounds_.x, bounds_.y2()-2, bounds_.x2(), bounds_.y2(), dc.theme->headerStyle.fgColor); } void ItemHeader::GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const { @@ -593,7 +593,7 @@ void PopupHeader::Draw(UIContext &dc) { } dc.DrawText(text_.c_str(), bounds_.x + tx, bounds_.centerY(), dc.theme->popupTitle.fgColor, ALIGN_LEFT | ALIGN_VCENTER); - dc.Draw()->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y2()-2, bounds_.x2(), bounds_.y2(), dc.theme->popupTitle.fgColor); + dc.Draw()->DrawImageCenterTexel(dc.theme->whiteImage, bounds_.x, bounds_.y2()-2, bounds_.x2(), bounds_.y2(), dc.theme->popupTitle.fgColor); if (availableWidth < tw) { dc.PopScissor(); @@ -1032,7 +1032,7 @@ void ProgressBar::GetContentDimensions(const UIContext &dc, float &w, float &h) void ProgressBar::Draw(UIContext &dc) { char temp[32]; sprintf(temp, "%i%%", (int)(progress_ * 100.0f)); - dc.Draw()->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y, bounds_.x + bounds_.w * progress_, bounds_.y2(), 0xc0c0c0c0); + dc.Draw()->DrawImageCenterTexel(dc.theme->whiteImage, bounds_.x, bounds_.y, bounds_.x + bounds_.w * progress_, bounds_.y2(), 0xc0c0c0c0); dc.SetFontStyle(dc.theme->uiFont); dc.DrawTextRect(temp, bounds_, 0xFFFFFFFF, ALIGN_CENTER); } diff --git a/Common/UI/ViewGroup.cpp b/Common/UI/ViewGroup.cpp index 60685b8b80..f022b6b137 100644 --- a/Common/UI/ViewGroup.cpp +++ b/Common/UI/ViewGroup.cpp @@ -1348,9 +1348,9 @@ void ChoiceStrip::Draw(UIContext &dc) { ViewGroup::Draw(dc); if (topTabs_) { if (orientation_ == ORIENT_HORIZONTAL) - dc.Draw()->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y2() - 4, bounds_.x2(), bounds_.y2(), dc.theme->itemDownStyle.background.color ); + dc.Draw()->DrawImageCenterTexel(dc.theme->whiteImage, bounds_.x, bounds_.y2() - 4, bounds_.x2(), bounds_.y2(), dc.theme->itemDownStyle.background.color ); else if (orientation_ == ORIENT_VERTICAL) - dc.Draw()->DrawImageStretch(dc.theme->whiteImage, bounds_.x2() - 4, bounds_.y, bounds_.x2(), bounds_.y2(), dc.theme->itemDownStyle.background.color ); + dc.Draw()->DrawImageCenterTexel(dc.theme->whiteImage, bounds_.x2() - 4, bounds_.y, bounds_.x2(), bounds_.y2(), dc.theme->itemDownStyle.background.color ); } } diff --git a/UI/DisplayLayoutScreen.cpp b/UI/DisplayLayoutScreen.cpp index 96b224c573..95bddf64cd 100644 --- a/UI/DisplayLayoutScreen.cpp +++ b/UI/DisplayLayoutScreen.cpp @@ -220,7 +220,7 @@ public: } void Draw(UIContext &dc) override { - dc.Draw()->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y, bounds_.x2(), bounds_.y2(), dc.theme->itemDownStyle.background.color); + dc.Draw()->DrawImageCenterTexel(dc.theme->whiteImage, bounds_.x, bounds_.y, bounds_.x2(), bounds_.y2(), dc.theme->itemDownStyle.background.color); } }; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index e86c0c6375..2f1e157eee 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1643,8 +1643,8 @@ void DeveloperToolsScreen::CreateViews() { if (g_Config.iGPUBackend == (int)GPUBackend::VULKAN || g_Config.iGPUBackend == (int)GPUBackend::OPENGL) { list->Add(new Choice(dev->T("GPU Driver Test")))->OnClick.Handle(this, &DeveloperToolsScreen::OnGPUDriverTest); } - list->Add(new Choice(dev->T("Framedump tests")))->OnClick.Handle(this, &DeveloperToolsScreen::OnFramedumpTest); list->Add(new CheckBox(&g_Config.bVendorBugChecksEnabled, dev->T("Enable driver bug workarounds"))); + list->Add(new Choice(dev->T("Framedump tests")))->OnClick.Handle(this, &DeveloperToolsScreen::OnFramedumpTest); list->Add(new Choice(dev->T("Touchscreen Test")))->OnClick.Handle(this, &DeveloperToolsScreen::OnTouchscreenTest); allowDebugger_ = !WebServerStopped(WebServerFlags::DEBUGGER);