Skip to content

Commit aaf4450

Browse files
committed
GPU Display: Cleanup: check for config changes only once
1 parent 9bad513 commit aaf4450

4 files changed

Lines changed: 17 additions & 24 deletions

File tree

‎GPU/GPUTracking/display/GPUDisplay.cxx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ int32_t GPUDisplay::InitDisplay(bool initFailure)
177177
retVal = 1;
178178
}
179179
mInitResult = retVal == 0 ? 1 : -1;
180+
mOldCfg = {mCfgH, mCfgL, mCfgR};
180181
return (retVal);
181182
}
182183

‎GPU/GPUTracking/display/GPUDisplay.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <atomic>
2525
#include <array>
26+
#include <tuple>
2627
#include <mutex>
2728
#include <condition_variable>
2829

@@ -59,12 +60,12 @@ class GPUDisplay : public GPUDisplayInterface
5960
void UpdateCalib(const GPUCalibObjectsConst* calib) override { mCalib = calib; }
6061
void UpdateParam(const GPUParam* param) override { mParam = param; }
6162

62-
void HandleKey(uint8_t key, bool doNotHandleConfigChanges = false); // With doNotHandleConfigChanges, the caller must call checkAndApplyConfigChanges
63+
void HandleKey(uint8_t key);
6364
int32_t DrawGLScene(bool suspended = false);
64-
void HandleExternalGUIKey(int32_t key); // Does not handle config changes, see HandleKey
65+
void HandleExternalGUIKey(int32_t key);
6566
int32_t InitDisplay(bool initFailure = false);
6667
void ResizeScene(int32_t width, int32_t height, bool init = false);
67-
void checkAndApplyConfigChanges(const GPUSettingsDisplayHeavy& oldCfgH, const GPUSettingsDisplayLight& oldCfgL, const GPUSettingsDisplayRenderer& oldCfgR); // Set update flags / apply the settings that changed compared to the old copies
68+
void checkAndApplyConfigChanges(); // Set update flags / apply the settings that changed compared to mOldCfg
6869

6970
const GPUSettingsDisplayRenderer& cfgR() const { return mCfgR; }
7071
const GPUSettingsDisplayLight& cfgL() const { return mCfgL; }
@@ -244,6 +245,7 @@ class GPUDisplay : public GPUDisplayInterface
244245
GPUSettingsDisplayLight mCfgL;
245246
GPUSettingsDisplayHeavy mCfgH;
246247
GPUSettingsDisplayRenderer mCfgR;
248+
std::tuple<GPUSettingsDisplayHeavy, GPUSettingsDisplayLight, GPUSettingsDisplayRenderer> mOldCfg; // Settings after the last draw, for checkAndApplyConfigChanges
247249
const GPUSettingsProcessing& mProcessingSettings;
248250
GPUQA* mQA;
249251

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontend.cxx‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,7 @@ void GPUDisplayFrontend::waitForFPSLimit()
9797

9898
void GPUDisplayFrontend::HandleExternalGUISignals()
9999
{
100-
const GPUSettingsDisplayHeavy oldCfgH = mDisplay->mCfgH;
101-
const GPUSettingsDisplayLight oldCfgL = mDisplay->mCfgL;
102-
const GPUSettingsDisplayRenderer oldCfgR = mDisplay->mCfgR;
103-
bool changes = HandleExternalGUIKeys();
100+
HandleExternalGUIKeys();
104101

105102
const bool gui = isGUIRunning();
106103
std::optional<GPUDisplayGUIChannel::Update> update;
@@ -116,12 +113,8 @@ void GPUDisplayFrontend::HandleExternalGUISignals()
116113
if (update->lineWidth) {
117114
mDisplay->mCfgL.lineWidth = *update->lineWidth;
118115
}
119-
changes = true;
120116
}
121117

