Exemple #1
0
CAMLprim value
ml_cairo_pop_group (value cr)
{
  cairo_pattern_t *p = cairo_pop_group (cairo_t_val (cr));
  check_cairo_status (cr);
  return Val_cairo_pattern_t (p);
}
Exemple #2
0
	value lime_cairo_pop_group (value handle) {
		
		cairo_pattern_t* pattern = cairo_pop_group ((cairo_t*)val_data (handle));
		cairo_pattern_reference (pattern);
		return CFFIPointer (pattern, gc_cairo_pattern);
		
	}
Exemple #3
0
static JSBool
popGroup_func(JSContext *context,
              unsigned   argc,
              jsval     *vp)
{
    JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
    JSObject *obj = JSVAL_TO_OBJECT(rec.thisv());

    cairo_t *cr;
    cairo_pattern_t *pattern;
    JSObject *pattern_wrapper;

    if (argc > 0) {
        gjs_throw(context, "Context.popGroup() takes no arguments");
        return JS_FALSE;
    }

    cr = gjs_cairo_context_get_context(context, obj);
    pattern = cairo_pop_group(cr);
    if (!gjs_cairo_check_status(context, cairo_status(cr), "context"))
        return JS_FALSE;

    /* pattern belongs to the context, so keep the reference */
    pattern_wrapper = gjs_cairo_pattern_from_pattern(context, pattern);
    if (!pattern_wrapper) {
        gjs_throw(context, "failed to create pattern");
        return JS_FALSE;
    }

    rec.rval().set(OBJECT_TO_JSVAL(pattern_wrapper));

    return JS_TRUE;
}
Exemple #4
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_pattern_t *pattern;

    cairo_translate (cr, PAD, PAD);

    /* mask */
    cairo_push_group (cr);
    cairo_set_source_rgba (cr, 0.8, 0.8, 0.8, 0.4);
    cairo_paint (cr);
    cairo_arc (cr, SIZE / 2, SIZE / 2, SIZE / 6, 0., 2. * M_PI);
    cairo_set_source_rgba (cr, 0.4, 0.4, 0.4, 0.8);
    cairo_fill (cr);
    pattern = cairo_pop_group (cr);

    /* source */
    cairo_push_group (cr);
    cairo_rectangle (cr, 0.3 * SIZE, 0.2 * SIZE, 0.5 * SIZE, 0.5 * SIZE);
    cairo_set_source_rgb (cr, 0, 0, 1);
    cairo_fill (cr);
    cairo_move_to     (cr,   0.0,          0.8 * SIZE);
    cairo_rel_line_to (cr,   0.7 * SIZE,   0.0);
    cairo_rel_line_to (cr, -0.375 * SIZE, -0.6 * SIZE);
    cairo_close_path (cr);
    cairo_set_source_rgb (cr, 0, 1, 0);
    cairo_fill (cr);
    cairo_pop_group_to_source (cr);

    cairo_mask (cr, pattern);
    cairo_pattern_destroy (pattern);

    return CAIRO_TEST_SUCCESS;
}
Exemple #5
0
static cairo_pattern_t *
draw_clb_pattern(drawing_context_t *ctx) {
  cairo_t *cr = ctx->cr;
  const double zoom = ctx->zoom;
  cairo_pattern_t *pat;
  unsigned width = SITE_WIDTH*zoom, height = SITE_HEIGHT*zoom;

  cairo_save (cr);

  cairo_set_source_rgb (cr, 0., 0., 0.);
  cairo_rectangle (cr, 0, 0, width, height);
  cairo_clip (cr);
  cairo_scale (cr, zoom, zoom);

  cairo_push_group (cr);

/*   cairo_rectangle (cr, 0, 0, SITE_WIDTH, SITE_HEIGHT); */
/*   cairo_set_source_rgb (cr, 0., 0., 0.); */
/*   cairo_paint (cr); */

  cairo_set_line_width (cr, 1.0);
  cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);

  _draw_clb_pattern (cr);
  pat = cairo_pop_group (cr);

  cairo_restore (cr);

  return pat;
}
Exemple #6
0
static JSBool
popGroup_func(JSContext *context,
              uintN      argc,
              jsval     *vp)
{
    JSObject *obj = JS_THIS_OBJECT(context, vp);
    cairo_t *cr;
    cairo_pattern_t *pattern;
    JSObject *pattern_wrapper;

    if (argc > 0) {
        gjs_throw(context, "Context.popGroup() takes no arguments");
        return JS_FALSE;
    }

    cr = gjs_cairo_context_get_context(context, obj);
    pattern = cairo_pop_group(cr);
    if (!gjs_cairo_check_status(context, cairo_status(cr), "context"))
        return JS_FALSE;

    /* pattern belongs to the context, so keep the reference */
    pattern_wrapper = gjs_cairo_pattern_from_pattern(context, pattern);
    if (!pattern_wrapper) {
        gjs_throw(context, "failed to create pattern");
        return JS_FALSE;
    }

    JS_SET_RVAL(context, vp, OBJECT_TO_JSVAL(pattern_wrapper));

    return JS_TRUE;
}
Exemple #7
0
static int
cr_pop_group (lua_State *L) {
    cairo_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_CONTEXT);
    cairo_pattern_t **pattern = create_pattern_userdata(L);
    *pattern = cairo_pop_group(*obj);
    return 1;
}
Exemple #8
0
static bool
popGroup_func(JSContext *context,
              unsigned   argc,
              JS::Value *vp)
{
    GJS_GET_PRIV(context, argc, vp, rec, obj, GjsCairoContext, priv);
    cairo_t *cr = priv ? priv->cr : NULL;
    cairo_pattern_t *pattern;
    JSObject *pattern_wrapper;

    if (argc > 0) {
        gjs_throw(context, "Context.popGroup() takes no arguments");
        return false;
    }

    pattern = cairo_pop_group(cr);
    if (!gjs_cairo_check_status(context, cairo_status(cr), "context"))
        return false;

    /* pattern belongs to the context, so keep the reference */
    pattern_wrapper = gjs_cairo_pattern_from_pattern(context, pattern);
    if (!pattern_wrapper) {
        gjs_throw(context, "failed to create pattern");
        return false;
    }

    rec.rval().setObject(*pattern_wrapper);

    return true;
}
already_AddRefed<gfxPattern>
gfxContext::PopGroup()
{
    cairo_pattern_t *pat = cairo_pop_group(mCairo);
    gfxPattern *wrapper = new gfxPattern(pat);
    cairo_pattern_destroy(pat);
    NS_IF_ADDREF(wrapper);
    return wrapper;
}
Exemple #10
0
cairo_pattern_t *CairoGroup::pop() {
    if (pushed) {
        cairo_pattern_t *ret = cairo_pop_group(ct);
        pushed = false;
        return ret;
    } else {
        throw std::logic_error("Cairo group popped without pushing it first");
    }
}
Exemple #11
0
Cairo::RefPtr<Cairo::Pattern> CairoGroup::popmm() {
    if (pushed) {
        cairo_pattern_t *ret = cairo_pop_group(ct);
        Cairo::RefPtr<Cairo::Pattern> retmm(new Cairo::Pattern(ret, true));
        pushed = false;
        return retmm;
    } else {
        throw std::logic_error("Cairo group popped without pushing it first");
    }
}
Exemple #12
0
__attribute__((unused)) static cairo_pattern_t *
draw_full_clb_pattern(drawing_context_t *ctx,
		      chip_descr_t *chip) {
  cairo_t *cr = ctx->cr;

  cairo_push_group (cr);
  /* draw the thing only using vector operations */
  iterate_over_sites(chip, draw_site_vector, ctx);
  return cairo_pop_group (cr);
}
static VALUE
cr_pop_group (VALUE self)
{
  VALUE rb_pattern;
  cairo_pattern_t *pattern;

  pattern = cairo_pop_group (_SELF);
  cr_check_status (_SELF);
  rb_pattern = CRPATTERN2RVAL (pattern);
  cairo_pattern_destroy (pattern);
  return rb_pattern;
}
Exemple #14
0
static int cairo_pop_group_l( lua_State* L )
{
  lua_cairo_t* lc = lua_cairo_check( L, 1 );

  lua_cairo_pattern_t* lcp = (lua_cairo_pattern_t*)lua_newuserdata( L, sizeof( lua_cairo_pattern_t ) );
  memset( lcp, 0, sizeof( lua_cairo_pattern_t ) );

  luaL_getmetatable( L, "lua_cairo_pattern_t" );
  lua_setmetatable( L, -2 );

  lcp->pattern = cairo_pop_group( lc->cairo );

  return( 1 );
}
static void
selection_render_mask (Selection *selection)
{
  cairo_t *cr;

  cr = gdk_cairo_create (gtk_widget_get_window (selection->shell->canvas));

  cairo_push_group_with_content (cr, CAIRO_CONTENT_ALPHA);

  cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
  cairo_set_line_width (cr, 1.0);

  gimp_cairo_add_segments (cr,
                           selection->segs_in,
                           selection->n_segs_in);
  cairo_stroke (cr);

  selection->segs_in_mask = cairo_pop_group (cr);

  cairo_destroy (cr);
}
static cairo_test_status_t
draw_with_extend (cairo_t *cr, int w, int h, cairo_extend_t extend)
{
    cairo_pattern_t *pattern;
    cairo_set_source_rgb (cr, 1,1,1);
    cairo_paint (cr);

    cairo_save (cr);

    /* When the destination surface is created by cairo-test-suite to
     * test device-offset, it is bigger than w x h. This test expects
     * the group to have a size which is exactly w x h, so it must
     * clip to the this rectangle to guarantee that the group will
     * have the correct size.
     */
    cairo_rectangle (cr, 0, 0, w, h);
    cairo_clip (cr);

    cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR); {
        /* A two by two checkerboard with black, red and yellow
         * cells. */
        cairo_set_source_rgb (cr, 1,0,0);
        cairo_rectangle (cr, w/2, 0, w-w/2, h/2);
        cairo_fill (cr);
        cairo_set_source_rgb (cr, 1,1,0);
        cairo_rectangle (cr, 0, h/2, w/2, h-h/2);
        cairo_fill (cr);
    }
    pattern = cairo_pop_group (cr);
    cairo_pattern_set_extend(pattern, extend);

    cairo_restore (cr);

    cairo_scale (cr, 0.5, 0.5);
    cairo_set_source (cr, pattern);
    cairo_paint (cr);

    cairo_pattern_destroy (pattern);
    return CAIRO_TEST_SUCCESS;
}
Exemple #17
0
bool GlyphLayerShadowInset::render(
	cairo_t*       c,
	cairo_glyph_t* glyph,
	unsigned int   width,
	unsigned int   height
) {
	if(cairo_status(c) || !glyph) return false;
	
	cairo_push_group(c);
	cairo_glyph_path(c, glyph, 1);
	cairo_clip(c);
	cairo_translate(c, getOffsetX(), getOffsetY());
	// cairo_set_line_join(c, CAIRO_LINE_JOIN_ROUND);
	cairo_set_line_width(c, static_cast<double>(_radius) - 0.5f);
	cairo_glyph_path(c, glyph, 1);
	cairo_stroke(c);
	
	cairo_pattern_t* pattern = cairo_pop_group(c);
	cairo_surface_t* tmp     = createBlurredSurface(CAIRO_FORMAT_A8, pattern, width, height);

	cairo_set_source_surface(
		c,
		tmp,
		-static_cast<double>(_getBlurSize()) * 2,
		-static_cast<double>(_getBlurSize()) * 2
	);

	cairo_glyph_path(c, glyph, 1);
	cairo_clip(c);
	cairo_paint(c);

	cairo_surface_destroy(tmp);
	cairo_pattern_destroy(pattern);
	
	return true;
}
Exemple #18
0
static void
brush_end_element (GMarkupParseContext  *context,
                   const gchar          *element_name,
                   gpointer              user_data,
                   GError              **error)
{
        GXPSBrush *brush = (GXPSBrush *)user_data;

        if (strcmp (element_name, "SolidColorBrush") == 0) {
        } else if (strcmp (element_name, "LinearGradientBrush") == 0) {
                g_markup_parse_context_pop (context);
        } else if (strcmp (element_name, "RadialGradientBrush") == 0) {
                g_markup_parse_context_pop (context);
        } else if (strcmp (element_name, "ImageBrush") == 0) {
                GXPSBrushImage  *brush_image;
                GXPSImage       *image;
                GError          *err = NULL;

                brush_image = g_markup_parse_context_pop (context);

                GXPS_DEBUG (g_message ("set_fill_pattern (image)"));
                image = gxps_page_get_image (brush->ctx->page, brush_image->image_uri, &err);
                if (image) {
                        cairo_matrix_t   matrix;
                        gdouble          x_scale, y_scale;
                        cairo_surface_t *clip_surface;

                        /* viewbox units is 1/96 inch, convert to pixels */
                        brush_image->viewbox.x *= image->res_x / 96;
                        brush_image->viewbox.y *= image->res_y / 96;
                        brush_image->viewbox.width *= image->res_x / 96;
                        brush_image->viewbox.height *= image->res_y / 96;

                        clip_surface = cairo_surface_create_for_rectangle (image->surface,
                                                                           brush_image->viewbox.x,
                                                                           brush_image->viewbox.y,
                                                                           brush_image->viewbox.width,
                                                                           brush_image->viewbox.height);
                        brush_image->brush->pattern = cairo_pattern_create_for_surface (clip_surface);
                        cairo_pattern_set_extend (brush_image->brush->pattern, brush_image->extend);

                        x_scale = brush_image->viewport.width / brush_image->viewbox.width;
                        y_scale = brush_image->viewport.height / brush_image->viewbox.height;
                        cairo_matrix_init (&matrix, x_scale, 0, 0, y_scale,
                                           brush_image->viewport.x, brush_image->viewport.y);
                        cairo_matrix_multiply (&matrix, &matrix, &brush_image->matrix);
                        cairo_matrix_invert (&matrix);
                        cairo_pattern_set_matrix (brush_image->brush->pattern, &matrix);

                        if (brush->opacity != 1.0) {
                                cairo_push_group (brush->ctx->cr);
                                cairo_set_source (brush->ctx->cr, brush_image->brush->pattern);
                                cairo_pattern_destroy (brush_image->brush->pattern);
                                cairo_paint_with_alpha (brush->ctx->cr, brush->opacity);
                                brush_image->brush->pattern = cairo_pop_group (brush->ctx->cr);
                        }

                        if (cairo_pattern_status (brush_image->brush->pattern)) {
                                GXPS_DEBUG (g_debug ("%s", cairo_status_to_string (cairo_pattern_status (brush_image->brush->pattern))));
                                cairo_pattern_destroy (brush_image->brush->pattern);
                                brush_image->brush->pattern = NULL;
                        }
                        cairo_surface_destroy (clip_surface);
                } else if (err) {
                        GXPS_DEBUG (g_debug ("%s", err->message));
                        g_error_free (err);
                }
                gxps_brush_image_free (brush_image);
        } else if (strcmp (element_name, "VisualBrush") == 0) {
                GXPSRenderContext *sub_ctx;
                GXPSBrushVisual   *visual;
                cairo_matrix_t     matrix;

                sub_ctx = g_markup_parse_context_pop (context);
                visual = sub_ctx->visual;
                g_slice_free (GXPSRenderContext, sub_ctx);

                GXPS_DEBUG (g_message ("set_fill_pattern (visual)"));
                visual->brush->pattern = cairo_pop_group (brush->ctx->cr);
                /* Undo the clip */
                cairo_restore (brush->ctx->cr);
                cairo_pattern_set_extend (visual->brush->pattern, visual->extend);
                cairo_pattern_get_matrix (visual->brush->pattern, &matrix);
                cairo_matrix_multiply (&matrix, &visual->matrix, &matrix);
                cairo_pattern_set_matrix (visual->brush->pattern, &matrix);
                if (cairo_pattern_status (visual->brush->pattern)) {
                        GXPS_DEBUG (g_debug ("%s", cairo_status_to_string (cairo_pattern_status (visual->brush->pattern))));
                        cairo_pattern_destroy (visual->brush->pattern);
                        visual->brush->pattern = NULL;
                }

                gxps_brush_visual_free (visual);
        } else {
                gxps_parse_error (context,
                                  brush->ctx->page->priv->source,
                                  G_MARKUP_ERROR_UNKNOWN_ELEMENT,
                                  element_name, NULL, NULL, error);

        }
}
Exemple #19
0
static PyObject *
pycairo_pop_group (PycairoContext *o) {
  return PycairoPattern_FromPattern (cairo_pop_group (o->ctx), NULL);
}
tile_t*
setup_text_tile (const cairo_font_options_t* font_opts,
		 gdouble                     dpi,
		 gint                        w,
		 gint                        h)
{
	tile_t*          tile    = NULL;
	cairo_status_t   status;
	cairo_surface_t* surface = NULL;
	cairo_surface_t* text    = NULL;
	cairo_surface_t* shadow  = NULL;
	cairo_t*         cr;
	gdouble          width   = (gdouble) w;
	gdouble          height  = (gdouble) h;
	raico_blur_t*    blur    = NULL;
	cairo_pattern_t* pattern = NULL;

	surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
	status = cairo_surface_status (surface);
	if (status != CAIRO_STATUS_SUCCESS)
		g_print ("Error: \"%s\"\n", cairo_status_to_string (status));

	cr = cairo_create (surface);
	status = cairo_status (cr);
	if (status != CAIRO_STATUS_SUCCESS)
	{
		cairo_surface_destroy (surface);
		g_print ("Error: \"%s\"\n", cairo_status_to_string (status));
	}

        // clear and render drop-shadow and bubble-background
	cairo_scale (cr, 1.0f, 1.0f);
	cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
	cairo_paint (cr);
	cairo_set_operator (cr, CAIRO_OPERATOR_OVER);

	text = render_text_to_surface (
			"After an evening of hacking at the"
			" Fataga hotel here at GUADEC I   "
			"can present you even text-scroll "
			"with blur-cache and fade-out mask"
			" and I dedicate this to Behdad who"
			" sadly burst his upper lip during "
			"the evening and had to go to the "
			"hospital. Some spanish KDE-folks "
			"kindly accompanied him to help out"
			" with translation. True collaboration!\0",
			width,
			height,
			font_opts,
			dpi);

	shadow = render_text_to_surface (
			"After an evening of hacking at the"
			" Fataga hotel here at GUADEC I   "
			"can present you even text-scroll "
			"with blur-cache and fade-out mask"
			" and I dedicate this to Behdad who"
			" sadly burst his upper lip during "
			"the evening and had to go to the "
			"hospital. Some spanish KDE-folks "
			"kindly accompanied him to help out"
			" with translation. True collaboration!\0",
			width,
			height,
			font_opts,
			dpi);

	// create and setup blur
	blur = raico_blur_create (RAICO_BLUR_QUALITY_LOW);
	raico_blur_set_radius (blur, 4);

	// now blur it
	raico_blur_apply (blur, shadow);

	// blur no longer needed
	raico_blur_destroy (blur);

	cairo_push_group (cr);
	cairo_set_source_surface (cr,
				  shadow,
				  0.0f,
				  0.0f);

	cairo_paint (cr);
	pattern = cairo_pop_group (cr);
	cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 1.0f);
	cairo_mask (cr, pattern);
	cairo_surface_destroy (shadow);
	cairo_pattern_destroy (pattern);
	cairo_set_source_surface (cr, text, 0.0f, 0.0f);
	cairo_paint (cr);

	cairo_destroy (cr);
	cairo_surface_destroy (text);
	tile = tile_new (surface, 6);
	cairo_surface_destroy (surface);

	return tile;
}
Exemple #21
0
	double lime_cairo_pop_group (double handle) {
		
		return (intptr_t)cairo_pop_group ((cairo_t*)(intptr_t)handle);
		
	}
