gdk: Remove gdk_texture_new_from_data()
authorBenjamin Otte <otte@redhat.com>
Sun, 18 Mar 2018 03:38:49 +0000 (04:38 +0100)
committerBenjamin Otte <otte@redhat.com>
Sun, 18 Mar 2018 04:57:07 +0000 (05:57 +0100)
Use gdk_memory_texture_new() instead.

docs/reference/gdk/gdk4-sections.txt
gdk/gdktexture.c
gdk/gdktexture.h
gsk/gskrendernodeimpl.c
gsk/vulkan/gskvulkanimage.c
gtk/gtkwindow.c

index 91c23004c6b8b1c7626ce475c9d8350b059017eb..6d16ed606dba76826585401ba4708ae2ea7715dd 100644 (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
index 663f53c283abe1915b8357373c941664610654e5..c2557c428043963413a567da78160e72903ae105 100644 (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
index 43bd9663e3ae82d3891f80522797c31cf72dd5d9..67c14e15380f510fa83bbc878786caeb6b2b27f1 100644 (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
index f0b451f9a4b7194f359aa4090576cba94dc9ca26..6df5cc0d977ad44326071a2888b7c0b3efa48684 100644 (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]));
 
index 34cfd3d5e2b8b9d4f95cde4acf9ce58d821fc10d..729d99326267f6b77334b2b95ea46477cde502b3 100644 (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);
 
index 1d0b95ef187459feafed3b7159cbed5888faf6d0..be5e903233677d52001bd5025310040f2a30df34 100644 (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;