Skip to content

Commit c0dc347

Browse files
committed
GPU Display: Cleanup
1 parent 9467ebb commit c0dc347

15 files changed

Lines changed: 40 additions & 34 deletions

‎GPU/GPUTracking/Definitions/GPUSettingsList.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ AddOption(debugOnFailureMaxSize, uint32_t, 0, "", 0, "Max size of existing dumps
422422
AddOption(debugOnFailureDirectory, std::string, ".", "", 0, "Target folder for debug / dump")
423423
AddOption(ROOTDumpFile, std::string, "gpudebug.root", "", 0, "File name for ROOT dump (default gpudebug.root)")
424424
AddOption(memoryStat, bool, false, "", 0, "Print memory statistics")
425+
AddVariable(runsStandalone, bool, false)
425426
AddVariable(eventDisplay, o2::gpu::GPUDisplayFrontendInterface*, nullptr)
426427
AddSubConfig(GPUSettingsProcessingRTC, rtc)
427428
AddSubConfig(GPUSettingsProcessingRTCtechnical, rtctech)

‎GPU/GPUTracking/Global/GPUChainTracking.cxx‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -849,24 +849,23 @@ int32_t GPUChainTracking::RunChainFinalize()
849849

850850
mEventDisplay->WaitTillEventShown();
851851

852-
if (GetProcessingSettings().eventDisplay->EnableSendKey()) {
852+
if (GetProcessingSettings().runsStandalone) {
853853
while (kbhit()) {
854854
getch();
855855
}
856856
GPUInfo("Press key for next event!");
857857
}
858-
859858
int32_t iKey;
860859
do {
861860
usleep(10000);
862-
if (GetProcessingSettings().eventDisplay->EnableSendKey()) {
861+
if (GetProcessingSettings().runsStandalone) {
863862
iKey = kbhit() ? getch() : 0;
864863
if (iKey == 27) {
865864
GetProcessingSettings().eventDisplay->setDisplayControl(2);
866865
} else if (iKey == 'n') {
867866
break;
868867
} else if (iKey) {
869-
GetProcessingSettings().eventDisplay->sendKey(iKey);
868+
GetProcessingSettings().eventDisplay->sendExternalGUIKey(iKey);
870869
}
871870
}
872871
} while (GetProcessingSettings().eventDisplay->getDisplayControl() == 0);

‎GPU/GPUTracking/Standalone/Benchmark/standalone.cxx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ int32_t main(int argc, char** argv)
760760
if (ReadConfiguration(argc, argv)) {
761761
return 1;
762762
}
763+
configStandalone.proc.runsStandalone = true;
763764
eventsDir = std::string(configStandalone.absoluteEventsDir ? "" : "events/") + configStandalone.eventsDir + "/";
764765

765766
GPUSettingsDeviceBackend deviceSet;

‎GPU/GPUTracking/display/GPUDisplay.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class GPUDisplay : public GPUDisplayInterface
6060

6161
void HandleKey(uint8_t key);
6262
int32_t DrawGLScene();
63-
void HandleSendKey(int32_t key);
63+
void HandleExternalGUIKey(int32_t key);
6464
int32_t InitDisplay(bool initFailure = false);
6565
void ResizeScene(int32_t width, int32_t height, bool init = false);
6666

‎GPU/GPUTracking/display/GPUDisplayInterface.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,9 @@ class GPUDisplayFrontendInterface
5757
virtual ~GPUDisplayFrontendInterface();
5858
static GPUDisplayFrontendInterface* getFrontend(const char* type);
5959
virtual void StopDisplay() = 0;
60-
virtual bool EnableSendKey() = 0;
6160
virtual int32_t getDisplayControl() const = 0;
6261
virtual void setDisplayControl(int32_t v) = 0;
63-
virtual void sendKey(int32_t v) = 0;
62+
virtual void sendExternalGUIKey(int32_t v) = 0;
6463
virtual const char* frontendName() const = 0;
6564

6665
protected:

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,27 +85,37 @@ void GPUDisplayFrontend::waitForFPSLimit()
8585
mNextFrameTime = now;
8686
return;
8787
}
88-
const auto period = std::chrono::duration_cast<std::chrono::steady_clock::duration>(std::chrono::duration<double>(1. / cfg.fpsRate));
88+
const auto period = std::chrono::duration_cast<std::chrono::steady_clock::duration>(std::chrono::duration<double>(1. / cfg.fpsRate)); // TODO: wake up on HasExternalGUISignals
8989
mNextFrameTime += period;
9090
if (mNextFrameTime < now - period) { // More than one frame behind (slow rendering, first frame), do not try to catch up
9191
mNextFrameTime = now;
9292
}
9393
std::this_thread::sleep_until(mNextFrameTime);
9494
}
9595

96-
void GPUDisplayFrontend::HandleSendKeys()
96+
void GPUDisplayFrontend::HandleExternalGUISignals()
9797
{
98-
std::lock_guard lock(mSendKeyMutex);
99-
for (auto key : mSendKeys) {
100-
mDisplay->HandleSendKey(key);
98+
HandleExternalGUIKeys();
99+
}
100+
101+
bool GPUDisplayFrontend::HasExternalGUISignals() const
102+
{
103+
104+
}
105+
106+
void GPUDisplayFrontend::HandleExternalGUIKeys()
107+
{
108+
std::lock_guard lock(mExternalGUIKeyMutex);
109+
for (auto key : mExternalGUIKeys) {
110+
mDisplay->HandleExternalGUIKey(key);
101111
}
102-
mSendKeys.clear();
112+
mExternalGUIKeys.clear();
103113
}
104114

105-
void GPUDisplayFrontend::sendKey(int32_t v)
115+
void GPUDisplayFrontend::sendExternalGUIKey(int32_t v)
106116
{
107-
std::lock_guard lock(mSendKeyMutex);
108-
mSendKeys.emplace_back(v);
117+
std::lock_guard lock(mExternalGUIKeyMutex);
118+
mExternalGUIKeys.emplace_back(v);
109119
}
110120

111121
void GPUDisplayFrontend::HandleKey(uint8_t key) { mDisplay->HandleKey(key); }
@@ -124,7 +134,6 @@ void GPUDisplayFrontend::ExitDisplay()
124134
stopGUI();
125135
mGUI.reset(nullptr);
126136
}
127-
bool GPUDisplayFrontend::EnableSendKey() { return true; }
128137

129138
void GPUDisplayFrontend::stopGUI()
130139
{

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class GPUDisplayFrontend : public GPUDisplayFrontendInterface
5757
virtual void ToggleMaximized(bool set) = 0; // Maximize window
5858
virtual void SetVSync(bool enable) = 0; // Enable / disable vsync
5959
virtual bool canSetVSync() { return false; } // OpenGL: swap interval can be set
60-
bool EnableSendKey() override; // Request external keys (e.g. from terminal)
6160
virtual void OpenGLPrint(const char* s, float x, float y, float r, float g, float b, float a, bool fromBotton = true) = 0; // Print text on the display (needs the backend to build the font)
6261
GPUDisplayBackend* backend();
6362
static GPUDisplayFrontend* getFrontend(const char* type);
@@ -69,7 +68,7 @@ class GPUDisplayFrontend : public GPUDisplayFrontendInterface
6968

7069
int32_t getDisplayControl() const override { return mDisplayControl; }
7170
void setDisplayControl(int32_t v) override { mDisplayControl = v; }
72-
void sendKey(int32_t v) override;
71+
void sendExternalGUIKey(int32_t v) override;
7372

7473
frontendTypes frontendType() const { return mFrontendType; }
7574
const char* frontendName() const override { return mFrontendName; }
@@ -121,8 +120,8 @@ class GPUDisplayFrontend : public GPUDisplayFrontendInterface
121120
// volatile variables to exchange control informations between display and backend
122121
volatile int32_t mDisplayControl = 0; // Control for next event (=1) or quit (=2)
123122
volatile int32_t mNeedUpdate = 0; // flag that backend shall update the GL window, and call DrawGLScene
124-
std::mutex mSendKeyMutex;
125-
std::vector<int32_t> mSendKeys; // Keys sent by external entity (usually console), may be ignored by backend.
123+
std::mutex mExternalGUIKeyMutex;
124+
std::vector<int32_t> mExternalGUIKeys; // Keys sent by external entity (usually console), may be ignored by backend.
126125
std::mutex mExitStateMutex;
127126

128127
// Keyboard / Mouse actions
@@ -151,7 +150,8 @@ class GPUDisplayFrontend : public GPUDisplayFrontendInterface
151150

152151
void HandleKey(uint8_t key); // Callback for handling key presses
153152
int32_t DrawGLScene(); // Callback to draw the GL scene
154-
void HandleSendKeys(); // Optional callback to handle key press from external source (e.g. stdin by default)
153+
void HandleExternalGUISignals(); // Callback to handle signals from external GUIs
154+
bool HasExternalGUISignals() const; // Returns whether there are currently pending signals from external GUIs to be handled
155155
void ResizeScene(int32_t width, int32_t height); // Callback when GL window is resized
156156
int32_t InitDisplay(bool initFailure = false); // Callback to initialize the GL Display (to be called in StartDisplay)
157157
void ExitDisplay(); // Callback to clean up the GL Display
@@ -160,6 +160,8 @@ class GPUDisplayFrontend : public GPUDisplayFrontendInterface
160160
void setWindowState(bool fullScreen, bool maximized); // Sync the settings if the window manager changed the window state
161161
void focusLost(); // Release all keys and mouse buttons when the window loses focus, since the release events go to another window
162162
void applyInitialWindowState(); // Switch to fullscreen / maximize at startup according to the settings
163+
private:
164+
void HandleExternalGUIKeys();
163165
};
164166
} // namespace o2::gpu
165167

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ int32_t GPUDisplayFrontendGlfw::FrontendMain()
326326

