static GpStatus gdip_texture_create_from_cloned_image (GpImage *image, GpWrapMode wrapMode, GpTexture **texture) { GpTexture *result; cairo_surface_t *imageSurface = NULL; result = gdip_texture_new (); if (!result) return OutOfMemory; result->image = image; /* note: we must keep the scan0 alive, so we must use the cloned image (and not the original) see bug #80971 */ imageSurface = cairo_image_surface_create_for_data ((BYTE*)result->image->active_bitmap->scan0, result->image->cairo_format, result->image->active_bitmap->width, result->image->active_bitmap->height, result->image->active_bitmap->stride); if (!imageSurface) { GdipDeleteBrush ((GpBrush *) result); return OutOfMemory; } result->wrapMode = wrapMode; if (result->image->surface) cairo_surface_destroy (result->image->surface); result->image->surface = imageSurface; result->rectangle.X = 0; result->rectangle.Y = 0; result->rectangle.Width = result->image->active_bitmap->width; result->rectangle.Height = result->image->active_bitmap->height; *texture = result; return Ok; }
/* coverity[+alloc : arg-*2] */ GpStatus WINGDIPAPI GdipCreateTexture (GpImage *image, GpWrapMode wrapMode, GpTexture **texture) { cairo_surface_t *imageSurface = NULL; GpTexture *result; GpStatus status; if (!image || !texture) return InvalidParameter; if ((wrapMode < WrapModeTile) || (wrapMode > WrapModeClamp)) return OutOfMemory; if (image->type != ImageTypeBitmap) return NotImplemented; result = gdip_texture_new (); if (!result) return OutOfMemory; result->image = NULL; status = GdipCloneImage (image, &result->image); if (status != Ok) goto failure; /* note: we must keep the scan0 alive, so we must use the cloned image (and not the original) see bug #80971 */ imageSurface = cairo_image_surface_create_for_data ((BYTE*)result->image->active_bitmap->scan0, image->cairo_format, image->active_bitmap->width, image->active_bitmap->height, image->active_bitmap->stride); if (!imageSurface) goto failure; result->wrapMode = wrapMode; if (result->image->surface) cairo_surface_destroy (result->image->surface); result->image->surface = imageSurface; result->rectangle.X = 0; result->rectangle.Y = 0; result->rectangle.Width = image->active_bitmap->width; result->rectangle.Height = image->active_bitmap->height; *texture = result; return Ok; failure: if (result->image) GdipDisposeImage (result->image); if (imageSurface) cairo_surface_destroy (imageSurface); GdipFree (result); *texture = NULL; return status; }
GpStatus gdip_texture_clone (GpBrush *brush, GpBrush **clonedBrush) { GpTexture *result; GpTexture *texture; GpStatus status; if (!brush || !clonedBrush) return InvalidParameter; result = gdip_texture_new (); if (!result) return OutOfMemory; texture = (GpTexture *) brush; result->base = texture->base; result->wrapMode = texture->wrapMode; /* Let the clone create its own pattern. */ result->pattern = NULL; result->base.changed = TRUE; gdip_cairo_matrix_copy (&result->matrix, &texture->matrix); result->rectangle.X = texture->rectangle.X; result->rectangle.Y = texture->rectangle.Y; result->rectangle.Width = texture->rectangle.Width; result->rectangle.Height = texture->rectangle.Height; result->image = NULL; status = GdipCloneImage (texture->image, &result->image); if (status != Ok) { GdipDeleteBrush ((GpBrush *) result); *clonedBrush = NULL; return status; } else { cairo_surface_reference (result->image->surface); } *clonedBrush = (GpBrush *) result; return status; }