OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "SkTypes.h" |
| 9 #include "Test.h" |
| 10 |
| 11 #if SK_SUPPORT_GPU |
| 12 |
| 13 #include "GrCaps.h" |
| 14 #include "GrWindowRectangles.h" |
| 15 |
| 16 class WinRectTestCaps : public GrCaps { |
| 17 public: |
| 18 constexpr int static kMaxWindows = 8; |
| 19 WinRectTestCaps() : GrCaps(GrContextOptions()) { fMaxWindowRectangles = kMax
Windows; } |
| 20 private: |
| 21 bool isConfigTexturable(GrPixelConfig) const override { return false; } |
| 22 bool isConfigRenderable(GrPixelConfig, bool) const override { return false;
} |
| 23 }; |
| 24 |
| 25 static SkIRect next_irect(SkRandom& r) { |
| 26 return {r.nextS(), r.nextS(), r.nextS(), r.nextS()}; |
| 27 } |
| 28 |
| 29 DEF_TEST(WindowRectangles, reporter) { |
| 30 WinRectTestCaps caps; |
| 31 SkRandom r; |
| 32 |
| 33 SkIRect windowData[WinRectTestCaps::kMaxWindows]; |
| 34 for (int i = 0; i < WinRectTestCaps::kMaxWindows; ++i) { |
| 35 windowData[i] = next_irect(r); |
| 36 } |
| 37 |
| 38 GrWindowRectangles wr; |
| 39 for (int i = 0; i < WinRectTestCaps::kMaxWindows - 1; ++i) { |
| 40 REPORTER_ASSERT(reporter, wr.count() == i); |
| 41 REPORTER_ASSERT(reporter, !memcmp(wr.data(), windowData, i * sizeof(SkIR
ect))); |
| 42 |
| 43 GrWindowRectangles wr2(wr); |
| 44 REPORTER_ASSERT(reporter, wr2 == wr); |
| 45 REPORTER_ASSERT(reporter, wr2.mode() == wr.mode()); |
| 46 REPORTER_ASSERT(reporter, wr2.count() == wr.count()); |
| 47 REPORTER_ASSERT(reporter, !memcmp(wr2.data(), wr.data(), i * sizeof(SkIR
ect))); |
| 48 |
| 49 wr.addWindow(windowData[i], caps); |
| 50 } |
| 51 |
| 52 SkASSERT(wr.count() == WinRectTestCaps::kMaxWindows - 1); |
| 53 { |
| 54 GrWindowRectangles A(wr), B(wr); |
| 55 REPORTER_ASSERT(reporter, B == A); |
| 56 REPORTER_ASSERT(reporter, B.data() == A.data()); // Should use copy-on-w
rite. |
| 57 |
| 58 A.addWindow(windowData[WinRectTestCaps::kMaxWindows - 1], caps); |
| 59 REPORTER_ASSERT(reporter, B.data() != A.data()); |
| 60 REPORTER_ASSERT(reporter, B != A); |
| 61 |
| 62 B.addWindow(SkIRect::MakeLargest(), caps); |
| 63 REPORTER_ASSERT(reporter, B != A); |
| 64 |
| 65 REPORTER_ASSERT(reporter, !memcmp(A.data(), windowData, |
| 66 WinRectTestCaps::kMaxWindows * sizeof(
SkIRect))); |
| 67 REPORTER_ASSERT(reporter, !memcmp(B.data(), windowData, |
| 68 (WinRectTestCaps::kMaxWindows - 1) * s
izeof(SkIRect))); |
| 69 REPORTER_ASSERT(reporter, |
| 70 B.data()[WinRectTestCaps::kMaxWindows - 1] == SkIRect::M
akeLargest()); |
| 71 } |
| 72 { |
| 73 GrWindowRectangles A(wr), B(wr); |
| 74 REPORTER_ASSERT(reporter, B == A); |
| 75 REPORTER_ASSERT(reporter, B.data() == A.data()); // Should use copy-on-w
rite. |
| 76 |
| 77 A.addWindow(windowData[WinRectTestCaps::kMaxWindows - 1], caps); |
| 78 B.addWindow(windowData[WinRectTestCaps::kMaxWindows - 1], caps); |
| 79 REPORTER_ASSERT(reporter, B == A); |
| 80 REPORTER_ASSERT(reporter, B.data() != A.data()); |
| 81 REPORTER_ASSERT(reporter, !memcmp(B.data(), A.data(), |
| 82 WinRectTestCaps::kMaxWindows * sizeof(
SkIRect))); |
| 83 REPORTER_ASSERT(reporter, !memcmp(A.data(), windowData, |
| 84 WinRectTestCaps::kMaxWindows * sizeof(
SkIRect))); |
| 85 } |
| 86 |
| 87 GrWindowRectangles wrI(GrWindowRectangles::Mode::kInclusive); |
| 88 for (int i = 0; i < wr.count(); ++i) { |
| 89 wrI.addWindow(windowData[i], caps); |
| 90 } |
| 91 REPORTER_ASSERT(reporter, wrI != wr); |
| 92 REPORTER_ASSERT(reporter, wrI.mode() != wr.mode()); |
| 93 REPORTER_ASSERT(reporter, wrI.count() == wr.count()); |
| 94 REPORTER_ASSERT(reporter, !memcmp(wrI.data(), wr.data(), wr.count() * sizeof
(SkIRect))); |
| 95 |
| 96 wr.reset(GrWindowRectangles::Mode::kInclusive); |
| 97 for (int i = 0; i < wrI.count(); ++i) { |
| 98 wr.addWindow(windowData[i], caps); |
| 99 } |
| 100 REPORTER_ASSERT(reporter, wrI == wr); |
| 101 } |
| 102 |
| 103 #endif |
OLD | NEW |