Exemplo n.º 1
0
static gboolean
fish_applet_draw (GtkWidget  *widget,
		  cairo_t    *cr,
		  FishApplet *fish)
{
	int width, height;
	int src_x, src_y;

	g_return_val_if_fail (fish->surface != NULL, FALSE);

	g_assert (fish->n_frames > 0);

	width = cairo_xlib_surface_get_width (fish->surface);
	height = cairo_xlib_surface_get_height (fish->surface);

	src_x = 0;
	src_y = 0;

	if (fish->rotate) {
		if (fish->orientation == PANEL_APPLET_ORIENT_RIGHT)
			src_y = ((height * (fish->n_frames - 1 - fish->current_frame)) / fish->n_frames);
		else if (fish->orientation == PANEL_APPLET_ORIENT_LEFT)
			src_y = ((height * fish->current_frame) / fish->n_frames);
		else
			src_x = ((width * fish->current_frame) / fish->n_frames);
	} else
		src_x = ((width * fish->current_frame) / fish->n_frames);

        cairo_save (cr);
        cairo_set_source_surface (cr, fish->surface, -src_x, -src_y);
        cairo_paint (cr);
        cairo_restore (cr);

        return FALSE;
}
Exemplo n.º 2
0
/* deal with the mask surface and make sure it is the correct size */
static void mask_surface_check(cairo_surface_t *cs, unsigned width, unsigned height) {
	/* deal with the mask surface */
	if(!mask_surface) {
		mask_surface=make_mask_surface(cs, width, height);
	} else {
		/* detect if mask should be resized and recreate it */
		if((int)height!=cairo_xlib_surface_get_height(mask_surface) || (int)width!=cairo_xlib_surface_get_width(mask_surface)) {
			destroy_mask_surface(mask_surface);
			mask_surface=make_mask_surface(cs, width, height);
		}
	}
}
Exemplo n.º 3
0
gfxXlibSurface::gfxXlibSurface(cairo_surface_t *csurf)
    : mPixmapTaken(PR_FALSE),
      mSize(cairo_xlib_surface_get_width(csurf),
            cairo_xlib_surface_get_height(csurf))
{
    NS_PRECONDITION(cairo_surface_status(csurf) == 0,
                    "Not expecting an error surface");

    mDrawable = cairo_xlib_surface_get_drawable(csurf);
    mDisplay = cairo_xlib_surface_get_display(csurf);

    Init(csurf, PR_TRUE);
}
Exemplo n.º 4
0
cairo_surface_t *
gitg_platform_support_create_cursor_surface (GdkDisplay    *display,
                                             GdkCursorType  cursor_type,
                                             gdouble       *hot_x,
                                             gdouble       *hot_y,
                                             gdouble       *width,
                                             gdouble       *height)
{
	GdkCursor *cursor;
	cairo_surface_t *surface;
	gdouble w = 0, h = 0;

	cursor = gdk_cursor_new_for_display (display, cursor_type);
	surface = gdk_cursor_get_surface (cursor, hot_x, hot_y);

	if (surface == NULL)
	{
		return NULL;
	}

	switch (cairo_surface_get_type (surface))
	{
	case CAIRO_SURFACE_TYPE_XLIB:
		w = cairo_xlib_surface_get_width (surface);
		h = cairo_xlib_surface_get_height (surface);
		break;
	case CAIRO_SURFACE_TYPE_IMAGE:
		w = cairo_image_surface_get_width (surface);
		h = cairo_image_surface_get_height (surface);
		break;
	}

	if (width)
	{
		*width = w;
	}

	if (height)
	{
		*height = h;
	}

	return surface;
}
/**
 * Try the direct path.
 * @return True if we took the direct path
 */
