Depsgraph: remove EvaluationContext, pass Depsgraph instead.
[blender.git] / source / blender / windowmanager / intern / wm_files.c
index e673b1d386b693dbdf7147e04388f66174f0c01f..9dcb83244ca86612804c6bb68f21e6c13252efb9 100644 (file)
 #include "BKE_sound.h"
 #include "BKE_scene.h"
 #include "BKE_screen.h"
+#include "BKE_undo_system.h"
 #include "BKE_workspace.h"
 
 #include "BLO_readfile.h"
 #include "BLO_writefile.h"
+#include "BLO_undofile.h"  /* to save from an undo memfile */
 
 #include "RNA_access.h"
 #include "RNA_define.h"
 #include "ED_screen.h"
 #include "ED_view3d.h"
 #include "ED_util.h"
+#include "ED_undo.h"
 
 #include "GHOST_C-api.h"
 #include "GHOST_Path-api.h"
@@ -534,9 +537,13 @@ static void wm_file_read_post(bContext *C, const bool is_startup_file, const boo
        }
 
        if (!G.background) {
-//             undo_editmode_clear();
-               BKE_undo_reset();
-               BKE_undo_write(C, "original");  /* save current state */
+               if (wm->undo_stack == NULL) {
+                       wm->undo_stack = BKE_undosys_stack_create();
+               }
+               else {
+                       BKE_undosys_stack_clear(wm->undo_stack);
+               }
+               BKE_undosys_stack_init_from_main(wm->undo_stack, CTX_data_main(C));
        }
 }
 
@@ -1018,10 +1025,6 @@ static ImBuf *blend_file_thumb(const bContext *C, Scene *scene, ViewLayer *view_
        ARegion *ar = NULL;
        View3D *v3d = NULL;
 
-       EvaluationContext eval_ctx;
-
-       CTX_data_eval_ctx(C, &eval_ctx);
-
        /* In case we are given a valid thumbnail data, just generate image from it. */
        if (*thumb_pt) {
                thumb = *thumb_pt;
@@ -1045,16 +1048,19 @@ static ImBuf *blend_file_thumb(const bContext *C, Scene *scene, ViewLayer *view_
        }
 
        /* gets scaled to BLEN_THUMB_SIZE */
+       Depsgraph *depsgraph = CTX_data_depsgraph(C);
+       RenderEngineType *engine_type = CTX_data_engine_type(C);
+
        if (scene->camera) {
                ibuf = ED_view3d_draw_offscreen_imbuf_simple(
-                       &eval_ctx, scene, view_layer, scene->camera,
+                       depsgraph, scene, view_layer, engine_type, scene->camera,
                        BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2,
                        IB_rect, V3D_OFSDRAW_NONE, OB_SOLID, R_ALPHAPREMUL, 0, NULL,
                        NULL, err_out);
        }
        else {
                ibuf = ED_view3d_draw_offscreen_imbuf(
-                       &eval_ctx, scene, view_layer, v3d, ar,
+                       depsgraph, scene, view_layer, engine_type, v3d, ar,
                        BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2,
                        IB_rect, V3D_OFSDRAW_NONE, R_ALPHAPREMUL, 0, NULL,
                        NULL, err_out);
@@ -1287,7 +1293,10 @@ void wm_autosave_timer(const bContext *C, wmWindowManager *wm, wmTimer *UNUSED(w
 
        if (U.uiflag & USER_GLOBALUNDO) {
                /* fast save of last undobuffer, now with UI */
-               BKE_undo_save_file(filepath);
+               struct MemFile *memfile = ED_undosys_stack_memfile_get_active(wm->undo_stack);
+               if (memfile) {
+                       BLO_memfile_write_file(memfile, filepath);
+               }
        }
        else {
                /*  save as regular blend file */