skia2/tests/graphite/IntersectionTreeTest.cpp
Chris Dalton 2fceb21cb7 [graphite] Add an IntersectionTree class
Implements a BSP tree with NEON/SSE optimizations that tracks
non-overlapping regions. This object can be used batch sets of paths
into non-overlapping draws. Performance on AppleM1 with our existing
benchmarks looks very promising:

    desk_motionmarkarcs.skp     1227 paths -> 69 draws    450us
    desk_motionmarksuits.skp    1417 paths -> 26 draws    201us
    desk_chalkboard.skp         1940 paths -> 11 draws     84us
    desk_ynevsvg.skp             859 paths -> 10 draws     31us
    desk_micrographygirl.skp     318 paths -> 29 draws     11us

Bug: skia:12466
Change-Id: I847a93ed726dea10cb403cb76e578bd81eb920d2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/460298
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Herb Derby <herb@google.com>
2021-10-19 19:45:01 +00:00

76 lines
2.5 KiB
C++

/*
* Copyright 2021 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "experimental/graphite/src/geom/IntersectionTree.h"
#include "include/utils/SkRandom.h"
#include "tests/Test.h"
namespace skgpu {
class SimpleIntersectionTree {
public:
bool add(SkRect rect) {
for (const SkRect& r : fRects) {
if (r.intersects(rect)) {
return false;
}
}
fRects.push_back(rect);
return true;
}
private:
std::vector<SkRect> fRects;
};
#define CHECK(A) REPORTER_ASSERT(reporter, A)
DEF_GRAPHITE_TEST(skgpu_IntersectionTree, reporter) {
SkRandom rand;
{
SimpleIntersectionTree simpleTree;
IntersectionTree tree;
for (int i = 0; i < 1000; ++i) {
Rect rect = Rect::XYWH(rand.nextRangeF(0, 500),
rand.nextRangeF(0, 500),
rand.nextRangeF(0, 70),
rand.nextRangeF(0, 70));
CHECK(tree.add(rect) == simpleTree.add({rect.left(),
rect.top(),
rect.right(),
rect.bot()}));
}
}
{
SimpleIntersectionTree simpleTree;
IntersectionTree tree;
for (int i = 0; i < 100; ++i) {
Rect rect = Rect::XYWH(rand.nextRangeF(0, 500),
rand.nextRangeF(0, 500),
rand.nextRangeF(0, 200),
rand.nextRangeF(0, 200));
CHECK(tree.add(rect) == simpleTree.add({rect.left(),
rect.top(),
rect.right(),
rect.bot()}));
}
}
{
SimpleIntersectionTree simpleTree;
IntersectionTree tree;
CHECK(tree.add(Rect(float2(-std::numeric_limits<float>::infinity()),
float2(std::numeric_limits<float>::infinity()))));
CHECK(!tree.add(Rect::WH(1,1)));
CHECK(!tree.add(Rect::WH(1,std::numeric_limits<float>::infinity())));
CHECK(tree.add(Rect::WH(0, 0)));
CHECK(tree.add(Rect::WH(-1, 1)));
CHECK(tree.add(Rect::WH(1, std::numeric_limits<float>::quiet_NaN())));
}
}
} // namespace skgpu