static GpStatus draw_tile_flipXY_texture (cairo_t *ct, GpBitmap *bitmap, GpTexture *brush) { cairo_surface_t *original = NULL; cairo_surface_t *texture; cairo_pattern_t *pat; GpMatrix tempMatrix; GpRect *rect = &brush->rectangle; GpStatus status; cairo_t *ct2; BYTE *premul = NULL; if (!rect) return InvalidParameter; gdip_bitmap_ensure_surface (bitmap); if (gdip_bitmap_format_needs_premultiplication (bitmap)) { premul = gdip_bitmap_get_premultiplied_scan0 (bitmap); if (premul) { BitmapData *data = bitmap->active_bitmap; original = cairo_image_surface_create_for_data (premul, CAIRO_FORMAT_ARGB32, data->width, data->height, data->stride); } } /* if premul isn't required (or couldn't be computed, e.g. out of memory) */ if (!original) original = bitmap->surface; /* Use the original as a pattern */ pat = cairo_pattern_create_for_surface (original); status = gdip_get_pattern_status(pat); if (status != Ok) goto cleanup; cairo_pattern_set_extend (pat, CAIRO_EXTEND_REPEAT); /* texture surface to be created */ texture = cairo_surface_create_similar (original, from_cairoformat_to_content (bitmap->cairo_format), 2 * rect->Width, 2 * rect->Height); status = gdip_get_status (cairo_surface_status (texture)); if (status != Ok) { cairo_pattern_destroy (pat); goto cleanup; } /* Draw upper left part of the texture */ ct2 = cairo_create (texture); cairo_set_source (ct2, pat); cairo_rectangle (ct2, 0, 0, rect->Width, rect->Height); cairo_fill (ct2); /* Not sure if this is a bug, but using rect->Height - 1 avoids the seam. */ cairo_matrix_init_identity (&tempMatrix); cairo_matrix_translate (&tempMatrix, 0, rect->Height - 1); /* scale in -Y direction to flip along Y */ cairo_matrix_scale (&tempMatrix, 1.0, -1.0); cairo_pattern_set_matrix (pat, &tempMatrix); /* Draw lower left part of the texture */ cairo_translate (ct2, 0, rect->Height); cairo_set_source (ct2, pat); cairo_rectangle (ct2, 0, 0, rect->Width, rect->Height); cairo_fill (ct2); /* Reset the pattern matrix and do fresh transformation */ cairo_matrix_init_identity (&tempMatrix); /* Not sure if this is a bug, but using rect->Width - 1 avoids the seam. */ cairo_matrix_translate (&tempMatrix, rect->Width - 1, 0); /* scale in -X direction to flip along X */ cairo_matrix_scale (&tempMatrix, -1.0, 1.0); cairo_pattern_set_matrix (pat, &tempMatrix); /* Draw upper right part of the texture */ cairo_translate (ct2, rect->Width, -rect->Height); cairo_set_source (ct2, pat); cairo_rectangle (ct2, 0, 0, rect->Width, rect->Height); cairo_fill (ct2); /* Not sure if this is a bug, but using rect->Height - 1 avoids the seam. */ cairo_matrix_translate (&tempMatrix, 0, rect->Height - 1); /* scale in -Y direction to flip along Y */ cairo_matrix_scale (&tempMatrix, 1.0, -1.0); cairo_pattern_set_matrix (pat, &tempMatrix); /* Draw lower right part of the texture */ cairo_translate (ct2, 0, rect->Height); cairo_set_source (ct2, pat); cairo_rectangle (ct2, 0, 0, rect->Width, rect->Height); cairo_fill (ct2); cairo_destroy(ct2); brush->pattern = cairo_pattern_create_for_surface (texture); status = gdip_get_pattern_status(brush->pattern); if (status != Ok) { cairo_pattern_destroy (pat); cairo_surface_destroy (texture); goto cleanup; } cairo_pattern_set_extend (brush->pattern, CAIRO_EXTEND_REPEAT); cairo_pattern_destroy (pat); cairo_surface_destroy (texture); status = gdip_get_status (cairo_status (ct)); cleanup: if (premul) { cairo_surface_destroy (original); GdipFree (premul); } return status; }
bool QCairoPaintEngine::begin(QPaintDevice *pd) { if (surface) { end(); } const QCairoPaintDevice* cpd=dynamic_cast<const QCairoPaintDevice*>(pd); surface = NULL; if (cpd) { exportText=cpd->getExportText(); QCairoPaintDevice::CairoFileType ft=cpd->getFileType(); QSizeF s=cpd->getFileSizeMM(); //qDebug()<<ft; if (ft==QCairoPaintDevice::cftPDF14) { //qDebug()<< "Cairo-PDF1.4"; surface = cairo_pdf_surface_create (cpd->getFileName().toLocal8Bit().data(), s.width()/25.4*72.0, s.height()/25.4*72.0); cairo_pdf_surface_restrict_to_version(surface, CAIRO_PDF_VERSION_1_4); } else if (ft==QCairoPaintDevice::cftPDF15) { //Debug()<< "Cairo-PDF1.5"<<s<<s.width()/25.4*72.0<<s.height()/25.4*72.0; surface = cairo_pdf_surface_create (cpd->getFileName().toLocal8Bit().data(), s.width()/25.4*72.0, s.height()/25.4*72.0); cairo_pdf_surface_restrict_to_version(surface, CAIRO_PDF_VERSION_1_5); } else if (ft==QCairoPaintDevice::cftPS2) { //qDebug()<< "Cairo-PS2"; surface = cairo_ps_surface_create (cpd->getFileName().toLocal8Bit().data(), s.width()/25.4*72.0, s.height()/25.4*72.0); cairo_ps_surface_restrict_to_level(surface, CAIRO_PS_LEVEL_2); } else if (ft==QCairoPaintDevice::cftPS3) { //qDebug()<< "Cairo-PS3"; surface = cairo_ps_surface_create (cpd->getFileName().toLocal8Bit().data(), s.width()/25.4*72.0, s.height()/25.4*72.0); cairo_ps_surface_restrict_to_level(surface, CAIRO_PS_LEVEL_2); } else if (ft==QCairoPaintDevice::cftEPS2) { //qDebug()<< "Cairo-EPS2"; surface = cairo_ps_surface_create (cpd->getFileName().toLocal8Bit().data(), s.width()/25.4*72.0, s.height()/25.4*72.0); cairo_ps_surface_restrict_to_level(surface, CAIRO_PS_LEVEL_2); cairo_ps_surface_set_eps(surface, 1); } else if (ft==QCairoPaintDevice::cftEPS3) { //qDebug()<< "Cairo-EPS3"; surface = cairo_ps_surface_create (cpd->getFileName().toLocal8Bit().data(), s.width()/25.4*72.0, s.height()/25.4*72.0); cairo_ps_surface_restrict_to_level(surface, CAIRO_PS_LEVEL_2); cairo_ps_surface_set_eps(surface, 1); } else if (ft==QCairoPaintDevice::cftSVG11) { //qDebug()<< "Cairo-SVG11"; surface = cairo_svg_surface_create (cpd->getFileName().toLocal8Bit().data(), s.width()/25.4*72.0, s.height()/25.4*72.0); cairo_svg_surface_restrict_to_version(surface, CAIRO_SVG_VERSION_1_1); } else if (ft==QCairoPaintDevice::cftSVG12) { //qDebug()<< "Cairo-SVG12"; surface = cairo_svg_surface_create (cpd->getFileName().toLocal8Bit().data(), s.width()/25.4*72.0, s.height()/25.4*72.0); cairo_svg_surface_restrict_to_version(surface, CAIRO_SVG_VERSION_1_2); } } if (surface) { if (cairo_surface_status(surface) == CAIRO_STATUS_SUCCESS) { cr = cairo_create(surface); if (cr) { if (cairo_status(cr) != CAIRO_STATUS_SUCCESS) { qDebug()<<"QCairoPaintDevice error initializing CAIRO: "<<cairo_status_to_string(cairo_status(cr)); end(); return false; } else { cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT); } } else { qDebug()<<"QCairoPaintDevice error initializing CAIRO !!!"; end(); return false; } } else { qDebug()<<"QCairoPaintDevice error creating surface: "<<cairo_status_to_string(cairo_surface_status(surface)); end(); return false; } } else { qDebug()<<"UNKNOWN QCairoPaintDevice type !!!"; return false; } return true; }
static void clutter_canvas_emit_draw (ClutterCanvas *self) { ClutterCanvasPrivate *priv = self->priv; int real_width, real_height; cairo_surface_t *surface; gboolean mapped_buffer; unsigned char *data; CoglBuffer *buffer; int window_scale = 1; gboolean res; cairo_t *cr; g_assert (priv->height > 0 && priv->width > 0); priv->dirty = TRUE; if (priv->scale_factor_set) window_scale = priv->scale_factor; else g_object_get (clutter_settings_get_default (), "window-scaling-factor", &window_scale, NULL); real_width = priv->width * window_scale; real_height = priv->height * window_scale; CLUTTER_NOTE (MISC, "Creating Cairo surface with size %d x %d (real: %d x %d, scale: %d)", priv->width, priv->height, real_width, real_height, window_scale); if (priv->buffer == NULL) { CoglContext *ctx; ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ()); priv->buffer = cogl_bitmap_new_with_size (ctx, real_width, real_height, CLUTTER_CAIRO_FORMAT_ARGB32); } buffer = COGL_BUFFER (cogl_bitmap_get_buffer (priv->buffer)); if (buffer == NULL) return; cogl_buffer_set_update_hint (buffer, COGL_BUFFER_UPDATE_HINT_DYNAMIC); data = cogl_buffer_map (buffer, COGL_BUFFER_ACCESS_READ_WRITE, COGL_BUFFER_MAP_HINT_DISCARD); if (data != NULL) { int bitmap_stride = cogl_bitmap_get_rowstride (priv->buffer); surface = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_ARGB32, real_width, real_height, bitmap_stride); mapped_buffer = TRUE; } else { surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, real_width, real_height); mapped_buffer = FALSE; } cairo_surface_set_device_scale (surface, window_scale, window_scale); self->priv->cr = cr = cairo_create (surface); g_signal_emit (self, canvas_signals[DRAW], 0, cr, priv->width, priv->height, &res); #ifdef CLUTTER_ENABLE_DEBUG if (_clutter_diagnostic_enabled () && cairo_status (cr)) { g_warning ("Drawing failed for <ClutterCanvas>[%p]: %s", self, cairo_status_to_string (cairo_status (cr))); } #endif self->priv->cr = NULL; cairo_destroy (cr); if (mapped_buffer) cogl_buffer_unmap (buffer); else { int size = cairo_image_surface_get_stride (surface) * priv->height; cogl_buffer_set_data (buffer, 0, cairo_image_surface_get_data (surface), size); } cairo_surface_destroy (surface); }
int lime_cairo_status (value handle) { return cairo_status ((cairo_t*)val_data (handle)); }
int main (int argc, char *argv[]) { int i, j, num_targets; cairo_perf_case_t *perf_case; cairo_perf_t perf; cairo_boilerplate_target_t **targets; cairo_surface_t *surface; parse_options (&perf, argc, argv); if (check_cpu_affinity()) { fputs( "NOTICE: cairo-perf and the X server should be bound to CPUs (either the same\n" "or separate) on SMP systems. Not doing so causes random results when the X\n" "server is moved to or from cairo-perf's CPU during the benchmarks:\n" "\n" " $ sudo taskset -cp 0 $(pidof X)\n" " $ taskset -cp 1 $$\n" "\n" "See taskset(1) for information about changing CPU affinity.\n", stderr); } targets = cairo_boilerplate_get_targets (&num_targets, NULL); for (i = 0; i < num_targets; i++) { cairo_boilerplate_target_t *target = targets[i]; if (! target_is_measurable (target)) continue; perf.target = target; perf.test_number = 0; for (j = 0; perf_cases[j].run; j++) { perf_case = &perf_cases[j]; for (perf.size = perf_case->min_size; perf.size <= perf_case->max_size; perf.size *= 2) { surface = (target->create_surface) (NULL, target->content, perf.size, perf.size, CAIRO_BOILERPLATE_MODE_PERF, &target->closure); if (surface == NULL) { fprintf (stderr, "Error: Failed to create target surface: %s\n", target->name); cairo_boilerplate_free_targets (targets); cairo_perf_fini (); exit (1); } cairo_perf_timer_set_synchronize (target->synchronize, target->closure); perf.cr = cairo_create (surface); perf_case->run (&perf, perf.cr, perf.size, perf.size); if (cairo_status (perf.cr)) { fprintf (stderr, "Error: Test left cairo in an error state: %s\n", cairo_status_to_string (cairo_status (perf.cr))); cairo_boilerplate_free_targets (targets); cairo_perf_fini (); exit (1); } cairo_destroy (perf.cr); cairo_surface_destroy (surface); if (target->cleanup) target->cleanup (target->closure); } } } cairo_boilerplate_free_targets (targets); cairo_perf_fini (); return 0; }
gboolean text_to_path (const Text *text, GArray *points) { cairo_t *cr; cairo_surface_t *surface; PangoLayout *layout; PangoRectangle ink_rect; char *str; gboolean ret = FALSE; if (!PANGO_IS_CAIRO_FONT_MAP (pango_context_get_font_map (dia_font_get_context()))) return FALSE; layout = pango_layout_new(dia_font_get_context()); pango_layout_set_font_description (layout, dia_font_get_description (text->font)); pango_layout_set_indent (layout, 0); pango_layout_set_justify (layout, FALSE); pango_layout_set_alignment (layout, text->alignment == ALIGN_LEFT ? PANGO_ALIGN_LEFT : text->alignment == ALIGN_RIGHT ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_CENTER); str = text_get_string_copy (text); pango_layout_set_text (layout, str, -1); g_free (str); pango_layout_get_extents (layout, &ink_rect, NULL); /* any surface should do - this one is always available */ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, ink_rect.width / PANGO_SCALE, ink_rect.height / PANGO_SCALE); cr = cairo_create (surface); cairo_surface_destroy (surface); pango_cairo_layout_path (cr, layout); /* convert the path */ if (cairo_status (cr) == CAIRO_STATUS_SUCCESS) { cairo_path_t *path; int i; path = cairo_copy_path (cr); for (i=0; i < path->num_data; i += path->data[i].header.length) { cairo_path_data_t *data = &path->data[i]; BezPoint bp; switch (data->header.type) { case CAIRO_PATH_MOVE_TO : bp.type = BEZ_MOVE_TO; bp.p1.x = data[1].point.x; bp.p1.y = data[1].point.y; break; case CAIRO_PATH_LINE_TO : bp.type = BEZ_LINE_TO; bp.p1.x = data[1].point.x; bp.p1.y = data[1].point.y; break; case CAIRO_PATH_CURVE_TO : bp.type = BEZ_CURVE_TO; bp.p1.x = data[1].point.x; bp.p1.y = data[1].point.y; bp.p2.x = data[2].point.x; bp.p2.y = data[2].point.y; bp.p3.x = data[3].point.x; bp.p3.y = data[3].point.y; break; case CAIRO_PATH_CLOSE_PATH : /* can't do anything */ default : continue; } g_array_append_val (points, bp); } ret = (path->status == CAIRO_STATUS_SUCCESS); cairo_path_destroy (path); } /* finally scale it ? */ /* clean up */ g_object_unref (layout); cairo_destroy (cr); return ret; }