summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2013-01-04 15:47:13 -0800
committerMartin Robinson <mrobinson@igalia.com>2013-01-04 16:29:51 -0800
commit9bff4508443abe002fcb0ffdb9b1897272f1c588 (patch)
tree0140ce5cbe425293dee57408e80d79b3efc18d33
parent8cd604e18adc1dbe22303d5c57dae374d7e8cd2b (diff)
downloadcairo-9bff4508443abe002fcb0ffdb9b1897272f1c588.tar.gz
boilerplate/glx: Add a target with multisampling and stencil support
Add a gl-window target that supports multisampling. This is useful for testing the MSAA backend on the default framebuffer.
-rw-r--r--boilerplate/cairo-boilerplate-glx.c170
1 files changed, 96 insertions, 74 deletions
diff --git a/boilerplate/cairo-boilerplate-glx.c b/boilerplate/cairo-boilerplate-glx.c
index 28026dccc..52cd99f9b 100644
--- a/boilerplate/cairo-boilerplate-glx.c
+++ b/boilerplate/cairo-boilerplate-glx.c
@@ -144,32 +144,21 @@ _cairo_boilerplate_gl_create_surface (const char *name,
}
static cairo_surface_t *
-_cairo_boilerplate_gl_create_window (const char *name,
- cairo_content_t content,
- double width,
- double height,
- double max_width,
- double max_height,
- cairo_boilerplate_mode_t mode,
- void **closure)
+_cairo_boilerplate_gl_create_window_common (int rgba_attribs[],
+ cairo_content_t content,
+ double width,
+ double height,
+ double max_width,
+ double max_height,
+ cairo_boilerplate_mode_t mode,
+ gl_target_closure_t *gltc)
{
- 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 *vi;
GLXContext ctx;
- gl_target_closure_t *gltc;
cairo_surface_t *surface;
Display *dpy;
XSetWindowAttributes attr;
- gltc = calloc (1, sizeof (gl_target_closure_t));
- *closure = gltc;
-
width = ceil (width);
height = ceil (height);
@@ -219,13 +208,75 @@ _cairo_boilerplate_gl_create_window (const char *name,
gltc->surface = surface = cairo_gl_surface_create_for_window (gltc->device,
gltc->drawable,
width, height);
- if (cairo_surface_status (surface))
+ if (cairo_surface_status (surface)) {
_cairo_boilerplate_gl_cleanup (gltc);
-
+ return NULL;
+ }
return surface;
}
static cairo_surface_t *
+_cairo_boilerplate_gl_create_window (const char *name,
+ cairo_content_t content,
+ double width,
+ double height,
+ double max_width,
+ double max_height,
+ cairo_boilerplate_mode_t mode,
+ void **closure)
+{
+ gl_target_closure_t *gltc;
+
+ int rgba_attribs[] = { GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_ALPHA_SIZE, 1,
+ GLX_DOUBLEBUFFER,
+ None };
+
+ gltc = calloc (1, sizeof (gl_target_closure_t));
+ *closure = gltc;
+
+ return _cairo_boilerplate_gl_create_window_common (rgba_attribs, content,
+ width, height,
+ max_width, max_height,
+ mode, gltc);
+}
+
+static cairo_surface_t *
+_cairo_boilerplate_gl_create_window_msaa (const char *name,
+ cairo_content_t content,
+ double width,
+ double height,
+ double max_width,
+ double max_height,
+ cairo_boilerplate_mode_t mode,
+ void **closure)
+{
+ gl_target_closure_t *gltc;
+
+ int rgba_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 };
+
+ gltc = calloc (1, sizeof (gl_target_closure_t));
+ *closure = gltc;
+ return _cairo_boilerplate_gl_create_window_common (rgba_attribs, content,
+ width, height,
+ max_width, max_height,
+ mode, gltc);
+
+}
+
+static cairo_surface_t *
_cairo_boilerplate_gl_create_window_db (const char *name,
cairo_content_t content,
double width,
@@ -235,6 +286,10 @@ _cairo_boilerplate_gl_create_window_db (const char *name,
cairo_boilerplate_mode_t mode,
void **closure)
{
+ cairo_status_t status;
+ cairo_surface_t *surface;
+ gl_target_closure_t *gltc;
+
int rgba_attribs[] = { GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
@@ -242,66 +297,18 @@ _cairo_boilerplate_gl_create_window_db (const char *name,
GLX_ALPHA_SIZE, 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;
- width = ceil (width);
- height = ceil (height);
-
- if (width == 0)
- width = 1;
- if (height == 0)
- height = 1;
+ surface = _cairo_boilerplate_gl_create_window_common (rgba_attribs, content,
+ width, height,
+ max_width, max_height,
+ mode, gltc);
- 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), rgba_attribs);
- if (vi == NULL) {
- fprintf (stderr, "Failed to create RGBA, double-buffered visual\n");
- XCloseDisplay (dpy);
- free (gltc);
+ if (! surface)
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,
- width, 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)
@@ -414,6 +421,21 @@ static const cairo_boilerplate_target_t targets[] = {
FALSE, FALSE, FALSE
},
{
+ "gl-window-msaa", "gl", NULL, NULL,
+ CAIRO_SURFACE_TYPE_GL, CAIRO_CONTENT_COLOR_ALPHA, 1,
+ "cairo_gl_surface_create_for_window",
+ _cairo_boilerplate_gl_create_window_msaa,
+ cairo_surface_create_similar,
+ NULL,
+ _cairo_boilerplate_gl_finish_window,
+ _cairo_boilerplate_get_image_surface,
+ cairo_surface_write_to_png,
+ _cairo_boilerplate_gl_cleanup,
+ _cairo_boilerplate_gl_synchronize,
+ _cairo_boilerplate_gl_describe,
+ FALSE, FALSE, FALSE
+ },
+ {
"gl-window&", "gl", NULL, NULL,
CAIRO_SURFACE_TYPE_GL, CAIRO_CONTENT_COLOR_ALPHA, 1,
"cairo_gl_surface_create_for_window",