blob: ed4e4039ecfb72e7eac7443e3be8abde028b8e65 [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
11#if SK_SUPPORT_GPU
12
13#include "GrWindowRectangles.h"
Brian Salomonc7fe0f72018-05-11 10:14:21 -040014#include "SkRandom.h"
Mike Reed274218e2018-01-08 15:05:02 -050015#include "SkRectPriv.h"
csmartdalton28341fa2016-08-17 10:00:21 -070016
17static SkIRect next_irect(SkRandom& r) {
18 return {r.nextS(), r.nextS(), r.nextS(), r.nextS()};
19}
20
21DEF_TEST(WindowRectangles, reporter) {
22 SkRandom r;
23
24 SkIRect windowData[GrWindowRectangles::kMaxWindows];
25 for (int i = 0; i < GrWindowRectangles::kMaxWindows; ++i) {
26 windowData[i] = next_irect(r);
27 }
28
29 GrWindowRectangles wr;
30 for (int i = 0; i < GrWindowRectangles::kMaxWindows - 1; ++i) {
31 REPORTER_ASSERT(reporter, wr.count() == i);
32 REPORTER_ASSERT(reporter, !memcmp(wr.data(), windowData, i * sizeof(SkIRect)));
33
34 GrWindowRectangles wr2(wr);
35 REPORTER_ASSERT(reporter, wr2 == wr);
csmartdalton28341fa2016-08-17 10:00:21 -070036 REPORTER_ASSERT(reporter, wr2.count() == wr.count());
37 REPORTER_ASSERT(reporter, !memcmp(wr2.data(), wr.data(), i * sizeof(SkIRect)));
38
39 wr.addWindow(windowData[i]);
40 }
41
42 SkASSERT(wr.count() == GrWindowRectangles::kMaxWindows - 1);
43 {
44 GrWindowRectangles A(wr), B(wr);
45 REPORTER_ASSERT(reporter, B == A);
46 REPORTER_ASSERT(reporter, B.data() == A.data()); // Should use copy-on-write.
47
48 A.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]);
49 REPORTER_ASSERT(reporter, B.data() != A.data());
50 REPORTER_ASSERT(reporter, B != A);
51
Mike Reed8008df12018-01-17 12:20:04 -050052 B.addWindow(SkRectPriv::MakeILarge());
csmartdalton28341fa2016-08-17 10:00:21 -070053 REPORTER_ASSERT(reporter, B != A);
54
55 REPORTER_ASSERT(reporter, !memcmp(A.data(), windowData,
56 GrWindowRectangles::kMaxWindows * sizeof(SkIRect)));
57 REPORTER_ASSERT(reporter, !memcmp(B.data(), windowData,
58 (GrWindowRectangles::kMaxWindows - 1) * sizeof(SkIRect)));
59 REPORTER_ASSERT(reporter,
Mike Reed8008df12018-01-17 12:20:04 -050060 B.data()[GrWindowRectangles::kMaxWindows - 1] == SkRectPriv::MakeILarge());
csmartdalton28341fa2016-08-17 10:00:21 -070061 }
62 {
63 GrWindowRectangles A(wr), B(wr);
64 REPORTER_ASSERT(reporter, B == A);
65 REPORTER_ASSERT(reporter, B.data() == A.data()); // Should use copy-on-write.
66
67 A.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]);
68 B.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]);
69 REPORTER_ASSERT(reporter, B == A);
70 REPORTER_ASSERT(reporter, B.data() != A.data());
71 REPORTER_ASSERT(reporter, !memcmp(B.data(), A.data(),
72 GrWindowRectangles::kMaxWindows * sizeof(SkIRect)));
73 REPORTER_ASSERT(reporter, !memcmp(A.data(), windowData,
74 GrWindowRectangles::kMaxWindows * sizeof(SkIRect)));
75 }
csmartdalton28341fa2016-08-17 10:00:21 -070076}
77
78#endif