diff options
author | Antonio Vazquez <blendergit@gmail.com> | 2021-05-26 13:43:03 +0300 |
---|---|---|
committer | Antonio Vazquez <blendergit@gmail.com> | 2021-05-26 13:43:03 +0300 |
commit | 8a6604f253e22bbade3dcf60b9a1c437ace44151 (patch) | |
tree | fee875d0a0b09fbe0df52aa83094159144048205 /source/blender/functions/intern/generic_virtual_array.cc | |
parent | edf1b833674a6e54df7a16c14f0c6193fbbb482e (diff) | |
parent | afec66c024dc2b75447537d45406c06342ec201e (diff) |
Merge branch 'master' into temp-gpencil-maskingtemp-gpencil-masking
Conflicts:
source/blender/blenloader/intern/versioning_300.c
Diffstat (limited to 'source/blender/functions/intern/generic_virtual_array.cc')
-rw-r--r-- | source/blender/functions/intern/generic_virtual_array.cc | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/source/blender/functions/intern/generic_virtual_array.cc b/source/blender/functions/intern/generic_virtual_array.cc index e11501828f8..87dae06ccdc 100644 --- a/source/blender/functions/intern/generic_virtual_array.cc +++ b/source/blender/functions/intern/generic_virtual_array.cc @@ -19,11 +19,71 @@ namespace blender::fn { /* -------------------------------------------------------------------- + * GVArray_For_ShallowCopy. + */ + +class GVArray_For_ShallowCopy : public GVArray { + private: + const GVArray &varray_; + + public: + GVArray_For_ShallowCopy(const GVArray &varray) + : GVArray(varray.type(), varray.size()), varray_(varray) + { + } + + private: + void get_impl(const int64_t index, void *r_value) const override + { + varray_.get(index, r_value); + } + + void get_to_uninitialized_impl(const int64_t index, void *r_value) const override + { + varray_.get_to_uninitialized(index, r_value); + } + + void materialize_to_uninitialized_impl(const IndexMask mask, void *dst) const override + { + varray_.materialize_to_uninitialized(mask, dst); + } +}; + +/* -------------------------------------------------------------------- * GVArray. */ +void GVArray::materialize(void *dst) const +{ + this->materialize(IndexMask(size_), dst); +} + +void GVArray::materialize(const IndexMask mask, void *dst) const +{ + this->materialize_impl(mask, dst); +} + +void GVArray::materialize_impl(const IndexMask mask, void *dst) const +{ + for (const int64_t i : mask) { + void *elem_dst = POINTER_OFFSET(dst, type_->size() * i); + this->get(i, elem_dst); + } +} + +void GVArray::materialize_to_uninitialized(void *dst) const +{ + this->materialize_to_uninitialized(IndexMask(size_), dst); +} + void GVArray::materialize_to_uninitialized(const IndexMask mask, void *dst) const { + BLI_assert(mask.min_array_size() <= size_); + this->materialize_to_uninitialized_impl(mask, dst); +} + +void GVArray::materialize_to_uninitialized_impl(const IndexMask mask, void *dst) const +{ for (const int64_t i : mask) { void *elem_dst = POINTER_OFFSET(dst, type_->size() * i); this->get_to_uninitialized(i, elem_dst); @@ -62,6 +122,26 @@ const void *GVArray::try_get_internal_varray_impl() const return nullptr; } +/** + * Creates a new `std::unique_ptr<GVArray>` based on this `GVArray`. + * The lifetime of the returned virtual array must not be longer than the lifetime of this virtual + * array. + */ +GVArrayPtr GVArray::shallow_copy() const +{ + if (this->is_span()) { + return std::make_unique<GVArray_For_GSpan>(this->get_internal_span()); + } + if (this->is_single()) { + BUFFER_FOR_CPP_TYPE_VALUE(*type_, buffer); + this->get_internal_single(buffer); + std::unique_ptr new_varray = std::make_unique<GVArray_For_SingleValue>(*type_, size_, buffer); + type_->destruct(buffer); + return new_varray; + } + return std::make_unique<GVArray_For_ShallowCopy>(*this); +} + /* -------------------------------------------------------------------- * GVMutableArray. */ @@ -80,6 +160,19 @@ void GVMutableArray::set_by_relocate_impl(const int64_t index, void *value) type_->destruct(value); } +void GVMutableArray::set_all_impl(const void *src) +{ + if (this->is_span()) { + const GMutableSpan span = this->get_internal_span(); + type_->copy_to_initialized_n(src, span.data(), size_); + } + else { + for (int64_t i : IndexRange(size_)) { + this->set_by_copy(i, POINTER_OFFSET(src, type_->size() * i)); + } + } +} + void *GVMutableArray::try_get_internal_mutable_varray_impl() { return nullptr; |