static cairo_surface_t* create_source_surface(int width, int height) { int rgba_attribs[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_ALPHA_SIZE, 1, GLX_DOUBLEBUFFER, None }; XVisualInfo *visinfo; GLXContext ctx; struct closure *arg; cairo_device_t *device; cairo_surface_t *surface; Display *dpy; dpy = XOpenDisplay(NULL); if (dpy == NULL) return NULL; visinfo = glXChooseVisual (dpy, DefaultScreen (dpy), rgba_attribs); if (visinfo == NULL) { XCloseDisplay (dpy); return NULL; } ctx = glXCreateContext (dpy, visinfo, NULL, True); XFree (visinfo); if (ctx == NULL) { XCloseDisplay (dpy); return NULL; } arg = (struct closure*)(malloc (sizeof (struct closure))); arg->dpy = dpy; arg->ctx = ctx; device = cairo_glx_device_create (dpy, ctx); if (cairo_device_set_user_data (device, (cairo_user_data_key_t *) cleanup, arg, cleanup)) { cleanup (arg); return NULL; } surface = cairo_gl_surface_create (device, CAIRO_CONTENT_COLOR_ALPHA, width, height); cairo_device_destroy (device); return surface; }
cairo_device_t* GLContextGLX::cairoDevice() { if (m_cairoDevice) return m_cairoDevice; #if ENABLE(ACCELERATED_2D_CANVAS) && CAIRO_HAS_GLX_FUNCTIONS m_cairoDevice = cairo_glx_device_create(m_x11Display, m_context.get()); #endif return m_cairoDevice; }
static cairo_surface_t * _cairo_boilerplate_gl_create_surface (const char *name, cairo_content_t content, double width, double height, double max_width, double max_height, cairo_boilerplate_mode_t mode, void **closure) { int rgba_attribs[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_ALPHA_SIZE, 1, GLX_DOUBLEBUFFER, None }; int rgb_attribs[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, None }; XVisualInfo *visinfo; GLXContext ctx; gl_target_closure_t *gltc; cairo_surface_t *surface; Display *dpy; gltc = calloc (1, sizeof (gl_target_closure_t)); *closure = gltc; if (width == 0) width = 1; if (height == 0) height = 1; dpy = XOpenDisplay (NULL); gltc->dpy = dpy; if (!gltc->dpy) { fprintf (stderr, "Failed to open display: %s\n", XDisplayName(0)); free (gltc); return NULL; } if (mode == CAIRO_BOILERPLATE_MODE_TEST) XSynchronize (gltc->dpy, 1); if (content == CAIRO_CONTENT_COLOR) visinfo = glXChooseVisual (dpy, DefaultScreen (dpy), rgb_attribs); else visinfo = glXChooseVisual (dpy, DefaultScreen (dpy), rgba_attribs); if (visinfo == NULL) { fprintf (stderr, "Failed to create RGB, double-buffered visual\n"); XCloseDisplay (dpy); free (gltc); return NULL; } ctx = glXCreateContext (dpy, visinfo, NULL, True); XFree (visinfo); gltc->ctx = ctx; gltc->device = cairo_glx_device_create (dpy, ctx); gltc->surface = surface = cairo_gl_surface_create (gltc->device, content, ceil (width), ceil (height)); if (cairo_surface_status (surface)) _cairo_boilerplate_gl_cleanup (gltc); return surface; }
static cairo_surface_t * _cairo_boilerplate_gl_create_window_db (const char *name, cairo_content_t content, double width, double height, double max_width, double max_height, cairo_boilerplate_mode_t mode, void **closure) { int rgba_attribs[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_ALPHA_SIZE, 1, GLX_DOUBLEBUFFER, None }; int msaa_attribs[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_ALPHA_SIZE, 1, GLX_STENCIL_SIZE, 1, GLX_SAMPLES, 4, GLX_SAMPLE_BUFFERS, 1, GLX_DOUBLEBUFFER, None }; XVisualInfo *vi; GLXContext ctx; gl_target_closure_t *gltc; cairo_surface_t *surface; Display *dpy; XSetWindowAttributes attr; cairo_status_t status; gltc = calloc (1, sizeof (gl_target_closure_t)); *closure = gltc; if (width == 0) width = 1; if (height == 0) height = 1; dpy = XOpenDisplay (NULL); gltc->dpy = dpy; if (!gltc->dpy) { fprintf (stderr, "Failed to open display: %s\n", XDisplayName(0)); free (gltc); return NULL; } if (mode == CAIRO_BOILERPLATE_MODE_TEST) XSynchronize (gltc->dpy, 1); vi = glXChooseVisual (dpy, DefaultScreen (dpy), msaa_attribs); if (vi == NULL) vi = glXChooseVisual (dpy, DefaultScreen (dpy), rgba_attribs); if (vi == NULL) { fprintf (stderr, "Failed to create RGBA, double-buffered visual\n"); XCloseDisplay (dpy); free (gltc); return NULL; } attr.colormap = XCreateColormap (dpy, RootWindow (dpy, vi->screen), vi->visual, AllocNone); attr.border_pixel = 0; attr.override_redirect = True; gltc->drawable = XCreateWindow (dpy, DefaultRootWindow (dpy), 0, 0, width, height, 0, vi->depth, InputOutput, vi->visual, CWOverrideRedirect | CWBorderPixel | CWColormap, &attr); XMapWindow (dpy, gltc->drawable); ctx = glXCreateContext (dpy, vi, NULL, True); XFree (vi); gltc->ctx = ctx; gltc->device = cairo_glx_device_create (dpy, ctx); gltc->surface = cairo_gl_surface_create_for_window (gltc->device, gltc->drawable, ceil (width), ceil (height)); surface = cairo_surface_create_similar (gltc->surface, content, width, height); status = cairo_surface_set_user_data (surface, &gl_closure_key, gltc, NULL); if (status == CAIRO_STATUS_SUCCESS) return surface; cairo_surface_destroy (surface); _cairo_boilerplate_gl_cleanup (gltc); return cairo_boilerplate_surface_create_in_error (status); }