Exemple #22
0
Pattern* Context::popGroup()
{
	return new Pattern( cairo_pop_group( mCairo ) );
}
Exemple #23
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    const cairo_test_context_t *ctx = cairo_test_get_context (cr);
    cairo_surface_t *surface;
    cairo_pattern_t *pattern;
    cairo_t *cr2;

    /*
     * 1. Test file-not-found from surface->pattern->cairo_t
     */

    /* Make a custom context to not interfere with the one passed in. */
    cr2 = cairo_create (cairo_get_target (cr));

    /* First, let's make a nil surface. */
    surface = cairo_image_surface_create_from_png ("___THIS_FILE_DOES_NOT_EXIST___");

    /* Let the error propagate into a nil pattern. */
    pattern = cairo_pattern_create_for_surface (surface);

    /* Then let it propagate into the cairo_t. */
    cairo_set_source (cr2, pattern);
    cairo_paint (cr2);

    cairo_pattern_destroy (pattern);
    cairo_surface_destroy (surface);

    /* Check that the error made it all that way. */
    if (cairo_status (cr2) != CAIRO_STATUS_FILE_NOT_FOUND) {
	cairo_test_log (ctx, "Error: Received status of \"%s\" rather than expected \"%s\"\n",
			cairo_status_to_string (cairo_status (cr2)),
			cairo_status_to_string (CAIRO_STATUS_FILE_NOT_FOUND));
	cairo_destroy (cr2);
	return CAIRO_TEST_FAILURE;
    }

    cairo_destroy (cr2);

    /*
     * 2. Test NULL pointer pattern->cairo_t
     */
    cr2 = cairo_create (cairo_get_target (cr));

    /* First, trigger the NULL pointer status. */
    pattern = cairo_pattern_create_for_surface (NULL);

    /* Then let it propagate into the cairo_t. */
    cairo_set_source (cr2, pattern);
    cairo_paint (cr2);

    cairo_pattern_destroy (pattern);

    /* Check that the error made it all that way. */
    if (cairo_status (cr2) != CAIRO_STATUS_NULL_POINTER) {
	cairo_test_log (ctx, "Error: Received status of \"%s\" rather than expected \"%s\"\n",
			cairo_status_to_string (cairo_status (cr2)),
			cairo_status_to_string (CAIRO_STATUS_NULL_POINTER));
	cairo_destroy (cr2);
	return CAIRO_TEST_FAILURE;
    }

    cairo_destroy (cr2);

    /*
     * 3. Test that cairo_surface_finish can accept NULL or a nil
     *    surface without crashing.
     */

    cairo_surface_finish (NULL);

    surface = cairo_image_surface_create_from_png ("___THIS_FILE_DOES_NOT_EXIST___");
    cairo_surface_finish (surface);
    cairo_surface_destroy (surface);

    /*
     * 4. OK, we're straying from the original name, but it's still a
     * similar kind of testing of error paths. Here we're making sure
     * we can still call a cairo_get_* function after triggering an
     * INVALID_RESTORE error.
     */
    cr2 = cairo_create (cairo_get_target (cr));

    /* Trigger invalid restore. */
    cairo_restore (cr2);
    if (cairo_status (cr2) != CAIRO_STATUS_INVALID_RESTORE) {
	cairo_test_log (ctx, "Error: Received status of \"%s\" rather than expected \"%s\"\n",
			cairo_status_to_string (cairo_status (cr2)),
			cairo_status_to_string (CAIRO_STATUS_INVALID_RESTORE));
	cairo_destroy (cr2);
	return CAIRO_TEST_FAILURE;
    }

    /* Test that we can still call cairo_get_fill_rule without crashing. */
    cairo_get_fill_rule (cr2);

    cairo_destroy (cr2);

    /*
     * 5. Create a cairo_t for the NULL surface.
     */
    cr2 = cairo_create (NULL);

    if (cairo_status (cr2) != CAIRO_STATUS_NULL_POINTER) {
	cairo_test_log (ctx, "Error: Received status of \"%s\" rather than expected \"%s\"\n",
			cairo_status_to_string (cairo_status (cr2)),
			cairo_status_to_string (CAIRO_STATUS_NULL_POINTER));
	cairo_destroy (cr2);
	return CAIRO_TEST_FAILURE;
    }

    /* Test that get_target returns something valid */
    if (cairo_get_target (cr2) == NULL) {
	cairo_test_log (ctx, "Error: cairo_get_target() returned NULL\n");
	cairo_destroy (cr2);
	return CAIRO_TEST_FAILURE;
    }

    /* Test that push_group doesn't crash */
    cairo_push_group (cr2);
    cairo_stroke (cr2);
    cairo_pop_group (cr2);

    cairo_destroy (cr2);

    return CAIRO_TEST_SUCCESS;
}
Exemple #24
0
CairoGroup::~CairoGroup() {
    if (pushed) {
        cairo_pattern_t *p = cairo_pop_group(ct);
        cairo_pattern_destroy(p);
    }
}
Exemple #25
0
void
cairo_perf_run (cairo_perf_t	   *perf,
		const char	   *name,
		cairo_perf_func_t   perf_func,
		cairo_count_func_t  count_func)
{
    static cairo_bool_t first_run = TRUE;
    unsigned int i, similar, has_similar;
    cairo_time_t *times;
    cairo_stats_t stats = {0.0, 0.0};
    int low_std_dev_count;

    if (perf->list_only) {
	printf ("%s\n", name);
	return;
    }

    if (first_run) {
	if (perf->raw) {
	    printf ("[ # ] %s.%-s %s %s %s ...\n",
		    "backend", "content", "test-size", "ticks-per-ms", "time(ticks)");
	}

	if (perf->summary) {
	    fprintf (perf->summary,
		     "[ # ] %8s.%-4s %28s %8s %8s %5s %5s %s %s\n",
		     "backend", "content", "test-size", "min(ticks)", "min(ms)", "median(ms)",
		     "stddev.", "iterations", "overhead");
	}
	first_run = FALSE;
    }

    times = perf->times;

    if (getenv ("CAIRO_PERF_OUTPUT") != NULL) { /* check output */
	char *filename;
	cairo_status_t status;

	xasprintf (&filename, "%s.%s.%s.%d.out.png",
		   name, perf->target->name,
		   _content_to_string (perf->target->content, 0),
		   perf->size);
	cairo_save (perf->cr);
	perf_func (perf->cr, perf->size, perf->size, 1);
	cairo_restore (perf->cr);
	status = cairo_surface_write_to_png (cairo_get_target (perf->cr), filename);
	if (status) {
	    fprintf (stderr, "Failed to generate output check '%s': %s\n",
		     filename, cairo_status_to_string (status));
	    return;
	}

	free (filename);
    }

    has_similar = cairo_perf_has_similar (perf);
    for (similar = 0; similar <= has_similar; similar++) {
	unsigned loops;

	if (perf->summary) {
	    fprintf (perf->summary,
		     "[%3d] %8s.%-5s %26s.%-3d ",
		     perf->test_number, perf->target->name,
		     _content_to_string (perf->target->content, similar),
		     name, perf->size);
	    fflush (perf->summary);
	}

	/* We run one iteration in advance to warm caches and calibrate. */
	cairo_perf_yield ();
	if (similar)
	    cairo_push_group_with_content (perf->cr,
					   cairo_boilerplate_content (perf->target->content));
	else
	    cairo_save (perf->cr);
	perf_func (perf->cr, perf->size, perf->size, 1);
	loops = cairo_perf_calibrate (perf, perf_func);
	if (similar)
	    cairo_pattern_destroy (cairo_pop_group (perf->cr));
	else
	    cairo_restore (perf->cr);

	low_std_dev_count = 0;
	for (i =0; i < perf->iterations; i++) {
	    cairo_perf_yield ();
	    if (similar)
		cairo_push_group_with_content (perf->cr,
					       cairo_boilerplate_content (perf->target->content));
	    else
		cairo_save (perf->cr);
	    times[i] = perf_func (perf->cr, perf->size, perf->size, loops) ;
	    if (similar)
		cairo_pattern_destroy (cairo_pop_group (perf->cr));
	    else
		cairo_restore (perf->cr);
	    if (perf->raw) {
		if (i == 0)
		    printf ("[*] %s.%s %s.%d %g",
			    perf->target->name,
			    _content_to_string (perf->target->content, similar),
			    name, perf->size,
			    _cairo_time_to_double (_cairo_time_from_s (1.)) / 1000.);
		printf (" %lld", (long long) (times[i] / (double) loops));
	    } else if (! perf->exact_iterations) {
		if (i > 0) {
		    _cairo_stats_compute (&stats, times, i+1);

		    if (stats.std_dev <= CAIRO_PERF_LOW_STD_DEV) {
			low_std_dev_count++;
			if (low_std_dev_count >= CAIRO_PERF_STABLE_STD_DEV_COUNT)
			    break;
		    } else {
			low_std_dev_count = 0;
		    }
		}
	    }
	}

	if (perf->raw)
	    printf ("\n");

	if (perf->summary) {
	    _cairo_stats_compute (&stats, times, i);
	    if (count_func != NULL) {
		double count = count_func (perf->cr, perf->size, perf->size);
		fprintf (perf->summary,
			 "%.3f [%10lld/%d] %#8.3f %#8.3f %#5.2f%% %3d: %.2f\n",
			 stats.min_ticks /(double) loops,
			 (long long) stats.min_ticks, loops,
			 _cairo_time_to_s (stats.min_ticks) * 1000.0 / loops,
			 _cairo_time_to_s (stats.median_ticks) * 1000.0 / loops,
			 stats.std_dev * 100.0, stats.iterations,
			 count / _cairo_time_to_s (stats.min_ticks));
	    } else {
		fprintf (perf->summary,
			 "%.3f [%10lld/%d] %#8.3f %#8.3f %#5.2f%% %3d\n",
			 stats.min_ticks /(double) loops,
			 (long long) stats.min_ticks, loops,
			 _cairo_time_to_s (stats.min_ticks) * 1000.0 / loops,
			 _cairo_time_to_s (stats.median_ticks) * 1000.0 / loops,
			 stats.std_dev * 100.0, stats.iterations);
	    }
	    fflush (perf->summary);
	}

	perf->test_number++;
    }
}
Exemple #26
0
void
cairo_perf_run (cairo_perf_t		*perf,
		const char		*name,
		cairo_perf_func_t	 perf_func)
{
    static cairo_bool_t first_run = TRUE;
    unsigned int i, similar, has_similar;
    cairo_perf_ticks_t *times;
    cairo_stats_t stats = {0.0, 0.0};
    int low_std_dev_count;

    if (perf->list_only) {
	printf ("%s\n", name);
	return;
    }

    if (first_run) {
	if (perf->raw)
	    printf ("[ # ] %s-%-s %s %s %s ...\n",
		    "backend", "content", "test-size", "ticks-per-ms", "time(ticks)");
	else
	    printf ("[ # ] %8s-%-4s %28s %8s %8s %5s %5s %s\n",
		    "backend", "content", "test-size", "min(ticks)", "min(ms)", "median(ms)",
		    "stddev.", "iterations");
	first_run = FALSE;
    }

    times = perf->times;

    has_similar = cairo_perf_has_similar (perf);
    for (similar = 0; similar <= has_similar; similar++) {
	/* We run one iteration in advance to warm caches, etc. */
	cairo_perf_yield ();
	if (similar)
	    cairo_push_group_with_content (perf->cr,
		                           cairo_boilerplate_content (perf->target->content));
	(perf_func) (perf->cr, perf->size, perf->size);
	if (similar)
	    cairo_pattern_destroy (cairo_pop_group (perf->cr));

	low_std_dev_count = 0;
	for (i =0; i < perf->iterations; i++) {
	    cairo_perf_yield ();
	    if (similar)
		cairo_push_group_with_content (perf->cr,
			                       cairo_boilerplate_content (perf->target->content));
	    times[i] = (perf_func) (perf->cr, perf->size, perf->size);
	    if (similar)
		cairo_pattern_destroy (cairo_pop_group (perf->cr));

	    if (perf->raw) {
		if (i == 0)
		    printf ("[*] %s-%s %s-%d %g",
			    perf->target->name,
			    _content_to_string (perf->target->content, similar),
			    name, perf->size,
			    cairo_perf_ticks_per_second () / 1000.0);
		printf (" %lld", (long long) times[i]);
	    } else if (! perf->exact_iterations) {
		if (i > 0) {
		    _cairo_stats_compute (&stats, times, i+1);

		    if (stats.std_dev <= CAIRO_PERF_LOW_STD_DEV)
		    {
			low_std_dev_count++;
			if (low_std_dev_count >= CAIRO_PERF_STABLE_STD_DEV_COUNT)
			    break;
		    } else {
			low_std_dev_count = 0;
		    }
		}
	    }
	}

	if (perf->raw) {
	    printf ("\n");
	} else {
	    _cairo_stats_compute (&stats, times, i);
	    printf ("[%3d] %8s-%-5s %26s-%-3d ",
		    perf->test_number, perf->target->name,
		    _content_to_string (perf->target->content, similar),
		    name, perf->size);

	    printf ("%10lld %#8.3f %#8.3f %#5.2f%% %3d\n",
		    (long long) stats.min_ticks,
		    (stats.min_ticks * 1000.0) / cairo_perf_ticks_per_second (),
		    (stats.median_ticks * 1000.0) / cairo_perf_ticks_per_second (),
		    stats.std_dev * 100.0, stats.iterations);
	}

	perf->test_number++;
    }
}
gboolean
expose_handler (GtkWidget* window,
				cairo_t*   cr,
				gpointer   data)
{
	cairo_pattern_t* pattern = NULL;
	cairo_pattern_t* mask    = NULL;


	// clear and render drop-shadow and bubble-background
	cairo_scale (cr, 1.0f, 1.0f);
	cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
	cairo_paint (cr);
	cairo_set_operator (cr, CAIRO_OPERATOR_OVER);

	if (g_distance < 1.0f)
	{
		tile_paint (g_tile, cr, 0.0f, 0.0f, g_distance, 1.0f - g_distance);

		cairo_push_group (cr);
		tile_paint (g_text,
			    cr,
			    2 * BUBBLE_SHADOW_SIZE,
			    BUBBLE_SHADOW_SIZE - g_offset,
			    g_distance,
			    1.0f - g_distance);
		pattern = cairo_pop_group (cr);
		cairo_set_source (cr, pattern);
		mask = cairo_pattern_create_linear (0.0f, 2 * BUBBLE_SHADOW_SIZE, 0.0f, BUBBLE_HEIGHT);
		cairo_pattern_add_color_stop_rgba (mask,
						   0.0f,
						   0.0f,
						   0.0f,
						   0.0f,
						   0.0f);
		cairo_pattern_add_color_stop_rgba (mask,
						   0.2f,
						   0.0f,
						   0.0f,
						   0.0f,
						   1.0f);
		cairo_pattern_add_color_stop_rgba (mask,
						   0.8f,
						   0.0f,
						   0.0f,
						   0.0f,
						   1.0f);
		cairo_pattern_add_color_stop_rgba (mask,
						   1.0f,
						   0.0f,
						   0.0f,
						   0.0f,
						   0.0f);
		cairo_mask (cr, mask);
		cairo_pattern_destroy (mask);
		cairo_pattern_destroy (pattern);

		gtk_window_set_opacity (GTK_WINDOW (window),
					0.3f + g_distance * 0.7f);
	}
	else
	{
		tile_paint (g_tile, cr, 0.0f, 0.0f, g_distance, 0.0f);

		cairo_push_group (cr);
		tile_paint (g_text, cr, 2 * BUBBLE_SHADOW_SIZE, BUBBLE_SHADOW_SIZE - g_offset, g_distance, 0.0f);
		pattern = cairo_pop_group (cr);
		cairo_set_source (cr, pattern);
		mask = cairo_pattern_create_linear (0.0f, 2 * BUBBLE_SHADOW_SIZE, 0.0f, BUBBLE_HEIGHT);
		cairo_pattern_add_color_stop_rgba (mask, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
		cairo_pattern_add_color_stop_rgba (mask, 0.2f, 0.0f, 0.0f, 0.0f, 1.0f);
		cairo_pattern_add_color_stop_rgba (mask, 0.8f, 0.0f, 0.0f, 0.0f, 1.0f);
		cairo_pattern_add_color_stop_rgba (mask, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f);
		cairo_mask (cr, mask);
		cairo_pattern_destroy (pattern);

		gtk_window_set_opacity (GTK_WINDOW (window), 1.0f);
	}

	return TRUE;
}
Exemple #28
0
IoObject *IoCairoContext_popGroup(IoCairoContext *self, IoObject *locals, IoMessage *m)
{
	cairo_pattern_t *pattern = cairo_pop_group(CONTEXT(self));
	return IoCairoPattern_newWithRawPattern_(IOSTATE, m, cairo_pattern_reference(pattern));
}