Skip to content

Commit f286172

Browse files
jason-simmonsloic-sharma
authored andcommitted
Remove DisplayList's dependency on SkAutoTMalloc (flutter#38359)
SkAutoTMalloc is not a public Skia API
1 parent 372330d commit f286172

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

display_list/display_list.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ DisplayList::DisplayList()
2525
bounds_({0, 0, 0, 0}),
2626
can_apply_group_opacity_(true) {}
2727

28-
DisplayList::DisplayList(uint8_t* ptr,
28+
DisplayList::DisplayList(DisplayListStorage&& storage,
2929
size_t byte_count,
3030
unsigned int op_count,
3131
size_t nested_byte_count,
3232
unsigned int nested_op_count,
3333
const SkRect& bounds,
3434
bool can_apply_group_opacity,
3535
sk_sp<const DlRTree> rtree)
36-
: storage_(ptr),
36+
: storage_(std::move(storage)),
3737
byte_count_(byte_count),
3838
op_count_(op_count),
3939
nested_byte_count_(nested_byte_count),

display_list/display_list.h

+22-5
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,26 @@ class SaveLayerOptions {
215215
};
216216
};
217217

218+
// Manages a buffer allocated with malloc.
219+
class DisplayListStorage {
220+
public:
221+
DisplayListStorage() = default;
222+
DisplayListStorage(DisplayListStorage&&) = default;
223+
224+
uint8_t* get() const { return ptr_.get(); }
225+
226+
void realloc(size_t count) {
227+
ptr_.reset(static_cast<uint8_t*>(std::realloc(ptr_.release(), count)));
228+
FML_CHECK(ptr_);
229+
}
230+
231+
private:
232+
struct FreeDeleter {
233+
void operator()(uint8_t* p) { std::free(p); }
234+
};
235+
std::unique_ptr<uint8_t, FreeDeleter> ptr_;
236+
};
237+
218238
// The base class that contains a sequence of rendering operations
219239
// for dispatch to a Dispatcher. These objects must be instantiated
220240
// through an instance of DisplayListBuilder::build().
@@ -263,7 +283,7 @@ class DisplayList : public SkRefCnt {
263283
static void DisposeOps(uint8_t* ptr, uint8_t* end);
264284

265285
private:
266-
DisplayList(uint8_t* ptr,
286+
DisplayList(DisplayListStorage&& ptr,
267287
size_t byte_count,
268288
unsigned int op_count,
269289
size_t nested_byte_count,
@@ -272,10 +292,7 @@ class DisplayList : public SkRefCnt {
272292
bool can_apply_group_opacity,
273293
sk_sp<const DlRTree> rtree);
274294

275-
struct SkFreeDeleter {
276-
void operator()(uint8_t* p) { sk_free(p); }
277-
};
278-
std::unique_ptr<uint8_t, SkFreeDeleter> storage_;
295+
DisplayListStorage storage_;
279296
size_t byte_count_;
280297
unsigned int op_count_;
281298

display_list/display_list_builder.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ sk_sp<DisplayList> DisplayListBuilder::Build() {
6161
nested_bytes_ = nested_op_count_ = 0;
6262
storage_.realloc(bytes);
6363
bool compatible = layer_stack_.back().is_group_opacity_compatible();
64-
return sk_sp<DisplayList>(new DisplayList(storage_.release(), bytes, count,
64+
return sk_sp<DisplayList>(new DisplayList(std::move(storage_), bytes, count,
6565
nested_bytes, nested_count,
6666
bounds(), compatible, rtree()));
6767
}

display_list/display_list_builder.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ class DisplayListBuilder final : public virtual Dispatcher,
362362
private:
363363
void checkForDeferredSave();
364364

365-
SkAutoTMalloc<uint8_t> storage_;
365+
DisplayListStorage storage_;
366366
size_t used_ = 0;
367367
size_t allocated_ = 0;
368368
int op_count_ = 0;

0 commit comments

Comments
 (0)