Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run behind pause screen #18515

Merged
merged 4 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Common/UI/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ void ScreenManager::resized() {
}
}

void ScreenManager::render() {
ScreenRenderFlags ScreenManager::render() {
ScreenRenderFlags flags = ScreenRenderFlags::NONE;
if (!stack_.empty()) {
// Collect the screens to render
TinySet<Screen *, 6> layers;
Expand All @@ -167,18 +168,20 @@ void ScreenManager::render() {
auto iter = stack_.end();
Screen *coveringScreen = nullptr;
Screen *backgroundScreen = nullptr;
bool first = true;
do {
--iter;
if (!coveringScreen) {
layers.push_back(iter->screen);
} else if (!backgroundScreen && iter->screen->canBeBackground()) {
if (!backgroundScreen && iter->screen->canBeBackground(first)) {
// There still might be a screen that wants to be background - generally the EmuScreen if present.
layers.push_back(iter->screen);
backgroundScreen = iter->screen;
} else if (!coveringScreen) {
layers.push_back(iter->screen);
}
if (iter->flags != LAYER_TRANSPARENT) {
coveringScreen = iter->screen;
}
first = false;
} while (iter != stack_.begin());

// Confusing-looking expression, argh! Note the '_'
Expand All @@ -188,15 +191,11 @@ void ScreenManager::render() {
}

// OK, now we iterate backwards over our little pile of collected screens.
bool first = true;
for (int i = (int)layers.size() - 1; i >= 0; i--) {
ScreenRenderMode mode = ScreenRenderMode::DEFAULT;
if (i == (int)layers.size() - 1) {
// Bottom.
mode = ScreenRenderMode::FIRST;
if (layers[i] == backgroundScreen && coveringScreen != layers[i]) {
mode |= ScreenRenderMode::BACKGROUND;
}
if (i == 0) {
mode |= ScreenRenderMode::TOP;
}
Expand All @@ -205,12 +204,12 @@ void ScreenManager::render() {
} else {
mode = ScreenRenderMode::BEHIND;
}
layers[i]->render(mode);
flags |= layers[i]->render(mode);
}

if (overlayScreen_) {
// It doesn't care about mode.
overlayScreen_->render(ScreenRenderMode::TOP);
flags |= overlayScreen_->render(ScreenRenderMode::TOP);
}

getUIContext()->Flush();
Expand All @@ -224,6 +223,7 @@ void ScreenManager::render() {
}

processFinishDialog();
return flags;
}

void ScreenManager::getFocusPosition(float &x, float &y, float &z) {
Expand Down
13 changes: 9 additions & 4 deletions Common/UI/Screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ enum class ScreenFocusChange {
enum class ScreenRenderMode {
DEFAULT = 0,
FIRST = 1,
BACKGROUND = 2,
BEHIND = 4,
TOP = 8,
};
ENUM_CLASS_BITOPS(ScreenRenderMode);

enum class ScreenRenderFlags {
NONE = 0,
HANDLED_THROTTLING = 1,
};
ENUM_CLASS_BITOPS(ScreenRenderFlags);

class Screen {
public:
Screen() : screenManager_(nullptr) { }
Expand All @@ -65,13 +70,13 @@ class Screen {

virtual void onFinish(DialogResult reason) {}
virtual void update() {}
virtual void render(ScreenRenderMode mode) {}
virtual ScreenRenderFlags render(ScreenRenderMode mode) = 0;
virtual void resized() {}
virtual void dialogFinished(const Screen *dialog, DialogResult result) {}
virtual void sendMessage(UIMessage message, const char *value) {}
virtual void deviceLost() {}
virtual void deviceRestored() {}
virtual bool canBeBackground() const { return false; }
virtual bool canBeBackground(bool isTop) const { return false; }
virtual bool wantBrightBackground() const { return false; } // special hack for DisplayLayoutScreen.

virtual void focusChanged(ScreenFocusChange focusChange);
Expand Down Expand Up @@ -128,7 +133,7 @@ class ScreenManager {
postRenderUserdata_ = userdata;
}

void render();
ScreenRenderFlags render();
void resized();
void shutdown();

Expand Down
23 changes: 14 additions & 9 deletions Common/UI/UIScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,27 +212,32 @@ void UIScreen::SetupViewport() {
draw->SetTargetSize(g_display.pixel_xres, g_display.pixel_yres);
}

void UIScreen::render(ScreenRenderMode mode) {
ScreenRenderFlags UIScreen::render(ScreenRenderMode mode) {
if (mode & ScreenRenderMode::FIRST) {
SetupViewport();
}

DoRecreateViews();

UIContext &uiContext = *screenManager()->getUIContext();
if (root_) {
UIContext &uiContext = *screenManager()->getUIContext();

UI::LayoutViewHierarchy(uiContext, root_, ignoreInsets_);
}

uiContext.PushTransform({translation_, scale_, alpha_});
uiContext.PushTransform({translation_, scale_, alpha_});

uiContext.Begin();
DrawBackground(uiContext);
uiContext.Begin();
DrawBackground(uiContext);
if (root_) {
root_->Draw(uiContext);
uiContext.Flush();

uiContext.PopTransform();
}
uiContext.Flush();
DrawForeground(uiContext);
uiContext.Flush();

uiContext.PopTransform();

return ScreenRenderFlags::NONE;
}

TouchInput UIScreen::transformTouch(const TouchInput &touch) {
Expand Down
4 changes: 3 additions & 1 deletion Common/UI/UIScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class UIScreen : public Screen {
~UIScreen();

void update() override;
void render(ScreenRenderMode mode) override;
ScreenRenderFlags render(ScreenRenderMode mode) override;
void deviceLost() override;
void deviceRestored() override;

Expand Down Expand Up @@ -72,6 +72,8 @@ class UIScreen : public Screen {

protected:
virtual void DrawBackground(UIContext &ui) {}
virtual void DrawForeground(UIContext &ui) {}

void SetupViewport();
void DoRecreateViews();

Expand Down
12 changes: 12 additions & 0 deletions Common/UI/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,18 @@ class Spacer : public InertView {
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override {
w = size_; h = size_;
}

void GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const override {
if (horiz.type == AT_MOST || horiz.type == EXACTLY)
w = horiz.size;
else
w = size_;
if (vert.type == AT_MOST || vert.type == EXACTLY)
h = vert.size;
else
h = size_;
}

void Draw(UIContext &dc) override {}
std::string DescribeText() const override { return ""; }

Expand Down
10 changes: 9 additions & 1 deletion Common/UI/ViewGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace UI {

static constexpr Size ITEM_HEIGHT = 64.f;

void ApplyGravity(const Bounds outer, const Margins &margins, float w, float h, int gravity, Bounds &inner) {
void ApplyGravity(const Bounds &outer, const Margins &margins, float w, float h, int gravity, Bounds &inner) {
inner.w = w;
inner.h = h;

Expand Down Expand Up @@ -495,6 +495,10 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
if (views_.empty())
return;

if (tag_ == "debug") {
tag_ = "debug";
hrydgard marked this conversation as resolved.
Show resolved Hide resolved
}

float sum = 0.0f;
float maxOther = 0.0f;
float totalWeight = 0.0f;
Expand Down Expand Up @@ -666,6 +670,10 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
void LinearLayout::Layout() {
const Bounds &bounds = bounds_;

if (tag_ == "debug") {
tag_ = "debug";
}

Bounds itemBounds;
float pos;

Expand Down
2 changes: 2 additions & 0 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ static const ConfigSetting generalSettings[] = {
ConfigSetting("EnablePlugins", &g_Config.bLoadPlugins, true, CfgFlag::PER_GAME),

ConfigSetting("IgnoreCompatSettings", &g_Config.sIgnoreCompatSettings, "", CfgFlag::PER_GAME | CfgFlag::REPORT),

ConfigSetting("RunBehindPauseMenu", &g_Config.bRunBehindPauseMenu, false, CfgFlag::DEFAULT),
};

static bool DefaultSasThread() {
Expand Down
3 changes: 2 additions & 1 deletion Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ struct Config {

// Not used on mobile devices.
bool bPauseExitsEmulator;

bool bPauseMenuExitsEmulator;

bool bRunBehindPauseMenu;

// Core
bool bIgnoreBadMemAccess;

Expand Down
6 changes: 5 additions & 1 deletion GPU/Common/FramebufferManagerCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,14 @@ void FramebufferManagerCommon::CheckPostShaders() {

void FramebufferManagerCommon::BeginFrame() {
DecimateFBOs();

presentation_->BeginFrame();
currentRenderVfb_ = nullptr;
}

bool FramebufferManagerCommon::PresentedThisFrame() const {
return presentation_->PresentedThisFrame();
}

void FramebufferManagerCommon::SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat format) {
displayFramebufPtr_ = framebuf & 0x3FFFFFFF;
if (Memory::IsVRAMAddress(displayFramebufPtr_))
Expand Down
2 changes: 2 additions & 0 deletions GPU/Common/FramebufferManagerCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ class FramebufferManagerCommon {
currentFramebufferCopy_ = nullptr;
}

bool PresentedThisFrame() const;

protected:
virtual void ReadbackFramebuffer(VirtualFramebuffer *vfb, int x, int y, int w, int h, RasterChannel channel, Draw::ReadbackMode mode);
// Used for when a shader is required, such as GLES.
Expand Down
1 change: 1 addition & 0 deletions GPU/Common/PresentationCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,7 @@ void PresentationCommon::CopyToOutput(OutputFlags flags, int uvRotation, float u
draw_->Invalidate(InvalidationFlags::CACHED_RENDER_STATE);

previousUniforms_ = uniforms;
presentedThisFrame_ = true;
}

void PresentationCommon::CalculateRenderResolution(int *width, int *height, int *scaleFactor, bool *upscaling, bool *ssaa) const {
Expand Down
8 changes: 8 additions & 0 deletions GPU/Common/PresentationCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ class PresentationCommon {

bool UpdatePostShader();

void BeginFrame() {
presentedThisFrame_ = false;
}
bool PresentedThisFrame() const {
return presentedThisFrame_;
}

void DeviceLost();
void DeviceRestore(Draw::DrawContext *draw);

Expand Down Expand Up @@ -159,6 +166,7 @@ class PresentationCommon {

bool usePostShader_ = false;
bool restorePostShader_ = false;
bool presentedThisFrame_ = false;
ShaderLanguage lang_;

struct PrevFBO {
Expand Down
4 changes: 4 additions & 0 deletions GPU/GPUCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,10 @@ void GPUCommon::BeginFrame() {
GPURecord::NotifyBeginFrame();
}

bool GPUCommon::PresentedThisFrame() const {
return framebufferManager_ ? framebufferManager_->PresentedThisFrame() : true;
}

void GPUCommon::SlowRunLoop(DisplayList &list) {
const bool dumpThisFrame = dumpThisFrame_;
while (downcount > 0) {
Expand Down
2 changes: 2 additions & 0 deletions GPU/GPUCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ class GPUCommon : public GPUInterface, public GPUDebugInterface {
fullInfo = reportingFullInfo_;
}

bool PresentedThisFrame() const override;

protected:
void ClearCacheNextFrame() override {}

Expand Down
1 change: 0 additions & 1 deletion GPU/GPUCommonHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,6 @@ void GPUCommonHW::UpdateCmdInfo() {

void GPUCommonHW::BeginFrame() {
GPUCommon::BeginFrame();

if (drawEngineCommon_->EverUsedExactEqualDepth() && !sawExactEqualDepth_) {
sawExactEqualDepth_ = true;
gstate_c.SetUseFlags(CheckGPUFeatures());
Expand Down
1 change: 1 addition & 0 deletions GPU/GPUInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ class GPUInterface {
virtual bool FramebufferDirty() = 0;
virtual bool FramebufferReallyDirty() = 0;
virtual bool BusyDrawing() = 0;
virtual bool PresentedThisFrame() const = 0;

// If any jit is being used inside the GPU.
virtual bool DescribeCodePtr(const u8 *ptr, std::string &name) = 0;
Expand Down
4 changes: 0 additions & 4 deletions UI/BackgroundAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,6 @@ void BackgroundAudio::SetGame(const Path &path) {
}

bool BackgroundAudio::Play() {
if (GetUIState() == UISTATE_INGAME) {
return false;
}

std::lock_guard<std::mutex> lock(mutex_);

// Immediately stop the sound if it is turned off while playing.
Expand Down
Loading