| 
									
										
										
										
											2019-11-29 11:43:40 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2017 Blender Foundation. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup depsgraph | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "intern/eval/deg_eval_runtime_backup.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "intern/eval/deg_eval_copy_on_write.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "DRW_engine.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 15:19:56 +02:00
										 |  |  | namespace blender::deg { | 
					
						
							| 
									
										
										
										
											2019-11-29 11:43:40 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | RuntimeBackup::RuntimeBackup(const Depsgraph *depsgraph) | 
					
						
							| 
									
										
										
										
											2020-03-27 23:20:55 +01:00
										 |  |  |     : have_backup(false), | 
					
						
							| 
									
										
										
										
											2020-03-23 09:55:15 +01:00
										 |  |  |       animation_backup(depsgraph), | 
					
						
							| 
									
										
										
										
											2019-11-29 15:48:32 +01:00
										 |  |  |       scene_backup(depsgraph), | 
					
						
							| 
									
										
										
										
											2019-11-29 11:43:40 +01:00
										 |  |  |       sound_backup(depsgraph), | 
					
						
							|  |  |  |       object_backup(depsgraph), | 
					
						
							| 
									
										
										
										
											2020-01-28 14:50:13 +01:00
										 |  |  |       drawdata_ptr(nullptr), | 
					
						
							| 
									
										
										
										
											2020-03-17 14:41:48 +01:00
										 |  |  |       movieclip_backup(depsgraph), | 
					
						
							|  |  |  |       volume_backup(depsgraph) | 
					
						
							| 
									
										
										
										
											2019-11-29 11:43:40 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-01-28 14:50:13 +01:00
										 |  |  |   drawdata_backup.first = drawdata_backup.last = nullptr; | 
					
						
							| 
									
										
										
										
											2019-11-29 11:43:40 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RuntimeBackup::init_from_id(ID *id) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (!deg_copy_on_write_is_expanded(id)) { | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-03-23 09:55:15 +01:00
										 |  |  |   have_backup = true; | 
					
						
							| 
									
										
										
										
											2019-11-29 11:43:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-29 15:48:32 +01:00
										 |  |  |   animation_backup.init_from_id(id); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-29 11:43:40 +01:00
										 |  |  |   const ID_Type id_type = GS(id->name); | 
					
						
							|  |  |  |   switch (id_type) { | 
					
						
							|  |  |  |     case ID_OB: | 
					
						
							|  |  |  |       object_backup.init_from_object(reinterpret_cast<Object *>(id)); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case ID_SCE: | 
					
						
							|  |  |  |       scene_backup.init_from_scene(reinterpret_cast<Scene *>(id)); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case ID_SO: | 
					
						
							|  |  |  |       sound_backup.init_from_sound(reinterpret_cast<bSound *>(id)); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case ID_MC: | 
					
						
							|  |  |  |       movieclip_backup.init_from_movieclip(reinterpret_cast<MovieClip *>(id)); | 
					
						
							|  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2020-03-17 14:41:48 +01:00
										 |  |  |     case ID_VO: | 
					
						
							|  |  |  |       volume_backup.init_from_volume(reinterpret_cast<Volume *>(id)); | 
					
						
							|  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2019-11-29 11:43:40 +01:00
										 |  |  |     default: | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Note that we never free GPU draw data from here since that's not
 | 
					
						
							|  |  |  |    * safe for threading and draw data is likely to be re-used. */ | 
					
						
							|  |  |  |   drawdata_ptr = DRW_drawdatalist_from_id(id); | 
					
						
							| 
									
										
										
										
											2020-01-28 14:50:13 +01:00
										 |  |  |   if (drawdata_ptr != nullptr) { | 
					
						
							| 
									
										
										
										
											2019-11-29 11:43:40 +01:00
										 |  |  |     drawdata_backup = *drawdata_ptr; | 
					
						
							| 
									
										
										
										
											2020-01-28 14:50:13 +01:00
										 |  |  |     drawdata_ptr->first = drawdata_ptr->last = nullptr; | 
					
						
							| 
									
										
										
										
											2019-11-29 11:43:40 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RuntimeBackup::restore_to_id(ID *id) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-03-23 09:55:15 +01:00
										 |  |  |   if (!have_backup) { | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-29 15:48:32 +01:00
										 |  |  |   animation_backup.restore_to_id(id); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-29 11:43:40 +01:00
										 |  |  |   const ID_Type id_type = GS(id->name); | 
					
						
							|  |  |  |   switch (id_type) { | 
					
						
							|  |  |  |     case ID_OB: | 
					
						
							|  |  |  |       object_backup.restore_to_object(reinterpret_cast<Object *>(id)); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case ID_SCE: | 
					
						
							|  |  |  |       scene_backup.restore_to_scene(reinterpret_cast<Scene *>(id)); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case ID_SO: | 
					
						
							|  |  |  |       sound_backup.restore_to_sound(reinterpret_cast<bSound *>(id)); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case ID_MC: | 
					
						
							|  |  |  |       movieclip_backup.restore_to_movieclip(reinterpret_cast<MovieClip *>(id)); | 
					
						
							|  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2020-03-17 14:41:48 +01:00
										 |  |  |     case ID_VO: | 
					
						
							|  |  |  |       volume_backup.restore_to_volume(reinterpret_cast<Volume *>(id)); | 
					
						
							|  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2019-11-29 11:43:40 +01:00
										 |  |  |     default: | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-01-28 14:50:13 +01:00
										 |  |  |   if (drawdata_ptr != nullptr) { | 
					
						
							| 
									
										
										
										
											2019-11-29 11:43:40 +01:00
										 |  |  |     *drawdata_ptr = drawdata_backup; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 15:19:56 +02:00
										 |  |  | }  // namespace blender::deg
 |