From e2f0b4a0cbe5934dbd591caa53f9259eee431cee Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Tue, 7 Dec 2021 10:14:27 +0100 Subject: Cleanup: Use rcti marking dirty regions when texture painting. Dirty regions when painting are not using rcti. Meaning less understandable code. Found issue when refactoring the image_gpu partial update. In a future change gpu partial update API will be using rcti also what makes the code even cleaner. Reviewed By: campbellbarton Differential Revision: https://developer.blender.org/D13260 --- source/blender/blenlib/BLI_rect.h | 1 + source/blender/blenlib/intern/rct.c | 9 +++++ source/blender/editors/sculpt_paint/paint_image.c | 42 ++++++++++------------ .../editors/sculpt_paint/paint_image_proj.c | 32 ++++++----------- source/blender/editors/sculpt_paint/paint_intern.h | 7 ++-- 5 files changed, 42 insertions(+), 49 deletions(-) (limited to 'source') diff --git a/source/blender/blenlib/BLI_rect.h b/source/blender/blenlib/BLI_rect.h index ca06a3e3545..7950596933c 100644 --- a/source/blender/blenlib/BLI_rect.h +++ b/source/blender/blenlib/BLI_rect.h @@ -48,6 +48,7 @@ void BLI_rcti_init_minmax(struct rcti *rect); void BLI_rctf_init_minmax(struct rctf *rect); void BLI_rcti_do_minmax_v(struct rcti *rect, const int xy[2]); void BLI_rctf_do_minmax_v(struct rctf *rect, const float xy[2]); +void BLI_rcti_do_minmax_rcti(struct rcti *rect, const struct rcti *other); void BLI_rctf_transform_pt_v(const rctf *dst, const rctf *src, diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c index b73c5865e1a..6bbe655b1cd 100644 --- a/source/blender/blenlib/intern/rct.c +++ b/source/blender/blenlib/intern/rct.c @@ -30,6 +30,7 @@ #include #include +#include "BLI_math_base.h" #include "BLI_rect.h" #include "BLI_utildefines.h" @@ -541,6 +542,14 @@ void BLI_rcti_do_minmax_v(rcti *rect, const int xy[2]) } } +void BLI_rcti_do_minmax_rcti(rcti *rect, const rcti *other) +{ + rect->xmin = min_ii(rect->xmin, other->xmin); + rect->xmax = max_ii(rect->xmax, other->xmax); + rect->ymin = min_ii(rect->ymin, other->ymin); + rect->ymax = max_ii(rect->ymax, other->ymax); +} + void BLI_rctf_do_minmax_v(rctf *rect, const float xy[2]) { if (xy[0] < rect->xmin) { diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 6ba5c43f698..ab868df770d 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -87,7 +87,7 @@ * Maybe it should be exposed as part of the paint operation, * but for now just give a public interface. */ -static ImagePaintPartialRedraw imapaintpartial = {0, 0, 0, 0, 0}; +static ImagePaintPartialRedraw imapaintpartial = {{0}}; ImagePaintPartialRedraw *get_imapaintpartial(void) { @@ -103,7 +103,7 @@ void set_imapaintpartial(struct ImagePaintPartialRedraw *ippr) void ED_imapaint_clear_partial_redraw(void) { - memset(&imapaintpartial, 0, sizeof(imapaintpartial)); + BLI_rcti_init_minmax(&imapaintpartial.dirty_region); } void imapaint_region_tiles( @@ -132,19 +132,9 @@ void ED_imapaint_dirty_region( return; } - if (!imapaintpartial.enabled) { - imapaintpartial.x1 = x; - imapaintpartial.y1 = y; - imapaintpartial.x2 = x + w; - imapaintpartial.y2 = y + h; - imapaintpartial.enabled = 1; - } - else { - imapaintpartial.x1 = min_ii(imapaintpartial.x1, x); - imapaintpartial.y1 = min_ii(imapaintpartial.y1, y); - imapaintpartial.x2 = max_ii(imapaintpartial.x2, x + w); - imapaintpartial.y2 = max_ii(imapaintpartial.y2, y + h); - } + rcti rect_to_merge; + BLI_rcti_init(&rect_to_merge, x, x + w, y, y + h); + BLI_rcti_do_minmax_rcti(&imapaintpartial.dirty_region, &rect_to_merge); imapaint_region_tiles(ibuf, x, y, w, h, &tilex, &tiley, &tilew, &tileh); @@ -167,23 +157,27 @@ void ED_imapaint_dirty_region( void imapaint_image_update( SpaceImage *sima, Image *image, ImBuf *ibuf, ImageUser *iuser, short texpaint) { - if (imapaintpartial.x1 != imapaintpartial.x2 && imapaintpartial.y1 != imapaintpartial.y2) { - IMB_partial_display_buffer_update_delayed( - ibuf, imapaintpartial.x1, imapaintpartial.y1, imapaintpartial.x2, imapaintpartial.y2); + if (BLI_rcti_is_empty(&imapaintpartial.dirty_region)) { + return; } if (ibuf->mipmap[0]) { ibuf->userflags |= IB_MIPMAP_INVALID; } + IMB_partial_display_buffer_update_delayed(ibuf, + imapaintpartial.dirty_region.xmin, + imapaintpartial.dirty_region.ymin, + imapaintpartial.dirty_region.xmax, + imapaintpartial.dirty_region.ymax); + /* TODO: should set_tpage create ->rect? */ if (texpaint || (sima && sima->lock)) { - int w = imapaintpartial.x2 - imapaintpartial.x1; - int h = imapaintpartial.y2 - imapaintpartial.y1; - if (w && h) { - /* Testing with partial update in uv editor too */ - BKE_image_update_gputexture(image, iuser, imapaintpartial.x1, imapaintpartial.y1, w, h); - } + const int w = BLI_rcti_size_x(&imapaintpartial.dirty_region); + const int h = BLI_rcti_size_y(&imapaintpartial.dirty_region); + /* Testing with partial update in uv editor too */ + BKE_image_update_gputexture( + image, iuser, imapaintpartial.dirty_region.xmin, imapaintpartial.dirty_region.ymin, w, h); } } diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index 33166988f7d..3e5d8e812d2 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -4649,13 +4649,7 @@ static void project_paint_end(ProjPaintState *ps) /* 1 = an undo, -1 is a redo. */ static void partial_redraw_single_init(ImagePaintPartialRedraw *pr) { - pr->x1 = INT_MAX; - pr->y1 = INT_MAX; - - pr->x2 = -1; - pr->y2 = -1; - - pr->enabled = 1; + BLI_rcti_init_minmax(&pr->dirty_region); } static void partial_redraw_array_init(ImagePaintPartialRedraw *pr) @@ -4671,16 +4665,11 @@ static bool partial_redraw_array_merge(ImagePaintPartialRedraw *pr, ImagePaintPartialRedraw *pr_other, int tot) { - bool touch = 0; + bool touch = false; while (tot--) { - pr->x1 = min_ii(pr->x1, pr_other->x1); - pr->y1 = min_ii(pr->y1, pr_other->y1); - - pr->x2 = max_ii(pr->x2, pr_other->x2); - pr->y2 = max_ii(pr->y2, pr_other->y2); - - if (pr->x2 != -1) { - touch = 1; + BLI_rcti_do_minmax_rcti(&pr->dirty_region, &pr_other->dirty_region); + if (!BLI_rcti_is_empty(&pr->dirty_region)) { + touch = true; } pr++; @@ -4703,7 +4692,7 @@ static bool project_image_refresh_tagged(ProjPaintState *ps) /* look over each bound cell */ for (i = 0; i < PROJ_BOUNDBOX_SQUARED; i++) { pr = &(projIma->partRedrawRect[i]); - if (pr->x2 != -1) { /* TODO: use 'enabled' ? */ + if (BLI_rcti_is_valid(&pr->dirty_region)) { set_imapaintpartial(pr); imapaint_image_update(NULL, projIma->ima, projIma->ibuf, &projIma->iuser, true); redraw = 1; @@ -5117,11 +5106,10 @@ static void do_projectpaint_mask_f(ProjPaintState *ps, ProjPixel *projPixel, flo static void image_paint_partial_redraw_expand(ImagePaintPartialRedraw *cell, const ProjPixel *projPixel) { - cell->x1 = min_ii(cell->x1, (int)projPixel->x_px); - cell->y1 = min_ii(cell->y1, (int)projPixel->y_px); - - cell->x2 = max_ii(cell->x2, (int)projPixel->x_px + 1); - cell->y2 = max_ii(cell->y2, (int)projPixel->y_px + 1); + rcti rect_to_add; + BLI_rcti_init( + &rect_to_add, projPixel->x_px, projPixel->x_px + 1, projPixel->y_px, projPixel->y_px + 1); + BLI_rcti_do_minmax_rcti(&cell->dirty_region, &rect_to_add); } static void copy_original_alpha_channel(ProjPixel *pixel, bool is_floatbuf) diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index 30314742958..d1bcf87e871 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -24,6 +24,9 @@ #pragma once #include "BKE_paint.h" + +#include "BLI_rect.h" + #include "DNA_scene_types.h" #ifdef __cplusplus @@ -45,7 +48,6 @@ struct Scene; struct VPaint; struct ViewContext; struct bContext; -struct rcti; struct wmEvent; struct wmKeyConfig; struct wmOperator; @@ -180,8 +182,7 @@ void ED_vpaint_proj_handle_free(struct VertProjHandle *vp_handle); /* paint_image.c */ typedef struct ImagePaintPartialRedraw { - int x1, y1, x2, y2; /* XXX, could use 'rcti' */ - int enabled; + rcti dirty_region; } ImagePaintPartialRedraw; bool image_texture_paint_poll(struct bContext *C); -- cgit v1.2.3