static cairo_surface_t * _cairo_boilerplate_svg_create_surface (const char *name, cairo_content_t content, cairo_svg_version_t version, int width, int height, int max_width, int max_height, cairo_boilerplate_mode_t mode, int id, void **closure) { svg_target_closure_t *ptc; cairo_surface_t *surface; cairo_status_t status; *closure = ptc = xmalloc (sizeof (svg_target_closure_t)); ptc->width = width; ptc->height = height; xasprintf (&ptc->filename, "%s-out.svg", name); xunlink (ptc->filename); surface = cairo_svg_surface_create (ptc->filename, width, height); if (cairo_surface_status (surface)) goto CLEANUP_FILENAME; cairo_svg_surface_restrict_to_version (surface, version); cairo_surface_set_fallback_resolution (surface, 72., 72.); if (content == CAIRO_CONTENT_COLOR) { ptc->target = surface; surface = cairo_surface_create_similar (ptc->target, CAIRO_CONTENT_COLOR, width, height); if (cairo_surface_status (surface)) goto CLEANUP_TARGET; } else ptc->target = NULL; status = cairo_surface_set_user_data (surface, &svg_closure_key, ptc, NULL); if (status == CAIRO_STATUS_SUCCESS) return surface; cairo_surface_destroy (surface); surface = cairo_boilerplate_surface_create_in_error (status); CLEANUP_TARGET: cairo_surface_destroy (ptc->target); CLEANUP_FILENAME: free (ptc->filename); free (ptc); return surface; }
static cairo_surface_t * _similar_surface_create (void *closure, cairo_content_t content, double width, double height, long uid) { struct trace *args = closure; cairo_surface_t *surface; struct scache skey, *s; if (args->observe) return cairo_surface_create_similar (args->surface, content, width, height); if (uid == 0 || surface_cache == NULL) return args->target->create_similar (args->surface, content, width, height); skey.entry.hash = uid; s = _cairo_hash_table_lookup (surface_cache, &skey.entry); if (s != NULL) { if (s->content == content && s->width == width && s->height == height) { return cairo_surface_reference (s->surface); } /* The surface has been resized, allow the original entry to expire * as it becomes inactive. */ } surface = args->target->create_similar (args->surface, content, width, height); s = malloc (sizeof (struct scache)); if (s == NULL) return surface; s->entry.hash = uid; s->content = content; s->width = width; s->height = height; s->surface = surface; if (_cairo_hash_table_insert (surface_cache, &s->entry)) { free (s); } else if (cairo_surface_set_user_data (surface, (const cairo_user_data_key_t *) &surface_cache, s, scache_remove)) { scache_remove (s); } return surface; }
cairo_surface_t *cairo_linuxfb_surface_create(const char *fb_name) { cairo_linuxfb_device_t *device; cairo_surface_t *surface; if (fb_name == NULL) { fb_name = "/dev/fb1"; } device = malloc(sizeof(*device)); // Open the file for reading and writing device->fb_fd = open(fb_name, O_RDWR); if (device->fb_fd == -1) { perror("Error: cannot open framebuffer device"); exit(1); } // Get variable screen information if (ioctl(device->fb_fd, FBIOGET_VSCREENINFO, &device->fb_vinfo) == -1) { perror("Error reading variable information"); exit(3); } // Figure out the size of the screen in bytes device->fb_screensize = device->fb_vinfo.xres * device->fb_vinfo.yres * device->fb_vinfo.bits_per_pixel / 8; // Map the device to memory device->fb_data = (char *)mmap(0, device->fb_screensize, PROT_READ | PROT_WRITE, MAP_SHARED, device->fb_fd, 0); if ((int)device->fb_data == -1) { perror("Error: failed to map framebuffer device to memory"); exit(4); } // Get fixed screen information if (ioctl(device->fb_fd, FBIOGET_FSCREENINFO, &device->fb_finfo) == -1) { perror("Error reading fixed information"); exit(2); } surface = cairo_image_surface_create_for_data(device->fb_data, CAIRO_FORMAT_RGB16_565, device->fb_vinfo.xres, device->fb_vinfo.yres, cairo_format_stride_for_width(CAIRO_FORMAT_RGB16_565, device->fb_vinfo.xres)); cairo_surface_set_user_data(surface, NULL, device, &cairo_linuxfb_surface_destroy); return surface; }
static void cr_set_user_data (cairo_t *cr, const cairo_user_data_key_t *key, void *user_data, cairo_destroy_func_t destroy) { #if CAIRO_CHECK_VERSION(1, 4, 0) cairo_set_user_data (cr, key, user_data, destroy); #else cairo_surface_t *surface; surface = cairo_get_target (cr); cairo_surface_set_user_data (surface, key, user_data, destroy); #endif }
int TestExistingSurface () { int failures = 0; int destroyed = 0; cairo_surface_t *cs = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 10, 10); cairo_surface_set_user_data (cs, &destruction_key, &destroyed, SurfaceDestroyNotifier); failures += CheckInt (cairo_surface_get_reference_count(cs), 1); failures += CheckInt (destroyed, 0); nsRefPtr<gfxASurface> s = gfxASurface::Wrap(cs); failures += CheckInt (GetASurfaceRefCount(s.get()), 2); cairo_surface_reference(cs); failures += CheckInt (GetASurfaceRefCount(s.get()), 3); failures += CheckInt (cairo_surface_get_reference_count(cs), 3); failures += CheckInt (destroyed, 0); gfxASurface *savedWrapper = s.get(); s = nullptr; failures += CheckInt (cairo_surface_get_reference_count(cs), 2); failures += CheckInt (destroyed, 0); s = gfxASurface::Wrap(cs); failures += CheckPointer (s.get(), savedWrapper); failures += CheckInt (GetASurfaceRefCount(s.get()), 3); failures += CheckInt (cairo_surface_get_reference_count(cs), 3); failures += CheckInt (destroyed, 0); cairo_surface_destroy(cs); failures += CheckInt (GetASurfaceRefCount(s.get()), 2); failures += CheckInt (cairo_surface_get_reference_count(cs), 2); failures += CheckInt (destroyed, 0); s = nullptr; failures += CheckInt (cairo_surface_get_reference_count(cs), 1); failures += CheckInt (destroyed, 0); cairo_surface_destroy(cs); failures += CheckInt (destroyed, 1); return failures; }
PassRefPtr<cairo_surface_t> ShareableBitmap::createCairoSurface() { RefPtr<cairo_surface_t> image = adoptRef(cairo_image_surface_create_for_data(static_cast<unsigned char*>(data()), CAIRO_FORMAT_ARGB32, m_size.width(), m_size.height(), m_size.width() * 4)); ref(); // Balanced by deref in releaseSurfaceData. static cairo_user_data_key_t dataKey; cairo_surface_set_user_data(image.get(), &dataKey, this, releaseSurfaceData); return image.release(); }
static cairo_surface_t * display_create_drm_surface(struct display *display, struct rectangle *rectangle) { struct drm_surface_data *data; EGLDisplay dpy = display->dpy; cairo_surface_t *surface; struct wl_visual *visual; EGLint name, stride; EGLint image_attribs[] = { EGL_WIDTH, 0, EGL_HEIGHT, 0, EGL_DRM_BUFFER_FORMAT_MESA, EGL_DRM_BUFFER_FORMAT_ARGB32_MESA, EGL_DRM_BUFFER_USE_MESA, EGL_DRM_BUFFER_USE_SCANOUT_MESA, EGL_NONE }; data = malloc(sizeof *data); if (data == NULL) return NULL; data->display = display; image_attribs[1] = rectangle->width; image_attribs[3] = rectangle->height; data->image = eglCreateDRMImageMESA(dpy, image_attribs); cairo_device_acquire(display->device); glGenTextures(1, &data->texture); glBindTexture(GL_TEXTURE_2D, data->texture); glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, data->image); cairo_device_release(display->device); eglExportDRMImageMESA(display->dpy, data->image, &name, NULL, &stride); visual = wl_display_get_premultiplied_argb_visual(display->display); data->data.buffer = wl_drm_create_buffer(display->drm, name, rectangle->width, rectangle->height, stride, visual); surface = cairo_gl_surface_create_for_texture(display->device, CAIRO_CONTENT_COLOR_ALPHA, data->texture, rectangle->width, rectangle->height); cairo_surface_set_user_data (surface, &surface_data_key, data, drm_surface_data_destroy); return surface; }
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; }
static void create_cairo_surface__gtt(int fd, struct igt_fb *fb) { void *ptr = gem_mmap__gtt(fd, fb->gem_handle, fb->size, PROT_READ | PROT_WRITE); fb->cairo_surface = cairo_image_surface_create_for_data(ptr, drm_format_to_cairo(fb->drm_format), fb->width, fb->height, fb->stride); cairo_surface_set_user_data(fb->cairo_surface, (cairo_user_data_key_t *)create_cairo_surface__gtt, fb, destroy_cairo_surface__gtt); }
cairo_surface_t * joy_gfx3d_screen_cairo_surface_create(JoyScreen *self, GFX3D_Image image) { g_return_val_if_fail(JOY_IS_GFX3D_SCREEN(self), NULL); g_return_val_if_fail(image, NULL); struct Private *priv = GET_PRIVATE(self); #if CAIRO_HAS_GFX3D_SURFACE cairo_surface_t *surface = cairo_gfx3d_surface_create(priv->display, image); cairo_status_t status = cairo_surface_status(surface); if (G_UNLIKELY(CAIRO_STATUS_SUCCESS != status)) { return NULL; } cairo_gfx3d_surface_set_owner(surface, TRUE); return surface; #else // CAIRO_HAS_GFX3D_SURFACE GFX3D_Rect rect; GFX3D_Image_GetRect(image, &rect); gint stride; void *pixels = GFX3D_NATIVE_Surface_GetAddress( GFX3D_Image_Get_NATIVE_Surface(image), &stride); if (G_UNLIKELY(!pixels)) { return NULL; } stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, rect.iWidth); cairo_surface_t *surface = cairo_image_surface_create_for_data(pixels, CAIRO_FORMAT_ARGB32, rect.iWidth, rect.iHeight, stride); cairo_status_t status = cairo_surface_status(surface); if (G_UNLIKELY(CAIRO_STATUS_SUCCESS != status)) { cairo_surface_destroy(surface); return NULL; } struct Data *data = g_slice_new0(struct Data); if (G_UNLIKELY(!data)) { cairo_surface_destroy(surface); return NULL; } data->display = priv->display; data->image = image; status = cairo_surface_set_user_data(surface, &key, data, (cairo_destroy_func_t)data_destroy); if (G_UNLIKELY(CAIRO_STATUS_SUCCESS != status)) { cairo_surface_destroy(surface); g_slice_free(struct Data, data); return NULL; } return surface; #endif // CAIRO_HAS_GFX3D_SURFACE }
void SharedDIBSurface::InitSurface(uint32_t aWidth, uint32_t aHeight, bool aTransparent) { long stride = long(aWidth * kBytesPerPixel); unsigned char* data = reinterpret_cast<unsigned char*>(mSharedDIB.GetBits()); gfxImageFormat format = aTransparent ? gfxImageFormat::ARGB32 : gfxImageFormat::RGB24; gfxImageSurface::InitWithData(data, gfxIntSize(aWidth, aHeight), stride, format); cairo_surface_set_user_data(mSurface, &SHAREDDIB_KEY, this, nullptr); }
cairo_pattern_t * gimp_cairo_stipple_pattern_create (const GimpRGB *fg, const GimpRGB *bg, gint index) { cairo_surface_t *surface; cairo_pattern_t *pattern; guchar *data; guchar *d; guchar fg_r, fg_g, fg_b, fg_a; guchar bg_r, bg_g, bg_b, bg_a; gint x, y; g_return_val_if_fail (fg != NULL, NULL); g_return_val_if_fail (bg != NULL, NULL); data = g_malloc (8 * 8 * 4); gimp_rgba_get_uchar (fg, &fg_r, &fg_g, &fg_b, &fg_a); gimp_rgba_get_uchar (bg, &bg_r, &bg_g, &bg_b, &bg_a); d = data; for (y = 0; y < 8; y++) { for (x = 0; x < 8; x++) { if ((x + y + index) % 8 >= 4) GIMP_CAIRO_ARGB32_SET_PIXEL (d, fg_r, fg_g, fg_b, fg_a); else GIMP_CAIRO_ARGB32_SET_PIXEL (d, bg_r, bg_g, bg_b, bg_a); d += 4; } } surface = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_ARGB32, 8, 8, 8 * 4); cairo_surface_set_user_data (surface, &surface_data_key, data, (cairo_destroy_func_t) g_free); pattern = cairo_pattern_create_for_surface (surface); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); cairo_surface_destroy (surface); return pattern; }
static cairo_surface_t * create_source_surface (int size) { #if CAIRO_HAS_XCB_SURFACE xcb_render_pictforminfo_t *render_format; struct closure *data; cairo_surface_t *surface; xcb_screen_t *root; xcb_void_cookie_t cookie; void *formats; data = xmalloc (sizeof (struct closure)); data->connection = xcb_connect (NULL, NULL); render_format = find_depth (data->connection, 32, &formats); if (render_format == NULL) { xcb_disconnect (data->connection); free (data); return NULL; } root = xcb_setup_roots_iterator (xcb_get_setup (data->connection)).data; data->pixmap = xcb_generate_id (data->connection); cookie = xcb_create_pixmap_checked (data->connection, 32, data->pixmap, root->root, size, size); /* slow, but sure */ if (xcb_request_check (data->connection, cookie) != NULL) { free (formats); xcb_disconnect (data->connection); free (data); return NULL; } surface = cairo_xcb_surface_create_with_xrender_format (data->connection, root, data->pixmap, render_format, size, size); free (formats); data->device = cairo_device_reference (cairo_surface_get_device (surface)); cairo_surface_set_user_data (surface, &closure_key, data, cleanup); return surface; #else return NULL; #endif }
static cairo_surface_t * _cairo_boilerplate_xcb_create_similar (cairo_surface_t *other, cairo_content_t content, int width, int height) { cairo_device_t *device = cairo_surface_get_device (other); struct xcb_info *info = cairo_device_get_user_data (device, &key); xcb_screen_t *root; cairo_surface_t *surface; struct similar *similar; xcb_render_pictforminfo_t *render_format; int depth; similar = malloc (sizeof (*similar)); switch (content) { default: case CAIRO_CONTENT_COLOR_ALPHA: depth = 32; render_format = info->render_format[0]; break; case CAIRO_CONTENT_COLOR: depth = 24; render_format = info->render_format[1]; break; case CAIRO_CONTENT_ALPHA: depth = 8; render_format = info->render_format[2]; break; } similar->connection = cairo_xcb_device_get_connection (cairo_surface_get_device(other)); similar->pixmap = xcb_generate_id (similar->connection); root = xcb_setup_roots_iterator(xcb_get_setup(similar->connection)).data; xcb_create_pixmap (similar->connection, depth, similar->pixmap, root->root, width, height); surface = cairo_xcb_surface_create_with_xrender_format (similar->connection, root, similar->pixmap, render_format, width, height); cairo_surface_set_user_data (surface, &key, similar, _destroy_similar); return surface; }
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 gfxXlibSurface::TakePixmap() { if (mPixmapTaken) return; pixmap_free_struct *pfs = new pixmap_free_struct; pfs->dpy = mDisplay; pfs->pixmap = mDrawable; cairo_surface_set_user_data (CairoSurface(), &pixmap_free_key, pfs, pixmap_free_func); mPixmapTaken = PR_TRUE; }
int TestNewSurface () { int failures = 0; int destroyed = 0; nsRefPtr<gfxASurface> s = new gfxImageSurface (gfxIntSize(10, 10), gfxImageFormat::ARGB32); cairo_surface_t *cs = s->CairoSurface(); cairo_surface_set_user_data (cs, &destruction_key, &destroyed, SurfaceDestroyNotifier); failures += CheckInt (GetASurfaceRefCount(s.get()), 1); failures += CheckInt (cairo_surface_get_reference_count(cs), 1); failures += CheckInt (destroyed, 0); cairo_surface_reference(cs); failures += CheckInt (GetASurfaceRefCount(s.get()), 2); failures += CheckInt (cairo_surface_get_reference_count(cs), 2); failures += CheckInt (destroyed, 0); gfxASurface *savedWrapper = s.get(); s = nullptr; failures += CheckInt (cairo_surface_get_reference_count(cs), 1); failures += CheckInt (destroyed, 0); s = gfxASurface::Wrap(cs); failures += CheckPointer (s.get(), savedWrapper); failures += CheckInt (GetASurfaceRefCount(s.get()), 2); failures += CheckInt (cairo_surface_get_reference_count(cs), 2); failures += CheckInt (destroyed, 0); cairo_surface_destroy(cs); failures += CheckInt (GetASurfaceRefCount(s.get()), 1); failures += CheckInt (cairo_surface_get_reference_count(cs), 1); failures += CheckInt (destroyed, 0); s = nullptr; failures += CheckInt (destroyed, 1); return failures; }
value lime_cairo_image_surface_create_for_data (value inData, int format, int width, int height, int stride) { Bytes *data = new Bytes (inData); cairo_surface_t *surface = cairo_image_surface_create_for_data (data->Data (), (cairo_format_t)format, width, height, stride); if (!surface) { delete data; return alloc_null (); } data->Pin (); cairo_surface_set_user_data (surface, &userData, data, gc_bytes); return CFFIPointer (surface, gc_cairo_surface); }
/** * _gdk_x11_drawable_finish: * @drawable: a #GdkDrawableImplX11. * * Performs necessary cleanup prior to freeing a pixmap or * destroying a window. **/ void _gdk_x11_drawable_finish (GdkDrawable *drawable) { GdkDrawableImplX11 *impl = GDK_DRAWABLE_IMPL_X11 (drawable); if (impl->picture) { XRenderFreePicture (GDK_SCREEN_XDISPLAY (impl->screen), impl->picture); impl->picture = None; } if (impl->cairo_surface) { cairo_surface_finish (impl->cairo_surface); cairo_surface_set_user_data (impl->cairo_surface, &gdk_x11_cairo_key, NULL, NULL); } }
static VALUE image_create_cairo_surface(VALUE obj) { cairo_surface_t* cairo_surface; cairo_format_t cairo_format; unsigned char* data; VALUE surface; struct image_data* image = get_image_data(obj); data = xmalloc(sizeof(unsigned char)*RSTRING_LEN(image->buffer)); MEMCPY(data, RSTRING_PTR(image->buffer), unsigned char, RSTRING_LEN(image->buffer)); cairo_format = pixel_format_to_cairo_format(image->pixel_format); cairo_surface = cairo_image_surface_create_for_data( data, cairo_format, (int)image->width, (int)image->height, (int)image->stride*pixel_format_size(image->pixel_format)); cairo_surface_set_user_data(cairo_surface, &cairo_data_key, data, image_surface_did_destroyed); surface = CRSURFACE2RVAL_WITH_DESTROY(cairo_surface); return surface; }
static cairo_surface_t * _cairo_boilerplate_test_paginated_create_surface (const char *name, cairo_content_t content, double width, double height, double max_width, double max_height, cairo_boilerplate_mode_t mode, int id, void **closure) { test_paginated_closure_t *tpc; cairo_format_t format; cairo_surface_t *surface; cairo_status_t status; *closure = tpc = xmalloc (sizeof (test_paginated_closure_t)); format = cairo_boilerplate_format_from_content (content); tpc->target = cairo_image_surface_create (format, ceil (width), ceil (height)); surface = _cairo_test_paginated_surface_create (tpc->target); if (cairo_surface_status (surface)) goto CLEANUP; status = cairo_surface_set_user_data (surface, &test_paginated_closure_key, tpc, NULL); if (status == CAIRO_STATUS_SUCCESS) return surface; cairo_surface_destroy (surface); surface = cairo_boilerplate_surface_create_in_error (status); cairo_surface_destroy (tpc->target); CLEANUP: free (tpc); return surface; }
static cairo_surface_t * _xrender_surface_create (void *closure, cairo_content_t content, double width, double height, long uid) { Display *dpy; Pixmap pixmap; XRenderPictFormat *xrender_format; cairo_surface_t *surface; dpy = _get_display (); content = CAIRO_CONTENT_COLOR_ALPHA; switch (content) { case CAIRO_CONTENT_COLOR_ALPHA: xrender_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); break; case CAIRO_CONTENT_COLOR: xrender_format = XRenderFindStandardFormat (dpy, PictStandardRGB24); break; case CAIRO_CONTENT_ALPHA: default: xrender_format = XRenderFindStandardFormat (dpy, PictStandardA8); } pixmap = XCreatePixmap (dpy, DefaultRootWindow (dpy), width, height, xrender_format->depth); surface = cairo_xlib_surface_create_with_xrender_format (dpy, pixmap, DefaultScreenOfDisplay (dpy), xrender_format, width, height); cairo_surface_set_user_data (surface, &_key, (void *) pixmap, _destroy_pixmap); return surface; }
static void go_spectre_build_surface (GOSpectre *spectre) { guint8 *data = NULL; int rowstride; static const cairo_user_data_key_t key; spectre_document_render (spectre->doc, &data, &rowstride); if (!data) return; if (spectre_document_status (spectre->doc) != SPECTRE_STATUS_SUCCESS) { g_free (data); return; } spectre->surface = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_RGB24, spectre->parent.width, spectre->parent.height, rowstride); cairo_surface_set_user_data (spectre->surface, &key, data, (cairo_destroy_func_t) g_free); }
CR::RefPtr<CR::ImageSurface> ConvertToSurface(RefPtr<Gdk::Pixbuf> pix) { // добавляем канал, если не 4 int real_channels = pix->get_n_channels(); RGBA::AddAlpha(pix); int wdh = pix->get_width(); int hgt = pix->get_height(); int stride = pix->get_rowstride(); guint8* pixels = pix->get_pixels(); Cairo::Format format = (real_channels == 3) ? Cairo::FORMAT_RGB24 : Cairo::FORMAT_ARGB32 ; CR::RefPtr<CR::ImageSurface> sur = CR::ImageSurface::create( pixels, format, wdh, hgt, stride ); static cairo_user_data_key_t key; cairo_surface_set_user_data (sur->cobj(), &key, new RefPtr<Gdk::Pixbuf>(pix), (cairo_destroy_func_t)FreePixbuf); ConvertPixbufToCairo32(pixels, stride, wdh, hgt, real_channels); return sur; }
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_surface_t * _cairo_boilerplate_xlib_create_similar (cairo_surface_t *other, cairo_content_t content, int width, int height) { XRenderPictFormat *xrender_format; uint32_t format; struct similar *similar; cairo_surface_t *surface; similar = malloc (sizeof (*similar)); similar->dpy = cairo_xlib_surface_get_display (other); switch (content) { default: case CAIRO_CONTENT_COLOR_ALPHA: format = PictStandardARGB32; break; case CAIRO_CONTENT_COLOR: format = PictStandardRGB24; break; case CAIRO_CONTENT_ALPHA: format = PictStandardA8; break; } xrender_format = XRenderFindStandardFormat (similar->dpy, format); similar->pixmap = XCreatePixmap (similar->dpy, DefaultRootWindow (similar->dpy), width, height, xrender_format->depth); surface = cairo_xlib_surface_create_with_xrender_format (similar->dpy, similar->pixmap, DefaultScreenOfDisplay (similar->dpy), xrender_format, width, height); cairo_surface_set_user_data (surface, &key, similar, _destroy_similar); return surface; }
cairo_surface_t * x11_window_create(struct config *config, int *width, int *height) { Display *dpy; Window win; int screen; cairo_surface_t *surface; XSetWindowAttributes attr; struct x11_window *priv; int x, y, w, h; dpy = XOpenDisplay(NULL); if (dpy == NULL) return NULL; screen = DefaultScreen(dpy); XSetErrorHandler(noop); x11_position(dpy, *width, *height, config, &x, &y, &w, &h); attr.override_redirect = True; win = XCreateWindow(dpy, DefaultRootWindow(dpy), x, y, w, h, 0, DefaultDepth(dpy, screen), InputOutput, DefaultVisual(dpy, screen), CWOverrideRedirect, &attr); surface = cairo_xlib_surface_create(dpy, win, DefaultVisual (dpy, screen), w, h); if (cairo_surface_status(surface)) goto err_win; priv = malloc(sizeof(*priv)); if (priv == NULL) goto err_surface; if (prefer_image(config)) priv->base.surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, w, h); else priv->base.surface = cairo_surface_create_similar(surface, CAIRO_CONTENT_COLOR, w, h); if (cairo_surface_status(priv->base.surface)) goto err_priv; priv->base.show = x11_window_show; priv->base.hide = x11_window_hide; priv->dpy = dpy; priv->win = win; priv->front = surface; priv->visible = false; priv->width = w; priv->height = h; cairo_surface_set_user_data(priv->base.surface, &overlay_key, priv, x11_window_destroy); *width = w; *height = h; return priv->base.surface; err_priv: free(priv); err_surface: cairo_surface_destroy(surface); err_win: XDestroyWindow(dpy, win); XCloseDisplay(dpy); return NULL; }
static cairo_surface_t * _cairo_boilerplate_win32_printing_create_surface (const char *name, cairo_content_t content, double width, double height, double max_width, double max_height, cairo_boilerplate_mode_t mode, void **closure) { win32_target_closure_t *ptc; cairo_surface_t *surface; DOCINFO di; if (content == CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED) content = CAIRO_CONTENT_COLOR_ALPHA; *closure = ptc = xmalloc (sizeof (win32_target_closure_t)); xasprintf (&ptc->filename, "%s.out.ps", name); xunlink (ptc->filename); memset (&di, 0, sizeof (DOCINFO)); di.cbSize = sizeof (DOCINFO); di.lpszDocName = ptc->filename; di.lpszOutput = ptc->filename; ptc->width = width; ptc->height = height; create_printer_dc (ptc); if (ptc->dc == NULL) { printf("\nFailed to create printer\n"); free (ptc->filename); free (ptc); return NULL; } StartDoc (ptc->dc, &di); StartPage (ptc->dc); surface = cairo_win32_printing_surface_create (ptc->dc); if (cairo_surface_status (surface)) { free (ptc->filename); free (ptc); return NULL; } cairo_surface_set_fallback_resolution (surface, 72., 72.); if (content == CAIRO_CONTENT_COLOR) { ptc->target = surface; surface = cairo_surface_create_similar (ptc->target, CAIRO_CONTENT_COLOR, width, height); } else { ptc->target = NULL; } if (cairo_surface_set_user_data (surface, &win32_closure_key, ptc, NULL) != CAIRO_STATUS_SUCCESS) { cairo_surface_destroy (surface); if (ptc->target != NULL) cairo_surface_destroy (ptc->target); free (ptc->filename); free (ptc); return NULL; } return surface; }
/** * _st_create_shadow_cairo_pattern: * @shadow_spec: the definition of the shadow * @src_pattern: surface pattern for which we create the shadow * (must be a surface pattern) * * This is a utility function for creating shadows used by * st-theme-node.c; it's in this file to share the gaussian * blur implementation. The usage of this function is quite different * depending on whether shadow_spec->inset is %TRUE or not. If * shadow_spec->inset is %TRUE, the caller should pass in a @src_pattern * which is the <i>inverse</i> of what they want shadowed, and must take * care of the spread and offset from the shadow spec themselves. If * shadow_spec->inset is %FALSE then the caller should pass in what they * want shadowed directly, and this function takes care of the spread and * the offset. */ cairo_pattern_t * _st_create_shadow_cairo_pattern (StShadow *shadow_spec, cairo_pattern_t *src_pattern) { static cairo_user_data_key_t shadow_pattern_user_data; cairo_t *cr; cairo_surface_t *src_surface; cairo_surface_t *surface_in; cairo_surface_t *surface_out; cairo_pattern_t *dst_pattern; guchar *pixels_in, *pixels_out; gint width_in, height_in, rowstride_in; gint width_out, height_out, rowstride_out; cairo_matrix_t shadow_matrix; int i, j; g_return_val_if_fail (shadow_spec != NULL, NULL); g_return_val_if_fail (src_pattern != NULL, NULL); cairo_pattern_get_surface (src_pattern, &src_surface); width_in = cairo_image_surface_get_width (src_surface); height_in = cairo_image_surface_get_height (src_surface); /* We want the output to be a color agnostic alpha mask, * so we need to strip the color channels from the input */ if (cairo_image_surface_get_format (src_surface) != CAIRO_FORMAT_A8) { surface_in = cairo_image_surface_create (CAIRO_FORMAT_A8, width_in, height_in); cr = cairo_create (surface_in); cairo_set_source_surface (cr, src_surface, 0, 0); cairo_paint (cr); cairo_destroy (cr); } else { surface_in = cairo_surface_reference (src_surface); } pixels_in = cairo_image_surface_get_data (surface_in); rowstride_in = cairo_image_surface_get_stride (surface_in); pixels_out = blur_pixels (pixels_in, width_in, height_in, rowstride_in, shadow_spec->blur, &width_out, &height_out, &rowstride_out); cairo_surface_destroy (surface_in); /* Invert pixels for inset shadows */ if (shadow_spec->inset) { for (j = 0; j < height_out; j++) { guchar *p = pixels_out + rowstride_out * j; for (i = 0; i < width_out; i++, p++) *p = ~*p; } } surface_out = cairo_image_surface_create_for_data (pixels_out, CAIRO_FORMAT_A8, width_out, height_out, rowstride_out); cairo_surface_set_user_data (surface_out, &shadow_pattern_user_data, pixels_out, (cairo_destroy_func_t) g_free); dst_pattern = cairo_pattern_create_for_surface (surface_out); cairo_surface_destroy (surface_out); cairo_pattern_get_matrix (src_pattern, &shadow_matrix); if (shadow_spec->inset) { /* For inset shadows, offsets and spread radius have already been * applied to the original pattern, so all left to do is shift the * blurred image left, so that it aligns centered under the * unblurred one */ cairo_matrix_translate (&shadow_matrix, (width_out - width_in) / 2.0, (height_out - height_in) / 2.0); cairo_pattern_set_matrix (dst_pattern, &shadow_matrix); return dst_pattern; } /* Read all the code from the cairo_pattern_set_matrix call * at the end of this function to here from bottom to top, * because each new affine transformation is applied in * front of all the previous ones */ /* 6. Invert the matrix back */ cairo_matrix_invert (&shadow_matrix); /* 5. Adjust based on specified offsets */ cairo_matrix_translate (&shadow_matrix, shadow_spec->xoffset, shadow_spec->yoffset); /* 4. Recenter the newly scaled image */ cairo_matrix_translate (&shadow_matrix, - shadow_spec->spread, - shadow_spec->spread); /* 3. Scale up the blurred image to fill the spread */ cairo_matrix_scale (&shadow_matrix, (width_in + 2.0 * shadow_spec->spread) / width_in, (height_in + 2.0 * shadow_spec->spread) / height_in); /* 2. Shift the blurred image left, so that it aligns centered * under the unblurred one */ cairo_matrix_translate (&shadow_matrix, - (width_out - width_in) / 2.0, - (height_out - height_in) / 2.0); /* 1. Invert the matrix so we can work with it in pattern space */ cairo_matrix_invert (&shadow_matrix); cairo_pattern_set_matrix (dst_pattern, &shadow_matrix); return dst_pattern; }