[Bf-blender-cvs] [302ab3ff7ce] temp-geometry-nodes-fields-prototype: cleanup
Jacques Lucke
noreply at git.blender.org
Thu Jul 29 21:41:13 CEST 2021
Commit: 302ab3ff7ce39ac2e0d0138bebbd5ff6fbf1e67b
Author: Jacques Lucke
Date: Thu Jul 29 19:56:54 2021 +0200
Branches: temp-geometry-nodes-fields-prototype
https://developer.blender.org/rB302ab3ff7ce39ac2e0d0138bebbd5ff6fbf1e67b
cleanup
===================================================================
M source/blender/blenkernel/BKE_customdata.h
M source/blender/blenkernel/BKE_geometry_set.hh
M source/blender/blenkernel/intern/attribute_access.cc
M source/blender/blenkernel/intern/attribute_access_intern.hh
M source/blender/blenkernel/intern/customdata.c
M source/blender/makesdna/DNA_customdata_types.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h
index 7fc7d8bddb1..b2a0e7fc7e8 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -484,11 +484,11 @@ void CustomData_external_reload(struct CustomData *data,
/* Anonymous layers. */
struct AnonymousCustomDataLayerID *CustomData_anonymous_id_new(const char *debug_name);
-void CustomData_anonymous_id_strong_decrement(struct AnonymousCustomDataLayerID *layer_id);
-void CustomData_anonymous_id_strong_increment(struct AnonymousCustomDataLayerID *layer_id);
-void CustomData_anonymous_id_weak_decrement(struct AnonymousCustomDataLayerID *layer_id);
-void CustomData_anonymous_id_weak_increment(struct AnonymousCustomDataLayerID *layer_id);
-bool CustomData_layer_is_unused_anonymous(struct CustomDataLayer *layer);
+void CustomData_anonymous_id_strong_decrement(const struct AnonymousCustomDataLayerID *layer_id);
+void CustomData_anonymous_id_strong_increment(const struct AnonymousCustomDataLayerID *layer_id);
+void CustomData_anonymous_id_weak_decrement(const struct AnonymousCustomDataLayerID *layer_id);
+void CustomData_anonymous_id_weak_increment(const struct AnonymousCustomDataLayerID *layer_id);
+bool CustomData_layer_is_unused_anonymous(const struct CustomDataLayer *layer);
/* Mesh-to-mesh transfer data. */
diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh
index 56cdffc9311..22bf4b34f98 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -128,10 +128,10 @@ class GeometryComponent {
const CustomDataType data_type,
const AttributeInit &initializer);
- AnonymousCustomDataLayerID *attribute_try_create_anonymous(const blender::StringRef debug_name,
- const AttributeDomain domain,
- const CustomDataType data_type,
- const AttributeInit &initializer);
+ bool attribute_try_create_anonymous(const AnonymousCustomDataLayerID &layer_id,
+ const AttributeDomain domain,
+ const CustomDataType data_type,
+ const AttributeInit &initializer);
blender::bke::ReadAttributeLookup attribute_try_get_anonymous_for_read(
const AnonymousCustomDataLayerID &layer_id) const;
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index 442be01a0dc..4a5fe98445a 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -506,22 +506,27 @@ static std::string get_anonymous_attribute_name()
return "anonymous_attribute_" + std::to_string(next_index);
}
-AnonymousCustomDataLayerID *CustomDataAttributeProvider::try_create_anonymous(
- GeometryComponent &component,
- const StringRef debug_name,
- const AttributeDomain domain,
- const CustomDataType data_type,
- const AttributeInit &initializer) const
+bool CustomDataAttributeProvider::try_create_anonymous(GeometryComponent &component,
+ const AnonymousCustomDataLayerID &layer_id,
+ const AttributeDomain domain,
+ const CustomDataType data_type,
+ const AttributeInit &initializer) const
{
if (domain_ != domain) {
- return nullptr;
+ return false;
}
if (!this->type_is_supported(data_type)) {
- return nullptr;
+ return false;
}
CustomData *custom_data = custom_data_access_.get_custom_data(component);
if (custom_data == nullptr) {
- return nullptr;
+ return false;
+ }
+ for (const CustomDataLayer &layer : Span(custom_data->layers, custom_data->totlayer)) {
+ if (layer.anonymous_id == &layer_id) {
+ /* Don't create two layers with the same id. */
+ return false;
+ }
}
const int domain_size = component.attribute_domain_size(domain_);
@@ -532,10 +537,9 @@ AnonymousCustomDataLayerID *CustomDataAttributeProvider::try_create_anonymous(
custom_data, data_type, attribute_name.c_str());
CustomDataLayer *layer = &custom_data->layers[layer_index];
layer->flag |= CD_FLAG_ANONYMOUS;
- layer->anonymous_id = CustomData_anonymous_id_new(
- BLI_strdupn(debug_name.data(), debug_name.size()));
- CustomData_anonymous_id_weak_increment(layer->anonymous_id);
- return layer->anonymous_id;
+ layer->anonymous_id = &layer_id;
+ CustomData_anonymous_id_weak_increment(&layer_id);
+ return true;
}
ReadAttributeLookup CustomDataAttributeProvider::try_get_anonymous_for_read(
@@ -961,23 +965,20 @@ bool GeometryComponent::attribute_try_create(const StringRef attribute_name,
return false;
}
-AnonymousCustomDataLayerID *GeometryComponent::attribute_try_create_anonymous(
- const blender::StringRef debug_name,
- const AttributeDomain domain,
- const CustomDataType data_type,
- const AttributeInit &initializer)
+bool GeometryComponent::attribute_try_create_anonymous(const AnonymousCustomDataLayerID &layer_id,
+ const AttributeDomain domain,
+ const CustomDataType data_type,
+ const AttributeInit &initializer)
{
using namespace blender::bke;
const ComponentAttributeProviders *providers = this->get_attribute_providers();
for (const DynamicAttributesProvider *dynamic_provider :
providers->dynamic_attribute_providers()) {
- AnonymousCustomDataLayerID *layer_id = dynamic_provider->try_create_anonymous(
- *this, debug_name, domain, data_type, initializer);
- if (layer_id != nullptr) {
- return layer_id;
+ if (dynamic_provider->try_create_anonymous(*this, layer_id, domain, data_type, initializer)) {
+ return true;
}
}
- return nullptr;
+ return false;
}
blender::bke::ReadAttributeLookup GeometryComponent::attribute_try_get_anonymous_for_read(
diff --git a/source/blender/blenkernel/intern/attribute_access_intern.hh b/source/blender/blenkernel/intern/attribute_access_intern.hh
index dbb595aade3..e58d320a33d 100644
--- a/source/blender/blenkernel/intern/attribute_access_intern.hh
+++ b/source/blender/blenkernel/intern/attribute_access_intern.hh
@@ -131,14 +131,13 @@ class DynamicAttributesProvider {
};
/** Returns the id of the new anonymous or null if no new attribute was created. */
- virtual AnonymousCustomDataLayerID *try_create_anonymous(
- GeometryComponent &UNUSED(component),
- const StringRef UNUSED(debug_name),
- const AttributeDomain UNUSED(domain),
- const CustomDataType UNUSED(data_type),
- const AttributeInit &UNUSED(initializer)) const
+ virtual bool try_create_anonymous(GeometryComponent &UNUSED(component),
+ const AnonymousCustomDataLayerID &UNUSED(layer_id),
+ const AttributeDomain UNUSED(domain),
+ const CustomDataType UNUSED(data_type),
+ const AttributeInit &UNUSED(initializer)) const
{
- return nullptr;
+ return false;
}
virtual ReadAttributeLookup try_get_anonymous_for_read(
@@ -192,11 +191,11 @@ class CustomDataAttributeProvider final : public DynamicAttributesProvider {
const CustomDataType data_type,
const AttributeInit &initializer) const final;
- AnonymousCustomDataLayerID *try_create_anonymous(GeometryComponent &component,
- const StringRef debug_name,
- const AttributeDomain domain,
- const CustomDataType data_type,
- const AttributeInit &initializer) const final;
+ bool try_create_anonymous(GeometryComponent &component,
+ const AnonymousCustomDataLayerID &layer_id,
+ const AttributeDomain domain,
+ const CustomDataType data_type,
+ const AttributeInit &initializer) const final;
ReadAttributeLookup try_get_anonymous_for_read(
const GeometryComponent &component, const AnonymousCustomDataLayerID &layer_id) const final;
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 9ff116127a1..b6af947605e 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -5049,11 +5049,10 @@ void CustomData_data_transfer(const MeshPairRemap *me_remap,
MEM_SAFE_FREE(tmp_data_src);
}
-/** Takes ownership of `debug_name`. */
AnonymousCustomDataLayerID *CustomData_anonymous_id_new(const char *debug_name)
{
AnonymousCustomDataLayerID *layer_id = MEM_callocN(sizeof(AnonymousCustomDataLayerID), __func__);
- layer_id->debug_name = debug_name;
+ layer_id->debug_name = BLI_strdup(debug_name);
return layer_id;
}
@@ -5065,40 +5064,44 @@ static void CustomData_anonymous_id_free(AnonymousCustomDataLayerID *layer_id)
MEM_freeN(layer_id);
}
-void CustomData_anonymous_id_strong_decrement(AnonymousCustomDataLayerID *layer_id)
+void CustomData_anonymous_id_strong_decrement(const AnonymousCustomDataLayerID *layer_id)
{
- int strong_references = atomic_sub_and_fetch_int32(&layer_id->strong_references, 1);
+ AnonymousCustomDataLayerID *mutable_layer_id = (AnonymousCustomDataLayerID *)layer_id;
+ int strong_references = atomic_sub_and_fetch_int32(&mutable_layer_id->strong_references, 1);
BLI_assert(strong_references >= 0);
UNUSED_VARS_NDEBUG(strong_references);
- int tot_references = a
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list