clutter: Pass 'radius' to public blur APIs instead of 'sigma'

Although they're in the same units, `radius` is easier to understand than
`sigma` and makes the public API independent of the blur algorithm used
behind the scenes. We now only keep the `sigma` terminology where the
implementation is Gaussian-specific.

The assumption that `sigma = radius / 2.0` is actually not new here. We
just move it from `_st_create_shadow_pipeline` (gnome-shell!1905) into
`clutter_blur_new`.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1908>
This commit is contained in:
Daniel van Vugt 2021-07-01 15:49:09 +08:00 committed by Marge Bot
parent a191af1f3d
commit 85f173d0d7
4 changed files with 15 additions and 13 deletions

View File

@ -26,7 +26,7 @@ G_BEGIN_DECLS
typedef struct _ClutterBlur ClutterBlur;
ClutterBlur * clutter_blur_new (CoglTexture *texture,
float sigma);
float radius);
void clutter_blur_apply (ClutterBlur *blur);

View File

@ -342,7 +342,7 @@ clear_blur_pass (BlurPass *pass)
*/
ClutterBlur *
clutter_blur_new (CoglTexture *texture,
float sigma)
float radius)
{
ClutterBlur *blur;
unsigned int height;
@ -351,17 +351,19 @@ clutter_blur_new (CoglTexture *texture,
BlurPass *vpass;
g_return_val_if_fail (texture != NULL, NULL);
g_return_val_if_fail (sigma >= 0.0, NULL);
g_return_val_if_fail (radius >= 0.0, NULL);
width = cogl_texture_get_width (texture);
height = cogl_texture_get_height (texture);
blur = g_new0 (ClutterBlur, 1);
blur->sigma = sigma;
blur->sigma = radius / 2.0;
blur->source_texture = g_object_ref (texture);
blur->downscale_factor = calculate_downscale_factor (width, height, sigma);
blur->downscale_factor = calculate_downscale_factor (width,
height,
blur->sigma);
if (G_APPROX_VALUE (sigma, 0.0, FLT_EPSILON))
if (G_APPROX_VALUE (blur->sigma, 0.0, FLT_EPSILON))
goto out;
vpass = &blur->pass[VERTICAL];

View File

@ -1492,7 +1492,7 @@ struct _ClutterBlurNode
ClutterLayerNode parent_instance;
ClutterBlur *blur;
unsigned int sigma;
unsigned int radius;
};
G_DEFINE_TYPE (ClutterBlurNode, clutter_blur_node, CLUTTER_TYPE_LAYER_NODE)
@ -1539,7 +1539,7 @@ clutter_blur_node_init (ClutterBlurNode *blur_node)
* clutter_blur_node_new:
* @width width of the blur layer
* @height: height of the blur layer
* @sigma: sigma value of the blur
* @radius: radius (in pixels) of the blur
*
* Creates a new #ClutterBlurNode.
*
@ -1552,7 +1552,7 @@ clutter_blur_node_init (ClutterBlurNode *blur_node)
ClutterPaintNode *
clutter_blur_node_new (unsigned int width,
unsigned int height,
float sigma)
float radius)
{
g_autoptr (CoglOffscreen) offscreen = NULL;
g_autoptr (GError) error = NULL;
@ -1562,10 +1562,10 @@ clutter_blur_node_new (unsigned int width,
CoglTexture *texture;
ClutterBlur *blur;
g_return_val_if_fail (sigma >= 0.0, NULL);
g_return_val_if_fail (radius >= 0.0, NULL);
blur_node = _clutter_paint_node_create (CLUTTER_TYPE_BLUR_NODE);
blur_node->sigma = sigma;
blur_node->radius = radius;
context = clutter_backend_get_cogl_context (clutter_get_default_backend ());
texture = cogl_texture_2d_new_with_size (context, width, height);
@ -1580,7 +1580,7 @@ clutter_blur_node_new (unsigned int width,
goto out;
}
blur = clutter_blur_new (texture, sigma);
blur = clutter_blur_new (texture, radius);
blur_node->blur = blur;
if (!blur)

View File

@ -194,6 +194,6 @@ GType clutter_blur_node_get_type (void) G_GNUC_CONST;
CLUTTER_EXPORT
ClutterPaintNode * clutter_blur_node_new (unsigned int width,
unsigned int height,
float sigma);
float radius);
G_END_DECLS