Undo: support implicit-sharing in memfile undo step #106903

Merged
Jacques Lucke merged 78 commits from JacquesLucke/blender:implicit-sharing-undo into main 2024-02-29 17:15:09 +01:00
4 changed files with 22 additions and 17 deletions
Showing only changes of commit 2019fe37de - Show all commits

View File

@ -5293,12 +5293,10 @@ void CustomData_blend_read(BlendDataReader *reader, CustomData *data, const int
else if (layer->type == CD_MDEFORMVERT) {
BKE_defvert_blend_read(reader, count, static_cast<MDeformVert *>(layer->data));
}
return layer->data ? make_implicit_sharing_info_for_layer(
eCustomDataType(layer->type), layer->data, count) :
nullptr;
});
if (layer->data != nullptr && layer->sharing_info == nullptr) {
/* Make layer data shareable. */
layer->sharing_info = make_implicit_sharing_info_for_layer(
eCustomDataType(layer->type), layer->data, count);
}
i++;
}
}

View File

@ -318,6 +318,7 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address
}
}
const blender::bke::MeshRuntime *mesh_runtime = mesh->runtime;
mesh->runtime = nullptr;
BLO_write_id_struct(writer, Mesh, id_address, &mesh->id);
@ -347,7 +348,10 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address
writer, &mesh->pdata, poly_layers, mesh->totpoly, CD_MASK_MESH.pmask, &mesh->id);
if (mesh->poly_offset_indices) {
BLO_write_int32_array(writer, mesh->totpoly + 1, mesh->poly_offset_indices);
BLO_write_shared(
writer, mesh->poly_offset_indices, mesh_runtime->poly_offsets_sharing_info, [&]() {
BLO_write_int32_array(writer, mesh->totpoly + 1, mesh->poly_offset_indices);
});
}
}
@ -393,9 +397,11 @@ static void mesh_blend_read_data(BlendDataReader *reader, ID *id)
mesh->runtime = new blender::bke::MeshRuntime();
if (mesh->poly_offset_indices) {
BLO_read_int32_array(reader, mesh->totpoly + 1, &mesh->poly_offset_indices);
mesh->runtime->poly_offsets_sharing_info = blender::implicit_sharing::info_for_mem_free(
mesh->poly_offset_indices);
mesh->runtime->poly_offsets_sharing_info = (blender::ImplicitSharingInfo *)BLO_read_shared(
reader, (void **)&mesh->poly_offset_indices, [&]() {
BLO_read_int32_array(reader, mesh->totpoly + 1, &mesh->poly_offset_indices);
return blender::implicit_sharing::info_for_mem_free(mesh->poly_offset_indices);
});
}
/* happens with old files */

View File

@ -268,9 +268,10 @@ void BLO_read_pointer_array(BlendDataReader *reader, void **ptr_p);
/* Misc. */
#ifdef __cplusplus
const blender::ImplicitSharingInfo *BLO_read_shared(BlendDataReader *reader,
void **data_ptr,
blender::FunctionRef<void()> read_cb);
const blender::ImplicitSharingInfo *BLO_read_shared(
BlendDataReader *reader,
void **data_ptr,
blender::FunctionRef<const blender::ImplicitSharingInfo *()> read_cb);
#endif
int BLO_read_fileversion_get(BlendDataReader *reader);

View File

@ -5133,9 +5133,10 @@ void BLO_read_pointer_array(BlendDataReader *reader, void **ptr_p)
*ptr_p = final_array;
}
const blender::ImplicitSharingInfo *BLO_read_shared(BlendDataReader *reader,
void **data_ptr,
blender::FunctionRef<void()> read_cb)
const blender::ImplicitSharingInfo *BLO_read_shared(
BlendDataReader *reader,
void **data_ptr,
blender::FunctionRef<const blender::ImplicitSharingInfo *()> read_cb)
{
if (BLO_read_data_is_undo(reader)) {
if (reader->fd->flags & FD_FLAGS_IS_MEMFILE) {
@ -5152,8 +5153,7 @@ const blender::ImplicitSharingInfo *BLO_read_shared(BlendDataReader *reader,
}
}
}
read_cb();
return nullptr;
return read_cb();
}
bool BLO_read_data_is_undo(BlendDataReader *reader)