fix leak of DisplayList storage (flutter/engine#28158)

This commit is contained in:
Jim Graham
2021-08-18 13:02:01 -07:00
committed by GitHub
parent 1472624caa
commit d30732ef0b
2 changed files with 13 additions and 8 deletions

View File

@@ -951,17 +951,19 @@ bool DisplayList::Equals(const DisplayList& other) const {
if (used_ != other.used_ || op_count_ != other.op_count_) {
return false;
}
if (ptr_ == other.ptr_) {
uint8_t* ptr = storage_.get();
uint8_t* o_ptr = other.storage_.get();
if (ptr == o_ptr) {
return true;
}
return CompareOps(ptr_, ptr_ + used_, other.ptr_, other.ptr_ + other.used_);
return CompareOps(ptr, ptr + used_, o_ptr, o_ptr + other.used_);
}
DisplayList::DisplayList(uint8_t* ptr,
size_t used,
int op_count,
const SkRect& cull)
: ptr_(ptr),
: storage_(ptr),
used_(used),
op_count_(op_count),
bounds_({0, 0, -1, -1}),
@@ -973,7 +975,8 @@ DisplayList::DisplayList(uint8_t* ptr,
}
DisplayList::~DisplayList() {
DisposeOps(ptr_, ptr_ + used_);
uint8_t* ptr = storage_.get();
DisposeOps(ptr, ptr + used_);
}
#define DL_BUILDER_PAGE 4096

View File

@@ -168,8 +168,7 @@ class DisplayList : public SkRefCnt {
static const SkSamplingOptions CubicSampling;
DisplayList()
: ptr_(nullptr),
used_(0),
: used_(0),
op_count_(0),
unique_id_(0),
bounds_({0, 0, 0, 0}),
@@ -177,7 +176,10 @@ class DisplayList : public SkRefCnt {
~DisplayList();
void Dispatch(Dispatcher& ctx) const { Dispatch(ctx, ptr_, ptr_ + used_); }
void Dispatch(Dispatcher& ctx) const {
uint8_t* ptr = storage_.get();
Dispatch(ctx, ptr, ptr + used_);
}
void RenderTo(SkCanvas* canvas) const;
@@ -199,7 +201,7 @@ class DisplayList : public SkRefCnt {
private:
DisplayList(uint8_t* ptr, size_t used, int op_count, const SkRect& cull_rect);
uint8_t* ptr_;
std::unique_ptr<uint8_t, SkFunctionWrapper<void(void*), sk_free>> storage_;
size_t used_;
int op_count_;