Cleanup: return managed pointer when copying geometry component

This commit is contained in:
Jacques Lucke
2023-12-01 11:23:00 +01:00
parent 7730ca2b9d
commit cefdb67db7
9 changed files with 26 additions and 24 deletions

View File

@@ -87,8 +87,10 @@ class GeometryComponent : public ImplicitSharingMixin {
virtual std::optional<AttributeAccessor> attributes() const;
virtual std::optional<MutableAttributeAccessor> attributes_for_write();
/* The returned component should be of the same type as the type this is called on. */
virtual GeometryComponent *copy() const = 0;
/**
* Copies the component. The returned component only has a single user and is therefor mutable.
*/
virtual GeometryComponentPtr copy() const = 0;
/** Remove referenced data from the geometry component. */
virtual void clear() = 0;
@@ -437,7 +439,7 @@ class MeshComponent : public GeometryComponent {
public:
MeshComponent();
~MeshComponent();
GeometryComponent *copy() const override;
GeometryComponentPtr copy() const override;
void clear() override;
bool has_mesh() const;
@@ -491,7 +493,7 @@ class PointCloudComponent : public GeometryComponent {
public:
PointCloudComponent();
~PointCloudComponent();
GeometryComponent *copy() const override;
GeometryComponentPtr copy() const override;
void clear() override;
bool has_pointcloud() const;
@@ -551,7 +553,7 @@ class CurveComponent : public GeometryComponent {
public:
CurveComponent();
~CurveComponent();
GeometryComponent *copy() const override;
GeometryComponentPtr copy() const override;
void clear() override;
bool has_curves() const;
@@ -592,7 +594,7 @@ class InstancesComponent : public GeometryComponent {
public:
InstancesComponent();
~InstancesComponent();
GeometryComponent *copy() const override;
GeometryComponentPtr copy() const override;
void clear() override;
@@ -626,7 +628,7 @@ class VolumeComponent : public GeometryComponent {
public:
VolumeComponent();
~VolumeComponent();
GeometryComponent *copy() const override;
GeometryComponentPtr copy() const override;
void clear() override;
bool has_volume() const;
@@ -681,7 +683,7 @@ class GeometryComponentEditData final : public GeometryComponent {
GeometryComponentEditData();
GeometryComponent *copy() const final;
GeometryComponentPtr copy() const final;
bool owns_direct_data() const final;
void ensure_owns_direct_data() final;
@@ -711,7 +713,7 @@ class GreasePencilComponent : public GeometryComponent {
public:
GreasePencilComponent();
~GreasePencilComponent();
GeometryComponent *copy() const override;
GeometryComponentPtr copy() const override;
void clear() override;
bool has_grease_pencil() const;

View File

@@ -32,14 +32,14 @@ CurveComponent::~CurveComponent()
this->clear();
}
GeometryComponent *CurveComponent::copy() const
GeometryComponentPtr CurveComponent::copy() const
{
CurveComponent *new_component = new CurveComponent();
if (curves_ != nullptr) {
new_component->curves_ = BKE_curves_copy_for_eval(curves_);
new_component->ownership_ = GeometryOwnershipType::Owned;
}
return new_component;
return GeometryComponentPtr(new_component);
}
void CurveComponent::clear()

View File

@@ -10,7 +10,7 @@ namespace blender::bke {
GeometryComponentEditData::GeometryComponentEditData() : GeometryComponent(Type::Edit) {}
GeometryComponent *GeometryComponentEditData::copy() const
GeometryComponentPtr GeometryComponentEditData::copy() const
{
GeometryComponentEditData *new_component = new GeometryComponentEditData();
if (curves_edit_hints_) {
@@ -20,7 +20,7 @@ GeometryComponent *GeometryComponentEditData::copy() const
new_component->grease_pencil_edit_hints_ = std::make_unique<GreasePencilEditHints>(
*grease_pencil_edit_hints_);
}
return new_component;
return GeometryComponentPtr(new_component);
}
bool GeometryComponentEditData::owns_direct_data() const

View File

@@ -23,14 +23,14 @@ GreasePencilComponent::~GreasePencilComponent()
this->clear();
}
GeometryComponent *GreasePencilComponent::copy() const
GeometryComponentPtr GreasePencilComponent::copy() const
{
GreasePencilComponent *new_component = new GreasePencilComponent();
if (grease_pencil_ != nullptr) {
new_component->grease_pencil_ = BKE_grease_pencil_copy_for_eval(grease_pencil_);
new_component->ownership_ = GeometryOwnershipType::Owned;
}
return new_component;
return GeometryComponentPtr(new_component);
}
void GreasePencilComponent::clear()

View File

@@ -37,14 +37,14 @@ InstancesComponent::~InstancesComponent()
this->clear();
}
GeometryComponent *InstancesComponent::copy() const
GeometryComponentPtr InstancesComponent::copy() const
{
InstancesComponent *new_component = new InstancesComponent();
if (instances_ != nullptr) {
new_component->instances_ = new Instances(*instances_);
new_component->ownership_ = GeometryOwnershipType::Owned;
}
return new_component;
return GeometryComponentPtr(new_component);
}
void InstancesComponent::clear()

View File

@@ -34,14 +34,14 @@ MeshComponent::~MeshComponent()
this->clear();
}
GeometryComponent *MeshComponent::copy() const
GeometryComponentPtr MeshComponent::copy() const
{
MeshComponent *new_component = new MeshComponent();
if (mesh_ != nullptr) {
new_component->mesh_ = BKE_mesh_copy_for_eval(mesh_);
new_component->ownership_ = GeometryOwnershipType::Owned;
}
return new_component;
return GeometryComponentPtr(new_component);
}
void MeshComponent::clear()

View File

@@ -23,14 +23,14 @@ PointCloudComponent::~PointCloudComponent()
this->clear();
}
GeometryComponent *PointCloudComponent::copy() const
GeometryComponentPtr PointCloudComponent::copy() const
{
PointCloudComponent *new_component = new PointCloudComponent();
if (pointcloud_ != nullptr) {
new_component->pointcloud_ = BKE_pointcloud_copy_for_eval(pointcloud_);
new_component->ownership_ = GeometryOwnershipType::Owned;
}
return new_component;
return GeometryComponentPtr(new_component);
}
void PointCloudComponent::clear()

View File

@@ -21,14 +21,14 @@ VolumeComponent::~VolumeComponent()
this->clear();
}
GeometryComponent *VolumeComponent::copy() const
GeometryComponentPtr VolumeComponent::copy() const
{
VolumeComponent *new_component = new VolumeComponent();
if (volume_ != nullptr) {
new_component->volume_ = BKE_volume_copy_for_eval(volume_);
new_component->ownership_ = GeometryOwnershipType::Owned;
}
return new_component;
return GeometryComponentPtr(new_component);
}
void VolumeComponent::clear()

View File

@@ -128,7 +128,7 @@ GeometryComponent &GeometrySet::get_component_for_write(GeometryComponent::Type
else {
/* If the referenced component is shared, make a copy. The copy is not shared and is
* therefore mutable. */
component_ptr = GeometryComponentPtr(component_ptr->copy());
component_ptr = component_ptr->copy();
}
return const_cast<GeometryComponent &>(*component_ptr);
}