Blender  V2.93
deg_builder_cache.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2018 Blender Foundation.
17  * All rights reserved.
18  */
19 
25 
26 #include "MEM_guardedalloc.h"
27 
28 #include "DNA_anim_types.h"
29 
30 #include "BLI_utildefines.h"
31 
32 #include "BKE_animsys.h"
33 
34 namespace blender::deg {
35 
36 /* Animated property storage. */
37 
38 AnimatedPropertyID::AnimatedPropertyID() : data(nullptr), property_rna(nullptr)
39 {
40 }
41 
43  const PropertyRNA *property_rna)
44  : AnimatedPropertyID(*pointer_rna, property_rna)
45 {
46 }
47 
49  const PropertyRNA *property_rna)
50  : data(pointer_rna.data), property_rna(property_rna)
51 {
52 }
53 
54 AnimatedPropertyID::AnimatedPropertyID(ID *id, StructRNA *type, const char *property_name)
55  : data(id)
56 {
58 }
59 
61  StructRNA *type,
62  void *data,
63  const char *property_name)
64  : data(data)
65 {
67 }
68 
70 {
71  return a.data == b.data && a.property_rna == b.property_rna;
72 }
73 
75 {
76  uintptr_t ptr1 = (uintptr_t)data;
78  return static_cast<uint64_t>(((ptr1 >> 4) * 33) ^ (ptr2 >> 4));
79 }
80 
81 namespace {
82 
83 struct AnimatedPropertyCallbackData {
85  AnimatedPropertyStorage *animated_property_storage;
86  DepsgraphBuilderCache *builder_cache;
87 };
88 
89 void animated_property_cb(ID * /*id*/, FCurve *fcurve, void *data_v)
90 {
91  if (fcurve->rna_path == nullptr || fcurve->rna_path[0] == '\0') {
92  return;
93  }
94  AnimatedPropertyCallbackData *data = static_cast<AnimatedPropertyCallbackData *>(data_v);
95  /* Resolve property. */
97  PropertyRNA *property_rna = nullptr;
99  &data->pointer_rna, fcurve->rna_path, &pointer_rna, &property_rna)) {
100  return;
101  }
102  /* Get storage for the ID.
103  * This is needed to deal with cases when nested datablock is animated by its parent. */
104  AnimatedPropertyStorage *animated_property_storage = data->animated_property_storage;
105  if (pointer_rna.owner_id != data->pointer_rna.owner_id) {
106  animated_property_storage = data->builder_cache->ensureAnimatedPropertyStorage(
108  }
109  /* Set the property as animated. */
111 }
112 
113 } // namespace
114 
116 {
117 }
118 
120 {
121  AnimatedPropertyCallbackData data;
122  RNA_id_pointer_create(id, &data.pointer_rna);
123  data.animated_property_storage = this;
124  data.builder_cache = builder_cache;
125  BKE_fcurves_id_cb(id, animated_property_cb, &data);
126 }
127 
129 {
130  animated_properties_set.add(property_id);
131 }
132 
134  const PropertyRNA *property_rna)
135 {
137 }
138 
140 {
141  return animated_properties_set.contains(property_id);
142 }
143 
145  const PropertyRNA *property_rna)
146 {
147  return isPropertyAnimated(AnimatedPropertyID(pointer_rna, property_rna));
148 }
149 
150 /* Builder cache itself. */
151 
153 {
157  }
158 }
159 
161 {
162  return animated_property_storage_map_.lookup_or_add_cb(
163  id, []() { return new AnimatedPropertyStorage(); });
164 }
165 
167 {
169  if (!animated_property_storage->is_fully_initialized) {
170  animated_property_storage->initializeFromID(this, id);
171  animated_property_storage->is_fully_initialized = true;
172  }
174 }
175 
176 } // namespace blender::deg
void BKE_fcurves_id_cb(struct ID *id, ID_FCurve_Edit_Callback func, void *user_data)
Definition: anim_data.c:1278
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
Set< AnimatedPropertyID > animated_properties_set
bool isPropertyAnimated(const AnimatedPropertyID &property_id)
void initializeFromID(DepsgraphBuilderCache *builder_cache, ID *id)
void tagPropertyAsAnimated(const AnimatedPropertyID &property_id)
AnimatedPropertyStorage * ensureAnimatedPropertyStorage(ID *id)
Map< ID *, AnimatedPropertyStorage * > animated_property_storage_map_
AnimatedPropertyStorage * ensureInitializedAnimatedPropertyStorage(ID *id)
AnimatedPropertyStorage * animated_property_storage
DepsgraphBuilderCache * builder_cache
PointerRNA pointer_rna
static unsigned a[3]
Definition: RandGen.cpp:92
bool operator==(const AnimatedPropertyID &a, const AnimatedPropertyID &b)
void RNA_id_pointer_create(ID *id, PointerRNA *r_ptr)
Definition: rna_access.c:122
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
Definition: rna_access.c:953
bool RNA_path_resolve_property(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition: rna_access.c:5434
_W64 unsigned int uintptr_t
Definition: stdint.h:122
unsigned __int64 uint64_t
Definition: stdint.h:93
char * rna_path
Definition: DNA_ID.h:273
struct ID * owner_id
Definition: RNA_types.h:50