Merge pull request #16414 from hrydgard/simpler-game-background

Pause menu background: Remove complicated transparency tricks
This commit is contained in:
Henrik Rydgård 2022-11-22 13:19:14 +01:00 committed by GitHub
commit f0a905cadd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 49 deletions

View File

@ -71,7 +71,6 @@ public:
DrawBuffer *Draw() const { return uidrawbuffer_; }
DrawBuffer *DrawTop() const { return uidrawbufferTop_; }
const UI::Theme *theme;
// Utility methods
TextDrawer *Text() const { return textDrawer_; }
@ -94,6 +93,9 @@ public:
const Bounds &GetBounds() const { return bounds_; }
Bounds GetLayoutBounds() const;
Draw::DrawContext *GetDrawContext() { return draw_; }
const UI::Theme &GetTheme() const {
return *theme;
}
void SetCurZ(float curZ);
void PushTransform(const UITransform &transform);
@ -106,6 +108,9 @@ public:
screenTag_ = tag;
}
// TODO: Move to private.
const UI::Theme *theme;
private:
Draw::DrawContext *draw_ = nullptr;
Bounds bounds_;

View File

@ -1392,30 +1392,6 @@ void EmuScreen::render() {
if (!thin3d)
return; // shouldn't really happen but I've seen a suspicious stack trace..
// We can still render behind the pause screen.
bool paused = screenManager()->topScreen() != this;
if (paused && screenManager()->topScreen()->isTransparent()) {
// If we're paused and PauseScreen is transparent (will only be in buffered rendering mode), we just copy display to output.
thin3d->BindFramebufferAsRenderTarget(nullptr, { RPAction::CLEAR, RPAction::DONT_CARE, RPAction::DONT_CARE }, "EmuScreen_Paused");
if (PSP_IsInited()) {
gpu->CheckDisplayResized();
gpu->CopyDisplayToOutput(true);
}
screenManager()->getUIContext()->BeginFrame();
DrawContext *draw = screenManager()->getDrawContext();
Viewport viewport;
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = pixel_xres;
viewport.Height = pixel_yres;
viewport.MaxDepth = 1.0;
viewport.MinDepth = 0.0;
draw->SetViewports(1, &viewport);
return;
}
if (invalid_) {
// Loading, or after shutdown?
if (loadingTextView_->GetVisibility() == UI::V_VISIBLE)

View File

@ -43,6 +43,7 @@
#include "Core/MIPS/JitCommon/JitCommon.h"
#include "Core/HLE/sceUtility.h"
#include "GPU/GPUState.h"
#include "GPU/GPUInterface.h"
#include "GPU/Common/PostShader.h"
#include "UI/ControlMappingScreen.h"
@ -355,7 +356,33 @@ void DrawBackground(UIContext &dc, float alpha, float x, float y, float z) {
}
}
void DrawGameBackground(UIContext &dc, const Path &gamePath, float x, float y, float z) {
void DrawGameBackground(UIContext &dc, const Path &gamePath, float x, float y, float z, bool darkenGame) {
using namespace Draw;
using namespace UI;
if (PSP_IsInited() && !g_Config.bSkipBufferEffects) {
gpu->CheckDisplayResized();
gpu->CopyDisplayToOutput(true);
DrawContext *draw = dc.GetDrawContext();
Viewport viewport;
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = pixel_xres;
viewport.Height = pixel_yres;
viewport.MaxDepth = 1.0;
viewport.MinDepth = 0.0;
draw->SetViewports(1, &viewport);
dc.BeginFrame();
dc.RebindTexture();
dc.Begin();
uint32_t color = colorAlpha(colorBlend(dc.GetTheme().backgroundColor, 0, 0.5f), 0.45f);
dc.FillRect(UI::Drawable(color), dc.GetBounds());
dc.Flush();
return;
}
std::shared_ptr<GameInfo> ginfo;
if (!gamePath.empty())
ginfo = g_gameInfoCache->GetInfo(dc.GetDrawContext(), gamePath, GAMEINFO_WANTBG);
@ -427,7 +454,7 @@ void UIScreenWithGameBackground::DrawBackground(UIContext &dc) {
float x, y, z;
screenManager()->getFocusPosition(x, y, z);
if (!gamePath_.empty()) {
DrawGameBackground(dc, gamePath_, x, y, z);
DrawGameBackground(dc, gamePath_, x, y, z, darkenGameBackground_);
} else {
::DrawBackground(dc, 1.0f, x, y, z);
dc.Flush();
@ -443,9 +470,11 @@ void UIScreenWithGameBackground::sendMessage(const char *message, const char *va
}
void UIDialogScreenWithGameBackground::DrawBackground(UIContext &dc) {
using namespace UI;
using namespace Draw;
float x, y, z;
screenManager()->getFocusPosition(x, y, z);
DrawGameBackground(dc, gamePath_, x, y, z);
DrawGameBackground(dc, gamePath_, x, y, z, true);
}
void UIDialogScreenWithGameBackground::sendMessage(const char *message, const char *value) {

View File

@ -51,6 +51,8 @@ public:
void sendMessage(const char *message, const char *value) override;
protected:
Path gamePath_;
bool darkenGameBackground_ = false;
};
class UIDialogScreenWithBackground : public UIDialogScreen {

View File

@ -256,24 +256,6 @@ GamePauseScreen::~GamePauseScreen() {
__DisplaySetWasPaused();
}
bool GamePauseScreen::isTransparent() const {
// We don't support transparent pause screen in skipbuffereffects mode.
return !g_Config.bSkipBufferEffects && !IsVREnabled();
}
void GamePauseScreen::DrawBackground(UIContext &dc) {
if (isTransparent()) {
// Darken the game screen coming from below, so the UI on top stands out.
dc.Flush();
uint32_t color = blackAlpha(0.45f);
dc.FillRect(UI::Drawable(color), dc.GetBounds());
dc.Flush();
return;
}
UIDialogScreenWithGameBackground::DrawBackground(dc);
}
void GamePauseScreen::CreateViews() {
static const int NUM_SAVESLOTS = 5;

View File

@ -44,9 +44,6 @@ protected:
void update() override;
void CallbackDeleteConfig(bool yes);
bool isTransparent() const override;
void DrawBackground(UIContext &dc) override;
private:
UI::EventReturn OnGameSettings(UI::EventParams &e);
UI::EventReturn OnExitToMenu(UI::EventParams &e);