Project
Loading...
Searching...
No Matches
GPUDisplayFrontend.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#ifndef GPUDISPLAYFRONTEND_H
16#define GPUDISPLAYFRONTEND_H
17
18#include "GPUCommonDef.h"
19#include "GPUDisplayInterface.h"
20#include <memory>
21#include <chrono>
22#include <mutex>
23#include <vector>
24
25namespace o2::gpu
26{
27class GPUReconstruction;
28class GPUDisplay;
29class GPUDisplayBackend;
30class GPUDisplayGUIWrapper;
31struct GPUDisplayGUIChannel;
32
34{
35 friend class GPUDisplay;
36 friend class GPUDisplayGUI; // Key codes
37
38 public:
41
51
52 // Compile time minimum version checked in display/CMakeLists.txt (OpenGL 4.6 headers for SPIR-V shaders), keep in sync!
53 static constexpr int32_t GL_MIN_VERSION_MAJOR = 4;
54 static constexpr int32_t GL_MIN_VERSION_MINOR = 6;
55
56 int32_t StartDisplay(); // Start the display. This function returns, and should spawn a thread that runs the display, and calls InitDisplay
57 void StopDisplay() override; // Stop the display. Display thread should call ExitDisplay. Functions waits for display thread to terminate
58 virtual void SwitchFullscreen(bool set) = 0; // Toggle full-screen mode
59 virtual void ToggleMaximized(bool set) = 0; // Maximize window
60 virtual void SetVSync(bool enable) = 0; // Enable / disable vsync
61 virtual bool canSetVSync() { return false; } // OpenGL: swap interval can be set
62 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)
64 static GPUDisplayFrontend* getFrontend(const char* type);
65 virtual void getSize(int32_t& width, int32_t& height) { width = height = 0; }
66 virtual float getRefreshRate() { return 0.f; } // Refresh rate of the display the window is on in Hz, 0 = unknown
67 virtual float getDisplayScale() const { return 1.f; } // HiDPI scale factor: physical pixels per logical pixel, text positions and sizes are scaled by it
68 virtual int32_t getVulkanSurface(void* instance, void* surface) { return 1; }
69 virtual uint32_t getReqVulkanExtensions(const char**& p) { return 0; };
70
71 int32_t getDisplayControl() const override { return mDisplayControl; }
72 void setDisplayControl(int32_t v) override { mDisplayControl = v; }
73 void sendExternalGUIKey(int32_t v) override;
74
76 const char* frontendName() const override { return mFrontendName; }
77
78 int32_t startGUI();
79 void stopGUI();
80 bool isGUIRunning();
81
82 protected:
83 virtual int32_t FrontendMain() = 0;
84 virtual void StopDisplayA();
85 static void* FrontendThreadWrapper(void*);
86 void waitForFPSLimit(); // Sleep until the next frame is due according to fpsRate (only in FPS_LIMIT_RATE mode, see GPUDisplayBackend::fpsLimitMode)
87
88 static constexpr int32_t INIT_WIDTH = 1024, INIT_HEIGHT = 768; // Initial window size, before maximizing
89 static constexpr int32_t MIN_WIDTH = 200, MIN_HEIGHT = 150; // Minimum window size
90 static constexpr const char* DISPLAY_WINDOW_NAME = "GPU CA Standalone Event Display"; // Title of event display set by backend
91 // Constant key codes for special mKeys (to unify different treatment in X11 / Windows / GLUT / etc.)
92 static constexpr int32_t KEY_UP = 1;
93 static constexpr int32_t KEY_DOWN = 2;
94 static constexpr int32_t KEY_LEFT = 3;
95 static constexpr int32_t KEY_RIGHT = 4;
96 static constexpr int32_t KEY_PAGEUP = 5;
97 static constexpr int32_t KEY_PAGEDOWN = 6;
98 static constexpr int32_t KEY_SHIFT = 8;
99 static constexpr int32_t KEY_ALT = 9;
100 static constexpr int32_t KEY_RALT = 10;
101 static constexpr int32_t KEY_CTRL = 11;
102 static constexpr int32_t KEY_RCTRL = 12;
103 static constexpr int32_t KEY_ENTER = 13; // fixed at 13
104 static constexpr int32_t KEY_F1 = 14;
105 static constexpr int32_t KEY_F2 = 15;
106 static constexpr int32_t KEY_F3 = 16;
107 static constexpr int32_t KEY_F4 = 17;
108 static constexpr int32_t KEY_F5 = 18;
109 static constexpr int32_t KEY_F6 = 19;
110 static constexpr int32_t KEY_F7 = 20;
111 static constexpr int32_t KEY_F8 = 21;
112 static constexpr int32_t KEY_F9 = 22;
113 static constexpr int32_t KEY_F10 = 23;
114 static constexpr int32_t KEY_F11 = 24;
115 static constexpr int32_t KEY_F12 = 25;
116 static constexpr int32_t KEY_INSERT = 26;
117 static constexpr int32_t KEY_ESCAPE = 27; // fixed at 27
118 static constexpr int32_t KEY_HOME = 28;
119 static constexpr int32_t KEY_END = 29;
120 static constexpr int32_t KEY_SPACE = 32; // fixed at 32
121
122 // volatile variables to exchange control informations between display and backend
123 volatile int32_t mDisplayControl = 0; // Control for next event (=1) or quit (=2)
124 volatile int32_t mNeedUpdate = 0; // flag that backend shall update the GL window, and call DrawGLScene
126 std::vector<int32_t> mExternalGUIKeys; // Keys sent by external entity (usually console), may be ignored by backend.
127 std::mutex mExitStateMutex;
128
129 // Keyboard / Mouse actions
130 bool mMouseDn = false; // Mouse button down
131 bool mMouseDnR = false; // Right mouse button down
132 bool mMouseDnM = false; // Middle mouse button down (not used yet)
133 float mMouseDnX, mMouseDnY; // X/Y position where mouse button was pressed
134 float mMouseMvX, mMouseMvY; // Current mouse pointer position
135 int32_t mMouseWheel = 0; // Incremental value of mouse wheel, ca +/- 100 per wheel tick
136 bool mKeys[256] = {false}; // Array of mKeys currently pressed
137 bool mKeysShift[256] = {false}; // Array whether shift was held during key-press
140 int32_t mCanDrawText = 0; // 1 = in compat mode, 2 = with shader
141
142 std::chrono::steady_clock::time_point mNextFrameTime;
143
144 GPUDisplay* mDisplay = nullptr; // Ptr to display, not owning, set by display when it connects to backend
145 GPUDisplayBackend* mBackend = nullptr; // Ptr to backend, not owning
146
148 const char* mFrontendName = nullptr;
149 volatile bool mDisplayRunning = false;
150
151 std::unique_ptr<GPUDisplayGUIChannel> mGUIChannel; // Must outlive mGUI
152 std::unique_ptr<GPUDisplayGUIWrapper> mGUI;
153
154 void HandleKey(uint8_t key); // Callback for handling key presses
155 int32_t DrawGLScene(); // Callback to draw the GL scene
156 void HandleExternalGUISignals(); // Callback to handle signals from external GUIs
157 bool HasExternalGUISignals() const; // Returns whether there are currently pending signals from external GUIs to be handled
158 void ResizeScene(int32_t width, int32_t height); // Callback when GL window is resized
159 int32_t InitDisplay(bool initFailure = false); // Callback to initialize the GL Display (to be called in StartDisplay)
160 void ExitDisplay(); // Callback to clean up the GL Display
161 int32_t& drawTextFontSize();
162 bool vsyncEnabled() const; // VSync setting (drawQualityVSync)
163 void setWindowState(bool fullScreen, bool maximized); // Sync the settings if the window manager changed the window state
164 void focusLost(); // Release all keys and mouse buttons when the window loses focus, since the release events go to another window
165 void applyInitialWindowState(); // Switch to fullscreen / maximize at startup according to the settings
166 private:
167 bool HandleExternalGUIKeys(); // Returns whether keys were handled, config changes are not handled
168};
169} // namespace o2::gpu
170
171#endif
const Acts::Surface * surface
StringRef key
std::unique_ptr< GPUDisplayGUIWrapper > mGUI
static constexpr int32_t KEY_F9
virtual uint32_t getReqVulkanExtensions(const char **&p)
static constexpr int32_t KEY_F2
static void * FrontendThreadWrapper(void *)
static constexpr int32_t KEY_ALT
virtual void getSize(int32_t &width, int32_t &height)
static constexpr int32_t KEY_F12
std::unique_ptr< GPUDisplayGUIChannel > mGUIChannel
virtual int32_t FrontendMain()=0
static constexpr int32_t KEY_F7
static constexpr int32_t KEY_END
static constexpr int32_t KEY_PAGEDOWN
static constexpr int32_t KEY_RALT
static constexpr int32_t KEY_F10
virtual void OpenGLPrint(const char *s, float x, float y, float r, float g, float b, float a, bool fromBotton=true)=0
static constexpr int32_t KEY_F4
static constexpr int32_t KEY_LEFT
virtual void ToggleMaximized(bool set)=0
static constexpr int32_t KEY_ENTER
static constexpr int32_t KEY_F6
int32_t getDisplayControl() const override
static GPUDisplayFrontend * getFrontend(const char *type)
static constexpr int32_t KEY_CTRL
static constexpr int32_t KEY_F1
void ResizeScene(int32_t width, int32_t height)
static constexpr const char * DISPLAY_WINDOW_NAME
frontendTypes frontendType() const
static constexpr int32_t INIT_WIDTH
void setDisplayControl(int32_t v) override
static constexpr int32_t GL_MIN_VERSION_MAJOR
static constexpr int32_t KEY_SHIFT
static constexpr int32_t KEY_F3
static constexpr int32_t KEY_INSERT
static constexpr int32_t KEY_F11
void setWindowState(bool fullScreen, bool maximized)
static constexpr int32_t KEY_SPACE
const char * frontendName() const override
static constexpr int32_t KEY_F5
void sendExternalGUIKey(int32_t v) override
static constexpr int32_t KEY_PAGEUP
static constexpr int32_t KEY_HOME
std::vector< int32_t > mExternalGUIKeys
virtual int32_t getVulkanSurface(void *instance, void *surface)
static constexpr int32_t GL_MIN_VERSION_MINOR
int32_t InitDisplay(bool initFailure=false)
virtual void SetVSync(bool enable)=0
static constexpr int32_t KEY_UP
static constexpr int32_t KEY_DOWN
static constexpr int32_t KEY_F8
static constexpr int32_t MIN_WIDTH
static constexpr int32_t INIT_HEIGHT
std::chrono::steady_clock::time_point mNextFrameTime
virtual float getDisplayScale() const
static constexpr int32_t KEY_RIGHT
static constexpr int32_t KEY_RCTRL
virtual void SwitchFullscreen(bool set)=0
static constexpr int32_t MIN_HEIGHT
static constexpr int32_t KEY_ESCAPE
GLint GLenum GLint x
Definition glcorearb.h:403
const GLdouble * v
Definition glcorearb.h:832
GLint GLsizei GLsizei height
Definition glcorearb.h:270
GLint GLsizei width
Definition glcorearb.h:270
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLint y
Definition glcorearb.h:270
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLboolean GLboolean g
Definition glcorearb.h:1233
GLboolean enable
Definition glcorearb.h:3991
GLboolean r
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233