blob: 2c2531bc0786e4d1e6ed69d33bfbc5ca06a16c60 [file] [log] [blame]
csmartdalton28341fa2016-08-17 10:00:21 -07001/*
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
csmartdalton28341fa2016-08-17 10:00:21 -070011#include "GrWindowRectangles.h"
Brian Salomonc7fe0f72018-05-11 10:14:21 -040012#include "SkRandom.h"
Mike Reed274218e2018-01-08 15:05:02 -050013#include "SkRectPriv.h"
csmartdalton28341fa2016-08-17 10:00:21 -070014
15static SkIRect next_irect(SkRandom& r) {
16 return {r.nextS(), r.nextS(), r.nextS(), r.nextS()};
17}
18
19DEF_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);
csmartdalton28341fa2016-08-17 10:00:21 -070034 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
Mike Reed8008df12018-01-17 12:20:04 -050050 B.addWindow(SkRectPriv::MakeILarge());
csmartdalton28341fa2016-08-17 10:00:21 -070051 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,
Mike Reed8008df12018-01-17 12:20:04 -050058 B.data()[GrWindowRectangles::kMaxWindows - 1] == SkRectPriv::MakeILarge());
csmartdalton28341fa2016-08-17 10:00:21 -070059 }
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 }
csmartdalton28341fa2016-08-17 10:00:21 -070074}