122-
if (changes) {
123-
mDisplay->checkAndApplyConfigChanges(oldCfgH, oldCfgL, oldCfgR);
124-
}
125118
if (gui) {
126119
{
127120
std::lock_guard lock(mGUIChannel->mutex);
@@ -149,7 +142,10 @@ void GPUDisplayFrontend::HandleKey(uint8_t key) { mDisplay->HandleKey(key); }
149142
int32_t GPUDisplayFrontend::HandleUpdatesAndDrawGLScene(bool suspended)
150143
{
151144
HandleExternalGUISignals();
152-
return mDisplay->DrawGLScene(suspended);
145+
mDisplay->checkAndApplyConfigChanges();
146+
const int32_t retVal = mDisplay->DrawGLScene(suspended);
147+
mDisplay->mOldCfg = {mDisplay->mCfgH, mDisplay->mCfgL, mDisplay->mCfgR}; // Also includes the changes during drawing (animation, scene reset, ...), which set their update flags themselves
148+
return retVal;
153149
}
154150

155151
void GPUDisplayFrontend::ResizeScene(int32_t width, int32_t height)

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontendConfig.cxx‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ namespace
121121
#include "utils/qconfig_genrtti.inc"
122122
} // namespace
123123

124-
void GPUDisplay::checkAndApplyConfigChanges(const GPUSettingsDisplayHeavy& oldCfgH, const GPUSettingsDisplayLight& oldCfgL, const GPUSettingsDisplayRenderer& oldCfgR)
124+
void GPUDisplay::checkAndApplyConfigChanges()
125125
{
126+
const auto& [oldCfgH, oldCfgL, oldCfgR] = mOldCfg;
126127
if (memcmp((void*)&oldCfgH, (void*)&mCfgH, sizeof(mCfgH)) != 0) {
127128
mUpdateEventData = true;
128129
}
@@ -164,7 +165,7 @@ void GPUDisplay::HandleExternalGUIKey(int32_t key)
164165
bool shifted = key >= 'A' && key <= 'Z';
165166
bool oldShift = mFrontend->mKeys[mFrontend->KEY_SHIFT];
166167
mFrontend->mKeys[mFrontend->KEY_SHIFT] = shifted;
167-
HandleKey(key, true);
168+
HandleKey(key);
168169
mFrontend->mKeys[mFrontend->KEY_SHIFT] = oldShift;
169170
}
170171

@@ -173,13 +174,13 @@ bool GPUDisplayFrontend::HasExternalGUISignals() const
173174
return mExternalGUIKeys.size();
174175
}
175176

176-
bool GPUDisplayFrontend::HandleExternalGUIKeys()
177+
void GPUDisplayFrontend::HandleExternalGUIKeys()
177178
{
178179
std::lock_guard lock(mExternalGUIKeyMutex);
179180
for (auto key : mExternalGUIKeys) {
180181
mDisplay->HandleExternalGUIKey(key);
181182
}
182-
return !std::exchange(mExternalGUIKeys, {}).empty();
183+
mExternalGUIKeys.clear();
183184
}
184185

185186
template <typename... Args>
@@ -360,17 +361,10 @@ bool GPUDisplayFrontend::processKeyLambda(uint32_t key)
360361
return false;
361362
}
362363

363-
void GPUDisplay::HandleKey(uint8_t key, bool doNotHandleConfigChanges)
364+
void GPUDisplay::HandleKey(uint8_t key)
364365
{
365-
const GPUSettingsDisplayHeavy oldCfgH = mCfgH;
366-
const GPUSettingsDisplayLight oldCfgL = mCfgL;
367-
const GPUSettingsDisplayRenderer oldCfgR = mCfgR;
368366
if (key == mFrontend->KEY_ALT) {
369367
mFrontend->mKeys[mFrontend->KEY_CTRL] = false; // Release CTRL with alt, to avoid orienting along y automatically!
370368
} else if (mFrontend->processKeyLambda(key)) {
371369
}
372-
373-
if (!doNotHandleConfigChanges) {
374-
checkAndApplyConfigChanges(oldCfgH, oldCfgL, oldCfgR);
375-
}
376370
}

0 commit comments

Comments
 (0)