Blender  V3.3
deg_builder_cache.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2018 Blender Foundation. All rights reserved. */
3 
9 
10 #include "MEM_guardedalloc.h"
11 
12 #include "DNA_anim_types.h"
13 
14 #include "BLI_utildefines.h"
15 
16 #include "BKE_animsys.h"
17 
18 #include "RNA_path.h"
19 
20 namespace blender::deg {
21 
22 /* Animated property storage. */
23 
24 AnimatedPropertyID::AnimatedPropertyID() : data(nullptr), property_rna(nullptr)
25 {
26 }
27 
29  const PropertyRNA *property_rna)
30  : AnimatedPropertyID(*pointer_rna, property_rna)
31 {
32 }
33 
35  const PropertyRNA *property_rna)
36  : data(pointer_rna.data), property_rna(property_rna)
37 {
38 }
39 
40 AnimatedPropertyID::AnimatedPropertyID(const ID *id, StructRNA *type, const char *property_name)
41  : data(id)
42 {
44 }
45 
47  StructRNA *type,
48  void *data,
49  const char *property_name)
50  : data(data)
51 {
53 }
54 
56 {
57  return a.data == b.data && a.property_rna == b.property_rna;
58 }
59 
61 {
62  uintptr_t ptr1 = (uintptr_t)data;
64  return static_cast<uint64_t>(((ptr1 >> 4) * 33) ^ (ptr2 >> 4));
65 }
66 
67 namespace {
68 
69 struct AnimatedPropertyCallbackData {
71  AnimatedPropertyStorage *animated_property_storage;
72  DepsgraphBuilderCache *builder_cache;
73 };
74 
75 void animated_property_cb(ID * /*id*/, FCurve *fcurve, void *data_v)
76 {
77  if (fcurve->rna_path == nullptr || fcurve->rna_path[0] == '\0') {
78  return;
79  }
80  AnimatedPropertyCallbackData *data = static_cast<AnimatedPropertyCallbackData *>(data_v);
81  /* Resolve property. */
83  PropertyRNA *property_rna = nullptr;
85  &data->pointer_rna, fcurve->rna_path, &pointer_rna, &property_rna)) {
86  return;
87  }
88  /* Get storage for the ID.
89  * This is needed to deal with cases when nested datablock is animated by its parent. */
90  AnimatedPropertyStorage *animated_property_storage = data->animated_property_storage;
91  if (pointer_rna.owner_id != data->pointer_rna.owner_id) {
92  animated_property_storage = data->builder_cache->ensureAnimatedPropertyStorage(
94  }
95  /* Set the property as animated. */
97 }
98 
99 } // namespace
100 
102 {
103 }
104 
106 {
107  AnimatedPropertyCallbackData data;
108  RNA_id_pointer_create(const_cast<ID *>(id), &data.pointer_rna);
109  data.animated_property_storage = this;
110  data.builder_cache = builder_cache;
111  BKE_fcurves_id_cb(const_cast<ID *>(id), animated_property_cb, &data);
112 }
113 
115 {
116  animated_objects_set.add(property_id.data);
117  animated_properties_set.add(property_id);
118 }
119 
121  const PropertyRNA *property_rna)
122 {
124 }
125 
127 {
128  return animated_properties_set.contains(property_id);
129 }
130 
132  const PropertyRNA *property_rna)
133 {
134  return isPropertyAnimated(AnimatedPropertyID(pointer_rna, property_rna));
135 }
136 
138 {
140 }
141 
142 /* Builder cache itself. */
143 
145 {
149  }
150 }
151 
153 {
154  return animated_property_storage_map_.lookup_or_add_cb(
155  id, []() { return new AnimatedPropertyStorage(); });
156 }
157 
159  const ID *id)
160 {
162  if (!animated_property_storage->is_fully_initialized) {
163  animated_property_storage->initializeFromID(this, id);
164  animated_property_storage->is_fully_initialized = true;
165  }
167 }
168 
169 } // namespace blender::deg
void BKE_fcurves_id_cb(struct ID *id, ID_FCurve_Edit_Callback func, void *user_data)
Definition: anim_data.c:1157
_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.
bool contains(const Key &key) const
Definition: BLI_set.hh:296
bool add(const Key &key)
Definition: BLI_set.hh:253
Set< AnimatedPropertyID > animated_properties_set
void initializeFromID(DepsgraphBuilderCache *builder_cache, const ID *id)
bool isAnyPropertyAnimated(const PointerRNA *pointer_rna)
bool isPropertyAnimated(const AnimatedPropertyID &property_id)
void tagPropertyAsAnimated(const AnimatedPropertyID &property_id)
Map< const ID *, AnimatedPropertyStorage * > animated_property_storage_map_
AnimatedPropertyStorage * ensureInitializedAnimatedPropertyStorage(const ID *id)
AnimatedPropertyStorage * ensureAnimatedPropertyStorage(const ID *id)
AnimatedPropertyStorage * animated_property_storage
DepsgraphBuilderCache * builder_cache
PointerRNA pointer_rna
static unsigned a[3]
Definition: RandGen.cpp:78
bool operator==(const AnimatedPropertyID &a, const AnimatedPropertyID &b)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void RNA_id_pointer_create(ID *id, PointerRNA *r_ptr)
Definition: rna_access.c:112
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
Definition: rna_access.c:806
bool RNA_path_resolve_property(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition: rna_path.cc:531
_W64 unsigned int uintptr_t
Definition: stdint.h:119
unsigned __int64 uint64_t
Definition: stdint.h:90
char * rna_path
Definition: DNA_ID.h:368
void * data
Definition: RNA_types.h:38
struct ID * owner_id
Definition: RNA_types.h:36