diff --git a/display_list/display_list.cc b/display_list/display_list.cc index d808f20c1ea82..9268ed3fdbcd7 100644 --- a/display_list/display_list.cc +++ b/display_list/display_list.cc @@ -25,7 +25,7 @@ DisplayList::DisplayList() bounds_({0, 0, 0, 0}), can_apply_group_opacity_(true) {} -DisplayList::DisplayList(uint8_t* ptr, +DisplayList::DisplayList(DisplayListStorage&& storage, size_t byte_count, unsigned int op_count, size_t nested_byte_count, @@ -33,7 +33,7 @@ DisplayList::DisplayList(uint8_t* ptr, const SkRect& bounds, bool can_apply_group_opacity, sk_sp rtree) - : storage_(ptr), + : storage_(std::move(storage)), byte_count_(byte_count), op_count_(op_count), nested_byte_count_(nested_byte_count), diff --git a/display_list/display_list.h b/display_list/display_list.h index 87c67d9c9f3d2..a20f93f56a025 100644 --- a/display_list/display_list.h +++ b/display_list/display_list.h @@ -215,6 +215,26 @@ class SaveLayerOptions { }; }; +// Manages a buffer allocated with malloc. +class DisplayListStorage { + public: + DisplayListStorage() = default; + DisplayListStorage(DisplayListStorage&&) = default; + + uint8_t* get() const { return ptr_.get(); } + + void realloc(size_t count) { + ptr_.reset(static_cast(std::realloc(ptr_.release(), count))); + FML_CHECK(ptr_); + } + + private: + struct FreeDeleter { + void operator()(uint8_t* p) { std::free(p); } + }; + std::unique_ptr ptr_; +}; + // The base class that contains a sequence of rendering operations // for dispatch to a Dispatcher. These objects must be instantiated // through an instance of DisplayListBuilder::build(). @@ -263,7 +283,7 @@ class DisplayList : public SkRefCnt { static void DisposeOps(uint8_t* ptr, uint8_t* end); private: - DisplayList(uint8_t* ptr, + DisplayList(DisplayListStorage&& ptr, size_t byte_count, unsigned int op_count, size_t nested_byte_count, @@ -272,10 +292,7 @@ class DisplayList : public SkRefCnt { bool can_apply_group_opacity, sk_sp rtree); - struct SkFreeDeleter { - void operator()(uint8_t* p) { sk_free(p); } - }; - std::unique_ptr storage_; + DisplayListStorage storage_; size_t byte_count_; unsigned int op_count_; diff --git a/display_list/display_list_builder.cc b/display_list/display_list_builder.cc index 2e0c7bcce3bf9..14289a3d47e8d 100644 --- a/display_list/display_list_builder.cc +++ b/display_list/display_list_builder.cc @@ -61,7 +61,7 @@ sk_sp DisplayListBuilder::Build() { nested_bytes_ = nested_op_count_ = 0; storage_.realloc(bytes); bool compatible = layer_stack_.back().is_group_opacity_compatible(); - return sk_sp(new DisplayList(storage_.release(), bytes, count, + return sk_sp(new DisplayList(std::move(storage_), bytes, count, nested_bytes, nested_count, bounds(), compatible, rtree())); } diff --git a/display_list/display_list_builder.h b/display_list/display_list_builder.h index b16e8b37ea012..94a784fc5488a 100644 --- a/display_list/display_list_builder.h +++ b/display_list/display_list_builder.h @@ -362,7 +362,7 @@ class DisplayListBuilder final : public virtual Dispatcher, private: void checkForDeferredSave(); - SkAutoTMalloc storage_; + DisplayListStorage storage_; size_t used_ = 0; size_t allocated_ = 0; int op_count_ = 0;