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; pixman_image_t *pixman_image; pixman_format_code_t pixman_format; SkColorType colorType; surface = (cairo_skia_surface_t *) malloc (sizeof (cairo_skia_surface_t)); if (unlikely (surface == NULL)) return (cairo_skia_surface_t *) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); pixman_format = sk_config_to_pixman_format_code (config, opaque); pixman_image = pixman_image_create_bits (pixman_format, width, height, (uint32_t *) data, stride); if (unlikely (pixman_image == NULL)) { free (surface); return (cairo_skia_surface_t *) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } _cairo_surface_init (&surface->image.base, &cairo_skia_surface_backend, NULL, /* device */ _cairo_content_from_pixman_format (pixman_format)); _cairo_image_surface_init (&surface->image, pixman_image, pixman_format); surface->bitmap = new SkBitmap; colorType = SkBitmapConfigToColorType(config); surface->bitmap->setAlphaType (opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); surface->bitmap->setInfo (SkImageInfo::Make(width, height, colorType, kPremul_SkAlphaType), surface->image.stride); surface->bitmap->setPixels (surface->image.data); surface->image.base.is_clear = data == NULL; return surface; }
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; pixman_image_t *pixman_image; pixman_format_code_t pixman_format; surface = (cairo_skia_surface_t *) malloc (sizeof (cairo_skia_surface_t)); if (unlikely (surface == NULL)) return (cairo_skia_surface_t *) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); pixman_format = sk_config_to_pixman_format_code (config, opaque); pixman_image = pixman_image_create_bits (pixman_format, width, height, (uint32_t *) data, stride); if (unlikely (pixman_image == NULL)) return (cairo_skia_surface_t *) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); _cairo_surface_init (&surface->image.base, &cairo_skia_surface_backend, NULL, /* device */ _cairo_content_from_pixman_format (pixman_format)); _cairo_image_surface_init (&surface->image, pixman_image, pixman_format); surface->bitmap = new SkBitmap; surface->bitmap->setConfig (config, width, height, surface->image.stride); surface->bitmap->setIsOpaque (opaque); surface->bitmap->setPixels (surface->image.data); surface->image.base.is_clear = data == NULL; return surface; }