Merge pull request #21654 from hrydgard/misc-fixes

Misc fixes
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2026-05-11 10:04:13 +02:00
commit d9b952e684
16 files changed
+154 -103

No files matched your search

+28 -22
View File
@@ -123,6 +123,7 @@ PathBrowser::~PathBrowser() {
}
void PathBrowser::SetPath(const Path &path) {
std::lock_guard<std::mutex> guard(pendingLock_);
path_ = path;
ApplyRestriction();
HandlePath();
@@ -130,18 +131,20 @@ void PathBrowser::SetPath(const Path &path) {
void PathBrowser::RestrictToRoot(const Path &root) {
VERBOSE_LOG(Log::IO, "Restricting to root: %s", root.c_str());
std::lock_guard<std::mutex> guard(pendingLock_);
restrictedRoot_ = root;
}
void PathBrowser::HandlePath() {
if (!path_.empty() && path_.ToString()[0] == '!') {
if (pendingActive_)
ResetPending();
if (pendingActive_) {
pendingCancel_ = true;
pendingPath_.clear();
}
ready_ = true;
return;
}
std::lock_guard<std::mutex> guard(pendingLock_);
ready_ = false;
pendingActive_ = true;
pendingCancel_ = false;
@@ -169,21 +172,24 @@ void PathBrowser::HandlePath() {
}
lastPath = pendingPath_;
if (lastPath.Type() == PathType::HTTP) {
std::string userAgentCopy = userAgent_;
guard.unlock();
results.clear();
success_ = LoadRemoteFileList(lastPath, userAgent_, &pendingCancel_, results);
bool tempSuccess = LoadRemoteFileList(lastPath, userAgentCopy, &pendingCancel_, results);
guard.lock();
success_ = tempSuccess;
} else if (lastPath.empty()) {
results.clear();
success_ = true;
} else {
guard.unlock();
results.clear();
success_ = File::GetFilesInDir(lastPath, &results, nullptr);
bool tempSuccess = File::GetFilesInDir(lastPath, &results, nullptr);
guard.lock();
success_ = tempSuccess;
if (!success_) {
WARN_LOG(Log::IO, "PathBrowser: Failed to list directory: %s", lastPath.c_str());
}
guard.lock();
}
if (pendingPath_ == lastPath) {
@@ -198,15 +204,9 @@ void PathBrowser::HandlePath() {
});
}
void PathBrowser::ResetPending() {
std::lock_guard<std::mutex> guard(pendingLock_);
pendingCancel_ = true;
pendingPath_.clear();
}
bool PathBrowser::GetListing(std::vector<File::FileInfo> &fileInfo, const char *extensionFilter, bool *cancel) {
std::unique_lock<std::mutex> guard(pendingLock_);
while (!IsListingReady() && (!cancel || !*cancel)) {
while (!ready_ && (!cancel || !*cancel)) {
// In case cancel changes, just sleep. TODO: Replace with condition variable.
guard.unlock();
sleep_ms(50, "pathbrowser-poll");
@@ -224,7 +224,8 @@ void PathBrowser::ApplyRestriction() {
}
}
bool PathBrowser::CanNavigateUp() {
bool PathBrowser::CanNavigateUp() const {
std::unique_lock<std::mutex> guard(pendingLock_);
if (path_ == restrictedRoot_) {
return false;
}
@@ -233,21 +234,26 @@ bool PathBrowser::CanNavigateUp() {
void PathBrowser::NavigateUp() {
_dbg_assert_(CanNavigateUp());
std::unique_lock<std::mutex> guard(pendingLock_);
path_ = path_.NavigateUp();
ApplyRestriction();
}
// TODO: Support paths like "../../hello"
void PathBrowser::Navigate(std::string_view path) {
if (path == ".")
std::unique_lock<std::mutex> guard(pendingLock_);
if (path == ".") {
// Same directory, nothing to do.
return;
if (path == "..") {
NavigateUp();
} else {
if (path.size() >= 2 && path[1] == ':' && path_.IsRoot())
path_ = Path(path);
else
path_ = path_ / path;
}
if (path == "..") {
path_ = path_.NavigateUp();
} else if (path.size() >= 2 && path[1] == ':' && path_.IsRoot()) {
path_ = Path(path);
} else {
path_ = path_ / path;
}
ApplyRestriction();
HandlePath();
}
+9 -6
View File
@@ -11,9 +11,9 @@
#include "Common/File/DirListing.h"
#include "Common/File/Path.h"
// Abstraction above path that lets you navigate easily.
// Abstraction above path that lets you navigate easily and get listings off-thread.
// "/" is a special path that means the root of the file system. On Windows,
// listing this will yield drives.
// listing "/" will yield drives.
class PathBrowser {
public:
PathBrowser() {}
@@ -24,11 +24,14 @@ public:
HandlePath();
}
bool IsListingReady() const {
std::lock_guard<std::mutex> guard(pendingLock_);
return ready_;
}
// If called before IsListingReady() returns true, will block (becomes synchronous). Don't do that.
bool GetListing(std::vector<File::FileInfo> &fileInfo, const char *filter = nullptr, bool *cancel = nullptr);
bool CanNavigateUp();
bool CanNavigateUp() const;
void NavigateUp();
void Navigate(std::string_view subdir);
@@ -38,6 +41,7 @@ public:
}
void SetUserAgent(std::string_view s) {
std::lock_guard<std::mutex> guard(pendingLock_);
userAgent_ = s;
}
void RestrictToRoot(const Path &root);
@@ -45,12 +49,12 @@ public:
return path_.empty();
}
bool Success() const {
std::lock_guard<std::mutex> guard(pendingLock_);
return success_;
}
private:
void HandlePath();
void ResetPending();
void ApplyRestriction();
Path path_;
@@ -59,7 +63,7 @@ private:
std::string userAgent_;
std::vector<File::FileInfo> pendingFiles_;
std::condition_variable pendingCond_;
std::mutex pendingLock_;
mutable std::mutex pendingLock_;
std::thread pendingThread_;
bool pendingActive_ = false;
bool pendingCancel_ = false;
@@ -67,4 +71,3 @@ private:
bool ready_ = false;
bool success_ = true;
};
+2 -2
View File
@@ -48,7 +48,7 @@ TouchInput GestureDetector::Update(const TouchInput &touch, const Bounds &bounds
const float dragThreshold = 5.0f / g_display.dpi_scale_y;
if (p.distanceY > p.distanceX) {
if ((gestureMask_ & GESTURE_DRAG_VERTICAL) && p.distanceY > p.distanceX) {
if (p.down) {
double timeDown = time_now_d() - p.downTime;
if (!p.active && p.distanceY > dragThreshold) {
@@ -63,7 +63,7 @@ TouchInput GestureDetector::Update(const TouchInput &touch, const Bounds &bounds
}
}
if (p.distanceX > p.distanceY) {
if ((gestureMask_ & GESTURE_DRAG_HORIZONTAL) && p.distanceX > p.distanceY) {
if (p.down) {
double timeDown = time_now_d() - p.downTime;
if (!p.active && p.distanceX > dragThreshold) {
+4
View File
@@ -13,6 +13,7 @@ enum Gesture {
GESTURE_DRAG_HORIZONTAL = 2,
GESTURE_TWO_FINGER_ZOOM = 4,
GESTURE_TWO_FINGER_ZOOM_ROTATE = 8,
GESTURE_ALL = 15,
};
// May track multiple gestures at the same time. You simply call GetGestureInfo
@@ -24,6 +25,7 @@ public:
void UpdateFrame();
bool IsGestureActive(Gesture gesture, int touchId) const;
bool GetGestureInfo(Gesture gesture, int touchId, float info[4]) const;
void SetGestureMask(Gesture gestureMask) { gestureMask_ = gestureMask; }
private:
enum Locals {
@@ -48,4 +50,6 @@ private:
};
Pointer pointers[MAX_PTRS]{};
Gesture gestureMask_ = GESTURE_ALL;
};
-1
View File
@@ -49,7 +49,6 @@ enum class LaunchUrlType {
EMAIL_ADDRESS,
LOCAL_FILE,
LOCAL_FOLDER, // Shows the folder. Not supported on all systems of course.
AUTO,
};
void System_Vibrate(int length_ms);
+9
View File
@@ -12,6 +12,15 @@ namespace UI {
float ScrollView::lastScrollPosX = 0;
float ScrollView::lastScrollPosY = 0;
ScrollView::ScrollView(Orientation orientation, LayoutParams *layoutParams)
: ViewGroup(layoutParams), orientation_(orientation) {
if (orientation == ORIENT_HORIZONTAL) {
gesture_.SetGestureMask(GESTURE_DRAG_HORIZONTAL);
} else {
gesture_.SetGestureMask(GESTURE_DRAG_VERTICAL);
}
}
ScrollView::~ScrollView() {
lastScrollPosX = 0;
lastScrollPosY = 0;
+1 -2
View File
@@ -8,8 +8,7 @@ namespace UI {
// A scrollview usually contains just a single child - a linear layout or similar.
class ScrollView : public ViewGroup {
public:
ScrollView(Orientation orientation, LayoutParams *layoutParams = 0)
: ViewGroup(layoutParams), orientation_(orientation) {}
ScrollView(Orientation orientation, LayoutParams *layoutParams = nullptr);
~ScrollView();
void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) override;
+43 -34
View File
@@ -145,11 +145,21 @@ bool TabHolder::SetCurrentTab(int tab, bool skipTween) {
return false;
}
bool created = false;
if (currentTab_ < 0 || currentTab_ >= (int)tabs_.size()) {
EnsureTab(tab);
_dbg_assert_(tabs_[tab]);
// No current tab, so just switch immediately.
currentTab_ = tab;
tabStrip_->SetSelection(tab, false);
if (tabs_[tab]) {
tabs_[tab]->SetVisibility(V_VISIBLE);
}
return true;
}
if (tab != currentTab_) {
_dbg_assert_(tabs_[currentTab_]); // we should always have a tab to switch *from*.
created = EnsureTab(tab);
if (tab == currentTab_) {
tabStrip_->SetSelection(tab, false);
return false;
}
auto setupTween = [this](View *view, AnchorTranslateTween *&tween) {
@@ -161,45 +171,44 @@ bool TabHolder::SetCurrentTab(int tab, bool skipTween) {
return;
}
tween = new AnchorTranslateTween(0.15f, bezierEaseInOut);
tween->Finish.Add([&](EventParams &e) {
tween->Finish.Add([this](EventParams &e) {
e.v->SetVisibility(tabs_[currentTab_] == e.v ? V_VISIBLE : V_GONE);
});
view->AddTween(tween)->Persist();
};
if (tab != currentTab_) {
Orientation orient = Opposite(orientation_);
// Direction from which the new tab will come.
float dir = tab < currentTab_ ? -1.0f : 1.0f;
bool created = EnsureTab(tab);
// First, setup any missing tweens.
setupTween(tabs_[currentTab_], tabTweens_[currentTab_]);
setupTween(tabs_[tab], tabTweens_[tab]);
Orientation orient = Opposite(orientation_);
// Direction from which the new tab will come.
float dir = tab < currentTab_ ? -1.0f : 1.0f;
// Currently displayed, so let's reset it.
if (skipTween) {
tabs_[currentTab_]->SetVisibility(V_GONE);
tabTweens_[tab]->Reset(Point2D(0.0f, 0.0f));
tabTweens_[tab]->Apply(tabs_[tab]);
// First, setup any missing tweens.
setupTween(tabs_[currentTab_], tabTweens_[currentTab_]);
setupTween(tabs_[tab], tabTweens_[tab]);
// Currently displayed, so let's reset it.
if (skipTween) {
tabs_[currentTab_]->SetVisibility(V_GONE);
tabTweens_[tab]->Reset(Point2D(0.0f, 0.0f));
tabTweens_[tab]->Apply(tabs_[tab]);
} else {
tabTweens_[currentTab_]->Reset(Point2D(0.0f, 0.0f));
if (orient == ORIENT_HORIZONTAL) {
tabTweens_[tab]->Reset(Point2D(bounds_.w * dir, 0.0f));
tabTweens_[currentTab_]->Divert(Point2D(bounds_.w * -dir, 0.0f));
} else {
tabTweens_[currentTab_]->Reset(Point2D(0.0f, 0.0f));
if (orient == ORIENT_HORIZONTAL) {
tabTweens_[tab]->Reset(Point2D(bounds_.w * dir, 0.0f));
tabTweens_[currentTab_]->Divert(Point2D(bounds_.w * -dir, 0.0f));
} else {
tabTweens_[tab]->Reset(Point2D(0.0f, bounds_.h * dir));
tabTweens_[currentTab_]->Divert(Point2D(0.0f, bounds_.h * -dir));
}
// Actually move it to the initial position now, just to avoid any flicker.
tabTweens_[tab]->Apply(tabs_[tab]);
tabTweens_[tab]->Divert(Point2D(0.0f, 0.0f));
tabTweens_[tab]->Reset(Point2D(0.0f, bounds_.h * dir));
tabTweens_[currentTab_]->Divert(Point2D(0.0f, bounds_.h * -dir));
}
tabs_[tab]->SetVisibility(V_VISIBLE);
currentTab_ = tab;
// Actually move it to the initial position now, just to avoid any flicker.
tabTweens_[tab]->Apply(tabs_[tab]);
tabTweens_[tab]->Divert(Point2D(0.0f, 0.0f));
}
tabStrip_->SetSelection(tab, false);
tabs_[tab]->SetVisibility(V_VISIBLE);
currentTab_ = tab;
return created;
}
@@ -208,7 +217,7 @@ void TabHolder::OnTabClick(EventParams &e) {
// We have e.b set when it was an explicit click action.
// In that case, we make the view gone and then visible - this scrolls scrollviews to the top.
if (e.b != 0) {
EnsureTab(e.a);
// SetCurrentTab calls EnsureTab if needed.
SetCurrentTab((int)e.a);
}
}
+1 -1
View File
@@ -66,7 +66,7 @@ private:
TabHolderFlags flags_ = TabHolderFlags::Default;
int currentTab_ = 0;
std::vector<ViewGroup *> tabs_;
std::vector<AnchorTranslateTween *> tabTweens_;
std::vector<AnchorTranslateTween *> tabTweens_; // NOTE: The tweens are actually owned by the tabs.
std::vector<std::function<ViewGroup *()>> createFuncs_;
};
+40 -21
View File
@@ -200,15 +200,19 @@ void BreakpointManager::ChangeBreakPoint(u32 addr, BreakAction result) {
}
}
void BreakpointManager::ClearAllBreakPoints()
{
// This is not actually called, currently.
void BreakpointManager::ClearAllBreakPoints() {
if (!anyBreakPoints_)
return;
std::unique_lock<std::mutex> guard(breakPointsMutex_);
if (!breakPoints_.empty())
{
if (!breakPoints_.empty()) {
// Same strategy as ClearTemporaryBreakPoints - if there's only one, we can update just that one.
if (breakPoints_.size() == 1) {
Update(breakPoints_[0].addr);
} else {
Update(0);
}
breakPoints_.clear();
Update();
}
}
@@ -216,15 +220,30 @@ void BreakpointManager::ClearTemporaryBreakPoints()
{
if (!anyBreakPoints_)
return;
std::unique_lock<std::mutex> guard(breakPointsMutex_);
for (int i = (int)breakPoints_.size()-1; i >= 0; --i)
{
if (breakPoints_[i].temporary)
{
breakPoints_.erase(breakPoints_.begin() + i);
Update();
std::vector<u32> addrsToUpdate;
for (auto it = breakPoints_.begin(); it != breakPoints_.end(); ) {
if (it->temporary) {
addrsToUpdate.push_back(it->addr);
it = breakPoints_.erase(it);
} else {
++it;
}
}
if (addrsToUpdate.size() == 1) {
// We can use the proper mechanism to update just one address.
// If there are any temp breakpoints, there's normally just one, so this is better
// than Update().
Update(addrsToUpdate[0]);
} else if (!addrsToUpdate.empty()) {
Update(0);
}
anyBreakPoints_ = !breakPoints_.empty();
}
void BreakpointManager::ChangeBreakPointAddCond(u32 addr, const BreakPointCond &cond)
@@ -316,7 +335,7 @@ int BreakpointManager::AddMemCheck(u32 start, u32 end, MemCheckCondition cond, B
if (!hadAny) {
MemBlockOverrideDetailed();
}
Update();
Update(0); // Memchecks are not per-address, so just update everything.
return (int)memChecks_.size() - 1;
} else {
memChecks_[mc].cond = (MemCheckCondition)(memChecks_[mc].cond | cond);
@@ -325,7 +344,7 @@ int BreakpointManager::AddMemCheck(u32 start, u32 end, MemCheckCondition cond, B
if (!hadAny) {
MemBlockOverrideDetailed();
}
Update();
Update(0);
return (int)mc;
}
}
@@ -341,7 +360,7 @@ void BreakpointManager::RemoveMemCheck(u32 start, u32 end)
bool hadAny = anyMemChecks_.exchange(!memChecks_.empty());
if (hadAny)
MemBlockReleaseDetailed();
Update();
Update(0);
}
}
@@ -353,7 +372,7 @@ void BreakpointManager::ChangeMemCheck(u32 start, u32 end, MemCheckCondition con
{
memChecks_[mc].cond = cond;
memChecks_[mc].result = result;
Update();
Update(0);
}
}
@@ -367,7 +386,7 @@ void BreakpointManager::ClearAllMemChecks()
bool hadAny = anyMemChecks_.exchange(false);
if (hadAny)
MemBlockReleaseDetailed();
Update();
Update(0);
}
}
@@ -379,7 +398,7 @@ void BreakpointManager::ChangeMemCheckAddCond(u32 start, u32 end, const BreakPoi
memChecks_[mc].hasCondition = true;
memChecks_[mc].condition = cond;
// No need to update jit for a condition add/remove, they're not baked in.
Update(-1);
Update(INVALID_ADDRESS);
}
}
@@ -389,7 +408,7 @@ void BreakpointManager::ChangeMemCheckRemoveCond(u32 start, u32 end) {
if (mc != INVALID_MEMCHECK) {
memChecks_[mc].hasCondition = false;
// No need to update jit for a condition add/remove, they're not baked in.
Update(-1);
Update(INVALID_ADDRESS);
}
}
@@ -406,7 +425,7 @@ void BreakpointManager::ChangeMemCheckLogFormat(u32 start, u32 end, const std::s
size_t mc = FindMemCheck(start, end);
if (mc != INVALID_MEMCHECK) {
memChecks_[mc].logFormat = fmt;
Update();
Update(0); // wipe the jit.
}
}
@@ -596,7 +615,7 @@ void BreakpointManager::Frame() {
}
std::lock_guard<std::mutex> guard(breakPointsMutex_);
if (MIPSComp::jit && updateAddr_ != -1) {
if (MIPSComp::jit && updateAddr_ != INVALID_ADDRESS) {
// In case this is a delay slot, clear the previous instruction too.
if (updateAddr_ != 0)
mipsr4k.InvalidateICache(updateAddr_ - 4, 8);
@@ -604,7 +623,7 @@ void BreakpointManager::Frame() {
mipsr4k.ClearJitCache();
}
if (anyMemChecks_ && updateAddr_ != -1)
if (anyMemChecks_ && updateAddr_ != INVALID_ADDRESS)
UpdateCachedMemCheckRanges();
// Redraw in order to show the breakpoint.
+6 -1
View File
@@ -191,7 +191,8 @@ public:
private:
// Should be called under lock.
void Update(u32 addr = 0) {
// 0 means to clear the whole jit cache, to apply some change that has been made.
void Update(u32 addr) {
needsUpdate_ = true;
updateAddr_ = addr;
}
@@ -217,6 +218,10 @@ private:
bool needsUpdate_ = true;
u32 updateAddr_ = 0;
enum {
INVALID_ADDRESS = -1
};
};
extern BreakpointManager g_breakpoints;
+5 -2
View File
@@ -303,8 +303,11 @@ void GPUDriverTestScreen::CreateViews() {
tabHolder_ = new TabHolder(ORIENT_HORIZONTAL, 30.0f, TabHolderFlags::Default, nullptr, nullptr, new AnchorLayoutParams(FILL_PARENT, FILL_PARENT, Centering::None));
anchor->Add(tabHolder_);
tabHolder_->AddTab("Discard", ImageID::invalid(), new LinearLayout(ORIENT_VERTICAL));
tabHolder_->AddTab("Shader", ImageID::invalid(), new LinearLayout(ORIENT_VERTICAL));
tabHolder_->AddTabDeferred("Discard", ImageID::invalid(), []() { return new LinearLayout(ORIENT_VERTICAL); });
tabHolder_->AddTabDeferred("Shader", ImageID::invalid(), []() { return new LinearLayout(ORIENT_VERTICAL); });
tabHolder_->SetInitialTab(0);
tabHolder_->EnsureTab(0);
Choice *back = new Choice(di->T("Back"), ImageID("I_NAVIGATE_BACK"), new AnchorLayoutParams(190, WRAP_CONTENT, 10, NONE, NONE, 10));
back->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
+2 -1
View File
@@ -713,6 +713,7 @@ static bool IsValidPBP(const Path &path, bool allowHomebrew) {
return false;
std::unique_ptr<FileLoader> loader(ConstructFileLoader(path));
PBPReader pbp(loader.get());
std::vector<u8> sfoData;
if (!pbp.GetSubFile(PBP_PARAM_SFO, &sfoData))
@@ -861,7 +862,7 @@ void GameBrowser::Refresh() {
for (size_t i = 0; i < fileInfo.size(); i++) {
bool isGame = !fileInfo[i].isDirectory;
bool isSaveData = false;
// Check if eboot directory
// Check if eboot directory. TODO: Should ideally be done off-thread somehow.
if (!isGame && path_.GetPath().size() >= 4 && IsValidPBP(path_.GetPath() / fileInfo[i].name / "EBOOT.PBP", true))
isGame = true;
else if (!isGame && File::Exists(path_.GetPath() / fileInfo[i].name / "PSP_GAME/SYSDIR"))
+3 -7
View File
@@ -220,8 +220,6 @@ void MemStickScreen::CreateViews() {
leftColumn->Add(new RadioButton(&choice_, CHOICE_SET_MANUAL, ms->T("Manually specify PSP folder")))->OnClick.Handle(this, &MemStickScreen::OnChoiceClick);
// TODO: Show current folder here if we have one set.
}
errorNoticeView_ = leftColumn->Add(new NoticeView(NoticeLevel::WARN, ms->T("Cancelled - try again"), ""));
errorNoticeView_->SetVisibility(UI::V_GONE);
if (choice_ == CHOICE_BROWSE_FOLDER || choice_ == CHOICE_SET_MANUAL) {
UI::View *extraView = nullptr;
@@ -419,7 +417,7 @@ void MemStickScreen::UseStorageRoot(UI::EventParams &params) {
void MemStickScreen::Browse(UI::EventParams &params) {
auto mm = GetI18NCategory(I18NCat::MAINMENU);
System_BrowseForFolder(GetRequesterToken(), mm->T("Choose folder"), g_Config.memStickDirectory, [=](const std::string &value, int) {
System_BrowseForFolder(GetRequesterToken(), mm->T("Choose folder"), g_Config.memStickDirectory, [this](const std::string &value, int) {
Path pendingMemStickFolder = Path(value);
INFO_LOG(Log::System, "Got folder: '%s' (old: %s)", pendingMemStickFolder.c_str(), g_Config.memStickDirectory.c_str());
// Browse finished. Let's pop up the confirmation dialog.
@@ -430,11 +428,9 @@ void MemStickScreen::Browse(UI::EventParams &params) {
done_ = true;
return;
}
errorNoticeView_->SetVisibility(UI::V_GONE);
screenManager()->push(new ConfirmMemstickMoveScreen(pendingMemStickFolder, initialSetup_));
}, [=]() {
errorNoticeView_->SetVisibility(UI::V_VISIBLE);
}, [this]() {
WARN_LOG(Log::System, "Folder browse cancelled");
});
}
-2
View File
@@ -80,8 +80,6 @@ private:
void OnConfirmClick(UI::EventParams &params);
void OnChoiceClick(UI::EventParams &params);
NoticeView *errorNoticeView_ = nullptr;
bool initialSetup_;
bool storageBrowserWorking_;
bool done_ = false;
+1 -1
View File
@@ -1,4 +1,4 @@
plugins {
id("com.android.application") version "9.2.0" apply false
id("com.android.application") version "9.2.1" apply false
id("com.google.protobuf") version "0.10.0" apply false
}