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 #include "SkRectPriv.h" 15 16 static SkIRect next_irect(SkRandom& r) { 17 return {r.nextS(), r.nextS(), r.nextS(), r.nextS()}; 18 } 19 20 DEF_TEST(WindowRectangles, reporter) { 21 SkRandom r; 22 23 SkIRect windowData[GrWindowRectangles::kMaxWindows]; 24 for (int i = 0; i < GrWindowRectangles::kMaxWindows; ++i) { 25 windowData[i] = next_irect(r); 26 } 27 28 GrWindowRectangles wr; 29 for (int i = 0; i < GrWindowRectangles::kMaxWindows - 1; ++i) { 30 REPORTER_ASSERT(reporter, wr.count() == i); 31 REPORTER_ASSERT(reporter, !memcmp(wr.data(), windowData, i * sizeof(SkIRect))); 32 33 GrWindowRectangles wr2(wr); 34 REPORTER_ASSERT(reporter, wr2 == wr); 35 REPORTER_ASSERT(reporter, wr2.count() == wr.count()); 36 REPORTER_ASSERT(reporter, !memcmp(wr2.data(), wr.data(), i * sizeof(SkIRect))); 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-write. 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(SkRectPriv::MakeILarge()); 52 REPORTER_ASSERT(reporter, B != A); 53 54 REPORTER_ASSERT(reporter, !memcmp(A.data(), windowData, 55 GrWindowRectangles::kMaxWindows * sizeof(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] == SkRectPriv::MakeILarge()); 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-write. 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 * sizeof(SkIRect))); 72 REPORTER_ASSERT(reporter, !memcmp(A.data(), windowData, 73 GrWindowRectangles::kMaxWindows * sizeof(SkIRect))); 74 } 75 } 76 77 #endif 78