Skip to content

Commit

Permalink
Add DlRegion class
Browse files Browse the repository at this point in the history
  • Loading branch information
knopp committed May 29, 2023
1 parent 456aa79 commit 3422516
Show file tree
Hide file tree
Showing 7 changed files with 551 additions and 0 deletions.
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ group("flutter") {
public_deps += [
"//flutter/display_list:display_list_benchmarks",
"//flutter/display_list:display_list_builder_benchmarks",
"//flutter/display_list:display_list_region_benchmarks",
"//flutter/fml:fml_benchmarks",
"//flutter/impeller/geometry:geometry_benchmarks",
"//flutter/lib/ui:ui_benchmarks",
Expand Down
6 changes: 6 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ ORIGIN: ../../../flutter/display_list/benchmarking/dl_complexity_gl.h + ../../..
ORIGIN: ../../../flutter/display_list/benchmarking/dl_complexity_helper.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/display_list/benchmarking/dl_complexity_metal.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/display_list/benchmarking/dl_complexity_metal.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/display_list/benchmarking/dl_region_benchmarks.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/display_list/display_list.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/display_list/display_list.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/display_list/dl_attributes.h + ../../../flutter/LICENSE
Expand Down Expand Up @@ -748,6 +749,8 @@ ORIGIN: ../../../flutter/display_list/effects/dl_path_effect.cc + ../../../flutt
ORIGIN: ../../../flutter/display_list/effects/dl_path_effect.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/display_list/effects/dl_runtime_effect.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/display_list/effects/dl_runtime_effect.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/display_list/geometry/dl_region.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/display_list/geometry/dl_region.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/display_list/geometry/dl_rtree.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/display_list/geometry/dl_rtree.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/display_list/image/dl_image.cc + ../../../flutter/LICENSE
Expand Down Expand Up @@ -3371,6 +3374,7 @@ FILE: ../../../flutter/display_list/benchmarking/dl_complexity_gl.h
FILE: ../../../flutter/display_list/benchmarking/dl_complexity_helper.h
FILE: ../../../flutter/display_list/benchmarking/dl_complexity_metal.cc
FILE: ../../../flutter/display_list/benchmarking/dl_complexity_metal.h
FILE: ../../../flutter/display_list/benchmarking/dl_region_benchmarks.cc
FILE: ../../../flutter/display_list/display_list.cc
FILE: ../../../flutter/display_list/display_list.h
FILE: ../../../flutter/display_list/dl_attributes.h
Expand Down Expand Up @@ -3405,6 +3409,8 @@ FILE: ../../../flutter/display_list/effects/dl_path_effect.cc
FILE: ../../../flutter/display_list/effects/dl_path_effect.h
FILE: ../../../flutter/display_list/effects/dl_runtime_effect.cc
FILE: ../../../flutter/display_list/effects/dl_runtime_effect.h
FILE: ../../../flutter/display_list/geometry/dl_region.cc
FILE: ../../../flutter/display_list/geometry/dl_region.h
FILE: ../../../flutter/display_list/geometry/dl_rtree.cc
FILE: ../../../flutter/display_list/geometry/dl_rtree.h
FILE: ../../../flutter/display_list/image/dl_image.cc
Expand Down
15 changes: 15 additions & 0 deletions display_list/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ source_set("display_list") {
"effects/dl_path_effect.h",
"effects/dl_runtime_effect.cc",
"effects/dl_runtime_effect.h",
"geometry/dl_region.cc",
"geometry/dl_region.h",
"geometry/dl_rtree.cc",
"geometry/dl_rtree.h",
"image/dl_image.cc",
Expand Down Expand Up @@ -112,6 +114,7 @@ if (enable_unittests) {
"effects/dl_image_filter_unittests.cc",
"effects/dl_mask_filter_unittests.cc",
"effects/dl_path_effect_unittests.cc",
"geometry/dl_region_unittests.cc",
"geometry/dl_rtree_unittests.cc",
"skia/dl_sk_conversions_unittests.cc",
"skia/dl_sk_paint_dispatcher_unittests.cc",
Expand Down Expand Up @@ -181,6 +184,18 @@ if (enable_unittests) {
"//flutter/testing:testing_lib",
]
}

executable("display_list_region_benchmarks") {
testonly = true

sources = [ "benchmarking/dl_region_benchmarks.cc" ]

deps = [
":display_list_fixtures",
"//flutter/benchmarking",
"//flutter/testing:testing_lib",
]
}
}

fixtures_location("display_list_benchmarks_fixtures") {
Expand Down
77 changes: 77 additions & 0 deletions display_list/benchmarking/dl_region_benchmarks.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/benchmarking/benchmarking.h"

#include "flutter/display_list/geometry/dl_region.h"
#include "third_party/skia/include/core/SkRegion.h"

#include <random>

class SkRegionAdapter {
public:
void addRect(const SkIRect& rect) { region_.op(rect, SkRegion::kUnion_Op); }

std::vector<SkIRect> getRects() {
std::vector<SkIRect> rects;
SkRegion::Iterator it(region_);
while (!it.done()) {
rects.push_back(it.rect());
it.next();
}
return rects;
}

private:
SkRegion region_;
};

template <typename Region>
void RunRegionBenchmark(benchmark::State& state, int maxSize) {
while (state.KeepRunning()) {
std::random_device d;
std::seed_seq seed{2, 1, 3};
std::mt19937 rng(seed);

std::uniform_int_distribution pos(0, 4000);
std::uniform_int_distribution size(1, maxSize);

Region region;

for (int i = 0; i < 2000; ++i) {
SkIRect rect =
SkIRect::MakeXYWH(pos(rng), pos(rng), size(rng), size(rng));
region.addRect(rect);
}

auto vec2 = region.getRects();
}
}

namespace flutter {

static void BM_RegionBenchmarkSkRegion(benchmark::State& state, int maxSize) {
RunRegionBenchmark<SkRegionAdapter>(state, maxSize);
}

static void BM_RegionBenchmarkDlRegion(benchmark::State& state, int maxSize) {
RunRegionBenchmark<DlRegion>(state, maxSize);
}

BENCHMARK_CAPTURE(BM_RegionBenchmarkDlRegion, Small, 100)
->Unit(benchmark::kMicrosecond);
BENCHMARK_CAPTURE(BM_RegionBenchmarkSkRegion, Small, 100)
->Unit(benchmark::kMicrosecond);

BENCHMARK_CAPTURE(BM_RegionBenchmarkDlRegion, Medium, 400)
->Unit(benchmark::kMicrosecond);
BENCHMARK_CAPTURE(BM_RegionBenchmarkSkRegion, Medium, 400)
->Unit(benchmark::kMicrosecond);

BENCHMARK_CAPTURE(BM_RegionBenchmarkDlRegion, Large, 1500)
->Unit(benchmark::kMicrosecond);
BENCHMARK_CAPTURE(BM_RegionBenchmarkSkRegion, Large, 1500)
->Unit(benchmark::kMicrosecond);

} // namespace flutter

0 comments on commit 3422516

Please sign in to comment.