static cairo_surface_t * _cairo_boilerplate_win32_printing_get_image_surface (cairo_surface_t *surface, int page, int width, int height) { win32_target_closure_t *ptc = cairo_surface_get_user_data (surface, &win32_closure_key); char *filename; cairo_status_t status; /* XXX test paginated interface */ if (page != 0) return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); xasprintf (&filename, "%s.png", ptc->filename); status = _cairo_boilerplate_win32_printing_surface_write_to_png (surface, filename); if (status) return cairo_boilerplate_surface_create_in_error (status); surface = cairo_boilerplate_get_image_surface_from_png (filename, width, height, ptc->target == NULL); remove (filename); free (filename); return surface; }
static cairo_status_t _cairo_boilerplate_xcb_finish_surface (cairo_surface_t *surface) { xcb_target_closure_t *xtc = cairo_surface_get_user_data (surface, &xcb_closure_key); cairo_status_t status; if (xtc->surface != NULL) { cairo_t *cr; cr = cairo_create (xtc->surface); cairo_set_source_surface (cr, surface, 0, 0); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_paint (cr); cairo_destroy (cr); surface = xtc->surface; } cairo_surface_flush (surface); if (cairo_surface_status (surface)) return cairo_surface_status (surface); /* First synchronize with the X server to make sure there are no more errors * in-flight which we would miss otherwise */ _cairo_boilerplate_xcb_sync_server (xtc); status = _cairo_boilerplate_xcb_handle_errors (xtc); if (status) return status; if (xcb_connection_has_error (xtc->c)) return CAIRO_STATUS_WRITE_ERROR; return CAIRO_STATUS_SUCCESS; }
static cairo_surface_t * _cairo_boilerplate_svg_convert_to_image (cairo_surface_t *surface) { svg_target_closure_t *ptc = cairo_surface_get_user_data (surface, &svg_closure_key); return cairo_boilerplate_convert_to_image (ptc->filename, 0); }
static cairo_surface_t * _cairo_boilerplate_pdf_convert_to_image (cairo_surface_t *surface, int page) { pdf_target_closure_t *ptc = cairo_surface_get_user_data (surface, &pdf_closure_key); return cairo_boilerplate_convert_to_image (ptc->filename, page+1); }
void BitmapImage::draw(GraphicsContext* context, const FloatRect& dst, const FloatRect& src, ColorSpace styleColorSpace, CompositeOperator op) { FloatRect srcRect(src); FloatRect dstRect(dst); if (dstRect.width() == 0.0f || dstRect.height() == 0.0f || srcRect.width() == 0.0f || srcRect.height() == 0.0f) return; startAnimation(); cairo_surface_t* image = frameAtIndex(m_currentFrame); if (!image) // If it's too early we won't have an image yet. return; //+EAWebKitChange //5/30/2012 #if ENABLE(IMAGE_COMPRESSION) // Check if this is a compressed surface. const void* pCompressedSurfaceUserData = cairo_surface_get_user_data (image, (cairo_user_data_key_t*) ImageCompressionGetUserDataKey()); #endif //-EAWebKitChange if (mayFillWithSolidColor()) { fillWithSolidColor(context, dstRect, solidColor(), styleColorSpace, op); //+EAWebKitChange //5/30/2012 #if ENABLE(IMAGE_COMPRESSION) if (pCompressedSurfaceUserData) cairo_surface_destroy(image); #endif //-EAWebKitChange return; } context->save(); // Set the compositing operation. if (op == CompositeSourceOver && !frameHasAlphaAtIndex(m_currentFrame)) context->setCompositeOperation(CompositeCopy); else context->setCompositeOperation(op); context->platformContext()->drawSurfaceToContext(image, dstRect, srcRect, context); context->restore(); if (imageObserver()) imageObserver()->didDraw(this); //+EAWebKitChange //5/30/2012 #if ENABLE(IMAGE_COMPRESSION) if (pCompressedSurfaceUserData) cairo_surface_destroy(image); #endif //-EAWebKitChange }
EGLImageKHR display_get_image_for_drm_surface(struct display *display, cairo_surface_t *surface) { struct drm_surface_data *data; data = cairo_surface_get_user_data (surface, &surface_data_key); return data->image; }
struct wl_buffer * display_get_buffer_for_surface(struct display *display, cairo_surface_t *surface) { struct surface_data *data; data = cairo_surface_get_user_data (surface, &surface_data_key); return data->buffer; }
static cairo_surface_t * display_create_drm_surface_from_file(struct display *display, const char *filename, struct rectangle *rect) { cairo_surface_t *surface; GdkPixbuf *pixbuf; GError *error = NULL; int stride, i; unsigned char *pixels, *p, *end; struct drm_surface_data *data; pixbuf = gdk_pixbuf_new_from_file_at_scale(filename, rect->width, rect->height, FALSE, &error); if (error != NULL) return NULL; if (!gdk_pixbuf_get_has_alpha(pixbuf) || gdk_pixbuf_get_n_channels(pixbuf) != 4) { gdk_pixbuf_unref(pixbuf); return NULL; } stride = gdk_pixbuf_get_rowstride(pixbuf); pixels = gdk_pixbuf_get_pixels(pixbuf); for (i = 0; i < rect->height; i++) { p = pixels + i * stride; end = p + rect->width * 4; while (p < end) { unsigned int t; MULT(p[0], p[0], p[3], t); MULT(p[1], p[1], p[3], t); MULT(p[2], p[2], p[3], t); p += 4; } } surface = display_create_drm_surface(display, rect); data = cairo_surface_get_user_data(surface, &surface_data_key); cairo_device_acquire(display->device); glBindTexture(GL_TEXTURE_2D, data->texture); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, rect->width, rect->height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); cairo_device_release(display->device); gdk_pixbuf_unref(pixbuf); return surface; }
static void yield_and_finish (VALUE self) { cairo_surface_t *surface; rb_yield (self); surface = _SELF; if (!cairo_surface_get_user_data (surface, &cr_finished_key)) cr_surface_finish (self); }
static cairo_test_status_t preamble (cairo_test_context_t *ctx) { cairo_surface_t *surface; static const cairo_user_data_key_t key1, key2; int data1, data2; data1 = 0; data2 = 0; surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1); assert (cairo_surface_set_user_data (surface, &key1, &data1, destroy_data1) == CAIRO_STATUS_SUCCESS); assert (cairo_surface_set_user_data (surface, &key2, &data2, destroy_data2) == CAIRO_STATUS_SUCCESS); assert (cairo_surface_get_user_data (surface, &key1) == &data1); assert (cairo_surface_set_user_data (surface, &key1, NULL, NULL) == CAIRO_STATUS_SUCCESS); assert (cairo_surface_get_user_data (surface, &key1) == NULL); assert (data1 == 1); assert (data2 == 0); assert (cairo_surface_set_user_data (surface, &key2, NULL, NULL) == CAIRO_STATUS_SUCCESS); assert (data2 == 2); data1 = 0; assert (cairo_surface_set_user_data (surface, &key1, &data1, NULL) == CAIRO_STATUS_SUCCESS); assert (cairo_surface_set_user_data (surface, &key1, NULL, NULL) == CAIRO_STATUS_SUCCESS); assert (data1 == 0); assert (cairo_surface_get_user_data (surface, &key1) == NULL); assert (cairo_surface_set_user_data (surface, &key1, &data1, destroy_data1) == CAIRO_STATUS_SUCCESS); cairo_surface_destroy (surface); assert (data1 == 1); assert (data2 == 2); return CAIRO_TEST_SUCCESS; }
static cairo_status_t _cairo_boilerplate_xcb_finish_surface (cairo_surface_t *surface) { xcb_target_closure_t *xtc = cairo_surface_get_user_data (surface, &xcb_closure_key); xcb_generic_event_t *ev; if (xtc->surface != NULL) { cairo_t *cr; cr = cairo_create (xtc->surface); cairo_surface_set_device_offset (surface, 0, 0); cairo_set_source_surface (cr, surface, 0, 0); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_paint (cr); cairo_destroy (cr); surface = xtc->surface; } cairo_surface_flush (surface); if (cairo_surface_status (surface)) return cairo_surface_status (surface); while ((ev = xcb_poll_for_event (xtc->c)) != NULL) { cairo_status_t status = CAIRO_STATUS_SUCCESS; if (ev->response_type == 0 /* trust me! */) { xcb_generic_error_t *error = (xcb_generic_error_t *) ev; #if XCB_GENERIC_ERROR_HAS_MAJOR_MINOR_CODES fprintf (stderr, "Detected error during xcb run: %d major=%d, minor=%d\n", error->error_code, error->major_code, error->minor_code); #else fprintf (stderr, "Detected error during xcb run: %d\n", error->error_code); #endif free (error); status = CAIRO_STATUS_WRITE_ERROR; } if (status) return status; } if (xcb_connection_has_error (xtc->c)) return CAIRO_STATUS_WRITE_ERROR; return CAIRO_STATUS_SUCCESS; }
cairo_surface_metadata_t * _cairo_image_surface_get_metadata (cairo_surface_t *surface) { cairo_surface_metadata_t *metadata; metadata = cairo_surface_get_user_data (surface, &surface_metadata_key); if (metadata == NULL) { metadata = g_new0 (cairo_surface_metadata_t, 1); cairo_surface_set_user_data (surface, &surface_metadata_key, metadata, surface_metadata_free); } return metadata; }
static SeedObject seed_object_from_cairo_pdf_surface (SeedContext ctx, cairo_surface_t *surf) { SeedObject jsobj; jsobj = cairo_surface_get_user_data (surf, seed_get_cairo_key()); if (jsobj) return jsobj; jsobj = seed_make_object (ctx, seed_cairo_pdf_surface_class, surf); cairo_surface_set_user_data (surf, seed_get_cairo_key(), jsobj, seed_cairo_destroy_func); return jsobj; }
gboolean _cairo_image_surface_get_has_alpha (cairo_surface_t *surface) { cairo_surface_metadata_t *metadata; if (surface == NULL) return FALSE; metadata = cairo_surface_get_user_data (surface, &surface_metadata_key); if (metadata != NULL) return metadata->has_alpha; return cairo_image_surface_get_format (surface) == CAIRO_FORMAT_ARGB32; }
void BitmapImage::checkForSolidColor() { m_isSolidColor = false; m_checkedForSolidColor = true; if (frameCount() > 1) return; cairo_surface_t* frameSurface = frameAtIndex(0); if (!frameSurface) return; //+EAWebKitChange //5/30/2012 #if ENABLE(IMAGE_COMPRESSION) // Check if this is a compressed surface. const void* pCompressedSurfaceUserData = cairo_surface_get_user_data (frameSurface, (cairo_user_data_key_t*) ImageCompressionGetUserDataKey()); #endif //-EAWebKitChange ASSERT(cairo_surface_get_type(frameSurface) == CAIRO_SURFACE_TYPE_IMAGE); int width = cairo_image_surface_get_width(frameSurface); int height = cairo_image_surface_get_height(frameSurface); if (width != 1 || height != 1) { //+EAWebKitChange //5/30/2012 #if ENABLE(IMAGE_COMPRESSION) if (pCompressedSurfaceUserData) cairo_surface_destroy(frameSurface); #endif //-EAWebKitChange return; } unsigned* pixelColor = reinterpret_cast<unsigned*>(cairo_image_surface_get_data(frameSurface)); m_solidColor = colorFromPremultipliedARGB(*pixelColor); m_isSolidColor = true; //+EAWebKitChange //5/30/2012 #if ENABLE(IMAGE_COMPRESSION) if (pCompressedSurfaceUserData) cairo_surface_destroy(frameSurface); #endif //-EAWebKitChange }
/* The only reason we go through all these machinations to write a PNG * image is to _really ensure_ that the data actually landed in our * buffer through the paginated surface to the test_paginated_surface. * * If we didn't implement this function then the default * cairo_surface_write_to_png would result in the paginated_surface's * acquire_source_image function replaying the recording-surface to an * intermediate image surface. And in that case the * test_paginated_surface would not be involved and wouldn't be * tested. */ static cairo_status_t _cairo_boilerplate_test_paginated_surface_write_to_png (cairo_surface_t *surface, const char *filename) { test_paginated_closure_t *tpc; cairo_status_t status; /* show page first. the automatic show_page is too late for us */ cairo_surface_show_page (surface); status = cairo_surface_status (surface); if (status) return status; tpc = cairo_surface_get_user_data (surface, &test_paginated_closure_key); return cairo_surface_write_to_png (tpc->target, filename); }
static cairo_surface_t * _cairo_boilerplate_svg_convert_to_image (cairo_surface_t *surface) { svg_target_closure_t *ptc = cairo_surface_get_user_data (surface, &svg_closure_key); FILE *file; cairo_surface_t *image; file = cairo_boilerplate_open_any2ppm (ptc->filename, 0); if (file == NULL) return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_READ_ERROR); image = cairo_boilerplate_image_surface_create_from_ppm_stream (file); fclose (file); return image; }
static cairo_test_status_t test_cairo_surface_set_user_data (cairo_surface_t *surface) { static cairo_user_data_key_t key; cairo_status_t status; status = cairo_surface_set_user_data (surface, &key, &key, NULL); if (status == CAIRO_STATUS_NO_MEMORY) return CAIRO_TEST_NO_MEMORY; else if (status) return CAIRO_TEST_SUCCESS; if (cairo_surface_get_user_data (surface, &key) != &key) return CAIRO_TEST_ERROR; return CAIRO_TEST_SUCCESS; }
void _cairo_boilerplate_svg_force_fallbacks (cairo_surface_t *abstract_surface, unsigned int flags) { svg_target_closure_t *ptc = cairo_surface_get_user_data (abstract_surface, &svg_closure_key); cairo_paginated_surface_t *paginated; cairo_svg_surface_t *surface; if (ptc->target) abstract_surface = ptc->target; paginated = (cairo_paginated_surface_t*) abstract_surface; surface = (cairo_svg_surface_t*) paginated->target; surface->force_fallbacks = TRUE; }
static VALUE cr_surface_finish (VALUE self) { cairo_surface_t *surface; cr_io_callback_closure_t *closure; surface = _SELF; closure = cairo_surface_get_user_data (surface, &cr_closure_key); cairo_surface_finish (surface); cairo_surface_set_user_data (surface, &cr_finished_key, (void *)CR_TRUE, NULL); cairo_surface_set_user_data (surface, &cr_object_holder_key, NULL, NULL); if (closure && !NIL_P (closure->error)) rb_exc_raise (closure->error); cr_surface_check_status (surface); return self; }
cairo_status_t _cairo_boilerplate_svg_finish_surface (cairo_surface_t *surface) { svg_target_closure_t *ptc = cairo_surface_get_user_data (surface, &svg_closure_key); cairo_status_t status; /* Both surface and ptc->target were originally created at the * same dimensions. We want a 1:1 copy here, so we first clear any * device offset on surface. * * In a more realistic use case of device offsets, the target of * this copying would be of a different size than the source, and * the offset would be desirable during the copy operation. */ cairo_surface_set_device_offset (surface, 0, 0); if (ptc->target) { cairo_t *cr; cr = cairo_create (ptc->target); cairo_set_source_surface (cr, surface, 0, 0); cairo_paint (cr); cairo_show_page (cr); status = cairo_status (cr); cairo_destroy (cr); if (status) return status; cairo_surface_finish (surface); status = cairo_surface_status (surface); if (status) return status; surface = ptc->target; } cairo_surface_finish (surface); status = cairo_surface_status (surface); if (status) return status; return CAIRO_STATUS_SUCCESS; }
cairo_status_t _cairo_boilerplate_svg_surface_write_to_png (cairo_surface_t *surface, const char *filename) { svg_target_closure_t *ptc = cairo_surface_get_user_data (surface, &svg_closure_key); char command[4096]; int exitstatus; sprintf (command, "./svg2png %s %s", ptc->filename, filename); exitstatus = system (command); #if _XOPEN_SOURCE && HAVE_SIGNAL_H if (WIFSIGNALED (exitstatus)) raise (WTERMSIG (exitstatus)); #endif if (exitstatus) return CAIRO_STATUS_WRITE_ERROR; return CAIRO_STATUS_SUCCESS; }
static void _cairo_boilerplate_ps_force_fallbacks (cairo_surface_t *abstract_surface, double x_pixels_per_inch, double y_pixels_per_inch) { ps_target_closure_t *ptc = cairo_surface_get_user_data (abstract_surface, &ps_closure_key); cairo_paginated_surface_t *paginated; cairo_ps_surface_t *surface; if (ptc->target) abstract_surface = ptc->target; paginated = (cairo_paginated_surface_t*) abstract_surface; surface = (cairo_ps_surface_t*) paginated->target; surface->force_fallbacks = TRUE; cairo_surface_set_fallback_resolution (&paginated->base, x_pixels_per_inch, y_pixels_per_inch); }
gboolean _cairo_image_surface_get_has_alpha (cairo_surface_t *surface) { cairo_surface_metadata_t *metadata; int width; int height; int row_stride; guchar *row; int h, w; if (surface == NULL) return FALSE; metadata = cairo_surface_get_user_data (surface, &surface_metadata_key); if ((metadata != NULL) && (metadata->valid_data & _CAIRO_METADATA_FLAG_HAS_ALPHA)) return metadata->has_alpha; if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_ARGB32) return FALSE; /* search an alpha value lower than 255 */ width = cairo_image_surface_get_width (surface); height = cairo_image_surface_get_height (surface); row_stride = cairo_image_surface_get_stride (surface); row = _cairo_image_surface_flush_and_get_data (surface); for (h = 0; h < height; h++) { guchar *pixel = row; for (w = 0; w < width; w++) { if (pixel[CAIRO_ALPHA] < 255) return TRUE; pixel += 4; } row += row_stride; } return FALSE; }
static cairo_surface_t * _cairo_boilerplate_test_paginated_get_image_surface (cairo_surface_t *surface, int page, int width, int height) { test_paginated_closure_t *tpc; cairo_status_t status; /* XXX separate finish as per PDF */ if (page != 0) return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); /* show page first. the automatic show_page is too late for us */ cairo_surface_show_page (surface); status = cairo_surface_status (surface); if (status) return cairo_boilerplate_surface_create_in_error (status); tpc = cairo_surface_get_user_data (surface, &test_paginated_closure_key); return _cairo_boilerplate_get_image_surface (tpc->target, 0, width, height); }
static cairo_status_t _cairo_boilerplate_gl_finish_window (cairo_surface_t *surface) { gl_target_closure_t *gltc = cairo_surface_get_user_data (surface, &gl_closure_key); if (gltc != NULL && gltc->surface != NULL) { cairo_t *cr; cr = cairo_create (gltc->surface); cairo_surface_set_device_offset (surface, 0, 0); cairo_set_source_surface (cr, surface, 0, 0); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_paint (cr); cairo_destroy (cr); surface = gltc->surface; } cairo_gl_surface_swapbuffers (surface); return CAIRO_STATUS_SUCCESS; }
void Image::drawPattern(GraphicsContext* context, const FloatRect& tileRect, const AffineTransform& patternTransform, const FloatPoint& phase, ColorSpace colorSpace, CompositeOperator op, const FloatRect& destRect) { cairo_surface_t* image = nativeImageForCurrentFrame(); if (!image) // If it's too early we won't have an image yet. return; cairo_t* cr = context->platformContext()->cr(); drawPatternToCairoContext(cr, image, size(), tileRect, patternTransform, phase, toCairoOperator(op), destRect); if (imageObserver()) imageObserver()->didDraw(this); //+EAWebKitChange //5/30/2012 #if ENABLE(IMAGE_COMPRESSION) // Check if this is a compressed surface. const void* pCompressedSurfaceUserData = cairo_surface_get_user_data (image, (cairo_user_data_key_t*) ImageCompressionGetUserDataKey()); if (pCompressedSurfaceUserData) cairo_surface_destroy(image); #endif //-EAWebKitChange }
static cairo_status_t _cairo_boilerplate_ps_surface_write_to_png (cairo_surface_t *surface, const char *filename) { ps_target_closure_t *ptc = cairo_surface_get_user_data (surface, &ps_closure_key); char command[4096]; int exitstatus; sprintf (command, "gs -q -r72 -g%dx%d -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pngalpha -sOutputFile=%s %s %s", ptc->width, ptc->height, filename, ptc->level == CAIRO_PS_LEVEL_2 ? "-c 2 .setlanguagelevel -f" : "", ptc->filename); exitstatus = system (command); #if _XOPEN_SOURCE && HAVE_SIGNAL_H if (WIFSIGNALED (exitstatus)) raise (WTERMSIG (exitstatus)); #endif if (exitstatus) return CAIRO_STATUS_WRITE_ERROR; return CAIRO_STATUS_SUCCESS; }
/* The only reason we go through all these machinations to write a PNG * image is to _really ensure_ that the data actually landed in our * buffer through the paginated surface to the test_paginated_surface. * * If we didn't implement this function then the default * cairo_surface_write_to_png would result in the paginated_surface's * acquire_source_image function replaying the meta-surface to an * intermediate image surface. And in that case the * test_paginated_surface would not be involved and wouldn't be * tested. */ cairo_status_t _cairo_boilerplate_test_paginated_surface_write_to_png (cairo_surface_t *surface, const char *filename) { cairo_surface_t *image; cairo_format_t format; test_paginated_closure_t *tpc; cairo_status_t status; /* show page first. the automatic show_page is too late for us */ /* XXX use cairo_surface_show_page() when that's added */ cairo_t *cr = cairo_create (surface); cairo_show_page (cr); cairo_destroy (cr); tpc = cairo_surface_get_user_data (surface, &test_paginated_closure_key); format = cairo_boilerplate_format_from_content (tpc->content); image = cairo_image_surface_create_for_data (tpc->data, format, tpc->width, tpc->height, tpc->stride); status = cairo_surface_write_to_png (image, filename); if (status) { CAIRO_BOILERPLATE_LOG ("Error writing %s: %s. Exiting\n", filename, cairo_status_to_string (status)); exit (1); } cairo_surface_destroy (image); return CAIRO_STATUS_SUCCESS; }
gboolean _cairo_image_surface_get_original_size (cairo_surface_t *surface, int *original_width, int *original_height) { cairo_surface_metadata_t *metadata; if (surface == NULL) return FALSE; metadata = cairo_surface_get_user_data (surface, &surface_metadata_key); if (metadata == NULL) return FALSE; if ((metadata->valid_data & _CAIRO_METADATA_FLAG_ORIGINAL_SIZE) == 0) return FALSE; if (original_width) *original_width = metadata->original_width; if (original_height) *original_height = metadata->original_height; return TRUE; }