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
22namespace o2::gpu
23{
24class GPUReconstruction;
25class GPUDisplay;
26class GPUDisplayBackend;
27class GPUDisplayGUIWrapper;
28
30{
31 friend class GPUDisplay;
32
33 public:
34 GPUDisplayFrontend() = default;
36
45
46 // Compile time minimum version defined in GPUDisplay.h, keep in sync!
47 static constexpr int32_t GL_MIN_VERSION_MAJOR = 4;
48 static constexpr int32_t GL_MIN_VERSION_MINOR = 5;
49
50 virtual int32_t StartDisplay() = 0; // Start the display. This function returns, and should spawn a thread that runs the display, and calls InitDisplay
51 void DisplayExit() override = 0; // Stop the display. Display thread should call ExitDisplay and the function returns after the thread has terminated
52 virtual void SwitchFullscreen(bool set) = 0; // Toggle full-screen mode
53 virtual void ToggleMaximized(bool set) = 0; // Maximize window
54 virtual void SetVSync(bool enable) = 0; // Enable / disable vsync
55 bool EnableSendKey() override; // Request external keys (e.g. from terminal)
56 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)
58 static GPUDisplayFrontend* getFrontend(const char* type);
59 virtual void getSize(int32_t& width, int32_t& height) { width = height = 0; }
60 virtual int32_t getVulkanSurface(void* instance, void* surface) { return 1; }
61 virtual uint32_t getReqVulkanExtensions(const char**& p) { return 0; };
62
63 int32_t getDisplayControl() const override { return mDisplayControl; }
64 int32_t getSendKey() const override { return mSendKey; }
65 int32_t getNeedUpdate() const override { return mNeedUpdate; }
66 void setDisplayControl(int32_t v) override { mDisplayControl = v; }
67 void setSendKey(int32_t v) override { mSendKey = v; }
68 void setNeedUpdate(int32_t v) override { mNeedUpdate = v; }
69
71 const char* frontendName() const override { return mFrontendName; }
72
73 int32_t startGUI();
74 void stopGUI();
75 bool isGUIRunning();
76
77 // volatile variables to exchange control informations between display and backend
78 volatile int32_t mDisplayControl = 0; // Control for next event (=1) or quit (=2)
79 volatile int32_t mSendKey = 0; // Key sent by external entity (usually console), may be ignored by backend.
80 volatile int32_t mNeedUpdate = 0; // flag that backend shall update the GL window, and call DrawGLScene
81
82 protected:
83 virtual int32_t FrontendMain() = 0;
84 static void* FrontendThreadWrapper(void*);
85
86 static constexpr int32_t INIT_WIDTH = 1024, INIT_HEIGHT = 768; // Initial window size, before maximizing
87 static constexpr const char* DISPLAY_WINDOW_NAME = "GPU CA Standalone Event Display"; // Title of event display set by backend
88 // Constant key codes for special mKeys (to unify different treatment in X11 / Windows / GLUT / etc.)
89 static constexpr int32_t KEY_UP = 1;
90 static constexpr int32_t KEY_DOWN = 2;
91 static constexpr int32_t KEY_LEFT = 3;
92 static constexpr int32_t KEY_RIGHT = 4;
93 static constexpr int32_t KEY_PAGEUP = 5;
94 static constexpr int32_t KEY_PAGEDOWN = 6;
95 static constexpr int32_t KEY_SHIFT = 8;
96 static constexpr int32_t KEY_ALT = 9;
97 static constexpr int32_t KEY_RALT = 10;
98 static constexpr int32_t KEY_CTRL = 11;
99 static constexpr int32_t KEY_RCTRL = 12;
100 static constexpr int32_t KEY_ENTER = 13; // fixed at 13
101 static constexpr int32_t KEY_F1 = 14;
102 static constexpr int32_t KEY_F2 = 15;
103 static constexpr int32_t KEY_F3 = 26;
104 static constexpr int32_t KEY_F4 = 17;
105 static constexpr int32_t KEY_F5 = 18;
106 static constexpr int32_t KEY_F6 = 19;
107 static constexpr int32_t KEY_F7 = 20;
108 static constexpr int32_t KEY_F8 = 21;
109 static constexpr int32_t KEY_F9 = 22;
110 static constexpr int32_t KEY_F10 = 23;
111 static constexpr int32_t KEY_F11 = 24;
112 static constexpr int32_t KEY_F12 = 25;
113 static constexpr int32_t KEY_INSERT = 26;
114 static constexpr int32_t KEY_ESCAPE = 27; // fixed at 27
115 static constexpr int32_t KEY_HOME = 28;
116 static constexpr int32_t KEY_END = 29;
117 static constexpr int32_t KEY_SPACE = 32; // fixed at 32
118
119 // Keyboard / Mouse actions
120 bool mMouseDn = false; // Mouse button down
121 bool mMouseDnR = false; // Right mouse button down
122 float mMouseDnX, mMouseDnY; // X/Y position where mouse button was pressed
123 float mMouseMvX, mMouseMvY; // Current mouse pointer position
124 int32_t mMouseWheel = 0; // Incremental value of mouse wheel, ca +/- 100 per wheel tick
125 bool mKeys[256] = {false}; // Array of mKeys currently pressed
126 bool mKeysShift[256] = {false}; // Array whether shift was held during key-press
129 int32_t mCanDrawText = 0; // 1 = in compat mode, 2 = with shader
130
131 int32_t mMaxFPSRate = 0; // run at highest possible frame rate, do not sleep in between frames
132
133 GPUDisplay* mDisplay = nullptr; // Ptr to display, not owning, set by display when it connects to backend
134 GPUDisplayBackend* mBackend = nullptr; // Ptr to backend, not owning
135
137 const char* mFrontendName = nullptr;
138
139 std::unique_ptr<GPUDisplayGUIWrapper> mGUI;
140
141 void HandleKey(uint8_t key); // Callback for handling key presses
142 int32_t DrawGLScene(); // Callback to draw the GL scene
143 void HandleSendKey(); // Optional callback to handle key press from external source (e.g. stdin by default)
144 void ResizeScene(int32_t width, int32_t height); // Callback when GL window is resized
145 int32_t InitDisplay(bool initFailure = false); // Callback to initialize the GL Display (to be called in StartDisplay)
146 void ExitDisplay(); // Callback to clean up the GL Display
147 int32_t& drawTextFontSize();
148};
149} // namespace o2::gpu
150
151#endif
StringRef key
std::unique_ptr< GPUDisplayGUIWrapper > mGUI
void setNeedUpdate(int32_t v) override
static constexpr int32_t KEY_F9
int32_t getNeedUpdate() const override
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
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
int32_t getSendKey() const override
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
static constexpr int32_t KEY_SPACE
const char * frontendName() const override
static constexpr int32_t KEY_F5
static constexpr int32_t KEY_PAGEUP
virtual int32_t StartDisplay()=0
static constexpr int32_t KEY_HOME
virtual int32_t getVulkanSurface(void *instance, void *surface)
void setSendKey(int32_t v) override
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
void DisplayExit() override=0
static constexpr int32_t KEY_F8
static constexpr int32_t INIT_HEIGHT
static constexpr int32_t KEY_RIGHT
static constexpr int32_t KEY_RCTRL
virtual void SwitchFullscreen(bool set)=0
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 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