skia2/tests/WindowRectanglesTest.cpp
csmartdalton 28341fad84 Implement difference clip rects with window rectangles
Plumbs the pipeline for window rectangles and uses them for a very
basic implementation of difference clip rects. This puts a common
Blink pattern on fast path, but we will still eventually need to make
more comprehensive use of window rectangles during clipping.

GTX 960 perf result:
                              gpu                     glinst4                 glinst16
desk_jsfiddlebigcar.skp       0.254 -> 0.177 [70%]    0.279 -> 0.197 [71%]    0.577 -> 0.196 [34%]
keymobi_sfgate_com_.skp       0.697 -> 0.513 [74%]    0.766 -> 0.451 [59%]    0.769 -> 0.597 [78%]
keymobi_blogger.skp           0.406 -> 0.314 [77%]    0.436 -> 0.292 [67%]    0.696 -> 0.319 [46%]
desk_pokemonwiki.skp          0.121 -> 0.098 [81%]     0.13 -> 0.105 [81%]    0.216 -> 0.097 [45%]
desk_wikipedia.skp            0.121 -> 0.098 [81%]     0.13 -> 0.104 [80%]    0.199 -> 0.104 [52%]
keymobi_androidpolice_co...   0.443 -> 0.382 [86%]    0.447 -> 0.398 [89%]    0.444 -> 0.396 [89%]
keymobi_booking_com_sear...   1 .15 ->  1.03 [90%]     1.17 ->  1.06 [91%]     1.17 ->  1.05 [90%]
keymobi_theverge_com.skp      0.417 -> 0.396 [95%]    0.426 -> 0.405 [95%]    0.429 ->   0.4 [93%]

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2251573002

Review-Url: https://codereview.chromium.org/2251573002
2016-08-17 10:00:22 -07:00

93 lines
3.4 KiB
C++

/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTypes.h"
#include "Test.h"
#if SK_SUPPORT_GPU
#include "GrWindowRectangles.h"
static SkIRect next_irect(SkRandom& r) {
return {r.nextS(), r.nextS(), r.nextS(), r.nextS()};
}
DEF_TEST(WindowRectangles, reporter) {
SkRandom r;
SkIRect windowData[GrWindowRectangles::kMaxWindows];
for (int i = 0; i < GrWindowRectangles::kMaxWindows; ++i) {
windowData[i] = next_irect(r);
}
GrWindowRectangles wr;
for (int i = 0; i < GrWindowRectangles::kMaxWindows - 1; ++i) {
REPORTER_ASSERT(reporter, wr.count() == i);
REPORTER_ASSERT(reporter, !memcmp(wr.data(), windowData, i * sizeof(SkIRect)));
GrWindowRectangles wr2(wr);
REPORTER_ASSERT(reporter, wr2 == wr);
REPORTER_ASSERT(reporter, wr2.mode() == wr.mode());
REPORTER_ASSERT(reporter, wr2.count() == wr.count());
REPORTER_ASSERT(reporter, !memcmp(wr2.data(), wr.data(), i * sizeof(SkIRect)));
wr.addWindow(windowData[i]);
}
SkASSERT(wr.count() == GrWindowRectangles::kMaxWindows - 1);
{
GrWindowRectangles A(wr), B(wr);
REPORTER_ASSERT(reporter, B == A);
REPORTER_ASSERT(reporter, B.data() == A.data()); // Should use copy-on-write.
A.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]);
REPORTER_ASSERT(reporter, B.data() != A.data());
REPORTER_ASSERT(reporter, B != A);
B.addWindow(SkIRect::MakeLargest());
REPORTER_ASSERT(reporter, B != A);
REPORTER_ASSERT(reporter, !memcmp(A.data(), windowData,
GrWindowRectangles::kMaxWindows * sizeof(SkIRect)));
REPORTER_ASSERT(reporter, !memcmp(B.data(), windowData,
(GrWindowRectangles::kMaxWindows - 1) * sizeof(SkIRect)));
REPORTER_ASSERT(reporter,
B.data()[GrWindowRectangles::kMaxWindows - 1] == SkIRect::MakeLargest());
}
{
GrWindowRectangles A(wr), B(wr);
REPORTER_ASSERT(reporter, B == A);
REPORTER_ASSERT(reporter, B.data() == A.data()); // Should use copy-on-write.
A.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]);
B.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]);
REPORTER_ASSERT(reporter, B == A);
REPORTER_ASSERT(reporter, B.data() != A.data());
REPORTER_ASSERT(reporter, !memcmp(B.data(), A.data(),
GrWindowRectangles::kMaxWindows * sizeof(SkIRect)));
REPORTER_ASSERT(reporter, !memcmp(A.data(), windowData,
GrWindowRectangles::kMaxWindows * sizeof(SkIRect)));
}
GrWindowRectangles wrI(GrWindowRectangles::Mode::kInclusive);
for (int i = 0; i < wr.count(); ++i) {
wrI.addWindow(windowData[i]);
}
REPORTER_ASSERT(reporter, wrI != wr);
REPORTER_ASSERT(reporter, wrI.mode() != wr.mode());
REPORTER_ASSERT(reporter, wrI.count() == wr.count());
REPORTER_ASSERT(reporter, !memcmp(wrI.data(), wr.data(), wr.count() * sizeof(SkIRect)));
wr.reset(GrWindowRectangles::Mode::kInclusive);
for (int i = 0; i < wrI.count(); ++i) {
wr.addWindow(windowData[i]);
}
REPORTER_ASSERT(reporter, wrI == wr);
}
#endif