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