From 0b4b341e6c8978c1ed1f86a12c2b5fa1bd19b942 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Thu, 17 Dec 2020 01:30:47 -0300 Subject: [PATCH] clutter/blur: Make sigma a float The shader already operates on floating point sigma, and there's just no reason for us to force it to be an unsigned integer. It's still important that sigma must be positive though. Make sigma a float, and make sure it's a positive number. Part-of: --- clutter/clutter/clutter-blur-private.h | 4 ++-- clutter/clutter/clutter-blur.c | 15 +++++++++------ clutter/clutter/clutter-paint-nodes.c | 4 +++- clutter/clutter/clutter-paint-nodes.h | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/clutter/clutter/clutter-blur-private.h b/clutter/clutter/clutter-blur-private.h index feb288f31..cf7cfd2f5 100644 --- a/clutter/clutter/clutter-blur-private.h +++ b/clutter/clutter/clutter-blur-private.h @@ -26,8 +26,8 @@ G_BEGIN_DECLS typedef struct _ClutterBlur ClutterBlur; -ClutterBlur * clutter_blur_new (CoglTexture *texture, - unsigned int sigma); +ClutterBlur * clutter_blur_new (CoglTexture *texture, + float sigma); void clutter_blur_apply (ClutterBlur *blur); diff --git a/clutter/clutter/clutter-blur.c b/clutter/clutter/clutter-blur.c index c60451d0a..9a8153e8f 100644 --- a/clutter/clutter/clutter-blur.c +++ b/clutter/clutter/clutter-blur.c @@ -125,7 +125,7 @@ typedef struct struct _ClutterBlur { CoglTexture *source_texture; - unsigned int sigma; + float sigma; float downscale_factor; BlurPass pass[2]; @@ -341,8 +341,8 @@ clear_blur_pass (BlurPass *pass) * Returns: (transfer full) (nullable): A newly created #ClutterBlur */ ClutterBlur * -clutter_blur_new (CoglTexture *texture, - unsigned int sigma) +clutter_blur_new (CoglTexture *texture, + float sigma) { ClutterBlur *blur; unsigned int height; @@ -350,6 +350,9 @@ clutter_blur_new (CoglTexture *texture, BlurPass *hpass; BlurPass *vpass; + g_return_val_if_fail (texture != NULL, NULL); + g_return_val_if_fail (sigma >= 0.0, NULL); + width = cogl_texture_get_width (texture); height = cogl_texture_get_height (texture); @@ -358,7 +361,7 @@ clutter_blur_new (CoglTexture *texture, blur->source_texture = cogl_object_ref (texture); blur->downscale_factor = calculate_downscale_factor (width, height, sigma); - if (sigma == 0) + if (G_APPROX_VALUE (sigma, 0.0, FLT_EPSILON)) goto out; vpass = &blur->pass[VERTICAL]; @@ -385,7 +388,7 @@ out: void clutter_blur_apply (ClutterBlur *blur) { - if (blur->sigma == 0) + if (G_APPROX_VALUE (blur->sigma, 0.0, FLT_EPSILON)) return; apply_blur_pass (&blur->pass[VERTICAL]); @@ -404,7 +407,7 @@ clutter_blur_apply (ClutterBlur *blur) CoglTexture * clutter_blur_get_texture (ClutterBlur *blur) { - if (blur->sigma == 0) + if (G_APPROX_VALUE (blur->sigma, 0.0, FLT_EPSILON)) return blur->source_texture; else return blur->pass[HORIZONTAL].texture; diff --git a/clutter/clutter/clutter-paint-nodes.c b/clutter/clutter/clutter-paint-nodes.c index 9da5b450f..3fb7d384a 100644 --- a/clutter/clutter/clutter-paint-nodes.c +++ b/clutter/clutter/clutter-paint-nodes.c @@ -1915,7 +1915,7 @@ clutter_blur_node_init (ClutterBlurNode *blur_node) ClutterPaintNode * clutter_blur_node_new (unsigned int width, unsigned int height, - unsigned int sigma) + float sigma) { g_autoptr (CoglOffscreen) offscreen = NULL; g_autoptr (GError) error = NULL; @@ -1926,6 +1926,8 @@ clutter_blur_node_new (unsigned int width, CoglTexture *texture; ClutterBlur *blur; + g_return_val_if_fail (sigma >= 0.0, NULL); + blur_node = _clutter_paint_node_create (CLUTTER_TYPE_BLUR_NODE); blur_node->sigma = sigma; context = clutter_backend_get_cogl_context (clutter_get_default_backend ()); diff --git a/clutter/clutter/clutter-paint-nodes.h b/clutter/clutter/clutter-paint-nodes.h index 8c01dd7d2..7f0d12857 100644 --- a/clutter/clutter/clutter-paint-nodes.h +++ b/clutter/clutter/clutter-paint-nodes.h @@ -282,7 +282,7 @@ GType clutter_blur_node_get_type (void) G_GNUC_CONST; CLUTTER_EXPORT ClutterPaintNode * clutter_blur_node_new (unsigned int width, unsigned int height, - unsigned int sigma); + float sigma); G_END_DECLS