st/image-content: Take a CoglContext on set_bytes/set_data functions
This avoids retrieving it from the global clutter backend and instead pass things around. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3528>
This commit is contained in:
parent
76f2262d9c
commit
44b84e458a
@ -377,28 +377,6 @@ st_image_content_get_is_symbolic (StImageContent *content)
|
|||||||
return content->is_symbolic;
|
return content->is_symbolic;
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
ClutterBackend *backend = clutter_get_default_backend ();
|
|
||||||
CoglContext *cogl_context = clutter_backend_get_cogl_context (backend);
|
|
||||||
CoglTexture *texture_2d;
|
|
||||||
|
|
||||||
texture_2d = cogl_texture_2d_new_from_data (cogl_context,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
pixel_format,
|
|
||||||
row_stride,
|
|
||||||
data,
|
|
||||||
error);
|
|
||||||
|
|
||||||
return texture_2d;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_image_size (StImageContent *self)
|
update_image_size (StImageContent *self)
|
||||||
@ -424,6 +402,7 @@ update_image_size (StImageContent *self)
|
|||||||
/**
|
/**
|
||||||
* st_image_content_set_data:
|
* st_image_content_set_data:
|
||||||
* @content: a #StImageContentImage
|
* @content: a #StImageContentImage
|
||||||
|
* @cogl_context: The context to use
|
||||||
* @data: (array): the image data, as an array of bytes
|
* @data: (array): the image data, as an array of bytes
|
||||||
* @pixel_format: the Cogl pixel format of the image data
|
* @pixel_format: the Cogl pixel format of the image data
|
||||||
* @width: the width of the image data
|
* @width: the width of the image data
|
||||||
@ -467,6 +446,7 @@ update_image_size (StImageContent *self)
|
|||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
st_image_content_set_data (StImageContent *content,
|
st_image_content_set_data (StImageContent *content,
|
||||||
|
CoglContext *cogl_context,
|
||||||
const guint8 *data,
|
const guint8 *data,
|
||||||
CoglPixelFormat pixel_format,
|
CoglPixelFormat pixel_format,
|
||||||
guint width,
|
guint width,
|
||||||
@ -480,12 +460,13 @@ st_image_content_set_data (StImageContent *content,
|
|||||||
if (content->texture != NULL)
|
if (content->texture != NULL)
|
||||||
g_object_unref (content->texture);
|
g_object_unref (content->texture);
|
||||||
|
|
||||||
content->texture = create_texture_from_data (width,
|
content->texture = cogl_texture_2d_new_from_data (cogl_context,
|
||||||
height,
|
width,
|
||||||
pixel_format,
|
height,
|
||||||
row_stride,
|
pixel_format,
|
||||||
data,
|
row_stride,
|
||||||
error);
|
data,
|
||||||
|
error);
|
||||||
|
|
||||||
if (content->texture == NULL)
|
if (content->texture == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -499,6 +480,7 @@ st_image_content_set_data (StImageContent *content,
|
|||||||
/**
|
/**
|
||||||
* st_image_content_set_bytes:
|
* st_image_content_set_bytes:
|
||||||
* @content: a #StImageContent
|
* @content: a #StImageContent
|
||||||
|
* @cogl_context: The context to use
|
||||||
* @data: the image data, as a #GBytes
|
* @data: the image data, as a #GBytes
|
||||||
* @pixel_format: the Cogl pixel format of the image data
|
* @pixel_format: the Cogl pixel format of the image data
|
||||||
* @width: the width of the image data
|
* @width: the width of the image data
|
||||||
@ -521,6 +503,7 @@ st_image_content_set_data (StImageContent *content,
|
|||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
st_image_content_set_bytes (StImageContent *content,
|
st_image_content_set_bytes (StImageContent *content,
|
||||||
|
CoglContext *cogl_context,
|
||||||
GBytes *data,
|
GBytes *data,
|
||||||
CoglPixelFormat pixel_format,
|
CoglPixelFormat pixel_format,
|
||||||
guint width,
|
guint width,
|
||||||
@ -536,12 +519,13 @@ st_image_content_set_bytes (StImageContent *content,
|
|||||||
if (content->texture != NULL)
|
if (content->texture != NULL)
|
||||||
g_object_unref (content->texture);
|
g_object_unref (content->texture);
|
||||||
|
|
||||||
content->texture = create_texture_from_data (width,
|
content->texture = cogl_texture_2d_new_from_data (cogl_context,
|
||||||
height,
|
width,
|
||||||
pixel_format,
|
height,
|
||||||
row_stride,
|
pixel_format,
|
||||||
g_bytes_get_data (data, NULL),
|
row_stride,
|
||||||
error);
|
g_bytes_get_data (data, NULL),
|
||||||
|
error);
|
||||||
|
|
||||||
if (content->texture == NULL)
|
if (content->texture == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -30,6 +30,7 @@ ClutterContent *st_image_content_new_with_preferred_size (int width,
|
|||||||
int height);
|
int height);
|
||||||
|
|
||||||
gboolean st_image_content_set_data (StImageContent *content,
|
gboolean st_image_content_set_data (StImageContent *content,
|
||||||
|
CoglContext *cogl_context,
|
||||||
const guint8 *data,
|
const guint8 *data,
|
||||||
CoglPixelFormat pixel_format,
|
CoglPixelFormat pixel_format,
|
||||||
guint width,
|
guint width,
|
||||||
@ -38,6 +39,7 @@ gboolean st_image_content_set_data (StImageContent *content,
|
|||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
gboolean st_image_content_set_bytes (StImageContent *content,
|
gboolean st_image_content_set_bytes (StImageContent *content,
|
||||||
|
CoglContext *cogl_context,
|
||||||
GBytes *data,
|
GBytes *data,
|
||||||
CoglPixelFormat pixel_format,
|
CoglPixelFormat pixel_format,
|
||||||
guint width,
|
guint width,
|
||||||
|
@ -526,6 +526,7 @@ pixbuf_to_st_content_image (GdkPixbuf *pixbuf,
|
|||||||
|
|
||||||
image = st_image_content_new_with_preferred_size (width, height);
|
image = st_image_content_new_with_preferred_size (width, height);
|
||||||
st_image_content_set_data (ST_IMAGE_CONTENT (image),
|
st_image_content_set_data (ST_IMAGE_CONTENT (image),
|
||||||
|
context,
|
||||||
gdk_pixbuf_get_pixels (pixbuf),
|
gdk_pixbuf_get_pixels (pixbuf),
|
||||||
gdk_pixbuf_get_has_alpha (pixbuf) ?
|
gdk_pixbuf_get_has_alpha (pixbuf) ?
|
||||||
COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
|
COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user