Created
August 25, 2020 06:36
-
-
Save yshui/d7b68429ceaf9543162cfb211e1504e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <GL/glx.h> | |
#include <X11/X.h> | |
#include <X11/Xlib-xcb.h> | |
#include <stddef.h> | |
#include <stdio.h> | |
#include <stdbool.h> | |
#include <stdlib.h> | |
#include <xcb/xcb.h> | |
#include <xcb/xfixes.h> | |
#define auto __auto_type | |
xcb_screen_t *x_screen_of_display(xcb_connection_t *c, int screen) { | |
xcb_screen_iterator_t iter; | |
iter = xcb_setup_roots_iterator(xcb_get_setup(c)); | |
for (; iter.rem; --screen, xcb_screen_next(&iter)) | |
if (screen == 0) | |
return iter.data; | |
return NULL; | |
} | |
void make_create_region_requests(xcb_connection_t *c) { | |
int r = random() % 200 + 30; | |
static int last_id = 0; | |
for (int i = 0; i < r; i++) { | |
auto region = xcb_generate_id(c); | |
if (region < last_id) { | |
fprintf(stderr, "id wrapped, was %#010x, now %#010x\n", last_id, region); | |
} | |
last_id = region; | |
auto e = xcb_request_check( | |
c, xcb_xfixes_create_region_checked(c, region, 0, NULL)); | |
if (e) { | |
fprintf(stderr, | |
"create region error, is idchoice: %d, %d\n", | |
e->error_code == XCB_ID_CHOICE, | |
e->error_code); | |
abort(); | |
} | |
// randomly keep some of the regions, so GetXIDRange won't just | |
// return the whole range always. | |
if (random() % 16) { | |
auto e = xcb_request_check(c, xcb_xfixes_destroy_region_checked(c, region)); | |
if (e) { | |
fprintf(stderr, "cannot destroy region"); | |
} | |
} | |
} | |
} | |
int main() { | |
auto dpy = XOpenDisplay(NULL); | |
auto scr = DefaultScreen(dpy); | |
auto root = RootWindow(dpy, scr); | |
auto c = XGetXCBConnection(dpy); | |
xcb_prefetch_extension_data(c, &xcb_xfixes_id); | |
xcb_xfixes_query_version(c, XCB_XFIXES_MAJOR_VERSION, XCB_XFIXES_MINOR_VERSION); | |
auto scrp = x_screen_of_display(c, scr); | |
auto vis = scrp->root_visual; | |
XVisualInfo vreq = {.visualid = vis}; | |
int nitems = 0; | |
auto xvis = XGetVisualInfo(dpy, VisualIDMask, &vreq, &nitems); | |
auto ctx = glXCreateContext(dpy, xvis, 0, 1); | |
auto pixmap = xcb_generate_id(c); | |
auto e = xcb_request_check( | |
c, xcb_create_pixmap_checked(c, 24, pixmap, root, 100, 100)); | |
glXMakeCurrent(dpy, pixmap, ctx); | |
auto fbcfg = | |
glXChooseFBConfig(dpy, scr, (const int[]){None}, &nitems); | |
while (true) { | |
auto glx_pixmap = glXCreatePixmap(dpy, fbcfg[0], pixmap, NULL); | |
//fprintf(stderr, "A%#010x\n", glx_pixmap); | |
make_create_region_requests(c); | |
//fprintf(stderr, "B%#010x\n", glx_pixmap); | |
glXDestroyPixmap(dpy, glx_pixmap); | |
make_create_region_requests(c); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment