blob: 8a911303fcf0e4a0337cc1669f6dd605af9d57c4 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkTypes.h"
9#include "tests/Test.h"
csmartdalton28341fa2016-08-17 10:00:21 -070010
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/utils/SkRandom.h"
12#include "src/core/SkRectPriv.h"
13#include "src/gpu/GrWindowRectangles.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}