Clamp surface dimensions to a minimum of 1. (_cairo_glitz_surface_get_image): Set the glitz clip to NULL before calling glitz_get_pixels, to return the full surface contents. Restore clip afterwards. (_cairo_glitz_surface_composite_trapezoid): Return UNSUPPORTED if the antialias is anything other than DEFAULT/GRAY.

Try to recover a standard cairo_format_t from given pixman format masks, so that various things that only work with a standard format work correctly.
Remove cairo_glitz_surface_write_to_png, replace with generic cairo_surface_write_to_png (since it works with image-surface create_with_masks fix)
This commit is contained in:
Vladimir Vukicevic 2006-01-03 09:23:48 +00:00
parent bd265e008b
commit c6cdfc5770
4 changed files with 104 additions and 36 deletions

View file

@ -1,3 +1,22 @@
2006-01-03 Vladimir Vukicevic <vladimir@pobox.com>
* src/cairo-glitz-surface.c (_cairo_glitz_surface_create_similar):
Clamp surface dimensions to a minimum of 1.
(_cairo_glitz_surface_get_image): Set the glitz clip to NULL before
calling glitz_get_pixels, to return the full surface contents.
Restore clip afterwards.
(_cairo_glitz_surface_composite_trapezoid): Return UNSUPPORTED if
the antialias is anything other than DEFAULT/GRAY.
* src/cairo-image-surface.c (_cairo_image_surface_create_with_masks):
Try to recover a standard cairo_format_t from given pixman format
masks, so that various things that only work with a standard
format work correctly.
* test/cairo-test.c: Remove cairo_glitz_surface_write_to_png,
replace with generic cairo_surface_write_to_png (since it works with
image-surface create_with_masks fix)
2006-01-03 Vladimir Vukicevic <vladimir@pobox.com>
* test/make-html.pl: Clean up output some; show only images that

View file

