7 #include "gl_platform.h"
12 * hacks for Broadcom VideoCore / Raspberry Pi..
13 * Why do I have to do this proprietary API stuff,
14 * couldn't they implement EGL properly? D:
20 static Display *x11display;
21 static Window x11window;
22 static DISPMANX_DISPLAY_HANDLE_T m_dispmanDisplay;
23 static EGL_DISPMANX_WINDOW_T m_nativeWindow;
26 #define FPTR(f) typeof(f) * p##f
27 static FPTR(XGetGeometry);
28 static FPTR(XGetWindowAttributes);
29 static FPTR(XTranslateCoordinates);
31 static void get_window_rect(VC_RECT_T *rect)
33 XWindowAttributes xattrs_root;
34 uint32_t disp_w = 0, disp_h = 0;
36 unsigned int dw = 0, dh = 0, dummy;
39 graphics_get_display_size(0, &disp_w, &disp_h);
40 if (disp_w == 0 || disp_h == 0)
41 fprintf(stderr, "ERROR: graphics_get_display_size is broken\n");
43 // default to fullscreen
44 rect->x = rect->y = 0;
46 rect->height = disp_h;
48 if (x11display == NULL || x11window == 0)
49 return; // use fullscreen
51 pXGetGeometry(x11display, x11window, &root, &dx, &dy, &dw, &dh,
53 pXGetWindowAttributes(x11display, root, &xattrs_root);
55 if (dw == xattrs_root.width && dh == xattrs_root.height)
56 return; // use fullscreen
58 pXTranslateCoordinates(x11display, x11window, root,
59 dx, dy, &dx, &dy, &dummyw);
61 // how to deal with that weird centering thing?
62 // this is not quite right..
63 dx += (disp_w - xattrs_root.width) / 2;
64 dy += (disp_h - xattrs_root.height) / 2;
72 static void submit_rect(void)
74 DISPMANX_UPDATE_HANDLE_T m_dispmanUpdate;
75 DISPMANX_ELEMENT_HANDLE_T m_dispmanElement;
76 VC_RECT_T srcRect = { 0, }; // unused, but we segfault without passing it??
79 get_window_rect(&dstRect);
81 m_dispmanDisplay = vc_dispmanx_display_open(0);
82 m_dispmanUpdate = vc_dispmanx_update_start(0);
84 m_dispmanElement = vc_dispmanx_element_add(m_dispmanUpdate,
85 m_dispmanDisplay, 0, &dstRect, 0, &srcRect,
86 DISPMANX_PROTECTION_NONE, 0, 0, DISPMANX_NO_ROTATE);
88 m_nativeWindow.element = m_dispmanElement;
89 m_nativeWindow.width = dstRect.width;
90 m_nativeWindow.height = dstRect.height;
92 vc_dispmanx_update_submit_sync(m_dispmanUpdate);
95 int gl_platform_init(void **display, void **window, int *quirks)
100 x11lib = dlopen("libX11.so.6", RTLD_LAZY);
101 if (x11lib != NULL) {
102 pXGetGeometry = dlsym(x11lib, "XGetGeometry");
103 pXGetWindowAttributes = dlsym(x11lib, "XGetWindowAttributes");
104 pXTranslateCoordinates = dlsym(x11lib, "XTranslateCoordinates");
105 if (pXGetGeometry != NULL && pXGetWindowAttributes != NULL
106 && pXTranslateCoordinates != NULL)
108 x11display = *display;
109 x11window = (Window)*window;
116 *display = EGL_DEFAULT_DISPLAY;
117 *window = &m_nativeWindow;
118 *quirks |= GL_QUIRK_ACTIVATE_RECREATE;
123 void gl_platform_finish(void)
125 vc_dispmanx_display_close(m_dispmanDisplay);
139 int gl_platform_init(void **display, void **window, int *quirks)
144 void gl_platform_finish(void)