shaped-texture: Put actual texture painting in helper

This is so that it can be reused later by meta_shaped_texture_get_image() for
drawing via an offscreen framebuffer.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/362
This commit is contained in:
Jonas Ådahl 2018-12-19 12:52:58 +01:00 committed by Ray Strode
parent 01d147a2d7
commit 847d37b4f1

View File

@ -373,47 +373,18 @@ set_cogl_texture (MetaShapedTexture *stex,
} }
static void static void
meta_shaped_texture_paint (ClutterActor *actor) do_paint (MetaShapedTexture *stex,
CoglFramebuffer *fb,
CoglTexture *paint_tex,
cairo_region_t *clip_region)
{ {
MetaShapedTexture *stex = (MetaShapedTexture *) actor;
MetaShapedTexturePrivate *priv = stex->priv; MetaShapedTexturePrivate *priv = stex->priv;
guint tex_width, tex_height; guint tex_width, tex_height;
guchar opacity; guchar opacity;
CoglContext *ctx; CoglContext *ctx;
CoglFramebuffer *fb;
CoglTexture *paint_tex;
ClutterActorBox alloc; ClutterActorBox alloc;
CoglPipelineFilter filter; CoglPipelineFilter filter;
if (priv->clip_region && cairo_region_is_empty (priv->clip_region))
return;
if (!CLUTTER_ACTOR_IS_REALIZED (CLUTTER_ACTOR (stex)))
clutter_actor_realize (CLUTTER_ACTOR (stex));
/* The GL EXT_texture_from_pixmap extension does allow for it to be
* used together with SGIS_generate_mipmap, however this is very
* rarely supported. Also, even when it is supported there
* are distinct performance implications from:
*
* - Updating mipmaps that we don't need
* - Having to reallocate pixmaps on the server into larger buffers
*
* So, we just unconditionally use our mipmap emulation code. If we
* wanted to use SGIS_generate_mipmap, we'd have to query COGL to
* see if it was supported (no API currently), and then if and only
* if that was the case, set the clutter texture quality to HIGH.
* Setting the texture quality to high without SGIS_generate_mipmap
* support for TFP textures will result in fallbacks to XGetImage.
*/
if (priv->create_mipmaps)
paint_tex = meta_texture_tower_get_paint_texture (priv->paint_tower);
else
paint_tex = COGL_TEXTURE (priv->texture);
if (paint_tex == NULL)
return;
tex_width = priv->tex_width; tex_width = priv->tex_width;
tex_height = priv->tex_height; tex_height = priv->tex_height;
@ -422,8 +393,6 @@ meta_shaped_texture_paint (ClutterActor *actor)
cairo_rectangle_int_t tex_rect = { 0, 0, tex_width, tex_height }; cairo_rectangle_int_t tex_rect = { 0, 0, tex_width, tex_height };
fb = cogl_get_draw_framebuffer ();
/* Use nearest-pixel interpolation if the texture is unscaled. This /* Use nearest-pixel interpolation if the texture is unscaled. This
* improves performance, especially with software rendering. * improves performance, especially with software rendering.
*/ */
@ -437,8 +406,8 @@ meta_shaped_texture_paint (ClutterActor *actor)
ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ()); ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
opacity = clutter_actor_get_paint_opacity (actor); opacity = clutter_actor_get_paint_opacity (CLUTTER_ACTOR (stex));
clutter_actor_get_allocation_box (actor, &alloc); clutter_actor_get_allocation_box (CLUTTER_ACTOR (stex), &alloc);
cairo_region_t *blended_region; cairo_region_t *blended_region;
gboolean use_opaque_region = (priv->opaque_region != NULL && opacity == 255); gboolean use_opaque_region = (priv->opaque_region != NULL && opacity == 255);
@ -576,6 +545,52 @@ meta_shaped_texture_paint (ClutterActor *actor)
cairo_region_destroy (blended_region); cairo_region_destroy (blended_region);
} }
static void
meta_shaped_texture_paint (ClutterActor *actor)
{
MetaShapedTexture *stex = META_SHAPED_TEXTURE (actor);
MetaShapedTexturePrivate *priv = stex->priv;
CoglTexture *paint_tex = NULL;
CoglFramebuffer *fb;
if (!priv->texture)
return;
if (priv->clip_region && cairo_region_is_empty (priv->clip_region))
return;
if (!CLUTTER_ACTOR_IS_REALIZED (CLUTTER_ACTOR (stex)))
clutter_actor_realize (CLUTTER_ACTOR (stex));
/* The GL EXT_texture_from_pixmap extension does allow for it to be
* used together with SGIS_generate_mipmap, however this is very
* rarely supported. Also, even when it is supported there
* are distinct performance implications from:
*
* - Updating mipmaps that we don't need
* - Having to reallocate pixmaps on the server into larger buffers
*
* So, we just unconditionally use our mipmap emulation code. If we
* wanted to use SGIS_generate_mipmap, we'd have to query COGL to
* see if it was supported (no API currently), and then if and only
* if that was the case, set the clutter texture quality to HIGH.
* Setting the texture quality to high without SGIS_generate_mipmap
* support for TFP textures will result in fallbacks to XGetImage.
*/
if (priv->create_mipmaps)
paint_tex = meta_texture_tower_get_paint_texture (priv->paint_tower);
if (!paint_tex)
paint_tex = COGL_TEXTURE (priv->texture);
if (cogl_texture_get_width (paint_tex) == 0 ||
cogl_texture_get_height (paint_tex) == 0)
return;
fb = cogl_get_draw_framebuffer ();
do_paint (META_SHAPED_TEXTURE (actor), fb, paint_tex, priv->clip_region);
}
static void static void
meta_shaped_texture_get_preferred_width (ClutterActor *self, meta_shaped_texture_get_preferred_width (ClutterActor *self,
gfloat for_height, gfloat for_height,