Remove DisplayList's dependency on SkAutoTMalloc (flutter/engine#38359)
SkAutoTMalloc is not a public Skia API
This commit is contained in:
@@ -25,7 +25,7 @@ DisplayList::DisplayList()
|
|||||||
bounds_({0, 0, 0, 0}),
|
bounds_({0, 0, 0, 0}),
|
||||||
can_apply_group_opacity_(true) {}
|
can_apply_group_opacity_(true) {}
|
||||||
|
|
||||||
DisplayList::DisplayList(uint8_t* ptr,
|
DisplayList::DisplayList(DisplayListStorage&& storage,
|
||||||
size_t byte_count,
|
size_t byte_count,
|
||||||
unsigned int op_count,
|
unsigned int op_count,
|
||||||
size_t nested_byte_count,
|
size_t nested_byte_count,
|
||||||
@@ -33,7 +33,7 @@ DisplayList::DisplayList(uint8_t* ptr,
|
|||||||
const SkRect& bounds,
|
const SkRect& bounds,
|
||||||
bool can_apply_group_opacity,
|
bool can_apply_group_opacity,
|
||||||
sk_sp<const DlRTree> rtree)
|
sk_sp<const DlRTree> rtree)
|
||||||
: storage_(ptr),
|
: storage_(std::move(storage)),
|
||||||
byte_count_(byte_count),
|
byte_count_(byte_count),
|
||||||
op_count_(op_count),
|
op_count_(op_count),
|
||||||
nested_byte_count_(nested_byte_count),
|
nested_byte_count_(nested_byte_count),
|
||||||
|
|||||||
@@ -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
|
// The base class that contains a sequence of rendering operations
|
||||||
// for dispatch to a Dispatcher. These objects must be instantiated
|
// for dispatch to a Dispatcher. These objects must be instantiated
|
||||||
// through an instance of DisplayListBuilder::build().
|
// through an instance of DisplayListBuilder::build().
|
||||||
@@ -263,7 +283,7 @@ class DisplayList : public SkRefCnt {
|
|||||||
static void DisposeOps(uint8_t* ptr, uint8_t* end);
|
static void DisposeOps(uint8_t* ptr, uint8_t* end);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DisplayList(uint8_t* ptr,
|
DisplayList(DisplayListStorage&& ptr,
|
||||||
size_t byte_count,
|
size_t byte_count,
|
||||||
unsigned int op_count,
|
unsigned int op_count,
|
||||||
size_t nested_byte_count,
|
size_t nested_byte_count,
|
||||||
@@ -272,10 +292,7 @@ class DisplayList : public SkRefCnt {
|
|||||||
bool can_apply_group_opacity,
|
bool can_apply_group_opacity,
|
||||||
sk_sp<const DlRTree> rtree);
|
sk_sp<const DlRTree> rtree);
|
||||||
|
|
||||||
struct SkFreeDeleter {
|
DisplayListStorage storage_;
|
||||||
void operator()(uint8_t* p) { sk_free(p); }
|
|
||||||
};
|
|
||||||
std::unique_ptr<uint8_t, SkFreeDeleter> storage_;
|
|
||||||
size_t byte_count_;
|
size_t byte_count_;
|
||||||
unsigned int op_count_;
|
unsigned int op_count_;
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ sk_sp<DisplayList> DisplayListBuilder::Build() {
|
|||||||
nested_bytes_ = nested_op_count_ = 0;
|
nested_bytes_ = nested_op_count_ = 0;
|
||||||
storage_.realloc(bytes);
|
storage_.realloc(bytes);
|
||||||
bool compatible = layer_stack_.back().is_group_opacity_compatible();
|
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,
|
nested_bytes, nested_count,
|
||||||
bounds(), compatible, rtree()));
|
bounds(), compatible, rtree()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -362,7 +362,7 @@ class DisplayListBuilder final : public virtual Dispatcher,
|
|||||||
private:
|
private:
|
||||||
void checkForDeferredSave();
|
void checkForDeferredSave();
|
||||||
|
|
||||||
SkAutoTMalloc<uint8_t> storage_;
|
DisplayListStorage storage_;
|
||||||
size_t used_ = 0;
|
size_t used_ = 0;
|
||||||
size_t allocated_ = 0;
|
size_t allocated_ = 0;
|
||||||
int op_count_ = 0;
|
int op_count_ = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user