mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-13 05:50:10 +00:00
gdk: Remove gdk_texture_new_from_data()
Use gdk_memory_texture_new() instead.
This commit is contained in:
parent
41a5e744d8
commit
ee8e42f19b
@ -733,7 +733,6 @@ gdk_paintable_invalidate_size
|
|||||||
<TITLE>Textures</TITLE>
|
<TITLE>Textures</TITLE>
|
||||||
<FILE>textures</FILE>
|
<FILE>textures</FILE>
|
||||||
GdkTexture
|
GdkTexture
|
||||||
gdk_texture_new_for_data
|
|
||||||
gdk_texture_new_for_pixbuf
|
gdk_texture_new_for_pixbuf
|
||||||
gdk_texture_new_from_resource
|
gdk_texture_new_from_resource
|
||||||
gdk_texture_new_from_file
|
gdk_texture_new_from_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:
|
* gdk_texture_new_for_surface:
|
||||||
* @surface: a cairo image surface
|
* @surface: a cairo image surface
|
||||||
|
@ -42,11 +42,6 @@ typedef struct _GdkTextureClass GdkTextureClass;
|
|||||||
GDK_AVAILABLE_IN_ALL
|
GDK_AVAILABLE_IN_ALL
|
||||||
GType gdk_texture_get_type (void) G_GNUC_CONST;
|
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
|
GDK_AVAILABLE_IN_ALL
|
||||||
GdkTexture * gdk_texture_new_for_pixbuf (GdkPixbuf *pixbuf);
|
GdkTexture * gdk_texture_new_for_pixbuf (GdkPixbuf *pixbuf);
|
||||||
GDK_AVAILABLE_IN_ALL
|
GDK_AVAILABLE_IN_ALL
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
#include "gskdebugprivate.h"
|
#include "gskdebugprivate.h"
|
||||||
#include "gskrendererprivate.h"
|
#include "gskrendererprivate.h"
|
||||||
#include "gskroundedrectprivate.h"
|
#include "gskroundedrectprivate.h"
|
||||||
|
|
||||||
|
#include "gdk/gdkmemorytextureprivate.h"
|
||||||
#include "gdk/gdktextureprivate.h"
|
#include "gdk/gdktextureprivate.h"
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -729,6 +731,7 @@ gsk_texture_node_deserialize (GVariant *variant,
|
|||||||
guint32 width, height;
|
guint32 width, height;
|
||||||
GVariant *pixel_variant;
|
GVariant *pixel_variant;
|
||||||
gsize n_pixels;
|
gsize n_pixels;
|
||||||
|
GBytes *bytes;
|
||||||
|
|
||||||
if (!check_variant_type (variant, GSK_TEXTURE_NODE_VARIANT_TYPE, error))
|
if (!check_variant_type (variant, GSK_TEXTURE_NODE_VARIANT_TYPE, error))
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -738,9 +741,23 @@ gsk_texture_node_deserialize (GVariant *variant,
|
|||||||
&width, &height, &pixel_variant);
|
&width, &height, &pixel_variant);
|
||||||
|
|
||||||
/* XXX: Make this work without copying the data */
|
/* 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)),
|
bytes = g_bytes_new_with_free_func (g_variant_get_fixed_array (pixel_variant, &n_pixels, sizeof (guint32)),
|
||||||
width, height, width * 4);
|
width * height * sizeof (guint32),
|
||||||
g_variant_unref (pixel_variant);
|
(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]));
|
node = gsk_texture_node_new (texture, &GRAPHENE_RECT_INIT(bounds[0], bounds[1], bounds[2], bounds[3]));
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include "gskvulkanmemoryprivate.h"
|
#include "gskvulkanmemoryprivate.h"
|
||||||
#include "gskvulkanpipelineprivate.h"
|
#include "gskvulkanpipelineprivate.h"
|
||||||
|
|
||||||
|
#include "gdk/gdkmemorytextureprivate.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
struct _GskVulkanUploader
|
struct _GskVulkanUploader
|
||||||
@ -633,6 +635,7 @@ gsk_vulkan_image_download (GskVulkanImage *self,
|
|||||||
{
|
{
|
||||||
GskVulkanBuffer *buffer;
|
GskVulkanBuffer *buffer;
|
||||||
GdkTexture *texture;
|
GdkTexture *texture;
|
||||||
|
GBytes *bytes;
|
||||||
guchar *mem;
|
guchar *mem;
|
||||||
|
|
||||||
gsk_vulkan_uploader_add_image_barrier (uploader,
|
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));
|
GSK_VK_CHECK (vkQueueWaitIdle, gdk_vulkan_context_get_queue (self->vulkan));
|
||||||
|
|
||||||
mem = gsk_vulkan_buffer_map (buffer);
|
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_unmap (buffer);
|
||||||
gsk_vulkan_buffer_free (buffer);
|
gsk_vulkan_buffer_free (buffer);
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@
|
|||||||
#include "inspector/init.h"
|
#include "inspector/init.h"
|
||||||
#include "inspector/window.h"
|
#include "inspector/window.h"
|
||||||
|
|
||||||
|
#include "gdk/gdktextureprivate.h"
|
||||||
#include "gdk/gdk-private.h"
|
#include "gdk/gdk-private.h"
|
||||||
|
|
||||||
#include <cairo-gobject.h>
|
#include <cairo-gobject.h>
|
||||||
@ -4600,10 +4601,7 @@ icon_from_list (GList *list,
|
|||||||
cairo_destroy (cr);
|
cairo_destroy (cr);
|
||||||
cairo_surface_destroy (source);
|
cairo_surface_destroy (source);
|
||||||
|
|
||||||
texture = gdk_texture_new_for_data (cairo_image_surface_get_data (target),
|
texture = gdk_texture_new_for_surface (target);
|
||||||
cairo_image_surface_get_width (target),
|
|
||||||
cairo_image_surface_get_height (target),
|
|
||||||
cairo_image_surface_get_stride (target));
|
|
||||||
cairo_surface_destroy (target);
|
cairo_surface_destroy (target);
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
|
Loading…
Reference in New Issue
Block a user