Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <jeroen@blender.org>2021-11-17 14:25:10 +0300
committerJeroen Bakker <jeroen@blender.org>2021-11-17 14:30:42 +0300
commite5f05bc7a61dbf1522f5c400c182bae7af413998 (patch)
tree5f01398dc08e479afca3bd29e41752426916ed2d /source/blender
parentf5dde382af8078a2e5265e7d6710df7cb1b320a0 (diff)
Cleanup: Painting - reduce reallocation of same memory.
Curve mask is freed/allocated every time, but could still reuse the previous allocated buffer when the diameter of the brush doesn't change.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/editors/sculpt_paint/paint_image_2d.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c b/source/blender/editors/sculpt_paint/paint_image_2d.c
index 63f61b6c5c1..318180e5eb4 100644
--- a/source/blender/editors/sculpt_paint/paint_image_2d.c
+++ b/source/blender/editors/sculpt_paint/paint_image_2d.c
@@ -381,18 +381,17 @@ static void brush_painter_mask_imbuf_partial_update(BrushPainter *painter,
}
/* create a mask with the falloff strength */
-static ushort *brush_painter_curve_mask_new(BrushPainter *painter,
- int diameter,
- float radius,
- const float pos[2])
+static ushort *brush_painter_curve_mask_init(
+ ushort *mask, BrushPainter *painter, int diameter, float radius, const float pos[2])
{
+ BLI_assert_msg(MEM_allocN_len(mask) == diameter * diameter * sizeof(ushort),
+ "Allocated size of mask doesn't match.");
+
Brush *brush = painter->brush;
int offset = (int)floorf(diameter / 2.0f);
- ushort *mask, *m;
-
- mask = MEM_mallocN(sizeof(ushort) * diameter * diameter, "brush_painter_mask");
+ ushort *m;
m = mask;
int aa_samples = 1.0f / (radius * 0.20f);
@@ -453,6 +452,20 @@ static ushort *brush_painter_curve_mask_new(BrushPainter *painter,
return mask;
}
+static void brush_painter_curve_mask_refresh(
+ BrushPainter *painter, ImagePaintTile *tile, int diameter, float radius, const float pos[2])
+{
+ BrushPainterCache *cache = &tile->cache;
+
+ if (diameter != cache->lastdiameter) {
+ if (cache->curve_mask != NULL) {
+ MEM_freeN(cache->curve_mask);
+ }
+ cache->curve_mask = MEM_mallocN(sizeof(ushort) * diameter * diameter, "brush_painter_mask");
+ }
+ brush_painter_curve_mask_init(cache->curve_mask, painter, diameter, radius, pos);
+}
+
/* create imbuf with brush color */
static ImBuf *brush_painter_imbuf_new(
BrushPainter *painter, ImagePaintTile *tile, const int size, float pressure, float distance)
@@ -858,10 +871,8 @@ static void brush_painter_2d_refresh_cache(ImagePaintState *s,
}
}
- /* curve mask can only change if the size changes */
- MEM_SAFE_FREE(cache->curve_mask);
-
- cache->curve_mask = brush_painter_curve_mask_new(painter, diameter, size, pos);
+ /* Re-initialize the curve mask. Mask is always recreated due to the change of position. */
+ brush_painter_curve_mask_refresh(painter, tile, diameter, size, pos);
/* detect if we need to recreate image brush buffer */
if (diameter != cache->lastdiameter || (tex_rotation != cache->last_tex_rotation) || do_random ||