bool
gfxXlibNativeRenderer::DrawDirect(gfxContext *ctx, nsIntSize size,
                                  PRUint32 flags,
                                  Screen *screen, Visual *visual)
{
    cairo_t *cr = ctx->GetCairo();

    /* Check that the target surface is an xlib surface. */
    cairo_surface_t *target = cairo_get_group_target (cr);
    if (cairo_surface_get_type (target) != CAIRO_SURFACE_TYPE_XLIB) {
        NATIVE_DRAWING_NOTE("FALLBACK: non-X surface");
        return false;
    }
    
    cairo_matrix_t matrix;
    cairo_get_matrix (cr, &matrix);
    double device_offset_x, device_offset_y;
    cairo_surface_get_device_offset (target, &device_offset_x, &device_offset_y);

    /* Draw() checked that the matrix contained only a very-close-to-integer
       translation.  Here (and in several other places and thebes) device
       offsets are assumed to be integer. */
    NS_ASSERTION(PRInt32(device_offset_x) == device_offset_x &&
                 PRInt32(device_offset_y) == device_offset_y,
                 "Expected integer device offsets");
    nsIntPoint offset(NS_lroundf(matrix.x0 + device_offset_x),
                      NS_lroundf(matrix.y0 + device_offset_y));
    
    int max_rectangles = 0;
    if (flags & DRAW_SUPPORTS_CLIP_RECT) {
      max_rectangles = 1;
    }
    if (flags & DRAW_SUPPORTS_CLIP_LIST) {
      max_rectangles = MAX_STATIC_CLIP_RECTANGLES;
    }

    /* The client won't draw outside the surface so consider this when
       analysing clip rectangles. */
    nsIntRect bounds(offset, size);
    bounds.IntersectRect(bounds,
                         nsIntRect(0, 0,
                                   cairo_xlib_surface_get_width(target),
                                   cairo_xlib_surface_get_height(target)));

    bool needs_clip = true;
    nsIntRect rectangles[MAX_STATIC_CLIP_RECTANGLES];
    int rect_count = 0;

    /* Check that the clip is rectangular and aligned on unit boundaries. */
    /* Temporarily set the matrix for _get_rectangular_clip. It's basically
       the identity matrix, but we must adjust for the fact that our
       offset-rect is in device coordinates. */
    cairo_identity_matrix (cr);
    cairo_translate (cr, -device_offset_x, -device_offset_y);
    bool have_rectangular_clip =
        _get_rectangular_clip (cr, bounds, &needs_clip,
                               rectangles, max_rectangles, &rect_count);
    cairo_set_matrix (cr, &matrix);
    if (!have_rectangular_clip)
        return false;

    /* Stop now if everything is clipped out */
    if (needs_clip && rect_count == 0)
        return true;
      
    /* Check that the screen is supported.
       Visuals belong to screens, so, if alternate visuals are not supported,
       then alternate screens cannot be supported. */  
    bool supports_alternate_visual =
        (flags & DRAW_SUPPORTS_ALTERNATE_VISUAL) != 0;
    bool supports_alternate_screen = supports_alternate_visual &&
        (flags & DRAW_SUPPORTS_ALTERNATE_SCREEN);
    if (!supports_alternate_screen &&
        cairo_xlib_surface_get_screen (target) != screen) {
        NATIVE_DRAWING_NOTE("FALLBACK: non-default screen");
        return false;
    }
        
    /* Check that there is a visual */
    Visual *target_visual = cairo_xlib_surface_get_visual (target);
    if (!target_visual) {
        NATIVE_DRAWING_NOTE("FALLBACK: no Visual for surface");
        return false;
    }        
    /* Check that the visual is supported */
    if (!supports_alternate_visual && target_visual != visual) {
        // Only the format of the visual is important (not the GLX properties)
        // for Xlib or XRender drawing.
        XRenderPictFormat *target_format =
            cairo_xlib_surface_get_xrender_format (target);
        if (!target_format ||
            (target_format !=
             XRenderFindVisualFormat (DisplayOfScreen(screen), visual))) {
            NATIVE_DRAWING_NOTE("FALLBACK: unsupported Visual");
            return false;
        }
    }
  
    /* we're good to go! */
    NATIVE_DRAWING_NOTE("TAKING FAST PATH\n");
    cairo_surface_flush (target);
    nsRefPtr<gfxASurface> surface = gfxASurface::Wrap(target);
    nsresult rv = DrawWithXlib(static_cast<gfxXlibSurface*>(surface.get()),
                               offset, rectangles,
                               needs_clip ? rect_count : 0);
    if (NS_SUCCEEDED(rv)) {
        cairo_surface_mark_dirty (target);
        return true;
    }
    return false;
}
Exemplo n.º 6
0
static cairo_test_status_t
do_test (const cairo_test_context_t *ctx,
         Display        *dpy,
         unsigned char  *reference_data,
         unsigned char  *test_data,
         unsigned char  *diff_data,
         cairo_bool_t    use_pixmap,
         cairo_bool_t    set_size,
         cairo_bool_t    offscreen)
{
    cairo_surface_t *surface;
    cairo_surface_t *test_surface;
    cairo_t *test_cr;
    buffer_diff_result_t result;
    Drawable drawable;
    int screen = DefaultScreen (dpy);

    if (use_pixmap && offscreen)
        return CAIRO_TEST_SUCCESS;

    if (use_pixmap) {
        drawable = XCreatePixmap (dpy, DefaultRootWindow (dpy),
                                  SIZE, SIZE, DefaultDepth (dpy, screen));
    } else {
        XSetWindowAttributes xwa;
        int x, y;

        xwa.override_redirect = True;

        if (offscreen) {
            x = - OFFSCREEN_OFFSET;
            y = - OFFSCREEN_OFFSET;
        } else {
            x = 0;
            y = 0;
        }

        drawable = XCreateWindow (dpy, DefaultRootWindow (dpy),
                                  x, y, SIZE, SIZE, 0,
                                  DefaultDepth (dpy, screen), InputOutput,
                                  DefaultVisual (dpy, screen),
                                  CWOverrideRedirect, &xwa);
        XMapWindow (dpy, drawable);
    }

    surface = cairo_xlib_surface_create (dpy,
                                         drawable,
                                         DefaultVisual (dpy, screen),
                                         SIZE, SIZE);

    if (! surface_compare_visual_and_format (surface))
        return CAIRO_TEST_FAILURE;

    if (set_size) {
        cairo_xlib_surface_set_size (surface, SIZE, SIZE);

        if (cairo_xlib_surface_get_width (surface) != SIZE ||
                cairo_xlib_surface_get_height (surface) != SIZE)
            return CAIRO_TEST_FAILURE;
    }

    if (! check_similar_visual_and_format (surface))
        return CAIRO_TEST_FAILURE;

    draw_pattern (surface);

    test_surface = cairo_image_surface_create_for_data (test_data,
                   CAIRO_FORMAT_RGB24,
                   SIZE, SIZE,
                   SIZE * 4);

    test_cr = cairo_create (test_surface);
    cairo_set_source_surface (test_cr, surface, 0, 0);
    cairo_paint (test_cr);

    cairo_destroy (test_cr);
    cairo_surface_destroy (test_surface);

    /* We erase the surface to black in case we get the same
     * memory back again for the pixmap case.
     */
    erase_pattern (surface);
    cairo_surface_destroy (surface);

    if (use_pixmap)
        XFreePixmap (dpy, drawable);
    else
        XDestroyWindow (dpy, drawable);

    if (offscreen) {
        size_t offset = 4 * (SIZE * OFFSCREEN_OFFSET + OFFSCREEN_OFFSET);

        buffer_diff_noalpha (reference_data + offset,
                             test_data + offset,
                             diff_data + offset,
                             SIZE - OFFSCREEN_OFFSET,
                             SIZE - OFFSCREEN_OFFSET,
                             4 * SIZE,
                             &result);
    } else {
        buffer_diff_noalpha (reference_data,
                             test_data,
                             diff_data,
                             SIZE,
                             SIZE,
                             4 * SIZE,
                             &result);
    }

    cairo_test_log (ctx, "xlib-surface: %s, %s, %s: %s\n",
                    set_size ? "   size" : "no-size",
                    use_pixmap ? "pixmap" : "window",
                    use_pixmap ?  "           " : (offscreen ? ", offscreen" : ",  onscreen"),
                    image_diff_is_failure (&result, 0) ? "FAIL" : "PASS");

    if (image_diff_is_failure (&result, 0))
        return CAIRO_TEST_FAILURE;
    else
        return CAIRO_TEST_SUCCESS;
}
Exemplo n.º 7
0
static cairo_test_status_t
test_cairo_xlib_surface_get_height (cairo_surface_t *surface)
{
    int height = cairo_xlib_surface_get_height (surface);
    return height == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
Exemplo n.º 8
0
static PyObject *
xlib_surface_get_height (PycairoXlibSurface *o)
{
    return PyInt_FromLong (cairo_xlib_surface_get_height (o->surface));
}
Exemplo n.º 9
0
Arquivo: line.c Projeto: rbuj/emerald
static void draw_shadow_background(decor_t * d, cairo_t * cr)
{
	cairo_matrix_t matrix;
	double w, x2;
	gint width = 0, height = 0;
	gint left, right, top, bottom;
	window_settings *ws = d->fs->ws;

	if (!ws->large_shadow_surface)
	{
		cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
		cairo_paint(cr);

		return;
	}

	if (cairo_surface_get_type(ws->large_shadow_surface) ==
	  CAIRO_SURFACE_TYPE_IMAGE)
	{
	    width = cairo_image_surface_get_width(ws->large_shadow_surface);
	    height = cairo_image_surface_get_height(ws->large_shadow_surface);
	}
	else if (cairo_surface_get_type(ws->large_shadow_surface) ==
	  CAIRO_SURFACE_TYPE_XLIB)
	{
	    width = cairo_xlib_surface_get_width(ws->large_shadow_surface);
	    height = cairo_xlib_surface_get_height(ws->large_shadow_surface);
	}

	left = ws->left_space + ws->left_corner_space;
	right = ws->right_space + ws->right_corner_space;
	top = ws->top_space + ws->top_corner_space;
	bottom = ws->bottom_space + ws->bottom_corner_space;

	if (d->width - left - right < 0)
	{
		left = d->width / 2;
		right = d->width - left;
	}

	if (d->height - top - bottom < 0)
	{
		top = d->height / 2;
		bottom = d->height - top;
	}

	w = d->width - left - right;

	x2 = d->width - right;

	/* top left */
	cairo_matrix_init_identity(&matrix);
	cairo_pattern_set_matrix(ws->shadow_pattern, &matrix);
	cairo_set_source(cr, ws->shadow_pattern);
	cairo_rectangle(cr, 0.0, 0.0, left, top);
	cairo_fill(cr);

	/* top */
	if (w > 0)
	{
		cairo_matrix_init_translate(&matrix, left, 0.0);
		cairo_matrix_scale(&matrix, 1.0 / w, 1.0);
		cairo_matrix_translate(&matrix, -left, 0.0);
		cairo_pattern_set_matrix(ws->shadow_pattern, &matrix);
		cairo_set_source(cr, ws->shadow_pattern);
		cairo_rectangle(cr, left, 0.0, w, top);
		cairo_fill(cr);
	}

	/* top right */
	cairo_matrix_init_translate(&matrix, width - right - x2, 0.0);
	cairo_pattern_set_matrix(ws->shadow_pattern, &matrix);
	cairo_set_source(cr, ws->shadow_pattern);
	cairo_rectangle(cr, x2, 0.0, right, top);
	cairo_clip_preserve(cr);
	cairo_fill(cr);
}