csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 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(SkIRect))); |
| 31 | |
| 32 | GrWindowRectangles wr2(wr); |
| 33 | REPORTER_ASSERT(reporter, wr2 == wr); |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 34 | REPORTER_ASSERT(reporter, wr2.count() == wr.count()); |
| 35 | REPORTER_ASSERT(reporter, !memcmp(wr2.data(), wr.data(), i * sizeof(SkIRect))); |
| 36 | |
| 37 | wr.addWindow(windowData[i]); |
| 38 | } |
| 39 | |
| 40 | SkASSERT(wr.count() == GrWindowRectangles::kMaxWindows - 1); |
| 41 | { |
| 42 | GrWindowRectangles A(wr), B(wr); |
| 43 | REPORTER_ASSERT(reporter, B == A); |
| 44 | REPORTER_ASSERT(reporter, B.data() == A.data()); // Should use copy-on-write. |
| 45 | |
| 46 | A.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]); |
| 47 | REPORTER_ASSERT(reporter, B.data() != A.data()); |
| 48 | REPORTER_ASSERT(reporter, B != A); |
| 49 | |
| 50 | B.addWindow(SkIRect::MakeLargest()); |
| 51 | REPORTER_ASSERT(reporter, B != A); |
| 52 | |
| 53 | REPORTER_ASSERT(reporter, !memcmp(A.data(), windowData, |
| 54 | GrWindowRectangles::kMaxWindows * sizeof(SkIRect))); |
| 55 | REPORTER_ASSERT(reporter, !memcmp(B.data(), windowData, |
| 56 | (GrWindowRectangles::kMaxWindows - 1) * sizeof(SkIRect))); |
| 57 | REPORTER_ASSERT(reporter, |
| 58 | B.data()[GrWindowRectangles::kMaxWindows - 1] == SkIRect::MakeLargest()); |
| 59 | } |
| 60 | { |
| 61 | GrWindowRectangles A(wr), B(wr); |
| 62 | REPORTER_ASSERT(reporter, B == A); |
| 63 | REPORTER_ASSERT(reporter, B.data() == A.data()); // Should use copy-on-write. |
| 64 | |
| 65 | A.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]); |
| 66 | B.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]); |
| 67 | REPORTER_ASSERT(reporter, B == A); |
| 68 | REPORTER_ASSERT(reporter, B.data() != A.data()); |
| 69 | REPORTER_ASSERT(reporter, !memcmp(B.data(), A.data(), |
| 70 | GrWindowRectangles::kMaxWindows * sizeof(SkIRect))); |
| 71 | REPORTER_ASSERT(reporter, !memcmp(A.data(), windowData, |
| 72 | GrWindowRectangles::kMaxWindows * sizeof(SkIRect))); |
| 73 | } |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | #endif |