[Bf-blender-cvs] [4df786e34e4] undo-experiments-idnames: undoexp: Move old-data-management code to memfile undo callbacks.
Bastien Montagne
noreply at git.blender.org
Thu Jan 9 11:25:57 CET 2020
Commit: 4df786e34e4f5fe70e7788a540ab06801e4c5b99
Author: Bastien Montagne
Date: Wed Jan 8 15:49:28 2020 +0100
Branches: undo-experiments-idnames
https://developer.blender.org/rB4df786e34e4f5fe70e7788a540ab06801e4c5b99
undoexp: Move old-data-management code to memfile undo callbacks.
Does not really make any sense to do that for any other kind of undo
currently, so better keep it in dedicated undotype callbacks.
===================================================================
M source/blender/blenkernel/intern/undo_system.c
M source/blender/editors/undo/memfile_undo.c
===================================================================
diff --git a/source/blender/blenkernel/intern/undo_system.c b/source/blender/blenkernel/intern/undo_system.c
index 3af7c978553..a97aa75cf54 100644
--- a/source/blender/blenkernel/intern/undo_system.c
+++ b/source/blender/blenkernel/intern/undo_system.c
@@ -26,9 +26,7 @@
#include "BLI_utildefines.h"
#include "BLI_sys_types.h"
-#include "BLI_ghash.h"
#include "BLI_listbase.h"
-#include "BLI_path_util.h"
#include "BLI_string.h"
#include "BLT_translation.h"
@@ -38,15 +36,10 @@
#include "BKE_context.h"
#include "BKE_global.h"
-#include "BKE_library.h"
#include "BKE_library_override.h"
-#include "BKE_library_query.h"
#include "BKE_main.h"
-#include "BKE_scene.h"
#include "BKE_undo_system.h"
-#include "DEG_depsgraph.h"
-
#include "MEM_guardedalloc.h"
#define undo_stack _wm_undo_stack_disallow /* pass in as a variable always. */
@@ -171,11 +164,6 @@ static bool undosys_step_encode(bContext *C, Main *bmain, UndoStack *ustack, Und
us->type->step_foreach_ID_ref(us, undosys_id_ref_store, bmain);
}
- /* Store the fact that we should not re-use old data with that undo step, and reset the Main
- * flag. */
- us->use_old_bmain_data = !bmain->use_memfile_full_barrier;
- bmain->use_memfile_full_barrier = false;
-
#ifdef WITH_GLOBAL_UNDO_CORRECT_ORDER
if (us->type == BKE_UNDOSYS_TYPE_MEMFILE) {
ustack->step_active_memfile = us;
@@ -188,25 +176,6 @@ static bool undosys_step_encode(bContext *C, Main *bmain, UndoStack *ustack, Und
return ok;
}
-static int undosys_step_id_reused_cb(void *user_data,
- ID *id_self,
- ID **id_pointer,
- int UNUSED(cb_flag))
-{
- BLI_assert((id_self->tag & LIB_TAG_UNDO_OLD_ID_REUSED) != 0);
- Main *bmain = user_data;
-
- ID *id = *id_pointer;
- if (id != NULL && id->lib == NULL && (id->tag & LIB_TAG_UNDO_OLD_ID_REUSED) == 0) {
- /* In case an old, re-used ID is using a newly read data-block (i.e. one of its ID pointers got
- * updated), we have to tell the depsgraph about it. */
- DEG_id_tag_update_ex(bmain, id_self, ID_RECALC_COPY_ON_WRITE);
- return IDWALK_RET_STOP_ITER;
- }
-
- return IDWALK_RET_NOP;
-}
-
static void undosys_step_decode(
bContext *C, Main *bmain, UndoStack *ustack, UndoStep *us, int dir, bool is_final)
{
@@ -237,35 +206,10 @@ static void undosys_step_decode(
us->type->step_foreach_ID_ref(us, undosys_id_ref_resolve, bmain);
}
- /* Extract depsgraphs from current bmain (which may be freed during undo step reading),
- * and store them for re-use. */
- GHash *depsgraphs = NULL;
- if (us->use_old_bmain_data) {
- depsgraphs = BKE_scene_undo_depsgraphs_extract(bmain);
- }
-
UNDO_NESTED_CHECK_BEGIN;
us->type->step_decode(C, bmain, us, dir, is_final);
UNDO_NESTED_CHECK_END;
- if (us->use_old_bmain_data) {
- /* Restore previous depsgraphs into current bmain. */
- bmain = G_MAIN;
- BKE_scene_undo_depsgraphs_restore(bmain, depsgraphs);
-
- /* We need to inform depsgraph about re-used old IDs that would be using newly read
- * data-blocks, at least COW evaluated copies need to be updated... */
- ID *id = NULL;
- FOREACH_MAIN_ID_BEGIN (bmain, id) {
- if (id->tag & LIB_TAG_UNDO_OLD_ID_REUSED) {
- BKE_library_foreach_ID_link(bmain, id, undosys_step_id_reused_cb, bmain, IDWALK_READONLY);
- }
- }
- FOREACH_MAIN_ID_END;
-
- BKE_main_id_tag_all(bmain, LIB_TAG_UNDO_OLD_ID_REUSED, false);
- }
-
#ifdef WITH_GLOBAL_UNDO_CORRECT_ORDER
if (us->type == BKE_UNDOSYS_TYPE_MEMFILE) {
ustack->step_active_memfile = us;
diff --git a/source/blender/editors/undo/memfile_undo.c b/source/blender/editors/undo/memfile_undo.c
index 30d8a7d5a61..ff2e304a9f4 100644
--- a/source/blender/editors/undo/memfile_undo.c
+++ b/source/blender/editors/undo/memfile_undo.c
@@ -23,12 +23,19 @@
#include "BLI_utildefines.h"
#include "BLI_sys_types.h"
+#include "BLI_ghash.h"
+
#include "DNA_object_enums.h"
#include "BKE_blender_undo.h"
#include "BKE_context.h"
-#include "BKE_undo_system.h"
+#include "BKE_library.h"
+#include "BKE_library_query.h"
#include "BKE_main.h"
+#include "BKE_scene.h"
+#include "BKE_undo_system.h"
+
+#include "../depsgraph/DEG_depsgraph.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -85,15 +92,47 @@ static bool memfile_undosys_step_encode(struct bContext *UNUSED(C),
us->data = BKE_memfile_undo_encode(bmain, us_prev ? us_prev->data : NULL);
us->step.data_size = us->data->undo_size;
+ /* Store the fact that we should not re-use old data with that undo step, and reset the Main
+ * flag. */
+ us->step.use_old_bmain_data = !bmain->use_memfile_full_barrier;
+ bmain->use_memfile_full_barrier = false;
+
return true;
}
+static int memfile_undosys_step_id_reused_cb(void *user_data,
+ ID *id_self,
+ ID **id_pointer,
+ int UNUSED(cb_flag))
+{
+ BLI_assert((id_self->tag & LIB_TAG_UNDO_OLD_ID_REUSED) != 0);
+ Main *bmain = user_data;
+
+ ID *id = *id_pointer;
+ if (id != NULL && id->lib == NULL && (id->tag & LIB_TAG_UNDO_OLD_ID_REUSED) == 0) {
+ /* In case an old, re-used ID is using a newly read data-block (i.e. one of its ID pointers got
+ * updated), we have to tell the depsgraph about it. */
+ DEG_id_tag_update_ex(bmain, id_self, ID_RECALC_COPY_ON_WRITE);
+ return IDWALK_RET_STOP_ITER;
+ }
+
+ return IDWALK_RET_NOP;
+}
+
static void memfile_undosys_step_decode(
struct bContext *C, struct Main *bmain, UndoStep *us_p, int UNUSED(dir), bool UNUSED(is_final))
{
+ MemFileUndoStep *us = (MemFileUndoStep *)us_p;
+
+ /* Extract depsgraphs from current bmain (which may be freed during undo step reading),
+ * and store them for re-use. */
+ GHash *depsgraphs = NULL;
+ if (us->step.use_old_bmain_data) {
+ depsgraphs = BKE_scene_undo_depsgraphs_extract(bmain);
+ }
+
ED_editors_exit(bmain, false);
- MemFileUndoStep *us = (MemFileUndoStep *)us_p;
BKE_memfile_undo_decode(us->data, us->step.use_old_bmain_data, C);
for (UndoStep *us_iter = us_p->next; us_iter; us_iter = us_iter->next) {
@@ -113,6 +152,24 @@ static void memfile_undosys_step_decode(
bmain = CTX_data_main(C);
ED_editors_init_for_undo(bmain);
+ if (us->step.use_old_bmain_data) {
+ /* Restore previous depsgraphs into current bmain. */
+ BKE_scene_undo_depsgraphs_restore(bmain, depsgraphs);
+
+ /* We need to inform depsgraph about re-used old IDs that would be using newly read
+ * data-blocks, at least COW evaluated copies need to be updated... */
+ ID *id = NULL;
+ FOREACH_MAIN_ID_BEGIN (bmain, id) {
+ if (id->tag & LIB_TAG_UNDO_OLD_ID_REUSED) {
+ BKE_library_foreach_ID_link(
+ bmain, id, memfile_undosys_step_id_reused_cb, bmain, IDWALK_READONLY);
+ }
+ }
+ FOREACH_MAIN_ID_END;
+
+ BKE_main_id_tag_all(bmain, LIB_TAG_UNDO_OLD_ID_REUSED, false);
+ }
+
WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, CTX_data_scene(C));
}
More information about the Bf-blender-cvs
mailing list