Merge pull request #18408 from hrydgard/ui-refactoring-1

UI: Remove unnecessary mutexes, assorted cleanup
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2023-11-11 12:08:39 +01:00
commit 3287c268ff
9 files changed
+41 -87

No files matched your search

-1
View File
@@ -129,7 +129,6 @@ bool VulkanQueueRunner::CreateSwapchain(VkCommandBuffer cmdInit) {
return true;
}
bool VulkanQueueRunner::InitBackbufferFramebuffers(int width, int height) {
VkResult res;
// We share the same depth buffer but have multiple color buffers, see the loop below.
-8
View File
@@ -56,18 +56,10 @@ ENUM_CLASS_BITOPS(PipelineFlags);
struct VkRenderData {
VKRRenderCommand cmd;
union {
struct {
VkPipeline pipeline;
VKRPipelineLayout *pipelineLayout;
} pipeline;
struct {
VKRGraphicsPipeline *pipeline;
VKRPipelineLayout *pipelineLayout;
} graphics_pipeline;
struct {
VKRComputePipeline *pipeline;
VKRPipelineLayout *pipelineLayout;
} compute_pipeline;
struct {
uint32_t descSetIndex;
int numUboOffsets;
+5 -27
View File
@@ -1,5 +1,3 @@
#include <atomic>
#include <mutex>
#include <deque>
#include "ppsspp_config.h"
@@ -12,14 +10,12 @@
namespace UI {
static std::mutex focusLock;
static std::vector<int> focusMoves;
extern bool focusForced;
static View *focusedView;
static bool focusMovementEnabled;
bool focusForced;
static std::mutex eventMutex_;
static std::function<void(UISound, float)> soundCallback;
static bool soundEnabled = true;
@@ -29,29 +25,20 @@ struct DispatchQueueItem {
EventParams params;
};
std::atomic<bool> hasDispatchQueue;
std::deque<DispatchQueueItem> g_dispatchQueue;
void EventTriggered(Event *e, EventParams params) {
DispatchQueueItem item{ e, params };
std::unique_lock<std::mutex> guard(eventMutex_);
// Set before adding so we lock and check the added value.
hasDispatchQueue = true;
g_dispatchQueue.push_front(item);
}
void DispatchEvents() {
while (hasDispatchQueue) {
while (!g_dispatchQueue.empty()) {
DispatchQueueItem item;
{
std::unique_lock<std::mutex> guard(eventMutex_);
if (g_dispatchQueue.empty())
break;
item = g_dispatchQueue.back();
g_dispatchQueue.pop_back();
hasDispatchQueue = !g_dispatchQueue.empty();
}
if (g_dispatchQueue.empty())
break;
item = g_dispatchQueue.back();
g_dispatchQueue.pop_back();
if (item.e) {
item.e->Dispatch(item.params);
}
@@ -59,9 +46,6 @@ void DispatchEvents() {
}
void RemoveQueuedEventsByView(View *view) {
if (!hasDispatchQueue)
return;
std::unique_lock<std::mutex> guard(eventMutex_);
for (auto it = g_dispatchQueue.begin(); it != g_dispatchQueue.end(); ) {
if (it->params.v == view) {
it = g_dispatchQueue.erase(it);
@@ -72,9 +56,6 @@ void RemoveQueuedEventsByView(View *view) {
}
void RemoveQueuedEventsByEvent(Event *event) {
if (!hasDispatchQueue)
return;
std::unique_lock<std::mutex> guard(eventMutex_);
for (auto it = g_dispatchQueue.begin(); it != g_dispatchQueue.end(); ) {
if (it->e == event) {
it = g_dispatchQueue.erase(it);
@@ -214,7 +195,6 @@ static KeyEventResult KeyEventToFocusMoves(const KeyInput &key) {
hk.deviceId = key.deviceId;
hk.triggerTime = time_now_d() + repeatDelay;
std::lock_guard<std::mutex> lock(focusLock);
// Check if the key is already held. If it is, ignore it. This is to avoid
// multiple key repeat mechanisms colliding.
if (heldKeys.find(hk) != heldKeys.end()) {
@@ -381,7 +361,6 @@ restart:
key.flags = KEY_DOWN;
KeyEvent(key, root);
std::lock_guard<std::mutex> lock(focusLock);
focusMoves.push_back(key.keyCode);
// Cannot modify the current item when looping over a set, so let's do this instead.
@@ -404,7 +383,6 @@ void UpdateViewHierarchy(ViewGroup *root) {
}
if (focusMoves.size()) {
std::lock_guard<std::mutex> lock(focusLock);
EnableFocusMovement(true);
if (!GetFocusedView()) {
// Find a view to focus.
+26 -38
View File
@@ -47,12 +47,12 @@ ViewGroup::~ViewGroup() {
Clear();
}
void ViewGroup::RemoveSubview(View *view) {
std::lock_guard<std::mutex> guard(modifyLock_);
void ViewGroup::RemoveSubview(View *subView) {
// loop counter needed, so can't convert loop.
for (size_t i = 0; i < views_.size(); i++) {
if (views_[i] == view) {
if (views_[i] == subView) {
views_.erase(views_.begin() + i);
delete view;
delete subView;
return;
}
}
@@ -67,17 +67,13 @@ bool ViewGroup::ContainsSubview(const View *view) const {
}
void ViewGroup::Clear() {
std::lock_guard<std::mutex> guard(modifyLock_);
for (size_t i = 0; i < views_.size(); i++) {
delete views_[i];
views_[i] = nullptr;
for (View *view : views_) {
delete view;
}
views_.clear();
}
void ViewGroup::PersistData(PersistStatus status, std::string anonId, PersistMap &storage) {
std::lock_guard<std::mutex> guard(modifyLock_);
std::string tag = Tag();
if (tag.empty()) {
tag = anonId;
@@ -89,12 +85,11 @@ void ViewGroup::PersistData(PersistStatus status, std::string anonId, PersistMap
}
bool ViewGroup::Touch(const TouchInput &input) {
std::lock_guard<std::mutex> guard(modifyLock_);
bool any = false;
for (auto iter = views_.begin(); iter != views_.end(); ++iter) {
for (View *view : views_) {
// TODO: If there is a transformation active, transform input coordinates accordingly.
if ((*iter)->GetVisibility() == V_VISIBLE) {
bool touch = (*iter)->Touch(input);
if (view->GetVisibility() == V_VISIBLE) {
bool touch = view->Touch(input);
any = any || touch;
if (exclusiveTouch_ && touch && (input.flags & TOUCH_DOWN)) {
break;
@@ -111,43 +106,39 @@ bool ViewGroup::Touch(const TouchInput &input) {
void ViewGroup::Query(float x, float y, std::vector<View *> &list) {
if (bounds_.Contains(x, y)) {
list.push_back(this);
for (auto iter = views_.begin(); iter != views_.end(); ++iter) {
(*iter)->Query(x, y, list);
for (View *view : views_) {
view->Query(x, y, list);
}
}
}
bool ViewGroup::Key(const KeyInput &input) {
std::lock_guard<std::mutex> guard(modifyLock_);
bool ret = false;
for (auto iter = views_.begin(); iter != views_.end(); ++iter) {
for (View *view : views_) {
// TODO: If there is a transformation active, transform input coordinates accordingly.
if ((*iter)->GetVisibility() == V_VISIBLE)
ret = ret || (*iter)->Key(input);
if (view->GetVisibility() == V_VISIBLE)
ret = ret || view->Key(input);
}
return ret;
}
void ViewGroup::Axis(const AxisInput &input) {
std::lock_guard<std::mutex> guard(modifyLock_);
for (auto iter = views_.begin(); iter != views_.end(); ++iter) {
for (View *view : views_) {
// TODO: If there is a transformation active, transform input coordinates accordingly.
if ((*iter)->GetVisibility() == V_VISIBLE)
(*iter)->Axis(input);
if (view->GetVisibility() == V_VISIBLE)
view->Axis(input);
}
}
void ViewGroup::DeviceLost() {
std::lock_guard<std::mutex> guard(modifyLock_);
for (auto iter = views_.begin(); iter != views_.end(); ++iter) {
(*iter)->DeviceLost();
for (View *view : views_) {
view->DeviceLost();
}
}
void ViewGroup::DeviceRestored(Draw::DrawContext *draw) {
std::lock_guard<std::mutex> guard(modifyLock_);
for (auto iter = views_.begin(); iter != views_.end(); ++iter) {
(*iter)->DeviceRestored(draw);
for (View *view : views_) {
view->DeviceRestored(draw);
}
}
@@ -245,21 +236,18 @@ void ViewGroup::Update() {
}
bool ViewGroup::SetFocus() {
std::lock_guard<std::mutex> guard(modifyLock_);
if (!CanBeFocused() && !views_.empty()) {
for (size_t i = 0; i < views_.size(); i++) {
if (views_[i]->SetFocus())
for (View *view : views_) {
if (view->SetFocus())
return true;
}
}
return false;
}
bool ViewGroup::SubviewFocused(View *view) {
for (size_t i = 0; i < views_.size(); i++) {
if (views_[i] == view)
return true;
if (views_[i]->SubviewFocused(view))
bool ViewGroup::SubviewFocused(View *queryView) {
for (View *view : views_) {
if (view == queryView || view->SubviewFocused(queryView))
return true;
}
return false;
-5
View File
@@ -45,7 +45,6 @@ public:
// Takes ownership! DO NOT add a view to multiple parents!
template <class T>
T *Add(T *view) {
std::lock_guard<std::mutex> guard(modifyLock_);
views_.push_back(view);
return view;
}
@@ -76,9 +75,6 @@ public:
void SetExclusiveTouch(bool exclusive) { exclusiveTouch_ = exclusive; }
void SetClickableBackground(bool clickableBackground) { clickableBackground_ = clickableBackground; }
void Lock() { modifyLock_.lock(); }
void Unlock() { modifyLock_.unlock(); }
void SetClip(bool clip) { clip_ = clip; }
std::string DescribeLog() const override { return "ViewGroup: " + View::DescribeLog(); }
std::string DescribeText() const override;
@@ -87,7 +83,6 @@ protected:
std::string DescribeListUnordered(const char *heading) const;
std::string DescribeListOrdered(const char *heading) const;
std::mutex modifyLock_; // Hold this when changing the subviews.
std::vector<View *> views_;
View *defaultFocusView_ = nullptr;
Drawable bg_;
-1
View File
@@ -177,7 +177,6 @@ public:
private:
void Invalidate(InvalidationCallbackFlags flags);
struct FrameData;
void ApplyDrawStateLate(VulkanRenderManager *renderManager, bool applyStencilRef, uint8_t stencilRef, bool useBlendConstant);
void ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManager, ShaderManagerVulkan *shaderManager, int prim, VulkanPipelineRasterStateKey &key, VulkanDynamicState &dynState);
void BindShaderBlendTex();
+6 -1
View File
@@ -580,7 +580,7 @@ bool EmuScreen::UnsyncTouch(const TouchInput &touch) {
}
if (root_) {
root_->Touch(touch);
UIScreen::UnsyncTouch(touch);
}
return true;
}
@@ -870,6 +870,11 @@ bool EmuScreen::key(const KeyInput &key) {
void EmuScreen::UnsyncAxis(const AxisInput *axes, size_t count) {
System_Notify(SystemNotification::ACTIVITY);
if (UI::IsFocusMovementEnabled()) {
return UIScreen::UnsyncAxis(axes, count);
}
return controlMapper_.Axis(axes, count);
}
+3 -6
View File
@@ -16,8 +16,6 @@
#include "Core/KeyMap.h"
#include "Core/HLE/sceCtrl.h"
static double newVibrationTime = 0.0;
// Utilities to dynamically load XInput. Adapted from SDL.
#if !PPSSPP_PLATFORM(UWP)
@@ -258,11 +256,11 @@ void XinputDevice::ApplyButtons(int pad, const XINPUT_STATE &state) {
void XinputDevice::ApplyVibration(int pad, XINPUT_VIBRATION &vibration) {
if (PSP_IsInited()) {
newVibrationTime = time_now_d();
newVibrationTime_ = time_now_d();
// We have to run PPSSPP_XInputSetState at time intervals
// since it bugs otherwise with very high fast-forward speeds
// and freezes at constant vibration or no vibration at all.
if (newVibrationTime - prevVibrationTime >= 1.0 / 64.0) {
if (newVibrationTime_ - prevVibrationTime >= 1.0 / 64.0) {
if (GetUIState() == UISTATE_INGAME) {
vibration.wLeftMotorSpeed = sceCtrlGetLeftVibration(); // use any value between 0-65535 here
vibration.wRightMotorSpeed = sceCtrlGetRightVibration(); // use any value between 0-65535 here
@@ -275,7 +273,7 @@ void XinputDevice::ApplyVibration(int pad, XINPUT_VIBRATION &vibration) {
PPSSPP_XInputSetState(pad, &vibration);
prevVibration[pad] = vibration;
}
prevVibrationTime = newVibrationTime;
prevVibrationTime = newVibrationTime_;
}
} else {
DWORD dwResult = PPSSPP_XInputSetState(pad, &vibration);
@@ -284,4 +282,3 @@ void XinputDevice::ApplyVibration(int pad, XINPUT_VIBRATION &vibration) {
}
}
}
+1
View File
@@ -21,4 +21,5 @@ private:
float prevAxisValue_[4][6]{};
bool notified_[XUSER_MAX_COUNT]{};
u32 prevButtons_[4]{};
double newVibrationTime_ = 0.0;
};