gdk: Remove gdk_texture_new_from_data()

Use gdk_memory_texture_new() instead.
This commit is contained in:
Benjamin Otte 2018-03-18 04:38:49 +01:00
parent 41a5e744d8
commit ee8e42f19b
6 changed files with 30 additions and 56 deletions

View File

@ -733,7 +733,6 @@ gdk_paintable_invalidate_size
<TITLE>Textures</TITLE>
<FILE>textures</FILE>
GdkTexture
gdk_texture_new_for_data
gdk_texture_new_for_pixbuf
gdk_texture_new_from_resource
gdk_texture_new_from_file

View File

@ -266,48 +266,6 @@ gdk_texture_init (GdkTexture *self)
{
}
/**
* gdk_texture_new_for_data:
* @data: (array): the pixel data
* @width: the number of pixels in each row
* @height: the number of rows
* @stride: the distance from the beginning of one row to the next, in bytes
*
* Creates a new texture object holding the given data.
* The data is assumed to be in CAIRO_FORMAT_ARGB32 format.
*
* Returns: a new #GdkTexture
*/
GdkTexture *
gdk_texture_new_for_data (const guchar *data,
int width,
int height,
int stride)
{
GdkTexture *texture;
cairo_surface_t *original, *copy;
cairo_t *cr;
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
original = cairo_image_surface_create_for_data ((guchar *) data, CAIRO_FORMAT_ARGB32, width, height, stride);
copy = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
cr = cairo_create (copy);
cairo_set_source_surface (cr, original, 0, 0);
cairo_paint (cr);
cairo_destroy (cr);
texture = gdk_texture_new_for_surface (copy);
cairo_surface_destroy (copy);
cairo_surface_finish (original);
cairo_surface_destroy (original);
return texture;
}
/**
* gdk_texture_new_for_surface:
* @surface: a cairo image surface

View File

@ -42,11 +42,6 @@ typedef struct _GdkTextureClass GdkTextureClass;
GDK_AVAILABLE_IN_ALL
GType gdk_texture_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GdkTexture * gdk_texture_new_for_data (const guchar *data,
int width,
int height,
int stride);
GDK_AVAILABLE_IN_ALL
GdkTexture * gdk_texture_new_for_pixbuf (GdkPixbuf *pixbuf);
GDK_AVAILABLE_IN_ALL

View File

@ -24,6 +24,8 @@
#include "gskdebugprivate.h"
#include "gskrendererprivate.h"
#include "gskroundedrectprivate.h"
#include "gdk/gdkmemorytextureprivate.h"
#include "gdk/gdktextureprivate.h"
static gboolean
@ -729,6 +731,7 @@ gsk_texture_node_deserialize (GVariant *variant,
guint32 width, height;
GVariant *pixel_variant;
gsize n_pixels;
GBytes *bytes;
if (!check_variant_type (variant, GSK_TEXTURE_NODE_VARIANT_TYPE, error))
return NULL;
@ -738,9 +741,23 @@ gsk_texture_node_deserialize (GVariant *variant,
&width, &height, &pixel_variant);
/* XXX: Make this work without copying the data */
texture = gdk_texture_new_for_data (g_variant_get_fixed_array (pixel_variant, &n_pixels, sizeof (guint32)),
width, height, width * 4);
g_variant_unref (pixel_variant);
bytes = g_bytes_new_with_free_func (g_variant_get_fixed_array (pixel_variant, &n_pixels, sizeof (guint32)),
width * height * sizeof (guint32),
(GDestroyNotify) g_variant_unref,
pixel_variant);
if (n_pixels != width * height)
{
g_set_error (error, GSK_SERIALIZATION_ERROR, GSK_SERIALIZATION_INVALID_DATA,
"Expected %u pixels but got %"G_GSIZE_FORMAT" for %ux%u image",
width * height, n_pixels, width, height);
g_bytes_unref (bytes);
return NULL;
}
texture = gdk_memory_texture_new (width, height,
GDK_MEMORY_CAIRO_FORMAT_ARGB32,
bytes,
width * 4);
node = gsk_texture_node_new (texture, &GRAPHENE_RECT_INIT(bounds[0], bounds[1], bounds[2], bounds[3]));

View File

@ -6,6 +6,8 @@
#include "gskvulkanmemoryprivate.h"
#include "gskvulkanpipelineprivate.h"
#include "gdk/gdkmemorytextureprivate.h"
#include <string.h>
struct _GskVulkanUploader
@ -633,6 +635,7 @@ gsk_vulkan_image_download (GskVulkanImage *self,
{
GskVulkanBuffer *buffer;
GdkTexture *texture;
GBytes *bytes;
guchar *mem;
gsk_vulkan_uploader_add_image_barrier (uploader,
@ -671,7 +674,11 @@ gsk_vulkan_image_download (GskVulkanImage *self,
GSK_VK_CHECK (vkQueueWaitIdle, gdk_vulkan_context_get_queue (self->vulkan));
mem = gsk_vulkan_buffer_map (buffer);
texture = gdk_texture_new_for_data (mem, self->width, self->height, self->width * 4);
bytes = g_bytes_new (mem, self->width * self->height * 4);
texture = gdk_memory_texture_new (self->width, self->height,
GDK_MEMORY_CAIRO_FORMAT_ARGB32,
bytes,
self->width * 4);
gsk_vulkan_buffer_unmap (buffer);
gsk_vulkan_buffer_free (buffer);

View File

@ -73,6 +73,7 @@
#include "inspector/init.h"
#include "inspector/window.h"
#include "gdk/gdktextureprivate.h"
#include "gdk/gdk-private.h"
#include <cairo-gobject.h>
@ -4600,10 +4601,7 @@ icon_from_list (GList *list,
cairo_destroy (cr);
cairo_surface_destroy (source);
texture = gdk_texture_new_for_data (cairo_image_surface_get_data (target),
cairo_image_surface_get_width (target),
cairo_image_surface_get_height (target),
cairo_image_surface_get_stride (target));
texture = gdk_texture_new_for_surface (target);
cairo_surface_destroy (target);
return texture;