327327
int32_t retVal = 0;
328328
while (!glfwWindowShouldClose(mWindow)) {
329-
HandleSendKeys();
329+
HandleExternalGUISignals();
330330
if (DrawGLScene()) {
331331
fprintf(stderr, "Error drawing GL scene\n");
332332
retVal = 1;
@@ -398,11 +398,6 @@ void GPUDisplayFrontendGlfw::SetVSync(bool enable)
398398

399399
bool GPUDisplayFrontendGlfw::canSetVSync() { return backend()->backendType() == GPUDisplayBackend::TYPE_OPENGL; }
400400

401-
bool GPUDisplayFrontendGlfw::EnableSendKey()
402-
{
403-
return true;
404-
}
405-
406401
float GPUDisplayFrontendGlfw::getRefreshRate()
407402
{
408403
GLFWmonitor* monitor = glfwGetWindowMonitor(mWindow) ? glfwGetWindowMonitor(mWindow) : glfwGetPrimaryMonitor(); // Monitor of a windowed window is not known, use the primary one

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontendGlfw.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class GPUDisplayFrontendGlfw : public GPUDisplayFrontend
3232
void ToggleMaximized(bool set) override;
3333
void SetVSync(bool enable) override;
3434
void OpenGLPrint(const char* s, float x, float y, float r, float g, float b, float a, bool fromBotton = true) override;
35-
bool EnableSendKey() override;
3635
void getSize(int32_t& width, int32_t& height) override;
3736
float getDisplayScale() const override { return mScale; }
3837
float getRefreshRate() override;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void GPUDisplayFrontendGlut::displayFunc() // TODO: Functions should be lambdas,
4545

4646
void GPUDisplayFrontendGlut::glutLoopFunc()
4747
{
48-
me->HandleSendKeys();
48+
me->HandleExternalGUISignals();
4949
displayFunc();
5050
}
5151

0 commit comments

Comments
 (0)