-
Notifications
You must be signed in to change notification settings - Fork 4
/
bcm_host.c
417 lines (348 loc) · 10.5 KB
/
bcm_host.c
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
#include <stdio.h>
#include <stdint.h>
#include <EGL/egl.h>
#include <GLES/gl.h>
#include <dlfcn.h>
#include <SDL.h>
#include <SDL_syswm.h>
void link_libglesv1_cm(void) __attribute__((constructor));
typedef void* DISPMANX_ELEMENT_HANDLE_T;
typedef void* DISPMANX_DISPLAY_HANDLE_T;
typedef void* DISPMANX_UPDATE_HANDLE_T;
typedef void* DISPMANX_RESOURCE_HANDLE_T;
typedef void* DISPMANX_PROTECTION_T;
typedef void* VC_DISPMANX_ALPHA_T;
typedef void* DISPMANX_CLAMP_T;
typedef void* DISPMANX_TRANSFORM_T;
typedef int VC_RECT_T;
typedef struct {
DISPMANX_ELEMENT_HANDLE_T element;
int width; /* This is necessary because dispmanx elements are not queriable. */
int height;
} EGL_DISPMANX_WINDOW_T;
void *libXext;
void *libGLESv1_CM;
/*
int gcoOS_DestroyContext() {
printf("gcoOS_DestroyContext()\n");
return NULL;
}
*/
static void *dlsym_assert(void *handle, const char *symbol) {
void *ret;
ret = dlsym(handle, symbol);
if (!ret) {
char err[2048];
snprintf(err, sizeof(err)-1, "Unable to get %s", symbol);
perror(err);
exit(1);
}
return ret;
}
static void *get_from_libEGL(const char *symbol) {
static void *libEGL;
if (!libEGL) {
libEGL = dlopen("libEGL.so", RTLD_LAZY);
if (!libEGL) {
perror("Unable to open libEGL.so");
exit(1);
}
}
return dlsym_assert(libEGL, symbol);
}
/*
void *XextAddDisplay (void *extinfo, void *dpy, char *ext_name,
void *hooks, int nevents, void *data) {
void *result;
static void *last_result;
static void *(*XextAddDisplayReal) (void *extinfo, void *dpy, char *ext_name,
void *hooks, int nevents, void *data);
static int counter = 0;
static int total_counter = 0;
printf("XextAddDisplay(%p, %p, %s, %p, %d, %p) %d\n", extinfo, dpy, ext_name, hooks, nevents, data, total_counter++);
if (!XextAddDisplayReal) {
if (!libXext) {
libXext = dlopen("libXext.so.6", RTLD_LAZY);
if (!libXext) {
perror("Unable to open libXext.so");
exit(1);
}
}
XextAddDisplayReal = dlsym_assert(libXext, "XextAddDisplay");
}
if (!strcmp(ext_name, "XFree86-DRI")) {
counter++;
if (counter == 1) {
printf("Skipping!\n");
return last_result;
}
}
result = XextAddDisplayReal(extinfo, dpy, ext_name, hooks, nevents, data);
if (!strcmp(ext_name, "XFree86-DRI"))
last_result = result;
printf("Result of XextAddDisplayReal(): %p\n", result);
return result;
}
*/
EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI(EGLenum api)
{
static EGLBoolean (*eglBindAPIReal)(EGLenum api);
static EGLBoolean ret;
static int counter = 0;
fprintf(stderr, "eglBindAPI(%d): ", api);
if (!eglBindAPIReal)
eglBindAPIReal = get_from_libEGL("eglBindAPI");
switch(counter++) {
default:
ret = eglBindAPIReal(api);
fprintf(stderr, "%d\n", ret);
return ret;
}
}
EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy)
{
static EGLBoolean (*eglTerminateReal)(EGLDisplay dpy);
static EGLBoolean ret;
static int counter = 0;
fprintf(stderr, "eglTerminateReal(%p): ", dpy);
if (!eglTerminateReal)
eglTerminateReal = get_from_libEGL("eglTerminate");
switch(counter++) {
case 0:
fprintf(stderr, "1 (lying)\n");
return 1;
default:
ret = eglTerminateReal(dpy);
fprintf(stderr, "%d\n", ret);
return ret;
}
}
EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
{
static EGLBoolean (*eglDestroySurfaceReal)(EGLDisplay dpy, EGLSurface surface);
static EGLBoolean ret;
static int counter = 0;
fprintf(stderr, "eglDestroySurface(%d, %d): ", dpy, surface);
if (!eglDestroySurfaceReal)
eglDestroySurfaceReal = get_from_libEGL("eglDestroySurface");
switch(counter++) {
case 0:
case 1:
fprintf(stderr, "1 (lying)\n");
return 1;
default:
ret = eglDestroySurfaceReal(dpy, surface);
fprintf(stderr, "%d\n", ret);
return ret;
}
}
EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
{
static EGLBoolean (*eglSwapBuffersReal)(EGLDisplay dpy, EGLSurface surface);
static EGLBoolean ret;
static int counter = 0;
// fprintf(stderr, "eglSwapBuffers(%p, %p): ", dpy, surface);
if (!eglSwapBuffersReal)
eglSwapBuffersReal = get_from_libEGL("eglSwapBuffers");
switch(counter++) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
fprintf(stderr, "1 (guessed)\n");
return 1;
default:
ret = eglSwapBuffersReal(dpy, surface);
//fprintf(stderr, "%d\n", ret);
return ret;
}
}
EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config,
EGLContext share_context,
const EGLint *attrib_list)
{
static EGLContext (*eglCreateContextReal)(EGLDisplay dpy, EGLConfig config,
EGLContext share_context,
const EGLint *attrib_list);
static EGLContext *ret;
static int counter = 0;
fprintf(stderr, "eglCreateContext(%p, %p, %p, %p): ", dpy, config, share_context, attrib_list);
if (!eglCreateContextReal)
eglCreateContextReal = get_from_libEGL("eglCreateContext");
switch(counter++) {
case 0:
fprintf(stderr, "NULL (guessed)\n");
return NULL;
case 1:
ret = eglCreateContextReal(dpy, config, share_context, attrib_list);
fprintf(stderr, "%p\n", ret);
return ret;
default:
fprintf(stderr, "%p (cached)\n", ret);
return ret;
}
}
EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list,
EGLConfig *configs, EGLint config_size,
EGLint *num_config)
{
static EGLBoolean (*eglChooseConfigReal)(EGLDisplay dpy, const EGLint *attrib_list,
EGLConfig *configs, EGLint config_size,
EGLint *num_config);
static EGLBoolean ret;
static int counter = 0;
fprintf(stderr, "eglChooseConfig(%p, %p, %p, %d, %p): ", dpy, attrib_list, configs, config_size, num_config);
if (!eglChooseConfigReal)
eglChooseConfigReal = get_from_libEGL("eglChooseConfig");
switch(counter++) {
case 0:
fprintf(stderr, "1 (guessed)\n");
return 1;
case 1:
ret = eglChooseConfigReal(dpy, attrib_list, configs, config_size, num_config);
fprintf(stderr, "%d\n", ret);
return ret;
default:
fprintf(stderr, "%d (cached)\n", ret);
return ret;
}
}
EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
{
static EGLBoolean (*eglInitializeReal)(EGLDisplay dpy, EGLint *major, EGLint *minor);
static EGLBoolean ret;
static int counter = 0;
fprintf(stderr, "eglInitialize(%p, %p, %p): ", dpy, major, minor);
if (!eglInitializeReal)
eglInitializeReal = get_from_libEGL("eglInitialize");
switch(counter++) {
case 0:
fprintf(stderr, "1 (guessed)\n");
return 1;
case 1:
ret = eglInitializeReal(dpy, major, minor);
fprintf(stderr, "%d\n", ret);
return ret;
default:
fprintf(stderr, "%d (cached)\n", ret);
return ret;
}
}
EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw,
EGLSurface read, EGLContext ctx)
{
static EGLBoolean (*eglMakeCurrentReal)(EGLDisplay dpy, EGLSurface draw,
EGLSurface read, EGLContext ctx);
static EGLBoolean ret;
static int counter = 0;
fprintf(stderr, "eglMakeCurrent(%p, %p, %p, %p): ", dpy, draw, read, ctx);
if (!eglMakeCurrentReal)
eglMakeCurrentReal = get_from_libEGL("eglMakeCurrent");
switch(counter++) {
case 0:
case 1:
fprintf(stderr, "1 (guessed)\n");
return 1;
case 2:
ret = eglMakeCurrentReal(dpy, draw, read, ctx);
fprintf(stderr, "%d\n", ret);
return ret;
default:
fprintf(stderr, "%d (cached)\n", ret);
return ret;
}
}
EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id)
{
static EGLDisplay (*eglGetDisplayReal)(EGLNativeDisplayType display_id);
static EGLDisplay ret;
static int counter = 0;
fprintf(stderr, "eglGetDisplay(%d): ", display_id);
if (!eglGetDisplayReal)
eglGetDisplayReal = get_from_libEGL("eglGetDisplay");
switch(counter++) {
case 0:
fprintf(stderr, "4 (lying)\n");
return (void *)4;
case 1:
ret = eglGetDisplayReal(display_id);
fprintf(stderr, "%p\n", ret);
return ret;
default:
fprintf(stderr, "%p (cached)\n", ret);
return ret;
}
}
EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
EGLNativeWindowType win,
const EGLint *attrib_list) {
static int counter = 0;
static EGLSurface (*eglCreateWindowSurfaceReal)(EGLDisplay dpy, EGLConfig config,
EGLNativeWindowType win,
const EGLint *attrib_list);
static EGLSurface *ret;
SDL_SysWMinfo sysInfo; //Will hold our Window information
fprintf(stderr, "eglCreateWindowSurface(%p, %p, %p, %p): ", dpy, config, win, attrib_list);
if (!eglCreateWindowSurfaceReal)
eglCreateWindowSurfaceReal = get_from_libEGL("eglCreateWindowSurface");
switch(counter++) {
case 0:
fprintf(stderr, "0x4 (guessed)\n");
return (EGLSurface)0x4;
case 1:
SDL_VERSION(&sysInfo.version); //Set SDL version
if(SDL_GetWMInfo(&sysInfo) <= 0)
{
fprintf(stderr, "Unable to get window handle");
return 0;
}
ret = eglCreateWindowSurfaceReal(dpy, config, (EGLNativeWindowType)sysInfo.info.x11.window, attrib_list);
fprintf(stderr, "%p\n", ret);
return ret;
default:
fprintf(stderr, "%p (cached)\n", ret);
return ret;
}
}
int32_t graphics_get_display_size( const uint16_t display_number, uint32_t *width, uint32_t *height) {
printf("graphics_get_display_size(%d, %p, %p)\n", display_number, width, height);
*width = 2560;
*height = 1700;
SDL_SetVideoMode(*width, *height, 32, SDL_FULLSCREEN);// | SDL_RESIZABLE);
return 0;
}
int vc_dispmanx_display_open(int device) {
printf("vc_dispmanx_display_open(%d)\n", device);
return 0;
}
DISPMANX_ELEMENT_HANDLE_T vc_dispmanx_element_add ( DISPMANX_UPDATE_HANDLE_T update,
DISPMANX_DISPLAY_HANDLE_T display,
int32_t layer, const VC_RECT_T *dest_rect, DISPMANX_RESOURCE_HANDLE_T src,
const VC_RECT_T *src_rect, DISPMANX_PROTECTION_T protection,
VC_DISPMANX_ALPHA_T *alpha,
DISPMANX_CLAMP_T *clamp, DISPMANX_TRANSFORM_T transform ) {
printf("vc_dispmanx_element_add(%p, %p, %d, %p, %p, %p, %p, %p, %p, %p)\n",
update, display, layer, dest_rect, src, src_rect, protection,
alpha, clamp, transform);
return NULL;
}
int vc_dispmanx_update_submit_sync( DISPMANX_UPDATE_HANDLE_T update ) {
printf("vc_dispmanx_update_submit_sync(%p)\n", update);
return 0;
}
void bcm_host_deinit(void) {
printf("bcm_host_deinit()\n");
return;
}
int vc_dispmanx_update_start( int32_t priority ) {
printf("vc_dispmanx_update_start(%d)\n", priority);
return 0;
}
void bcm_host_init(void) {
printf("bcm_host_init()\n");
return;
}