@ -92,7 +92,11 @@ _cairo_glitz_surface_create_similar (void *abstract_src,
return (cairo_surface_t*) &_cairo_surface_nil;
}
surface = glitz_surface_create (drawable, gformat, width, height, 0, NULL);
surface = glitz_surface_create (drawable, gformat,
width <= 0 ? 1 : width,
height <= 0 ? 1 : height,
0, NULL);
if (surface == NULL) {
_cairo_error (CAIRO_STATUS_NO_MEMORY);
return (cairo_surface_t*) &_cairo_surface_nil;
@ -202,6 +206,10 @@ _cairo_glitz_surface_get_image (cairo_glitz_surface_t *surface,
return CAIRO_STATUS_NO_MEMORY;
}
/* clear out the glitz clip; the clip affects glitz_get_pixels */
glitz_surface_set_clip_region (surface->surface,
0, 0, NULL, 0);
glitz_get_pixels (surface->surface,
x1, y1,
width, height,
@ -210,6 +218,10 @@ _cairo_glitz_surface_get_image (cairo_glitz_surface_t *surface,
glitz_buffer_destroy (buffer);
/* restore the clip, if any */
surface->base.current_clip_serial = 0;
_cairo_surface_set_clip (&surface->base, surface->base.clip);
image = (cairo_image_surface_t *)
_cairo_image_surface_create_with_masks (pixels,
&format,
@ -993,6 +1005,10 @@ _cairo_glitz_surface_composite_trapezoids (cairo_operator_t op,
cairo_int_status_t status;
unsigned short alpha;
if (antialias != CAIRO_ANTIALIAS_DEFAULT &&
antialias != CAIRO_ANTIALIAS_GRAY)
return CAIRO_INT_STATUS_UNSUPPORTED;
if (dst->base.status)
return dst->base.status;
@ -2094,6 +2110,16 @@ UNLOCK:
return CAIRO_STATUS_SUCCESS;
}
static cairo_status_t
_cairo_glitz_surface_flush (void *abstract_surface)
{
cairo_glitz_surface_t *surface = abstract_surface;
glitz_surface_flush (surface->surface);
return CAIRO_STATUS_SUCCESS;
}
static const cairo_surface_backend_t cairo_glitz_surface_backend = {
_cairo_glitz_surface_create_similar,
_cairo_glitz_surface_finish,
@ -2112,7 +2138,7 @@ static const cairo_surface_backend_t cairo_glitz_surface_backend = {
_cairo_glitz_surface_get_extents,
_cairo_glitz_surface_old_show_glyphs,
NULL, /* get_font_options */
NULL, /* flush */
_cairo_glitz_surface_flush,
NULL, /* mark_dirty_rectangle */
_cairo_glitz_surface_scaled_font_fini,
_cairo_glitz_surface_scaled_glyph_fini

View file

@ -80,6 +80,46 @@ _cairo_image_surface_create_for_pixman_image (pixman_image_t *pixman_image,
return &surface->base;
}
/* Try to recover a cairo_format_t from a pixman_format
* by looking at the bpp and masks values. */
static cairo_format_t
_cairo_format_from_pixman_format (pixman_format_t *pixman_format)
{
int bpp, am, rm, gm, bm;
pixman_format_get_masks (pixman_format, &bpp, &am, &rm, &gm, &bm);
if (bpp == 32 &&
am == 0xff000000 &&
rm == 0x00ff0000 &&
gm == 0x0000ff00 &&
bm == 0x000000ff)
return CAIRO_FORMAT_ARGB32;
if (bpp == 32 &&
am == 0x0 &&
rm == 0x00ff0000 &&
gm == 0x0000ff00 &&
bm == 0x000000ff)
return CAIRO_FORMAT_RGB24;
if (bpp == 8 &&
am == 0xff &&
rm == 0x0 &&
gm == 0x0 &&
bm == 0x0)
return CAIRO_FORMAT_A8;
if (bpp == 1 &&
am == 0x1 &&
rm == 0x0 &&
gm == 0x0 &&
bm == 0x0)
return CAIRO_FORMAT_A1;
return (cairo_format_t) -1;
}
cairo_surface_t *
_cairo_image_surface_create_with_masks (unsigned char *data,
cairo_format_masks_t *format,
@ -90,6 +130,7 @@ _cairo_image_surface_create_with_masks (unsigned char *data,
cairo_surface_t *surface;
pixman_format_t *pixman_format;
pixman_image_t *pixman_image;
cairo_format_t cairo_format;
pixman_format = pixman_format_create_masks (format->bpp,
format->alpha_mask,
@ -102,6 +143,8 @@ _cairo_image_surface_create_with_masks (unsigned char *data,
return (cairo_surface_t*) &_cairo_surface_nil;
}
cairo_format = _cairo_format_from_pixman_format (pixman_format);
pixman_image = pixman_image_create_for_data ((pixman_bits_t *) data, pixman_format,
width, height, format->bpp, stride);
@ -113,7 +156,7 @@ _cairo_image_surface_create_with_masks (unsigned char *data,
}
surface = _cairo_image_surface_create_for_pixman_image (pixman_image,
(cairo_format_t)-1);
cairo_format);
return surface;
}

View file

@ -302,29 +302,6 @@ typedef struct _glitz_target_closure_base {
cairo_format_t format;
} glitz_target_closure_base_t;
static cairo_status_t
cairo_glitz_surface_write_to_png (cairo_surface_t *surface,
const char *filename)
{
glitz_target_closure_base_t *closure;
cairo_surface_t * imgsr;
cairo_t * imgcr;
closure = cairo_surface_get_user_data (surface, &glitz_closure_key);
imgsr = cairo_image_surface_create (closure->format, closure->width, closure->height);
imgcr = cairo_create (imgsr);
cairo_set_source_surface (imgcr, surface, 0, 0);
cairo_paint (imgcr);
cairo_surface_write_to_png (imgsr, filename);
cairo_destroy (imgcr);
cairo_surface_destroy (imgsr);
return CAIRO_STATUS_SUCCESS;
}
#if CAIRO_CAN_TEST_GLITZ_GLX_SURFACE
#include <glitz-glx.h>
@ -362,6 +339,8 @@ create_glitz_glx_surface (glitz_format_name_t formatname,
templ.color.fourcc = GLITZ_FOURCC_RGB;
templ.samples = 1;
glitz_glx_init (NULL);
mask = GLITZ_FORMAT_SAMPLES_MASK | GLITZ_FORMAT_FOURCC_MASK |
GLITZ_FORMAT_RED_SIZE_MASK | GLITZ_FORMAT_GREEN_SIZE_MASK |
GLITZ_FORMAT_BLUE_SIZE_MASK;
@ -373,7 +352,7 @@ create_glitz_glx_surface (glitz_format_name_t formatname,
dformat = glitz_glx_find_pbuffer_format (dpy, scr, mask, &templ, 0);
if (dformat) {
closure->win = NULL;
closure->win = None;
drawable = glitz_glx_create_pbuffer_drawable (dpy, scr, dformat,
width, height);
@ -405,7 +384,8 @@ create_glitz_glx_surface (glitz_format_name_t formatname,
xsh.x, xsh.y, xsh.width, xsh.height,
0, vinfo->depth, CopyFromParent,
vinfo->visual, CWColormap, &xswa);
XFree (vinfo);
drawable =
glitz_glx_create_drawable_for_window (dpy, scr,
dformat, closure->win,
@ -424,7 +404,7 @@ create_glitz_glx_surface (glitz_format_name_t formatname,
if (!sr)
goto DESTROY_DRAWABLE;
if (closure->win == NULL || dformat->doublebuffer) {
if (closure->win == None || dformat->doublebuffer) {
glitz_surface_attach (sr, drawable, GLITZ_DRAWABLE_BUFFER_BACK_COLOR);
} else {
XMapWindow (closure->dpy, closure->win);
@ -461,7 +441,7 @@ create_cairo_glitz_glx_surface (cairo_test_t *test,
if (height == 0)
height = 1;
gxtc->dpy = XOpenDisplay (NULL);
gxtc->dpy = XOpenDisplay (getenv("CAIRO_TEST_GLITZ_DISPLAY"));
if (!gxtc->dpy) {
cairo_test_log ("Failed to open display: %s\n", XDisplayName(0));
goto FAIL;
@ -1392,26 +1372,26 @@ cairo_test_expecting (cairo_test_t *test, cairo_test_draw_function_t draw,
#ifdef CAIRO_HAS_GLITZ_SURFACE
#if CAIRO_CAN_TEST_GLITZ_GLX_SURFACE
{ "glitz-glx", CAIRO_FORMAT_ARGB32,
create_cairo_glitz_glx_surface, cairo_glitz_surface_write_to_png,
create_cairo_glitz_glx_surface, cairo_surface_write_to_png,
cleanup_cairo_glitz_glx },
{ "glitz-glx", CAIRO_FORMAT_RGB24,
create_cairo_glitz_glx_surface, cairo_glitz_surface_write_to_png,
create_cairo_glitz_glx_surface, cairo_surface_write_to_png,
cleanup_cairo_glitz_glx },
#endif
#if CAIRO_CAN_TEST_GLITZ_AGL_SURFACE
{ "glitz-agl", CAIRO_FORMAT_ARGB32,
create_cairo_glitz_agl_surface, cairo_glitz_surface_write_to_png,
create_cairo_glitz_agl_surface, cairo_surface_write_to_png,
cleanup_cairo_glitz_agl },
{ "glitz-agl", CAIRO_FORMAT_RGB24,
create_cairo_glitz_agl_surface, cairo_glitz_surface_write_to_png,
create_cairo_glitz_agl_surface, cairo_surface_write_to_png,
cleanup_cairo_glitz_agl },
#endif
#if CAIRO_CAN_TEST_GLITZ_WGL_SURFACE
{ "glitz-wgl", CAIRO_FORMAT_ARGB32,
create_cairo_glitz_wgl_surface, cairo_glitz_surface_write_to_png,
create_cairo_glitz_wgl_surface, cairo_surface_write_to_png,
cleanup_cairo_glitz_wgl },
{ "glitz-wgl", CAIRO_FORMAT_RGB24,
create_cairo_glitz_wgl_surface, cairo_glitz_surface_write_to_png,
create_cairo_glitz_wgl_surface, cairo_surface_write_to_png,
cleanup_cairo_glitz_wgl },
#endif
#endif /* CAIRO_HAS_GLITZ_SURFACE */