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:
19 static Display *x11display;
20 static Window x11window;
21 static DISPMANX_DISPLAY_HANDLE_T m_dispmanDisplay;
22 static EGL_DISPMANX_WINDOW_T m_nativeWindow;
24 static void get_window_rect(VC_RECT_T *rect)
26 XWindowAttributes xattrs_root;
27 uint32_t disp_w = 0, disp_h = 0;
29 unsigned int dw = 0, dh = 0, dummy;
32 graphics_get_display_size(0, &disp_w, &disp_h);
33 if (disp_w == 0 || disp_h == 0)
34 fprintf(stderr, "ERROR: graphics_get_display_size is broken\n");
36 // default to fullscreen
37 rect->x = rect->y = 0;
39 rect->height = disp_h;
41 if (x11display == NULL || x11window == 0)
42 return; // use fullscreen
44 XGetGeometry(x11display, x11window, &root, &dx, &dy, &dw, &dh,
46 XGetWindowAttributes(x11display, root, &xattrs_root);
48 if (dw == xattrs_root.width && dh == xattrs_root.height)
49 return; // use fullscreen
51 XTranslateCoordinates(x11display, x11window, root,
52 dx, dy, &dx, &dy, &dummyw);
54 // how to deal with that weird centering thing?
55 // this is not quite right..
56 dx += (disp_w - xattrs_root.width) / 2;
57 dy += (disp_h - xattrs_root.height) / 2;
65 static void submit_rect(void)
67 DISPMANX_UPDATE_HANDLE_T m_dispmanUpdate;
68 DISPMANX_ELEMENT_HANDLE_T m_dispmanElement;
69 VC_RECT_T srcRect = { 0, }; // unused, but we segfault without passing it??
72 get_window_rect(&dstRect);
74 m_dispmanDisplay = vc_dispmanx_display_open(0);
75 m_dispmanUpdate = vc_dispmanx_update_start(0);
77 m_dispmanElement = vc_dispmanx_element_add(m_dispmanUpdate,
78 m_dispmanDisplay, 0, &dstRect, 0, &srcRect,
79 DISPMANX_PROTECTION_NONE, 0, 0, DISPMANX_NO_ROTATE);
81 m_nativeWindow.element = m_dispmanElement;
82 m_nativeWindow.width = dstRect.width;
83 m_nativeWindow.height = dstRect.height;
85 vc_dispmanx_update_submit_sync(m_dispmanUpdate);
88 int gl_platform_init(void **display, void **window, int *quirks)
90 x11display = *display;
91 x11window = (Window)*window;
96 *display = EGL_DEFAULT_DISPLAY;
97 *window = &m_nativeWindow;
98 *quirks |= GL_QUIRK_ACTIVATE_RECREATE;
103 void gl_platform_finish(void)
105 vc_dispmanx_display_close(m_dispmanDisplay);
111 int gl_platform_init(void **display, void **window, int *quirks)
116 void gl_platform_finish(void)