shaped-texture: Add API to check opaqueness

It is opaque if the texture has no alpha channel, or if the opaque
region covers the whole content.

Internally uses a function that checks whether there is an alpha
channel. This API will be exposed at a later time as well.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/734
This commit is contained in:
Jonas Ådahl 2019-08-16 18:08:30 +02:00
parent 65d8f27b6b
commit dcd0f4322a
2 changed files with 55 additions and 0 deletions

View File

@ -41,6 +41,7 @@ void meta_shaped_texture_set_fallback_size (MetaShapedTexture *stex,
int fallback_width,
int fallback_height);
cairo_region_t * meta_shaped_texture_get_opaque_region (MetaShapedTexture *stex);
gboolean meta_shaped_texture_is_opaque (MetaShapedTexture *stex);
void meta_shaped_texture_set_transform (MetaShapedTexture *stex,
MetaMonitorTransform transform);
void meta_shaped_texture_set_viewport_src_rect (MetaShapedTexture *stex,

View File

@ -1019,6 +1019,60 @@ meta_shaped_texture_get_opaque_region (MetaShapedTexture *stex)
return stex->opaque_region;
}
static gboolean
meta_shaped_texture_has_alpha (MetaShapedTexture *stex)
{
CoglTexture *texture;
texture = stex->texture;
if (!texture)
return TRUE;
switch (cogl_texture_get_components (texture))
{
case COGL_TEXTURE_COMPONENTS_A:
case COGL_TEXTURE_COMPONENTS_RGBA:
return TRUE;
case COGL_TEXTURE_COMPONENTS_RG:
case COGL_TEXTURE_COMPONENTS_RGB:
case COGL_TEXTURE_COMPONENTS_DEPTH:
return FALSE;
}
g_warn_if_reached ();
return FALSE;
}
gboolean
meta_shaped_texture_is_opaque (MetaShapedTexture *stex)
{
CoglTexture *texture;
cairo_rectangle_int_t opaque_rect;
texture = stex->texture;
if (!texture)
return FALSE;
if (!meta_shaped_texture_has_alpha (stex))
return TRUE;
if (!stex->opaque_region)
return FALSE;
if (cairo_region_num_rectangles (stex->opaque_region) != 1)
return FALSE;
cairo_region_get_extents (stex->opaque_region, &opaque_rect);
ensure_size_valid (stex);
return meta_rectangle_equal (&opaque_rect,
&(MetaRectangle) {
.width = stex->dst_width,
.height = stex->dst_height
});
}
void
meta_shaped_texture_set_transform (MetaShapedTexture *stex,
MetaMonitorTransform transform)