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 "GrWindowRectangles.h" |
| 14 |
| 15 static SkIRect next_irect(SkRandom& r) { |
| 16 return {r.nextS(), r.nextS(), r.nextS(), r.nextS()}; |
| 17 } |
| 18 |
| 19 DEF_TEST(WindowRectangles, reporter) { |
| 20 SkRandom r; |
| 21 |
| 22 SkIRect windowData[GrWindowRectangles::kMaxWindows]; |
| 23 for (int i = 0; i < GrWindowRectangles::kMaxWindows; ++i) { |
| 24 windowData[i] = next_irect(r); |
| 25 } |
| 26 |
| 27 GrWindowRectangles wr; |
| 28 for (int i = 0; i < GrWindowRectangles::kMaxWindows - 1; ++i) { |
| 29 REPORTER_ASSERT(reporter, wr.count() == i); |
| 30 REPORTER_ASSERT(reporter, !memcmp(wr.data(), windowData, i * sizeof(SkIR
ect))); |
| 31 |
| 32 GrWindowRectangles wr2(wr); |
| 33 REPORTER_ASSERT(reporter, wr2 == wr); |
| 34 REPORTER_ASSERT(reporter, wr2.mode() == wr.mode()); |
| 35 REPORTER_ASSERT(reporter, wr2.count() == wr.count()); |
| 36 REPORTER_ASSERT(reporter, !memcmp(wr2.data(), wr.data(), i * sizeof(SkIR
ect))); |
| 37 |
| 38 wr.addWindow(windowData[i]); |
| 39 } |
| 40 |
| 41 SkASSERT(wr.count() == GrWindowRectangles::kMaxWindows - 1); |
| 42 { |
| 43 GrWindowRectangles A(wr), B(wr); |
| 44 REPORTER_ASSERT(reporter, B == A); |
| 45 REPORTER_ASSERT(reporter, B.data() == A.data()); // Should use copy-on-w
rite. |
| 46 |
| 47 A.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]); |
| 48 REPORTER_ASSERT(reporter, B.data() != A.data()); |
| 49 REPORTER_ASSERT(reporter, B != A); |
| 50 |
| 51 B.addWindow(SkIRect::MakeLargest()); |
| 52 REPORTER_ASSERT(reporter, B != A); |
| 53 |
| 54 REPORTER_ASSERT(reporter, !memcmp(A.data(), windowData, |
| 55 GrWindowRectangles::kMaxWindows * size
of(SkIRect))); |
| 56 REPORTER_ASSERT(reporter, !memcmp(B.data(), windowData, |
| 57 (GrWindowRectangles::kMaxWindows - 1)
* sizeof(SkIRect))); |
| 58 REPORTER_ASSERT(reporter, |
| 59 B.data()[GrWindowRectangles::kMaxWindows - 1] == SkIRect
::MakeLargest()); |
| 60 } |
| 61 { |
| 62 GrWindowRectangles A(wr), B(wr); |
| 63 REPORTER_ASSERT(reporter, B == A); |
| 64 REPORTER_ASSERT(reporter, B.data() == A.data()); // Should use copy-on-w
rite. |
| 65 |
| 66 A.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]); |
| 67 B.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]); |
| 68 REPORTER_ASSERT(reporter, B == A); |
| 69 REPORTER_ASSERT(reporter, B.data() != A.data()); |
| 70 REPORTER_ASSERT(reporter, !memcmp(B.data(), A.data(), |
| 71 GrWindowRectangles::kMaxWindows * size
of(SkIRect))); |
| 72 REPORTER_ASSERT(reporter, !memcmp(A.data(), windowData, |
| 73 GrWindowRectangles::kMaxWindows * size
of(SkIRect))); |
| 74 } |
| 75 |
| 76 GrWindowRectangles wrI(GrWindowRectangles::Mode::kInclusive); |
| 77 for (int i = 0; i < wr.count(); ++i) { |
| 78 wrI.addWindow(windowData[i]); |
| 79 } |
| 80 REPORTER_ASSERT(reporter, wrI != wr); |
| 81 REPORTER_ASSERT(reporter, wrI.mode() != wr.mode()); |
| 82 REPORTER_ASSERT(reporter, wrI.count() == wr.count()); |
| 83 REPORTER_ASSERT(reporter, !memcmp(wrI.data(), wr.data(), wr.count() * sizeof
(SkIRect))); |
| 84 |
| 85 wr.reset(GrWindowRectangles::Mode::kInclusive); |
| 86 for (int i = 0; i < wrI.count(); ++i) { |
| 87 wr.addWindow(windowData[i]); |
| 88 } |
| 89 REPORTER_ASSERT(reporter, wrI == wr); |
| 90 } |
| 91 |
| 92 #endif |
OLD | NEW |