[Bf-blender-cvs] [7b3b452f82d] greasepencil-object: Add optimization to skip decoding uneccessary steps
Falk David
noreply at git.blender.org
Mon Feb 7 18:35:15 CET 2022
Commit: 7b3b452f82d912374648447a821acce43ad0b114
Author: Falk David
Date: Fri Feb 4 15:41:43 2022 +0100
Branches: greasepencil-object
https://developer.blender.org/rB7b3b452f82d912374648447a821acce43ad0b114
Add optimization to skip decoding uneccessary steps
Co-authored-by: @yann-lty
===================================================================
M source/blender/editors/gpencil/gpencil_undo.c
===================================================================
diff --git a/source/blender/editors/gpencil/gpencil_undo.c b/source/blender/editors/gpencil/gpencil_undo.c
index 9427e3111f3..ff8d1a16a05 100644
--- a/source/blender/editors/gpencil/gpencil_undo.c
+++ b/source/blender/editors/gpencil/gpencil_undo.c
@@ -487,6 +487,31 @@ static bool gpencil_undosys_step_encode(struct bContext *C,
return true;
}
+static bool step_is_skippable(GPencilUndoData *data_current,
+ GPencilUndoData *data_next,
+ bool is_taget_step)
+{
+ /* If the step is e.g. a frame change, there is no cache, so we can safely skip it. */
+ if (data_current->gpd_cache == NULL) {
+ return true;
+ }
+
+ /* We must always decode the target step. */
+ if (is_taget_step) {
+ return false;
+ }
+
+ /* If decoding the changes of the current step will be overwritten by the next one, then we can
+ * skip it. */
+ if (data_next->gpd_cache != NULL &&
+ !BKE_gpencil_compare_update_caches(data_next->gpd_cache, data_current->gpd_cache)) {
+ return true;
+ }
+
+ /* Otherwise decode the step as usual. */
+ return false;
+}
+
static void gpencil_undosys_step_decode(struct bContext *C,
struct Main *UNUSED(bmain),
UndoStep *us_p,
@@ -566,8 +591,9 @@ static void gpencil_undosys_step_decode(struct bContext *C,
/* Once we find a good undo step, we need to go Back to the Future, so re-apply all the steps
* until we reach the target step. */
while (us_iter != us_next) {
- /* We skip over undo steps that don't store a cache (e.g. a frame change). */
- if (data_iter->gpd_cache != NULL) {
+ data_next = ((GPencilUndoStep *)us_iter->next)->undo_data;
+ /* Check if we can skip this step. If we can't we need to decode it. */
+ if (!step_is_skippable(data_iter, data_next, us_iter->next == us_next)) {
decode_undo_data_to_gpencil_data(data_iter, gpd, true);
}
us_iter = us_iter->next;
More information about the Bf-blender-cvs
mailing list