/
egl-rpi-fb.cpp
170 lines (134 loc) · 4.77 KB
/
egl-rpi-fb.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
Copyright (c) 2014 Harm Hanemaaijer <fgenfb@yahoo.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <sys/time.h>
#include <assert.h>
#include <bcm_host.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <EGL/eglplatform.h>
#include <GLES2/gl2.h>
#include "sre.h"
#include "sreBackend.h"
#include "gui-common.h"
#include "egl-common.h"
#include "linux-fb-ui.h"
class sreBackendGLES2RPIFB : public sreBackend {
public :
virtual void Initialize(int *argc, char ***argv, int requested_width,
int requested_height, int& actual_width, int& actual_height, unsigned int backend_flags);
virtual void Finalize();
virtual void GLSwapBuffers();
virtual void GLSync();
virtual double GetCurrentTime();
virtual void ProcessGUIEvents();
virtual void ToggleFullScreenMode(int& width, int& height,
bool pan_with_mouse);
virtual void HideCursor();
virtual void RestoreCursor();
virtual void WarpCursor(int x, int y);
};
sreBackend *sreCreateBackendGLES2RPIFB() {
sreBackend *b = new sreBackendGLES2RPIFB;
b->name = "OpenGL-ES2.0 Raspberry Pi Framebuffer";
return b;
}
void *EGLGetNativeDisplay() {
return (void *)EGL_DEFAULT_DISPLAY;
}
#define check() assert(glGetError() == 0)
static EGL_DISPMANX_WINDOW_T native_window;
void EGLInitializeSubsystemWindow(int requested_width, int requested_height,
int& width, int& height, void *&window) {
bcm_host_init();
int success = graphics_get_display_size(0 /* LCD */,
(uint32_t *)&width, (uint32_t *)&height);
assert(success >= 0);
static EGL_DISPMANX_WINDOW_T native_window;
DISPMANX_ELEMENT_HANDLE_T dispman_element;
DISPMANX_DISPLAY_HANDLE_T dispman_display;
DISPMANX_UPDATE_HANDLE_T dispman_update;
VC_RECT_T dst_rect;
VC_RECT_T src_rect;
dst_rect.x = 0;
dst_rect.y = 0;
dst_rect.width = width;
dst_rect.height = height;
src_rect.x = 0;
src_rect.y = 0;
src_rect.width = width << 16;
src_rect.height = height << 16;
dispman_display = vc_dispmanx_display_open(0 /* LCD */);
dispman_update = vc_dispmanx_update_start(0);
VC_DISPMANX_ALPHA_T alpha;
alpha.flags = DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS;
alpha.opacity = 0xFF;
alpha.mask = DISPMANX_NO_HANDLE;
dispman_element = vc_dispmanx_element_add(dispman_update, dispman_display,
0/*layer*/, &dst_rect, 0/*src*/,
&src_rect, DISPMANX_PROTECTION_NONE, &alpha /*alpha*/, 0/*clamp*/,
(DISPMANX_TRANSFORM_T)0/*transform*/);
// nativewindow.element = dispman_element;
// nativewindow.width = width;
// nativewindow.height = height;
vc_dispmanx_update_submit_sync(dispman_update);
check();
LinuxFBInitializeUI(width, height);
native_window.element = dispman_element;
native_window.width = width;
native_window.height = height;
window = &native_window;
}
void EGLDeinitializeSubsystem() {
LinuxFBRestoreConsoleState();
}
// Back-end class implementation.
void sreBackendGLES2RPIFB::Initialize(int *argc, char ***argv,
int requested_width, int requested_height,
int& actual_width, int& actual_height, unsigned int backend_flags) {
EGLInitialize(argc, argv, requested_width, requested_height,
actual_width, actual_height, backend_flags);
// The Linux console mouse interface has relatively low sensitivity.
// Also reverse the y movement.
mouse_sensitivity = Vector2D(2.0f, - 2.0f);
flags |= SRE_BACKEND_FLAG_START_WITH_MOUSE_PANNING;
}
void sreBackendGLES2RPIFB::Finalize() {
EGLFinalize();
}
void sreBackendGLES2RPIFB::GLSwapBuffers() {
EGLSwapBuffers();
}
void sreBackendGLES2RPIFB::GLSync() {
EGLSync();
}
double sreBackendGLES2RPIFB::GetCurrentTime() {
return LinuxFBGetCurrentTime();
}
void sreBackendGLES2RPIFB::ProcessGUIEvents() {
LinuxFBProcessGUIEvents();
}
void sreBackendGLES2RPIFB::ToggleFullScreenMode(int& width, int& height,
bool pan_with_mouse) {
}
void sreBackendGLES2RPIFB::HideCursor() {
}
void sreBackendGLES2RPIFB::RestoreCursor() {
}
void sreBackendGLES2RPIFB::WarpCursor(int x, int y) {
LinuxFBWarpCursor(x, y);
}