Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Remove DisplayList's dependency on SkAutoTMalloc #38359

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions display_list/display_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ 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,
unsigned int nested_op_count,
const SkRect& bounds,
bool can_apply_group_opacity,
sk_sp<const DlRTree> rtree)
: storage_(ptr),
: storage_(std::move(storage)),
byte_count_(byte_count),
op_count_(op_count),
nested_byte_count_(nested_byte_count),
Expand Down
27 changes: 22 additions & 5 deletions display_list/display_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t*>(std::realloc(ptr_.release(), count)));
FML_CHECK(ptr_);
}

private:
struct FreeDeleter {
void operator()(uint8_t* p) { std::free(p); }
};
std::unique_ptr<uint8_t, FreeDeleter> 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().
Expand Down Expand Up @@ -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,
Expand All @@ -272,10 +292,7 @@ class DisplayList : public SkRefCnt {
bool can_apply_group_opacity,
sk_sp<const DlRTree> rtree);

struct SkFreeDeleter {
void operator()(uint8_t* p) { sk_free(p); }
};
std::unique_ptr<uint8_t, SkFreeDeleter> storage_;
DisplayListStorage storage_;
size_t byte_count_;
unsigned int op_count_;

Expand Down
2 changes: 1 addition & 1 deletion display_list/display_list_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ sk_sp<DisplayList> DisplayListBuilder::Build() {
nested_bytes_ = nested_op_count_ = 0;
storage_.realloc(bytes);
bool compatible = layer_stack_.back().is_group_opacity_compatible();
return sk_sp<DisplayList>(new DisplayList(storage_.release(), bytes, count,
return sk_sp<DisplayList>(new DisplayList(std::move(storage_), bytes, count,
nested_bytes, nested_count,
bounds(), compatible, rtree()));
}
Expand Down
2 changes: 1 addition & 1 deletion display_list/display_list_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class DisplayListBuilder final : public virtual Dispatcher,
private:
void checkForDeferredSave();

SkAutoTMalloc<uint8_t> storage_;
DisplayListStorage storage_;
size_t used_ = 0;
size_t allocated_ = 0;
int op_count_ = 0;
Expand Down