cairo_surface_t * cairo_xynth_surface_create (unsigned int width, unsigned int height, cairo_format_t cairo_format) { S_RENDER_FORMAT render_format; cairo_xynth_surface_t *surface; ENTER(); if (!CAIRO_FORMAT_VALID(cairo_format)) { _cairo_error(CAIRO_STATUS_INVALID_FORMAT); return NULL; } render_format = _cairo_xynth_format_from_cairo_format(cairo_format); if (render_format == S_RENDER_FORMAT_NONE) { _cairo_error(CAIRO_STATUS_INVALID_FORMAT); return NULL; } surface = (cairo_xynth_surface_t *) malloc(sizeof(cairo_xynth_surface_t)); if (surface == NULL) { _cairo_error(CAIRO_STATUS_NO_MEMORY); return NULL; } memset(surface, 0, sizeof(cairo_xynth_surface_t)); if (s_render_init(&surface->render, render_format, width, height)) { free(surface); _cairo_error(CAIRO_STATUS_NO_MEMORY); return NULL; } _cairo_surface_init(&surface->cairo, &cairo_xynth_surface_backend, _cairo_content_from_format(cairo_format)); LEAVE(); return &surface->cairo; }
static cairo_surface_t * gallium_surface_create_internal (gallium_device_t *device, enum pipe_format pipe_format, int width, int height) { gallium_surface_t *surface; struct pipe_resource template; cairo_status_t status; cairo_format_t format; int stride, size; surface = malloc (sizeof (gallium_surface_t)); if (unlikely (surface == NULL)) return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); format = _cairo_format_from_pipe_format (pipe_format); _cairo_surface_init (&surface->drm.base, &gallium_surface_backend, &device->drm.base, _cairo_content_from_format (format)); _cairo_drm_surface_init (&surface->drm, format, width, height); stride = gallium_format_stride_for_width (pipe_format, width); size = stride * height; surface->drm.stride = stride; surface->drm.bo = _gallium_fake_bo_create (size, 0); memset(&template, 0, sizeof(template));
static void radeon_surface_init (radeon_surface_t *surface, cairo_drm_device_t *device, cairo_format_t format, int width, int height) { _cairo_surface_init (&surface->base.base, &radeon_surface_backend, &device->base, _cairo_content_from_format (format)); _cairo_drm_surface_init (&surface->base, format, width, height); }
static cairo_status_t _cairo_win32_surface_get_subimage (cairo_win32_surface_t *surface, int x, int y, int width, int height, cairo_win32_surface_t **local_out) { cairo_win32_surface_t *local; cairo_status_t status; cairo_content_t content = _cairo_content_from_format (surface->format); local = (cairo_win32_surface_t *) _cairo_win32_surface_create_similar (surface, content, width, height); if (local->base.status) return CAIRO_STATUS_NO_MEMORY; if (!BitBlt (local->dc, 0, 0, width, height, surface->dc, x, y, SRCCOPY)) { /* If we fail to BitBlt here, most likely the source is a printer. * You can't reliably get bits from a printer DC, so just fill in * the surface as white (common case for printing). */ RECT r; r.left = r.top = 0; r.right = width; r.bottom = height; FillRect(local->dc, &r, (HBRUSH)GetStockObject(WHITE_BRUSH)); } *local_out = local; return CAIRO_STATUS_SUCCESS; FAIL: status = _cairo_win32_print_gdi_error ("_cairo_win32_surface_get_subimage"); if (local) cairo_surface_destroy (&local->base); return status; }
void intel_surface_init (intel_surface_t *surface, const cairo_surface_backend_t *backend, cairo_drm_device_t *device, cairo_format_t format, int width, int height) { _cairo_surface_init (&surface->drm.base, backend, &device->base, _cairo_content_from_format (format)); _cairo_drm_surface_init (&surface->drm, format, width, height); surface->snapshot_cache_entry.hash = 0; }
static cairo_skia_surface_t * _cairo_skia_surface_create_internal (SkBitmap::Config config, bool opaque, unsigned char *data, int width, int height, int stride) { cairo_skia_surface_t *surface; cairo_format_t format; surface = (cairo_skia_surface_t *) malloc (sizeof (cairo_skia_surface_t)); if (surface == NULL) return (cairo_skia_surface_t *) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); memset (surface, 0, sizeof (cairo_skia_surface_t)); format = sk_config_to_format (config, opaque); assert (format != -1); _cairo_surface_init (&surface->base, &cairo_skia_surface_backend, NULL, /* device */ _cairo_content_from_format (format)); _cairo_surface_clipper_init (&surface->clipper, _cairo_skia_surface_clipper_intersect_clip_path); surface->bitmap = new SkBitmap; if (data == NULL) stride = cairo_format_stride_for_width (format, width); surface->bitmap->setConfig (config, width, height, stride); surface->bitmap->setIsOpaque (opaque); if (data != NULL) surface->bitmap->setPixels (data); else surface->bitmap->allocPixels (); surface->canvas = new SkCanvas (*surface->bitmap); //surface->canvas->translate (SkIntToScalar (0), SkIntToScalar (height)); //surface->canvas->scale (SkIntToScalar (1), SkIntToScalar (-1)); surface->canvas->save (); return surface; }
cairo_surface_t * cairo_qt_surface_create_with_qimage (cairo_format_t format, int width, int height) { cairo_qt_surface_t *qs; qs = (cairo_qt_surface_t *) malloc (sizeof(cairo_qt_surface_t)); if (qs == NULL) return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); memset (qs, 0, sizeof(cairo_qt_surface_t)); _cairo_surface_init (&qs->base, &cairo_qt_surface_backend, NULL, /* device */ _cairo_content_from_format (format)); _cairo_surface_clipper_init (&qs->clipper, _cairo_qt_surface_clipper_intersect_clip_path); QImage *image = new QImage (width, height, _qimage_format_from_cairo_format (format)); qs->image = image; if (!image->isNull()) { qs->p = new QPainter(image); qs->supports_porter_duff = qs->p->paintEngine()->hasFeature(QPaintEngine::PorterDuff); } qs->image_equiv = cairo_image_surface_create_for_data (image->bits(), format, width, height, image->bytesPerLine()); qs->window = QRect(0, 0, width, height); D(fprintf(stderr, "qpainter_surface_create: qimage: [%d %d %d %d] pd:%d\n", qs->window.x(), qs->window.y(), qs->window.width(), qs->window.height(), qs->supports_porter_duff)); return &qs->base; }
/** * cairo_win32_surface_create: * @hdc: the DC to create a surface for * * Creates a cairo surface that targets the given DC. The DC will be * queried for its initial clip extents, and this will be used as the * size of the cairo surface. The resulting surface will always be of * format %CAIRO_FORMAT_RGB24; should you need another surface format, * you will need to create one through * cairo_win32_surface_create_with_dib(). * * Return value: the newly created surface * * Since: 1.0 **/ cairo_surface_t * cairo_win32_surface_create (HDC hdc) { cairo_win32_display_surface_t *surface; cairo_format_t format; cairo_status_t status; cairo_device_t *device; /* Assume that everything coming in as a HDC is RGB24 */ format = CAIRO_FORMAT_RGB24; surface = malloc (sizeof (*surface)); if (surface == NULL) return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); status = _cairo_win32_save_initial_clip (hdc, surface); if (status) { free (surface); return _cairo_surface_create_in_error (status); } surface->image = NULL; surface->fallback = NULL; surface->win32.format = format; surface->win32.dc = hdc; surface->bitmap = NULL; surface->is_dib = FALSE; surface->saved_dc_bitmap = NULL; surface->win32.flags = _cairo_win32_flags_for_dc (surface->win32.dc); device = _cairo_win32_device_get (); _cairo_surface_init (&surface->win32.base, &cairo_win32_display_surface_backend, device, _cairo_content_from_format (format)); cairo_device_destroy (device); return &surface->win32.base; }
static cairo_status_t _cairo_xcb_surface_clone_similar (void *abstract_surface, cairo_surface_t *src, cairo_surface_t **clone_out) { cairo_xcb_surface_t *surface = abstract_surface; cairo_xcb_surface_t *clone; if (src->backend == surface->base.backend ) { cairo_xcb_surface_t *xcb_src = (cairo_xcb_surface_t *)src; if (_cairo_xcb_surface_same_screen(surface, xcb_src)) { *clone_out = cairo_surface_reference (src); return CAIRO_STATUS_SUCCESS; } } else if (_cairo_surface_is_image (src)) { cairo_image_surface_t *image_src = (cairo_image_surface_t *)src; cairo_content_t content = _cairo_content_from_format (image_src->format); if (surface->base.status) return surface->base.status; clone = (cairo_xcb_surface_t *) _cairo_xcb_surface_create_similar (surface, content, image_src->width, image_src->height); if (clone->base.status) return CAIRO_STATUS_NO_MEMORY; _draw_image_surface (clone, image_src, 0, 0); *clone_out = &clone->base; return CAIRO_STATUS_SUCCESS; } return CAIRO_INT_STATUS_UNSUPPORTED; }
/** * cairo_quartz_image_surface_create * @surface: a cairo image surface to wrap with a quartz image surface * * Creates a Quartz surface backed by a CGImageRef that references the * given image surface. The resulting surface can be rendered quickly * when used as a source when rendering to a #cairo_quartz_surface. If * the data in the image surface is ever updated, cairo_surface_flush() * must be called on the #cairo_quartz_image_surface to ensure that the * CGImageRef refers to the updated data. * * Return value: the newly created surface. * * Since: 1.6 */ cairo_surface_t * cairo_quartz_image_surface_create (cairo_surface_t *surface) { cairo_quartz_image_surface_t *qisurf; CGImageRef image; cairo_image_surface_t *image_surface; int width, height, stride; cairo_format_t format; unsigned char *data; if (cairo_surface_get_type(surface) != CAIRO_SURFACE_TYPE_IMAGE) return SURFACE_ERROR_TYPE_MISMATCH; image_surface = (cairo_image_surface_t*) surface; width = image_surface->width; height = image_surface->height; stride = image_surface->stride; format = image_surface->format; data = image_surface->data; if (!_cairo_quartz_verify_surface_size(width, height)) return SURFACE_ERROR_NO_MEMORY; if (width == 0 || height == 0) return SURFACE_ERROR_NO_MEMORY; if (format != CAIRO_FORMAT_ARGB32 && format != CAIRO_FORMAT_RGB24) return SURFACE_ERROR_INVALID_FORMAT; qisurf = malloc(sizeof(cairo_quartz_image_surface_t)); if (qisurf == NULL) return SURFACE_ERROR_NO_MEMORY; memset (qisurf, 0, sizeof(cairo_quartz_image_surface_t)); /* In case the create_cgimage fails, this ref will * be released via the callback (which will be called in * case of failure.) */ cairo_surface_reference (surface); image = _cairo_quartz_create_cgimage (format, width, height, stride, data, TRUE, NULL, DataProviderReleaseCallback, image_surface); if (!image) { free (qisurf); return SURFACE_ERROR_NO_MEMORY; } _cairo_surface_init (&qisurf->base, &cairo_quartz_image_surface_backend, _cairo_content_from_format (format)); qisurf->extents.x = qisurf->extents.y = 0; qisurf->extents.width = width; qisurf->extents.height = height; qisurf->image = image; qisurf->imageSurface = image_surface; return &qisurf->base; }
/** * cairo_os2_surface_create: * @hps_client_window: the presentation handle to bind the surface to * @width: the width of the surface * @height: the height of the surface * * Create a Cairo surface which is bound to a given presentation space (HPS). * The surface will be created to have the given size. * By default every change to the surface will be made visible immediately by * blitting it into the window. This can be changed with * cairo_os2_surface_set_manual_window_refresh(). * Note that the surface will contain garbage when created, so the pixels have * to be initialized by hand first. You can use the Cairo functions to fill it * with black, or use cairo_surface_mark_dirty() to fill the surface with pixels * from the window/HPS. * * Return value: the newly created surface * * Since: 1.4 **/ cairo_surface_t * cairo_os2_surface_create (HPS hps_client_window, int width, int height) { cairo_os2_surface_t *local_os2_surface; cairo_status_t status; int rc; /* Check the size of the window */ if ((width <= 0) || (height <= 0)) { /* Invalid window size! */ return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); } local_os2_surface = (cairo_os2_surface_t *) malloc (sizeof (cairo_os2_surface_t)); if (!local_os2_surface) { /* Not enough memory! */ return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } /* Initialize the OS/2 specific parts of the surface! */ /* Create mutex semaphore */ rc = DosCreateMutexSem (NULL, &(local_os2_surface->hmtx_use_private_fields), 0, FALSE); if (rc != NO_ERROR) { /* Could not create mutex semaphore! */ free (local_os2_surface); return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } /* Save PS handle */ local_os2_surface->hps_client_window = hps_client_window; /* Defaults */ local_os2_surface->hwnd_client_window = NULLHANDLE; local_os2_surface->blit_as_changes = TRUE; local_os2_surface->pixel_array_lend_count = 0; rc = DosCreateEventSem (NULL, &(local_os2_surface->hev_pixel_array_came_back), 0, FALSE); if (rc != NO_ERROR) { /* Could not create event semaphore! */ DosCloseMutexSem (local_os2_surface->hmtx_use_private_fields); free (local_os2_surface); return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } /* Prepare BITMAPINFO2 structure for our buffer */ memset (&(local_os2_surface->bitmap_info), 0, sizeof (local_os2_surface->bitmap_info)); local_os2_surface->bitmap_info.cbFix = sizeof (BITMAPINFOHEADER2); local_os2_surface->bitmap_info.cx = width; local_os2_surface->bitmap_info.cy = height; local_os2_surface->bitmap_info.cPlanes = 1; local_os2_surface->bitmap_info.cBitCount = 32; /* Allocate memory for pixels */ local_os2_surface->pixels = (unsigned char *) _buffer_alloc (height, width, 4); if (!(local_os2_surface->pixels)) { /* Not enough memory for the pixels! */ DosCloseEventSem (local_os2_surface->hev_pixel_array_came_back); DosCloseMutexSem (local_os2_surface->hmtx_use_private_fields); free (local_os2_surface); return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } /* Create image surface from pixel array */ local_os2_surface->image_surface = (cairo_image_surface_t *) cairo_image_surface_create_for_data (local_os2_surface->pixels, CAIRO_FORMAT_ARGB32, width, /* Width */ height, /* Height */ width * 4); /* Rowstride */ status = local_os2_surface->image_surface->base.status; if (status) { /* Could not create image surface! */ _buffer_free (local_os2_surface->pixels); DosCloseEventSem (local_os2_surface->hev_pixel_array_came_back); DosCloseMutexSem (local_os2_surface->hmtx_use_private_fields); free (local_os2_surface); return _cairo_surface_create_in_error (status); } /* Initialize base surface */ _cairo_surface_init (&local_os2_surface->base, &cairo_os2_surface_backend, _cairo_content_from_format (CAIRO_FORMAT_ARGB32)); return (cairo_surface_t *)local_os2_surface; }
static cairo_surface_t * _cairo_win32_display_surface_create_for_dc (HDC original_dc, cairo_format_t format, int width, int height) { cairo_status_t status; cairo_device_t *device; cairo_win32_display_surface_t *surface; unsigned char *bits; int rowstride; surface = malloc (sizeof (*surface)); if (surface == NULL) return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); surface->fallback = NULL; status = _create_dc_and_bitmap (surface, original_dc, format, width, height, &bits, &rowstride); if (status) goto FAIL; surface->image = cairo_image_surface_create_for_data (bits, format, width, height, rowstride); status = surface->image->status; if (status) goto FAIL; _cairo_image_surface_set_parent (to_image_surface(surface->image), &surface->win32.base); surface->win32.format = format; surface->win32.extents.x = 0; surface->win32.extents.y = 0; surface->win32.extents.width = width; surface->win32.extents.height = height; surface->initial_clip_rgn = NULL; surface->had_simple_clip = FALSE; device = _cairo_win32_device_get (); _cairo_surface_init (&surface->win32.base, &cairo_win32_display_surface_backend, device, _cairo_content_from_format (format)); cairo_device_destroy (device); return &surface->win32.base; FAIL: if (surface->bitmap) { SelectObject (surface->win32.dc, surface->saved_dc_bitmap); DeleteObject (surface->bitmap); DeleteDC (surface->win32.dc); } free (surface); return _cairo_surface_create_in_error (status); }
/** * cairo_os2_surface_create: * @hps_client_window: the presentation handle to bind the surface to * @width: the width of the surface * @height: the height of the surface * * Create a Cairo surface which is bound to a given presentation space (HPS). * The caller retains ownership of the HPS and must dispose of it after the * the surface has been destroyed. The surface will be created to have the * given size. By default every change to the surface will be made visible * immediately by blitting it into the window. This can be changed with * cairo_os2_surface_set_manual_window_refresh(). * Note that the surface will contain garbage when created, so the pixels * have to be initialized by hand first. You can use the Cairo functions to * fill it with black, or use cairo_surface_mark_dirty() to fill the surface * with pixels from the window/HPS. * * Return value: the newly created surface * * Since: 1.4 **/ cairo_surface_t * cairo_os2_surface_create (HPS hps_client_window, int width, int height) { cairo_os2_surface_t *local_os2_surface = 0; cairo_status_t status; int rc; /* Check the size of the window */ if ((width <= 0) || (height <= 0)) { status = _cairo_error (CAIRO_STATUS_INVALID_SIZE); goto error_exit; } /* Allocate an OS/2 surface structure. */ local_os2_surface = (cairo_os2_surface_t *) malloc (sizeof (cairo_os2_surface_t)); if (!local_os2_surface) { status = _cairo_error (CAIRO_STATUS_NO_MEMORY); goto error_exit; } memset(local_os2_surface, 0, sizeof(cairo_os2_surface_t)); /* Allocate resources: mutex & event semaphores and the pixel buffer */ if (DosCreateMutexSem (NULL, &(local_os2_surface->hmtx_use_private_fields), 0, FALSE)) { status = _cairo_error (CAIRO_STATUS_DEVICE_ERROR); goto error_exit; } if (DosCreateEventSem (NULL, &(local_os2_surface->hev_pixel_array_came_back), 0, FALSE)) { status = _cairo_error (CAIRO_STATUS_DEVICE_ERROR); goto error_exit; } local_os2_surface->pixels = (unsigned char *) _buffer_alloc (height, width, 4); if (!local_os2_surface->pixels) { status = _cairo_error (CAIRO_STATUS_NO_MEMORY); goto error_exit; } /* Create image surface from pixel array */ local_os2_surface->image_surface = (cairo_image_surface_t *) cairo_image_surface_create_for_data (local_os2_surface->pixels, CAIRO_FORMAT_ARGB32, width, /* Width */ height, /* Height */ width * 4); /* Rowstride */ status = local_os2_surface->image_surface->base.status; if (status) goto error_exit; /* Set values for OS/2-specific data that aren't zero/NULL/FALSE. * Note: hps_client_window may be null if this was called by * cairo_os2_surface_create_for_window(). */ local_os2_surface->hps_client_window = hps_client_window; local_os2_surface->blit_as_changes = TRUE; /* Prepare BITMAPINFO2 structure for our buffer */ local_os2_surface->bitmap_info.cbFix = sizeof (BITMAPINFOHEADER2); local_os2_surface->bitmap_info.cx = width; local_os2_surface->bitmap_info.cy = height; local_os2_surface->bitmap_info.cPlanes = 1; local_os2_surface->bitmap_info.cBitCount = 32; /* Initialize base surface */ _cairo_surface_init (&local_os2_surface->base, &cairo_os2_surface_backend, NULL, /* device */ _cairo_content_from_format (CAIRO_FORMAT_ARGB32)); /* Successful exit */ return (cairo_surface_t *)local_os2_surface; error_exit: /* This point will only be reached if an error occurred */ if (local_os2_surface) { if (local_os2_surface->pixels) _buffer_free (local_os2_surface->pixels); if (local_os2_surface->hev_pixel_array_came_back) DosCloseEventSem (local_os2_surface->hev_pixel_array_came_back); if (local_os2_surface->hmtx_use_private_fields) DosCloseMutexSem (local_os2_surface->hmtx_use_private_fields); free (local_os2_surface); } return _cairo_surface_create_in_error (status); }
static cairo_surface_t * _cairo_win32_surface_create_for_dc (HDC original_dc, cairo_format_t format, int width, int height) { cairo_status_t status; cairo_win32_surface_t *surface; char *bits; int rowstride; _cairo_win32_initialize (); surface = malloc (sizeof (cairo_win32_surface_t)); if (surface == NULL) { _cairo_error (CAIRO_STATUS_NO_MEMORY); return &_cairo_surface_nil; } status = _create_dc_and_bitmap (surface, original_dc, format, width, height, &bits, &rowstride); if (status) goto FAIL; surface->image = cairo_image_surface_create_for_data (bits, format, width, height, rowstride); if (surface->image->status) { status = CAIRO_STATUS_NO_MEMORY; goto FAIL; } surface->format = format; surface->clip_rect.x = 0; surface->clip_rect.y = 0; surface->clip_rect.width = width; surface->clip_rect.height = height; surface->saved_clip = CreateRectRgn (0, 0, 0, 0); if (GetClipRgn (surface->dc, surface->saved_clip) == 0) { DeleteObject(surface->saved_clip); surface->saved_clip = NULL; } surface->extents = surface->clip_rect; _cairo_surface_init (&surface->base, &cairo_win32_surface_backend, _cairo_content_from_format (format)); return (cairo_surface_t *)surface; FAIL: if (surface->bitmap) { SelectObject (surface->dc, surface->saved_dc_bitmap); DeleteObject (surface->bitmap); DeleteDC (surface->dc); } if (surface) free (surface); if (status == CAIRO_STATUS_NO_MEMORY) { _cairo_error (CAIRO_STATUS_NO_MEMORY); return &_cairo_surface_nil; } else { _cairo_error (status); return &_cairo_surface_nil; } }