Skip to content

Commit 2d26ab9

Browse files
committed
GPU Display: Unify calling DrawGLScene and handling of events
1 parent b791638 commit 2d26ab9

12 files changed

Lines changed: 41 additions & 34 deletions

‎GPU/GPUTracking/display/GPUDisplay.cxx‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void GPUDisplay::ExitDisplay()
204204
mBackend->ExitBackend();
205205
}
206206

207-
int32_t GPUDisplay::DrawGLScene()
207+
int32_t GPUDisplay::DrawGLScene(bool suspended)
208208
{
209209
// Make sure event gets not overwritten during display
210210
mSemLockDisplay.Lock();
@@ -220,7 +220,7 @@ int32_t GPUDisplay::DrawGLScene()
220220
mNCollissions = std::max(1u, mIOPtrs->nMCInfosTPCCol);
221221
}
222222
try {
223-
DrawGLScene_internal();
223+
DrawGLScene_internal(suspended);
224224
} catch (const std::runtime_error& e) {
225225
GPUError("Runtime error %s during display", e.what());
226226
retVal = 1;
@@ -238,7 +238,7 @@ int32_t GPUDisplay::DrawGLScene()
238238
return retVal;
239239
}
240240

241-
void GPUDisplay::DrawGLScene_cameraAndAnimation(float animateTime, float& mixSlaveImage, hmm_mat4& nextViewMatrix)
241+
void GPUDisplay::DrawGLScene_cameraAndAnimation(bool suspended, float animateTime, float& mixSlaveImage, hmm_mat4& nextViewMatrix)
242242
{
243243
HighResTimer timer(mUpdateVertexLists && mChain->GetProcessingSettings().debugLevel >= 2);
244244
int32_t mMouseWheelTmp = mFrontend->mMouseWheel;
@@ -266,7 +266,7 @@ void GPUDisplay::DrawGLScene_cameraAndAnimation(float animateTime, float& mixSla
266266

267267
// Perform new rotation / translation / animation
268268

269-
if (animateCamera(animateTime, mixSlaveImage, nextViewMatrix)) {
269+
if (animateCamera(suspended, animateTime, mixSlaveImage, nextViewMatrix)) {
270270
// Do nothing else
271271
} else if (mCfgC.mResetScene.load()) {
272272
const float initialZpos = mCfgH.projectXY ? 16 : (mParam->par.continuousTracking ? (mMaxClusterZ * GL_SCALE_FACTOR + 8) : 8);
@@ -627,7 +627,7 @@ void GPUDisplay::DrawGLScene_drawCommands()
627627
}
628628
}
629629

630-
void GPUDisplay::DrawGLScene_internal(float animateTime, bool renderToMixBuffer) // negative time = no mixing
630+
void GPUDisplay::DrawGLScene_internal(bool suspended, float animateTime, bool renderToMixBuffer) // negative time = no mixing
631631
{
632632
if (mCfgC.mRequestScreenshot || mCfgC.mAnimateScreenshot) {
633633
const uint32_t factor = std::max(1, mCfgR.drawQualityDownsampleFSAA) * std::max(1, mCfgR.screenshotScaleFactor);
@@ -660,7 +660,7 @@ void GPUDisplay::DrawGLScene_internal(float animateTime, bool renderToMixBuffer)
660660

661661
hmm_mat4 nextViewMatrix = MY_HMM_IDENTITY;
662662
float mixSlaveImage = 0.f;
663-
DrawGLScene_cameraAndAnimation(animateTime, mixSlaveImage, nextViewMatrix);
663+
DrawGLScene_cameraAndAnimation(suspended, animateTime, mixSlaveImage, nextViewMatrix);
664664

665665
// Prepare Event
666666
if (mUpdateVertexLists && mIOPtrs) {
@@ -670,6 +670,10 @@ void GPUDisplay::DrawGLScene_internal(float animateTime, bool renderToMixBuffer)
670670
}
671671
}
672672

673+
if (suspended) {
674+
return;
675+
}
676+
673677
// Draw Event
674678
nextViewMatrix = nextViewMatrix * *mModelMatrix;
675679
const float zFar = ((mParam->par.continuousTracking ? (mMaxClusterZ * GL_SCALE_FACTOR) : 8.f) + 50.f) * 2.f;

‎GPU/GPUTracking/display/GPUDisplay.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class GPUDisplay : public GPUDisplayInterface
6060
void UpdateParam(const GPUParam* param) override { mParam = param; }
6161

6262
void HandleKey(uint8_t key, bool doNotHandleConfigChanges = false); // With doNotHandleConfigChanges, the caller must call checkAndApplyConfigChanges
63-
int32_t DrawGLScene();
63+
int32_t DrawGLScene(bool suspended = false);
6464
void HandleExternalGUIKey(int32_t key); // Does not handle config changes, see HandleKey
6565
int32_t InitDisplay(bool initFailure = false);
6666
void ResizeScene(int32_t width, int32_t height, bool init = false);
@@ -170,9 +170,9 @@ class GPUDisplay : public GPUDisplayInterface
170170
static const GPUSettingsDisplay& GetConfig(GPUChainTracking* chain);
171171
static const GPUSettingsProcessing& GetProcessingConfig(GPUChainTracking* chain);
172172

173-
void DrawGLScene_internal(float animateTime = -1.f, bool renderToMixBuffer = false);
173+
void DrawGLScene_internal(bool suspended, float animateTime = -1.f, bool renderToMixBuffer = false); // suspended: return before drawing
174174
void DrawGLScene_updateEventData();
175-
void DrawGLScene_cameraAndAnimation(float animateTime, float& mixSlaveImage, hmm_mat4& nextViewMatrix);
175+
void DrawGLScene_cameraAndAnimation(bool suspended, float animateTime, float& mixSlaveImage, hmm_mat4& nextViewMatrix);
176176
size_t DrawGLScene_updateVertexList();
177177
void DrawGLScene_drawCommands();
178178
int32_t InitDisplay_internal();
@@ -195,7 +195,7 @@ class GPUDisplay : public GPUDisplayInterface
195195
void resetAnimation();
196196
void removeAnimationPoint();
197197
void startAnimation();
198-
int32_t animateCamera(float& animateTime, float& mixSlaveImage, hmm_mat4& nextViewMatrix);
198+
int32_t animateCamera(bool suspended, float& animateTime, float& mixSlaveImage, hmm_mat4& nextViewMatrix);
199199
void showInfo(const char* info);
200200
void ActivateColor();
201201
void SetColorTRD();

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ int32_t GPUDisplayFrontend::getDisplayControl() const { return mDisplay->mCfgC.m
146146
void GPUDisplayFrontend::setDisplayControl(int32_t v) { mDisplay->mCfgC.mDisplayControl.store(v); }
147147

148148
void GPUDisplayFrontend::HandleKey(uint8_t key) { mDisplay->HandleKey(key); }
149-
int32_t GPUDisplayFrontend::DrawGLScene() { return mDisplay->DrawGLScene(); }
149+
int32_t GPUDisplayFrontend::HandleUpdatesAndDrawGLScene(bool suspended)
150+
{
151+
HandleExternalGUISignals();
152+
return mDisplay->DrawGLScene(suspended);
153+
}
150154

151155
void GPUDisplayFrontend::ResizeScene(int32_t width, int32_t height)
152156
{

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ class GPUDisplayFrontend : public GPUDisplayFrontendInterface
126126
std::unique_ptr<GPUDisplayGUIChannel> mGUIChannel; // Must outlive mGUI
127127
std::unique_ptr<GPUDisplayGUIWrapper> mGUI;
128128

129+
int32_t HandleUpdatesAndDrawGLScene(bool suspended = false); // Handle external GUI signals and config changes, then draw the scene (suspended: only update, no drawing, e.g. for a hidden window)
130+
129131
void HandleKey(uint8_t key); // Callback for handling key presses
130-
int32_t DrawGLScene(); // Callback to draw the GL scene
131132
void HandleExternalGUISignals(); // Callback to handle signals from external GUIs
132133
bool HasExternalGUISignals() const; // Returns whether there are currently pending signals from external GUIs to be handled
133134
bool processKeyLambda(uint32_t key); // Process key lambda callback

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,7 @@ int32_t GPUDisplayFrontendGlfw::FrontendMain()
322322

323323
int32_t retVal = 0;
324324
while (!glfwWindowShouldClose(mWindow)) {
325-
HandleExternalGUISignals();
326-
if (DrawGLScene()) {
325+
if (HandleUpdatesAndDrawGLScene()) {
327326
fprintf(stderr, "Error drawing GL scene\n");
328327
retVal = 1;
329328
break; // Cleanup below

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,20 @@ GPUDisplayFrontendGlut::GPUDisplayFrontendGlut()
3838

3939
void GPUDisplayFrontendGlut::displayFunc() // TODO: Functions should be lambdas, to get rid of the static me variable!
4040
{
41-
me->DrawGLScene();
41+
me->mRedisplayPending = false;
42+
me->HandleUpdatesAndDrawGLScene();
4243
glutSwapBuffers();
4344
me->waitForFPSLimit();
4445
}
4546

4647
void GPUDisplayFrontendGlut::glutLoopFunc()
4748
{
48-
me->HandleExternalGUISignals();
49-
displayFunc();
49+
if (me->mRedisplayPending) { // Last redisplay not served (window not visible): handle updates without drawing
50+
me->HandleUpdatesAndDrawGLScene(true);
51+
me->waitForFPSLimit();
52+
}
53+
me->mRedisplayPending = true;
54+
glutPostRedisplay(); // Drawing only in displayFunc, so that expose events do not draw twice
5055
}
5156

5257
int32_t GPUDisplayFrontendGlut::GetKey(int32_t key)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class GPUDisplayFrontendGlut : public GPUDisplayFrontend
5151
int32_t mWidth = INIT_WIDTH;
5252
int32_t mHeight = INIT_HEIGHT;
5353
bool mFullScreen = false;
54+
bool mRedisplayPending = false; // glutPostRedisplay called in glutLoopFunc, not yet served by displayFunc
5455
};
5556
} // namespace o2::gpu
5657

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ int32_t GPUDisplayFrontendNone::FrontendMain()
2828
return 1;
2929
}
3030
do {
31-
HandleExternalGUISignals();
32-
DrawGLScene();
31+
HandleUpdatesAndDrawGLScene();
3332
waitForFPSLimit();
3433
} while (getDisplayControl() != 2);
3534
return 0;

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,7 @@ int32_t GPUDisplayFrontendWayland::FrontendMain()
610610
break;
611611
}
612612
handleKeyRepeat();
613-
HandleExternalGUISignals();
614-
if (!mSuspended) { // Window not visible, compositor would not release swapchain images
615-
DrawGLScene();
616-
}
613+
HandleUpdatesAndDrawGLScene(mSuspended); // Window not visible, compositor would not release swapchain images
617614
waitForFPSLimit();
618615
}
619616

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,11 @@ int32_t GPUDisplayFrontendWindows::FrontendMain()
350350
DispatchMessage(&msg); // Dispatch The Message
351351
}
352352
} else {
353-
HandleExternalGUISignals();
354-
if (active) // Program Active?
355-
{
356-
if (mKeys[VK_ESCAPE]) {
357-
done = TRUE;
358-
} else {
359-
DrawGLScene(); // Draw The Scene
353+
if (active && mKeys[VK_ESCAPE]) {
354+
done = TRUE;
355+
} else {
356+
HandleUpdatesAndDrawGLScene(!active); // Only draw if the program is active
357+
if (active) {
360358
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
361359
waitForFPSLimit();
362360
}

0 commit comments

Comments
 (0)