MediaX v1.0.0rc7 [7e6cb74]
Video streaming for military vehicles
Loading...
Searching...
No Matches
display_manager_gtk4.h
Go to the documentation of this file.
1//
2// Copyright (c) 2025, Astute Systems PTY LTD
3//
4// This file is part of the VivoeX project developed by Astute Systems.
5//
6// Licensed under the Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)
7// License. See the LICENSE file in the project root for full license details.
8//
10
11#ifndef HARDWARE_DISPLAY_MANAGER_GTK4_H_
12#define HARDWARE_DISPLAY_MANAGER_GTK4_H_
13
14#include <GL/gl.h>
15#include <errno.h>
16#include <fcntl.h>
17#include <gtk/gtk.h>
18#include <linux/fb.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22#include <sys/ioctl.h>
23#include <sys/mman.h>
24#include <sys/stat.h>
25#include <sys/types.h>
26#include <unistd.h>
27
28#include <mutex>
29#include <string>
30#include <vector>
31
32#include "common/datatypes.h"
34
35namespace mediax::gtk4 {
36
39 public:
44 DisplayManager(std::string name = "");
45
51
56 DisplayManager(const DisplayManager &) = delete;
57
64
69 Status Initalise(uint32_t width, uint32_t height, bool fullscreen);
70 Status Initalise() override;
71
77 Resolution GetResolution() override;
78
84 int GetBytesPerPixel() final { return 4; }
85
91 mediax::rtp::ColourspaceType GetColourspace() final { return mediax::rtp::ColourspaceType::kColourspaceRgba; }
92
102 Status DisplayBuffer(uint8_t *frame_buffer, Resolution resolution, std::string text) override;
103
108 void Flush() override;
109
114 void ToggleFullscreen() override;
115
119 void Run() override;
120
125 void Stop() override;
126
128 static std::string text_;
129
130 private:
137 static void Activate(GtkApplication *app, gpointer user_data);
138
145 static void Destroy(GtkWidget *widget, gpointer data);
146
156 static void DrawCallback(GtkDrawingArea *area, cairo_t *cr, int width, int height, gpointer user_data);
157
166 static void DrawText(unsigned char *bitmap, int width, int height, const char *text);
167
175 static gboolean RenderCallback(GtkGLArea *area, GdkGLContext *context);
176
184 static void ResizeCallback(GtkGLArea *area, int width, int height);
185
191 static void RealizeCallback(GtkGLArea *area);
192
198 static void UnrealizeCallback(GtkGLArea *area);
199
201 static GLuint texture_;
203 static GLuint texture2_;
205 static std::vector<uint8_t> frame_buffer_;
207 static int width_;
209 static int height_;
211 bool initaliased_ = false;
213 static GtkApplication *app_;
215 static GtkWidget *window_;
217 static GtkWidget *drawing_area_;
219 static std::mutex frame_buffer_mutex_;
221 static std::vector<uint8_t> draw_buffer_;
223 static std::vector<uint8_t> draw_buffer_flip_;
225 static GtkWidget *gl_area_;
227 static bool fullscreen_;
229 static bool opengl_;
230};
231
232} // namespace mediax::gtk4
233
234#endif // HARDWARE_DISPLAY_MANAGER_GTK4_H_
The display manager class.
Definition display_manager_base.h:35
The display manager class.
Definition display_manager_gtk4.h:38
void Stop() override
Stop the main loop if there is one.
Definition display_manager_gtk4.cc:253
static void RealizeCallback(GtkGLArea *area)
Create the context.
Definition display_manager_gtk4.cc:144
static void Destroy(GtkWidget *widget, gpointer data)
Destroy the GTK4 window.
Definition display_manager_gtk4.cc:296
static std::vector< uint8_t > draw_buffer_flip_
The draw buffer flip.
Definition display_manager_gtk4.h:223
Status DisplayBuffer(uint8_t *frame_buffer, Resolution resolution, std::string text) override
Buffer must be in the format RGBA.
Definition display_manager_gtk4.cc:353
static void DrawCallback(GtkDrawingArea *area, cairo_t *cr, int width, int height, gpointer user_data)
Refesh the display.
Definition display_manager_gtk4.cc:181
bool initaliased_
Initalized flag.
Definition display_manager_gtk4.h:211
static GtkWidget * drawing_area_
The drawing area.
Definition display_manager_gtk4.h:217
static std::mutex frame_buffer_mutex_
The mutex for the frame buffer.
Definition display_manager_gtk4.h:219
static gboolean RenderCallback(GtkGLArea *area, GdkGLContext *context)
Render the display.
Definition display_manager_gtk4.cc:100
Status Initalise() override
Initalise the display manager.
Definition display_manager_gtk4.cc:222
static GtkApplication * app_
The GTK4 application.
Definition display_manager_gtk4.h:213
static GtkWidget * window_
The GTK4 window.
Definition display_manager_gtk4.h:215
void ToggleFullscreen() override
Toggle Fullscreen.
Definition display_manager_gtk4.cc:298
void Flush() override
Flush the framebuffer /dev/fb0.
Definition display_manager_gtk4.cc:312
static int height_
The default height.
Definition display_manager_gtk4.h:209
static void UnrealizeCallback(GtkGLArea *area)
Unrealize the context.
Definition display_manager_gtk4.cc:163
~DisplayManager()
Destroy the Display Manager object.
Definition display_manager_gtk4.cc:60
int GetBytesPerPixel() final
Get the Bits Per Pixel object.
Definition display_manager_gtk4.h:84
static GLuint texture2_
The second texture.
Definition display_manager_gtk4.h:203
static std::string text_
The text to display.
Definition display_manager_gtk4.h:128
static GLuint texture_
The frame buffer.
Definition display_manager_gtk4.h:201
static void DrawText(unsigned char *bitmap, int width, int height, const char *text)
Draw text on the screen.
static GtkWidget * gl_area_
The running flag.
Definition display_manager_gtk4.h:225
DisplayManager & operator=(const DisplayManager &)=delete
Delete the copy operator.
Resolution GetResolution() override
Get the Resolution attribute.
Definition display_manager_gtk4.cc:321
DisplayManager(const DisplayManager &)=delete
Construct a new Display Manager object (deleted)
mediax::rtp::ColourspaceType GetColourspace() final
Get the Colourspace object.
Definition display_manager_gtk4.h:91
void Run() override
Run the main event loop.
Definition display_manager_gtk4.cc:248
static std::vector< uint8_t > frame_buffer_
Frame buffer device.
Definition display_manager_gtk4.h:205
static bool fullscreen_
The running flag.
Definition display_manager_gtk4.h:227
static int width_
The default width.
Definition display_manager_gtk4.h:207
static bool opengl_
The running flag.
Definition display_manager_gtk4.h:229
static void ResizeCallback(GtkGLArea *area, int width, int height)
Resize the display.
Definition display_manager_gtk4.cc:98
static void Activate(GtkApplication *app, gpointer user_data)
GTK4 Activate callback.
Definition display_manager_gtk4.cc:258
static std::vector< uint8_t > draw_buffer_
The draw buffer.
Definition display_manager_gtk4.h:221
ColourspaceType
Supported colour spaces.
Definition rtp_types.h:102
Status
Enum of status.
Definition datatypes.h:21
The video resolution structure.
Definition datatypes.h:34