summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2018-03-18 04:38:49 +0100
committerBenjamin Otte <otte@redhat.com>2018-03-18 05:57:07 +0100
commitee8e42f19bb2cf0505d74265dfb71470040b0502 (patch)
tree87d121547dd4a55a4bac96891a7dfd19f9620e22
parent41a5e744d82efe95cb1e145caf2f3c3f22eac950 (diff)
downloadgtk+-ee8e42f19bb2cf0505d74265dfb71470040b0502.tar.gz
gdk: Remove gdk_texture_new_from_data()
Use gdk_memory_texture_new() instead.
-rw-r--r--docs/reference/gdk/gdk4-sections.txt1
-rw-r--r--gdk/gdktexture.c42
-rw-r--r--gdk/gdktexture.h5
-rw-r--r--gsk/gskrendernodeimpl.c23
-rw-r--r--gsk/vulkan/gskvulkanimage.c9
-rw-r--r--gtk/gtkwindow.c6
6 files changed, 30 insertions, 56 deletions
diff --git a/docs/reference/gdk/gdk4-sections.txt b/docs/reference/gdk/gdk4-sections.txt
index 91c23004c6..6d16ed606d 100644
--- a/docs/reference/gdk/gdk4-sections.txt
+++ b/docs/reference/gdk/gdk4-sections.txt
@@ -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
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c
index 663f53c283..c2557c4280 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -267,48 +267,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
*
diff --git a/gdk/gdktexture.h b/gdk/gdktexture.h
index 43bd9663e3..67c14e1538 100644
--- a/gdk/gdktexture.h
+++ b/gdk/gdktexture.h
@@ -43,11 +43,6 @@ 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
GdkTexture * gdk_texture_new_from_resource (const char *resource_path);
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index f0b451f9a4..6df5cc0d97 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -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]));
diff --git a/gsk/vulkan/gskvulkanimage.c b/gsk/vulkan/gskvulkanimage.c
index 34cfd3d5e2..729d993262 100644
--- a/gsk/vulkan/gskvulkanimage.c
+++ b/gsk/vulkan/gskvulkanimage.c
@@ -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);
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 1d0b95ef18..be5e903233 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -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;