Blender  V3.3
deg_eval_runtime_backup.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2017 Blender Foundation. All rights reserved. */
3 
9 
11 
12 #include "BLI_utildefines.h"
13 
14 #include "DRW_engine.h"
15 
16 namespace blender::deg {
17 
19  : have_backup(false),
20  id_data({nullptr}),
21  animation_backup(depsgraph),
22  scene_backup(depsgraph),
23  sound_backup(depsgraph),
24  object_backup(depsgraph),
25  drawdata_ptr(nullptr),
26  movieclip_backup(depsgraph),
27  volume_backup(depsgraph),
28  gpencil_backup(depsgraph)
29 {
30  drawdata_backup.first = drawdata_backup.last = nullptr;
31 }
32 
34 {
36  return;
37  }
38  have_backup = true;
39 
40  /* Clear, so freeing the expanded data doesn't touch this Python reference. */
41  id_data.py_instance = id->py_instance;
42  id->py_instance = nullptr;
43 
45 
46  const ID_Type id_type = GS(id->name);
47  switch (id_type) {
48  case ID_OB:
49  object_backup.init_from_object(reinterpret_cast<Object *>(id));
50  break;
51  case ID_SCE:
52  scene_backup.init_from_scene(reinterpret_cast<Scene *>(id));
53  break;
54  case ID_SO:
55  sound_backup.init_from_sound(reinterpret_cast<bSound *>(id));
56  break;
57  case ID_MC:
58  movieclip_backup.init_from_movieclip(reinterpret_cast<MovieClip *>(id));
59  break;
60  case ID_VO:
61  volume_backup.init_from_volume(reinterpret_cast<Volume *>(id));
62  break;
63  case ID_GD:
64  gpencil_backup.init_from_gpencil(reinterpret_cast<bGPdata *>(id));
65  default:
66  break;
67  }
68 
69  /* Note that we never free GPU draw data from here since that's not
70  * safe for threading and draw data is likely to be re-used. */
72  if (drawdata_ptr != nullptr) {
74  drawdata_ptr->first = drawdata_ptr->last = nullptr;
75  }
76 }
77 
79 {
80  if (!have_backup) {
81  return;
82  }
83 
84  id->py_instance = id_data.py_instance;
85 
87 
88  const ID_Type id_type = GS(id->name);
89  switch (id_type) {
90  case ID_OB:
91  object_backup.restore_to_object(reinterpret_cast<Object *>(id));
92  break;
93  case ID_SCE:
94  scene_backup.restore_to_scene(reinterpret_cast<Scene *>(id));
95  break;
96  case ID_SO:
97  sound_backup.restore_to_sound(reinterpret_cast<bSound *>(id));
98  break;
99  case ID_MC:
100  movieclip_backup.restore_to_movieclip(reinterpret_cast<MovieClip *>(id));
101  break;
102  case ID_VO:
103  volume_backup.restore_to_volume(reinterpret_cast<Volume *>(id));
104  break;
105  case ID_GD:
106  gpencil_backup.restore_to_gpencil(reinterpret_cast<bGPdata *>(id));
107  default:
108  break;
109  }
110  if (drawdata_ptr != nullptr) {
112  }
113 }
114 
115 } // namespace blender::deg
ID_Type
Definition: DNA_ID_enums.h:44
@ ID_MC
Definition: DNA_ID_enums.h:73
@ ID_VO
Definition: DNA_ID_enums.h:83
@ ID_SO
Definition: DNA_ID_enums.h:64
@ ID_SCE
Definition: DNA_ID_enums.h:45
@ ID_GD
Definition: DNA_ID_enums.h:71
@ ID_OB
Definition: DNA_ID_enums.h:47
struct DrawDataList * DRW_drawdatalist_from_id(struct ID *id)
Definition: draw_manager.c:836
struct blender::deg::RuntimeBackup::@192 id_data
RuntimeBackup(const Depsgraph *depsgraph)
const Depsgraph * depsgraph
#define GS(x)
Definition: iris.c:225
bool deg_copy_on_write_is_expanded(const ID *id_cow)
struct DrawData * first
Definition: DNA_ID.h:44
struct DrawData * last
Definition: DNA_ID.h:44
Definition: DNA_ID.h:368
char name[66]
Definition: DNA_ID.h:378