Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate DlRTree and DlRegion to DisplayList/Impeller geometry classes #57175

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions display_list/benchmarking/dl_builder_benchmarks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ static void BM_DisplayListDispatchByVectorDefault(
DlOpReceiverIgnore receiver;
while (state.KeepRunning()) {
std::vector<DlIndex> indices =
display_list->GetCulledIndices(display_list->bounds());
display_list->GetCulledIndices(display_list->GetBounds());
for (DlIndex index : indices) {
display_list->Dispatch(receiver, index);
}
Expand Down Expand Up @@ -299,8 +299,8 @@ static void BM_DisplayListDispatchByVectorCull(
InvokeAllOps(builder);
}
auto display_list = builder.Build();
SkRect rect = SkRect::MakeLTRB(0, 0, 100, 100);
EXPECT_FALSE(rect.contains(display_list->bounds()));
DlRect rect = DlRect::MakeLTRB(0, 0, 100, 100);
EXPECT_FALSE(rect.Contains(display_list->GetBounds()));
DlOpReceiverIgnore receiver;
while (state.KeepRunning()) {
std::vector<DlIndex> indices = display_list->GetCulledIndices(rect);
Expand Down
81 changes: 44 additions & 37 deletions display_list/benchmarking/dl_region_benchmarks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,54 @@

namespace {

using DlIRect = flutter::DlIRect;

template <typename RNG>
std::vector<SkIRect> GenerateRects(RNG& rng,
const SkIRect& bounds,
std::vector<DlIRect> GenerateRects(RNG& rng,
const DlIRect& bounds,
int numRects,
int maxSize) {
auto max_size_x = std::min(maxSize, bounds.width());
auto max_size_y = std::min(maxSize, bounds.height());
auto max_size_x = std::min(maxSize, bounds.GetWidth());
auto max_size_y = std::min(maxSize, bounds.GetHeight());

std::uniform_int_distribution pos_x(bounds.fLeft, bounds.fRight - max_size_x);
std::uniform_int_distribution pos_y(bounds.fTop, bounds.fBottom - max_size_y);
std::uniform_int_distribution pos_x(bounds.GetLeft(),
bounds.GetRight() - max_size_x);
std::uniform_int_distribution pos_y(bounds.GetTop(),
bounds.GetBottom() - max_size_y);
std::uniform_int_distribution size_x(1, max_size_x);
std::uniform_int_distribution size_y(1, max_size_y);

std::vector<SkIRect> rects;
std::vector<DlIRect> rects;
for (int i = 0; i < numRects; ++i) {
SkIRect rect =
SkIRect::MakeXYWH(pos_x(rng), pos_y(rng), size_x(rng), size_y(rng));
DlIRect rect =
DlIRect::MakeXYWH(pos_x(rng), pos_y(rng), size_x(rng), size_y(rng));
rects.push_back(rect);
}
return rects;
}

template <typename RNG>
SkIRect RandomSubRect(RNG& rng, const SkIRect& rect, double size_factor) {
DlIRect RandomSubRect(RNG& rng, const DlIRect& rect, double size_factor) {
FML_DCHECK(size_factor <= 1);

int32_t width = rect.width() * size_factor;
int32_t height = rect.height() * size_factor;
int32_t width = rect.GetWidth() * size_factor;
int32_t height = rect.GetHeight() * size_factor;

std::uniform_int_distribution pos_x(0, rect.width() - width);
std::uniform_int_distribution pos_y(0, rect.height() - height);
std::uniform_int_distribution pos_x(0, rect.GetWidth() - width);
std::uniform_int_distribution pos_y(0, rect.GetHeight() - height);

return SkIRect::MakeXYWH(rect.fLeft + pos_x(rng), rect.fTop + pos_y(rng),
return DlIRect::MakeXYWH(rect.GetLeft() + pos_x(rng),
rect.GetTop() + pos_y(rng), //
width, height);
}

class SkRegionAdapter {
public:
explicit SkRegionAdapter(const std::vector<SkIRect>& rects) {
region_.setRects(rects.data(), rects.size());
explicit SkRegionAdapter(const std::vector<DlIRect>& rects) {
region_.setRects(flutter::ToSkIRects(rects.data()), rects.size());
}

SkIRect getBounds() { return region_.getBounds(); }
DlIRect getBounds() { return flutter::ToDlIRect(region_.getBounds()); }

static SkRegionAdapter unionRegions(const SkRegionAdapter& a1,
const SkRegionAdapter& a2) {
Expand All @@ -74,13 +79,15 @@ class SkRegionAdapter {
return region_.intersects(region.region_);
}

bool intersects(const SkIRect& rect) { return region_.intersects(rect); }
bool intersects(const DlIRect& rect) {
return region_.intersects(flutter::ToSkIRect(rect));
}

std::vector<SkIRect> getRects() {
std::vector<SkIRect> rects;
std::vector<DlIRect> getRects() {
std::vector<DlIRect> rects;
SkRegion::Iterator it(region_);
while (!it.done()) {
rects.push_back(it.rect());
rects.push_back(flutter::ToDlIRect(it.rect()));
it.next();
}
return rects;
Expand All @@ -92,7 +99,7 @@ class SkRegionAdapter {

class DlRegionAdapter {
public:
explicit DlRegionAdapter(const std::vector<SkIRect>& rects)
explicit DlRegionAdapter(const std::vector<DlIRect>& rects)
: region_(rects) {}

static DlRegionAdapter unionRegions(const DlRegionAdapter& a1,
Expand All @@ -107,15 +114,15 @@ class DlRegionAdapter {
flutter::DlRegion::MakeIntersection(a1.region_, a2.region_));
}

SkIRect getBounds() { return region_.bounds(); }
DlIRect getBounds() { return region_.bounds(); }

bool intersects(const DlRegionAdapter& region) {
return region_.intersects(region.region_);
}

bool intersects(const SkIRect& rect) { return region_.intersects(rect); }
bool intersects(const DlIRect& rect) { return region_.intersects(rect); }

std::vector<SkIRect> getRects() { return region_.getRects(false); }
std::vector<DlIRect> getRects() { return region_.getRects(false); }

private:
explicit DlRegionAdapter(flutter::DlRegion&& region)
Expand All @@ -133,9 +140,9 @@ void RunFromRectsBenchmark(benchmark::State& state, int maxSize) {
std::uniform_int_distribution pos(0, 4000);
std::uniform_int_distribution size(1, maxSize);

std::vector<SkIRect> rects;
std::vector<DlIRect> rects;
for (int i = 0; i < 2000; ++i) {
SkIRect rect = SkIRect::MakeXYWH(pos(rng), pos(rng), size(rng), size(rng));
DlIRect rect = DlIRect::MakeXYWH(pos(rng), pos(rng), size(rng), size(rng));
rects.push_back(rect);
}

Expand All @@ -153,9 +160,9 @@ void RunGetRectsBenchmark(benchmark::State& state, int maxSize) {
std::uniform_int_distribution pos(0, 4000);
std::uniform_int_distribution size(1, maxSize);

std::vector<SkIRect> rects;
std::vector<DlIRect> rects;
for (int i = 0; i < 2000; ++i) {
SkIRect rect = SkIRect::MakeXYWH(pos(rng), pos(rng), size(rng), size(rng));
DlIRect rect = DlIRect::MakeXYWH(pos(rng), pos(rng), size(rng), size(rng));
rects.push_back(rect);
}

Expand All @@ -178,8 +185,8 @@ void RunRegionOpBenchmark(benchmark::State& state,
std::seed_seq seed{2, 1, 3};
std::mt19937 rng(seed);

SkIRect bounds1 = SkIRect::MakeWH(4000, 4000);
SkIRect bounds2 = RandomSubRect(rng, bounds1, sizeFactor);
DlIRect bounds1 = DlIRect::MakeWH(4000, 4000);
DlIRect bounds2 = RandomSubRect(rng, bounds1, sizeFactor);

auto rects = GenerateRects(rng, bounds1, 500, maxSize);
Region region1(rects);
Expand Down Expand Up @@ -210,8 +217,8 @@ void RunIntersectsRegionBenchmark(benchmark::State& state,
std::seed_seq seed{2, 1, 3};
std::mt19937 rng(seed);

SkIRect bounds1 = SkIRect::MakeWH(4000, 4000);
SkIRect bounds2 = RandomSubRect(rng, bounds1, sizeFactor);
DlIRect bounds1 = DlIRect::MakeWH(4000, 4000);
DlIRect bounds2 = RandomSubRect(rng, bounds1, sizeFactor);

auto rects = GenerateRects(rng, bounds1, 500, maxSize);
Region region1(rects);
Expand All @@ -233,16 +240,16 @@ void RunIntersectsSingleRectBenchmark(benchmark::State& state, int maxSize) {
std::uniform_int_distribution pos(0, 4000);
std::uniform_int_distribution size(1, maxSize);

std::vector<SkIRect> rects;
std::vector<DlIRect> rects;
for (int i = 0; i < 500; ++i) {
SkIRect rect = SkIRect::MakeXYWH(pos(rng), pos(rng), size(rng), size(rng));
DlIRect rect = DlIRect::MakeXYWH(pos(rng), pos(rng), size(rng), size(rng));
rects.push_back(rect);
}
Region region1(rects);

rects.clear();
for (int i = 0; i < 100; ++i) {
SkIRect rect = SkIRect::MakeXYWH(pos(rng), pos(rng), size(rng), size(rng));
DlIRect rect = DlIRect::MakeXYWH(pos(rng), pos(rng), size(rng), size(rng));
rects.push_back(rect);
}

Expand Down
17 changes: 8 additions & 9 deletions display_list/display_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ DisplayList::DisplayList()
nested_op_count_(0),
total_depth_(0),
unique_id_(0),
bounds_({0, 0, 0, 0}),
can_apply_group_opacity_(true),
is_ui_thread_safe_(true),
modifies_transparent_black_(false),
Expand All @@ -37,7 +36,7 @@ DisplayList::DisplayList(DisplayListStorage&& storage,
size_t nested_byte_count,
uint32_t nested_op_count,
uint32_t total_depth,
const SkRect& bounds,
const DlRect& bounds,
bool can_apply_group_opacity,
bool is_ui_thread_safe,
bool modifies_transparent_black,
Expand Down Expand Up @@ -187,16 +186,16 @@ void DisplayList::Dispatch(DlOpReceiver& receiver) const {
}

void DisplayList::Dispatch(DlOpReceiver& receiver,
const SkIRect& cull_rect) const {
Dispatch(receiver, SkRect::Make(cull_rect));
const DlIRect& cull_rect) const {
Dispatch(receiver, DlRect::Make(cull_rect));
}

void DisplayList::Dispatch(DlOpReceiver& receiver,
const SkRect& cull_rect) const {
if (cull_rect.isEmpty()) {
const DlRect& cull_rect) const {
if (cull_rect.IsEmpty()) {
return;
}
if (!has_rtree() || cull_rect.contains(bounds())) {
if (!has_rtree() || cull_rect.Contains(GetBounds())) {
Dispatch(receiver);
} else {
auto op_indices = GetCulledIndices(cull_rect);
Expand Down Expand Up @@ -366,9 +365,9 @@ static void FillAllIndices(std::vector<DlIndex>& indices, DlIndex size) {
}

std::vector<DlIndex> DisplayList::GetCulledIndices(
const SkRect& cull_rect) const {
const DlRect& cull_rect) const {
std::vector<DlIndex> indices;
if (!cull_rect.isEmpty()) {
if (!cull_rect.IsEmpty()) {
if (rtree_) {
std::vector<int> rect_indices;
rtree_->search(cull_rect, &rect_indices);
Expand Down
20 changes: 13 additions & 7 deletions display_list/display_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,14 @@ class DisplayList : public SkRefCnt {
~DisplayList();

void Dispatch(DlOpReceiver& ctx) const;
void Dispatch(DlOpReceiver& ctx, const SkRect& cull_rect) const;
void Dispatch(DlOpReceiver& ctx, const SkIRect& cull_rect) const;
void Dispatch(DlOpReceiver& ctx, const SkRect& cull_rect) const {
Dispatch(ctx, ToDlRect(cull_rect));
}
void Dispatch(DlOpReceiver& ctx, const SkIRect& cull_rect) const {
Dispatch(ctx, ToDlIRect(cull_rect));
}
void Dispatch(DlOpReceiver& ctx, const DlRect& cull_rect) const;
void Dispatch(DlOpReceiver& ctx, const DlIRect& cull_rect) const;

// From historical behavior, SkPicture always included nested bytes,
// but nested ops are only included if requested. The defaults used
Expand All @@ -290,8 +296,8 @@ class DisplayList : public SkRefCnt {

uint32_t unique_id() const { return unique_id_; }

const SkRect& bounds() const { return bounds_; }
const DlRect& GetBounds() const { return ToDlRect(bounds_); }
const SkRect& bounds() const { return ToSkRect(bounds_); }
const DlRect& GetBounds() const { return bounds_; }

bool has_rtree() const { return rtree_ != nullptr; }
sk_sp<const DlRTree> rtree() const { return rtree_; }
Expand Down Expand Up @@ -500,7 +506,7 @@ class DisplayList : public SkRefCnt {
/// primarily for debugging use
///
/// @see |Dispatch(receiver, index)|
std::vector<DlIndex> GetCulledIndices(const SkRect& cull_rect) const;
std::vector<DlIndex> GetCulledIndices(const DlRect& cull_rect) const;

private:
DisplayList(DisplayListStorage&& ptr,
Expand All @@ -509,7 +515,7 @@ class DisplayList : public SkRefCnt {
size_t nested_byte_count,
uint32_t nested_op_count,
uint32_t total_depth,
const SkRect& bounds,
const DlRect& bounds,
bool can_apply_group_opacity,
bool is_ui_thread_safe,
bool modifies_transparent_black,
Expand All @@ -533,7 +539,7 @@ class DisplayList : public SkRefCnt {
const uint32_t total_depth_;

const uint32_t unique_id_;
const SkRect bounds_;
const DlRect bounds_;

const bool can_apply_group_opacity_;
const bool is_ui_thread_safe_;
Expand Down
Loading
Loading