compositor: Don't use cogl_texture_new_with_data in the obvious cases

It's a deprecated API that can surprise us. Namely, when the internal
format passed is COGL_PIXEL_FORMAT_ANY, it will *always* allocate an
RGBA8888 pixel format texture, even if we only passed it a RGB format
or even an A8 format.

cogl_texture_2d_new_with_data is the newer, better API and doesn't have
these warts.
This commit is contained in:
Jasper St. Pierre 2014-08-07 13:35:35 -04:00
parent 584460deec
commit d72bf0cd5d
3 changed files with 41 additions and 43 deletions

View File

@ -785,6 +785,8 @@ meta_background_load_gradient (MetaBackground *self,
ClutterColor *color,
ClutterColor *second_color)
{
ClutterBackend *backend = clutter_get_default_backend ();
CoglContext *ctx = clutter_backend_get_cogl_context (backend);
MetaBackgroundPrivate *priv = self->priv;
CoglTexture *texture;
guint width, height;
@ -820,12 +822,11 @@ meta_background_load_gradient (MetaBackground *self,
pixels[6] = second_color->blue;
pixels[7] = 0xFF;
texture = cogl_texture_new_from_data (width, height,
COGL_TEXTURE_NO_SLICING,
COGL_PIXEL_FORMAT_RGB_888,
COGL_PIXEL_FORMAT_ANY,
4,
pixels);
texture = COGL_TEXTURE (cogl_texture_2d_new_from_data (ctx, width, height,
COGL_PIXEL_FORMAT_RGB_888,
4,
pixels,
NULL));
set_texture (self, COGL_TEXTURE (texture));
}
@ -843,6 +844,8 @@ void
meta_background_load_color (MetaBackground *self,
ClutterColor *color)
{
ClutterBackend *backend = clutter_get_default_backend ();
CoglContext *ctx = clutter_backend_get_cogl_context (backend);
MetaBackgroundPrivate *priv = self->priv;
CoglTexture *texture;
ClutterActor *stage = meta_get_stage_for_screen (priv->screen);
@ -865,12 +868,11 @@ meta_background_load_color (MetaBackground *self,
pixels[2] = color->blue;
pixels[3] = 0xFF;
texture = cogl_texture_new_from_data (1, 1,
COGL_TEXTURE_NO_SLICING,
COGL_PIXEL_FORMAT_RGB_888,
COGL_PIXEL_FORMAT_ANY,
4,
pixels);
texture = COGL_TEXTURE (cogl_texture_2d_new_from_data (ctx, 1, 1,
COGL_PIXEL_FORMAT_RGB_888,
4,
pixels,
NULL));
set_texture (self, COGL_TEXTURE (texture));
}
@ -968,6 +970,8 @@ meta_background_load_file_finish (MetaBackground *self,
GAsyncResult *result,
GError **error)
{
ClutterBackend *backend = clutter_get_default_backend ();
CoglContext *ctx = clutter_backend_get_cogl_context (backend);
GTask *task;
LoadFileTaskData *task_data;
CoglTexture *texture;
@ -976,6 +980,7 @@ meta_background_load_file_finish (MetaBackground *self,
guchar *pixels;
gboolean has_alpha;
gboolean loaded = FALSE;
CoglPixelFormat pixel_format;
g_return_val_if_fail (g_task_is_valid (result, self), FALSE);
@ -994,15 +999,13 @@ meta_background_load_file_finish (MetaBackground *self,
pixels = gdk_pixbuf_get_pixels (pixbuf);
has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
texture = cogl_texture_new_from_data (width,
height,
COGL_TEXTURE_NO_ATLAS,
has_alpha ?
COGL_PIXEL_FORMAT_RGBA_8888 :
COGL_PIXEL_FORMAT_RGB_888,
COGL_PIXEL_FORMAT_ANY,
row_stride,
pixels);
pixel_format = has_alpha ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888;
texture = COGL_TEXTURE (cogl_texture_2d_new_from_data (ctx, width, height,
pixel_format,
row_stride,
pixels,
NULL));
if (texture == NULL)
{

View File

@ -704,6 +704,8 @@ static void
make_shadow (MetaShadow *shadow,
cairo_region_t *region)
{
ClutterBackend *backend = clutter_get_default_backend ();
CoglContext *ctx = clutter_backend_get_cogl_context (backend);
int d = get_box_filter_size (shadow->key.radius);
int spread = get_shadow_spread (shadow->key.radius);
cairo_rectangle_int_t extents;
@ -793,15 +795,15 @@ make_shadow (MetaShadow *shadow,
* in the case of top_fade >= 0. We also account for padding at the left for symmetry
* though that doesn't currently occur.
*/
shadow->texture = cogl_texture_new_from_data (shadow->outer_border_left + extents.width + shadow->outer_border_right,
shadow->outer_border_top + extents.height + shadow->outer_border_bottom,
COGL_TEXTURE_NONE,
COGL_PIXEL_FORMAT_A_8,
COGL_PIXEL_FORMAT_ANY,
buffer_width,
(buffer +
(y_offset - shadow->outer_border_top) * buffer_width +
(x_offset - shadow->outer_border_left)));
shadow->texture = COGL_TEXTURE (cogl_texture_2d_new_from_data (ctx,
shadow->outer_border_left + extents.width + shadow->outer_border_right,
shadow->outer_border_top + extents.height + shadow->outer_border_bottom,
COGL_PIXEL_FORMAT_A_8,
buffer_width,
(buffer +
(y_offset - shadow->outer_border_top) * buffer_width +
(x_offset - shadow->outer_border_left)),
NULL));
cairo_region_destroy (row_convolve_region);
cairo_region_destroy (column_convolve_region);

View File

@ -1657,6 +1657,8 @@ build_and_scan_frame_mask (MetaWindowActor *self,
cairo_rectangle_int_t *client_area,
cairo_region_t *shape_region)
{
ClutterBackend *backend = clutter_get_default_backend ();
CoglContext *ctx = clutter_backend_get_cogl_context (backend);
MetaWindowActorPrivate *priv = self->priv;
guchar *mask_data;
guint tex_width, tex_height;
@ -1719,10 +1721,7 @@ build_and_scan_frame_mask (MetaWindowActor *self,
if (meta_texture_rectangle_check (paint_tex))
{
ClutterBackend *backend = clutter_get_default_backend ();
CoglContext *context = clutter_backend_get_cogl_context (backend);
mask_texture = COGL_TEXTURE (cogl_texture_rectangle_new_with_size (context, tex_width, tex_height));
mask_texture = COGL_TEXTURE (cogl_texture_rectangle_new_with_size (ctx, tex_width, tex_height));
cogl_texture_set_components (mask_texture, COGL_TEXTURE_COMPONENTS_A);
cogl_texture_set_region (mask_texture,
0, 0, /* src_x/y */
@ -1734,15 +1733,9 @@ build_and_scan_frame_mask (MetaWindowActor *self,
}
else
{
/* Note: we don't allow slicing for this texture because we
* need to use it with multi-texturing which doesn't support
* sliced textures */
mask_texture = cogl_texture_new_from_data (tex_width, tex_height,
COGL_TEXTURE_NO_SLICING,
COGL_PIXEL_FORMAT_A_8,
COGL_PIXEL_FORMAT_ANY,
stride,
mask_data);
mask_texture = COGL_TEXTURE (cogl_texture_2d_new_from_data (ctx, tex_width, tex_height,
COGL_PIXEL_FORMAT_A_8,
stride, mask_data, NULL));
}
meta_shaped_texture_set_mask_texture (stex, mask_texture);