📄 cairo-test.c
字号:
int height = test->height; glitz_glx_target_closure_t *gxtc; glitz_surface_t * glitz_surface; cairo_surface_t * surface; *closure = gxtc = xmalloc (sizeof (glitz_glx_target_closure_t)); if (width == 0) width = 1; if (height == 0) height = 1; gxtc->dpy = XOpenDisplay (getenv("CAIRO_TEST_GLITZ_DISPLAY")); if (!gxtc->dpy) { cairo_test_log ("Failed to open display: %s\n", XDisplayName(0)); goto FAIL; } XSynchronize (gxtc->dpy, 1); gxtc->scr = DefaultScreen(gxtc->dpy); switch (content) { case CAIRO_CONTENT_COLOR: glitz_surface = create_glitz_glx_surface (GLITZ_STANDARD_RGB24, width, height, gxtc); break; case CAIRO_CONTENT_COLOR_ALPHA: glitz_surface = create_glitz_glx_surface (GLITZ_STANDARD_ARGB32, width, height, gxtc); break; default: cairo_test_log ("Invalid content for glitz-glx test: %d\n", content); goto FAIL_CLOSE_DISPLAY; } if (!glitz_surface) { cairo_test_log ("Failed to create glitz-glx surface\n"); goto FAIL_CLOSE_DISPLAY; } surface = cairo_glitz_surface_create (glitz_surface); gxtc->base.width = test->width; gxtc->base.height = test->height; gxtc->base.content = content; cairo_surface_set_user_data (surface, &glitz_closure_key, gxtc, NULL); return surface; FAIL_CLOSE_DISPLAY: XCloseDisplay (gxtc->dpy); FAIL: return NULL;}static voidcleanup_cairo_glitz_glx (void *closure){ glitz_glx_target_closure_t *gxtc = closure; glitz_glx_fini (); if (gxtc->win) XDestroyWindow (gxtc->dpy, gxtc->win); XCloseDisplay (gxtc->dpy); free (gxtc);}#endif /* CAIRO_CAN_TEST_GLITZ_GLX_SURFACE */#if CAIRO_CAN_TEST_GLITZ_AGL_SURFACE#include <glitz-agl.h>typedef struct _glitz_agl_target_closure { glitz_target_closure_base_t base;} glitz_agl_target_closure_t;static glitz_surface_t *create_glitz_agl_surface (glitz_format_name_t formatname, int width, int height, glitz_agl_target_closure_t *closure){ glitz_drawable_format_t *dformat; glitz_drawable_format_t templ; glitz_drawable_t *gdraw; glitz_format_t *format; glitz_surface_t *sr = NULL; unsigned long mask; memset(&templ, 0, sizeof(templ)); templ.color.red_size = 8; templ.color.green_size = 8; templ.color.blue_size = 8; templ.color.alpha_size = 8; templ.color.fourcc = GLITZ_FOURCC_RGB; templ.samples = 1; mask = GLITZ_FORMAT_SAMPLES_MASK | GLITZ_FORMAT_FOURCC_MASK | GLITZ_FORMAT_RED_SIZE_MASK | GLITZ_FORMAT_GREEN_SIZE_MASK | GLITZ_FORMAT_BLUE_SIZE_MASK; if (formatname == GLITZ_STANDARD_ARGB32) mask |= GLITZ_FORMAT_ALPHA_SIZE_MASK; dformat = glitz_agl_find_pbuffer_format (mask, &templ, 0); if (!dformat) { cairo_test_log ("Glitz failed to find pbuffer format for template."); goto FAIL; } gdraw = glitz_agl_create_pbuffer_drawable (dformat, width, height); if (!gdraw) { cairo_test_log ("Glitz failed to create pbuffer drawable."); goto FAIL; } format = glitz_find_standard_format (gdraw, formatname); if (!format) { cairo_test_log ("Glitz failed to find standard format for drawable."); goto DESTROY_DRAWABLE; } sr = glitz_surface_create (gdraw, format, width, height, 0, NULL); if (!sr) { cairo_test_log ("Glitz failed to create a surface."); goto DESTROY_DRAWABLE; } glitz_surface_attach (sr, gdraw, GLITZ_DRAWABLE_BUFFER_FRONT_COLOR); DESTROY_DRAWABLE: glitz_drawable_destroy (gdraw); FAIL: return sr; /* will be NULL unless we create it and attach */}static cairo_surface_t *create_cairo_glitz_agl_surface (cairo_test_t *test, cairo_content_t content, void **closure){ glitz_surface_t *glitz_surface; cairo_surface_t *surface; glitz_agl_target_closure_t *aglc; glitz_agl_init (); *closure = aglc = xmalloc (sizeof (glitz_agl_target_closure_t)); switch (content) { case CAIRO_CONTENT_COLOR: glitz_surface = create_glitz_agl_surface (GLITZ_STANDARD_RGB24, test->width, test->height, NULL); break; case CAIRO_CONTENT_COLOR_ALPHA: glitz_surface = create_glitz_agl_surface (GLITZ_STANDARD_ARGB32, test->width, test->height, NULL); break; default: cairo_test_log ("Invalid content for glitz-agl test: %d\n", content); goto FAIL; } if (!glitz_surface) goto FAIL; surface = cairo_glitz_surface_create (glitz_surface); aglc->base.width = test->width; aglc->base.height = test->height; aglc->base.content = content; cairo_surface_set_user_data (surface, &glitz_closure_key, aglc, NULL); return surface; FAIL: return NULL;}static voidcleanup_cairo_glitz_agl (void *closure){ free (closure); glitz_agl_fini ();}#endif /* CAIRO_CAN_TEST_GLITZ_AGL_SURFACE */#if CAIRO_CAN_TEST_GLITZ_WGL_SURFACE#include <glitz-wgl.h>typedef struct _glitz_wgl_target_closure { glitz_target_closure_base_t base;} glitz_wgl_target_closure_t;static glitz_surface_t *create_glitz_wgl_surface (glitz_format_name_t formatname, int width, int height, glitz_wgl_target_closure_t *closure){ glitz_drawable_format_t *dformat; glitz_drawable_format_t templ; glitz_drawable_t *gdraw; glitz_format_t *format; glitz_surface_t *sr = NULL; unsigned long mask; memset(&templ, 0, sizeof(templ)); templ.color.red_size = 8; templ.color.green_size = 8; templ.color.blue_size = 8; templ.color.alpha_size = 8; templ.color.fourcc = GLITZ_FOURCC_RGB; templ.samples = 1; mask = GLITZ_FORMAT_SAMPLES_MASK | GLITZ_FORMAT_FOURCC_MASK | GLITZ_FORMAT_RED_SIZE_MASK | GLITZ_FORMAT_GREEN_SIZE_MASK | GLITZ_FORMAT_BLUE_SIZE_MASK; if (formatname == GLITZ_STANDARD_ARGB32) mask |= GLITZ_FORMAT_ALPHA_SIZE_MASK; dformat = glitz_wgl_find_pbuffer_format (mask, &templ, 0); if (!dformat) { cairo_test_log ("Glitz failed to find pbuffer format for template."); goto FAIL; } gdraw = glitz_wgl_create_pbuffer_drawable (dformat, width, height); if (!gdraw) { cairo_test_log ("Glitz failed to create pbuffer drawable."); goto FAIL; } format = glitz_find_standard_format (gdraw, formatname); if (!format) { cairo_test_log ("Glitz failed to find standard format for drawable."); goto DESTROY_DRAWABLE; } sr = glitz_surface_create (gdraw, format, width, height, 0, NULL); if (!sr) { cairo_test_log ("Glitz failed to create a surface."); goto DESTROY_DRAWABLE; } glitz_surface_attach (sr, gdraw, GLITZ_DRAWABLE_BUFFER_FRONT_COLOR); DESTROY_DRAWABLE: glitz_drawable_destroy (gdraw); FAIL: return sr; /* will be NULL unless we create it and attach */}static cairo_surface_t *create_cairo_glitz_wgl_surface (cairo_test_t *test, cairo_content_t content, void **closure){ glitz_surface_t *glitz_surface; cairo_surface_t *surface; glitz_wgl_target_closure_t *wglc; glitz_wgl_init (NULL); *closure = wglc = xmalloc (sizeof (glitz_wgl_target_closure_t)); switch (content) { case CAIRO_CONTENT_COLOR: glitz_surface = create_glitz_wgl_surface (GLITZ_STANDARD_RGB24, test->width, test->height, NULL); break; case CAIRO_CONTENT_COLOR_ALPHA: glitz_surface = create_glitz_wgl_surface (GLITZ_STANDARD_ARGB32, test->width, test->height, NULL); break; default: cairo_test_log ("Invalid content for glitz-wgl test: %d\n", content); goto FAIL; } if (!glitz_surface) goto FAIL; surface = cairo_glitz_surface_create (glitz_surface); wglc->base.width = test->width; wglc->base.height = test->height; wglc->base.content = content; cairo_surface_set_user_data (surface, &glitz_closure_key, wglc, NULL); return surface; FAIL: return NULL;}static voidcleanup_cairo_glitz_wgl (void *closure){ free (closure); glitz_wgl_fini ();}#endif /* CAIRO_CAN_TEST_GLITZ_WGL_SURFACE */#endif /* CAIRO_HAS_GLITZ_SURFACE */#if 0 && CAIRO_HAS_QUARTZ_SURFACEstatic cairo_surface_t *create_quartz_surface (int width, int height, void **closure){#error Not yet implemented}static voidcleanup_quartz (void *closure){#error Not yet implemented}#endif/* Testing the win32 surface isn't interesting, since for * ARGB images it just chains to the image backend */#if CAIRO_HAS_WIN32_SURFACE#include "cairo-win32.h"typedef struct _win32_target_closure{ HDC dc; HBITMAP bmp;} win32_target_closure_t;static cairo_surface_t *create_win32_surface (cairo_test_t *test, cairo_content_t content, void **closure){ int width = test->width; int height = test->height; BITMAPINFO bmpInfo; unsigned char *bits = NULL; win32_target_closure_t *data = malloc(sizeof(win32_target_closure_t)); *closure = data; data->dc = CreateCompatibleDC(NULL); /* initialize the bitmapinfoheader */ memset(&bmpInfo.bmiHeader, 0, sizeof(BITMAPINFOHEADER)); bmpInfo.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); bmpInfo.bmiHeader.biWidth = width; bmpInfo.bmiHeader.biHeight = -height; bmpInfo.bmiHeader.biPlanes = 1; bmpInfo.bmiHeader.biBitCount = 24; bmpInfo.bmiHeader.biCompression = BI_RGB; /* create a DIBSection */ data->bmp = CreateDIBSection(data->dc, &bmpInfo, DIB_RGB_COLORS, (void**)&bits, NULL, 0); /* Flush GDI to make sure the DIBSection is actually created */ GdiFlush(); /* Select the bitmap in to the DC */ SelectObject(data->dc, data->bmp); return cairo_win32_surface_create(data->dc);}static voidcleanup_win32 (void *closure){ win32_target_closure_t *data = (win32_target_closure_t*)closure; DeleteObject(data->bmp); DeleteDC(data->dc); free(closure);}#endif#if CAIRO_HAS_XCB_SURFACE#include "cairo-xcb-xrender.h"typedef struct _xcb_target_closure{ XCBConnection *c; XCBDRAWABLE drawable;} xcb_target_closure_t;/* XXX: This is a nasty hack. Something like this should be in XCB's * bindings for Render, not here in this test. */static XCBRenderPICTFORMINFO_format_from_cairo(XCBConnection *c, cairo_format_t fmt){ XCBRenderPICTFORMINFO ret = {{ 0 }}; struct tmpl_t { XCBRenderDIRECTFORMAT direct; CARD8 depth; }; static const struct tmpl_t templates[] = { /* CAIRO_FORMAT_ARGB32 */ { { 16, 0xff, 8, 0xff, 0, 0xff, 24, 0xff }, 32 }, /* CAIRO_FORMAT_RGB24 */ { { 16, 0xff, 8, 0xff, 0, 0xff, 0, 0x00 }, 24 }, /* CAIRO_FORMAT_A8 */ { { 0, 0x00, 0, 0x00, 0, 0x00, 0, 0xff }, 8 }, /* CAIRO_FORMAT_A1 */ { { 0, 0x00, 0, 0x00, 0, 0x00, 0, 0x01 }, 1 }, }; const struct tmpl_t *tmpl; XCBRenderQueryPictFormatsRep *r; XCBRenderPICTFORMINFOIter fi; if(fmt < 0 || fmt >= (sizeof(templates) / sizeof(*templates))) return ret; tmpl = templates + fmt; r = XCBRenderQueryPictFormatsReply(c, XCBRenderQueryPictFormats(c), 0); if(!r) return ret; for(fi = XCBRenderQueryPictFormatsFormatsIter(r); fi.rem; XCBRenderPICTFORMINFONext(&fi)) { const XCBRenderDIRECTFORMAT *t, *f; if(fi.data->type != XCBRenderPictTypeDirect) continue; if(fi.data->depth != tmpl->depth) continue; t = &tmpl->direct; f = &fi.data->direct; if(t->red_mask && (t->red_mask != f->red_mask || t->red_shift != f->red_shift)) continue; if(t->green_mask && (t->green_mask != f->green_mask || t->green_shift != f->green_shift)) continue; if(t->blue_mask && (t->blue_mask != f->blue_mask || t->blue_shift != f->blue_shift)) continue; if(t->alpha_mask && (t->alpha_mask != f->alpha_mask || t->alpha_shift != f->alpha_shift)) continue; ret = *fi.data; } free(r); return ret;}static cairo_surface_t *create_xcb_surface (cairo_test_t *test, cairo_content_t content, void **closure){ int width = test->width; int height = test->height; XCBSCREEN *root; xcb_target_closure_t *xtc; cairo_surface_t *surface; XCBConnection *c; XCBRenderPICTFORMINFO render_format; cairo_format_t format; *closure = xtc = xmalloc (sizeof (xcb_target_closure_t)); if (width == 0) width = 1; if (height == 0) height = 1; xtc->c = c = XCBConnect(NULL,NULL); if (c == NULL) { cairo_test_log ("Failed to connect to X server through XCB\n"); return NULL; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -