clutter/image: Port to cogl_texture_2d_new_from_data

Stop using cogl_texture_new_from_data() in favour of the undeprecated
cogl_texture_2d_new_from_data().

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2355>
This commit is contained in:
Georges Basile Stavracas Neto 2022-03-31 12:48:37 -03:00
parent f927e692c7
commit f1ac534cd2

View File

@ -68,6 +68,29 @@ clutter_image_error_quark (void)
return g_quark_from_static_string ("clutter-image-error-quark");
}
static CoglTexture *
create_texture_from_data (unsigned int width,
unsigned int height,
CoglPixelFormat pixel_format,
unsigned int row_stride,
const uint8_t *data,
GError **error)
{
CoglContext *ctx =
clutter_backend_get_cogl_context (clutter_get_default_backend ());
CoglTexture2D *texture_2d;
texture_2d = cogl_texture_2d_new_from_data (ctx,
width,
height,
pixel_format,
row_stride,
data,
error);
return texture_2d ? COGL_TEXTURE (texture_2d) : NULL;
}
static void
update_image_size (ClutterImage *self)
{
@ -231,7 +254,6 @@ clutter_image_set_data (ClutterImage *image,
GError **error)
{
ClutterImagePrivate *priv;
CoglTextureFlags flags;
g_return_val_if_fail (CLUTTER_IS_IMAGE (image), FALSE);
g_return_val_if_fail (data != NULL, FALSE);
@ -241,16 +263,13 @@ clutter_image_set_data (ClutterImage *image,
if (priv->texture != NULL)
cogl_object_unref (priv->texture);
flags = COGL_TEXTURE_NONE;
if (width >= 512 && height >= 512)
flags |= COGL_TEXTURE_NO_ATLAS;
priv->texture = cogl_texture_new_from_data (width, height,
flags,
priv->texture = create_texture_from_data (width,
height,
pixel_format,
COGL_PIXEL_FORMAT_ANY,
row_stride,
data);
data,
NULL);
if (priv->texture == NULL)
{
g_set_error_literal (error, CLUTTER_IMAGE_ERROR,
@ -300,7 +319,6 @@ clutter_image_set_bytes (ClutterImage *image,
GError **error)
{
ClutterImagePrivate *priv;
CoglTextureFlags flags;
g_return_val_if_fail (CLUTTER_IS_IMAGE (image), FALSE);
g_return_val_if_fail (data != NULL, FALSE);
@ -310,16 +328,13 @@ clutter_image_set_bytes (ClutterImage *image,
if (priv->texture != NULL)
cogl_object_unref (priv->texture);
flags = COGL_TEXTURE_NONE;
if (width >= 512 && height >= 512)
flags |= COGL_TEXTURE_NO_ATLAS;
priv->texture = cogl_texture_new_from_data (width, height,
flags,
priv->texture = create_texture_from_data (width,
height,
pixel_format,
COGL_PIXEL_FORMAT_ANY,
row_stride,
g_bytes_get_data (data, NULL));
g_bytes_get_data (data, NULL),
NULL);
if (priv->texture == NULL)
{
g_set_error_literal (error, CLUTTER_IMAGE_ERROR,
@ -381,18 +396,12 @@ clutter_image_set_area (ClutterImage *image,
if (priv->texture == NULL)
{
CoglTextureFlags flags = COGL_TEXTURE_NONE;
if (area->width >= 512 && area->height >= 512)
flags |= COGL_TEXTURE_NO_ATLAS;
priv->texture = cogl_texture_new_from_data (area->width,
priv->texture = create_texture_from_data (area->width,
area->height,
flags,
pixel_format,
COGL_PIXEL_FORMAT_ANY,
row_stride,
data);
data,
NULL);
}
else
{