blob: d6c4756168533224b193e3c303dacfad4e426e67 [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"
Mike Reed274218e2018-01-08 15:05:02 -050014#include "SkRectPriv.h"
csmartdalton28341fa2016-08-17 10:00:21 -070015
16static SkIRect next_irect(SkRandom& r) {
17 return {r.nextS(), r.nextS(), r.nextS(), r.nextS()};
18}
19
20DEF_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);
csmartdalton28341fa2016-08-17 10:00:21 -070035 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
Mike Reed8008df12018-01-17 12:20:04 -050051 B.addWindow(SkRectPriv::MakeILarge());
csmartdalton28341fa2016-08-17 10:00:21 -070052 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,
Mike Reed8008df12018-01-17 12:20:04 -050059 B.data()[GrWindowRectangles::kMaxWindows - 1] == SkRectPriv::MakeILarge());
csmartdalton28341fa2016-08-17 10:00:21 -070060 }
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 }
csmartdalton28341fa2016-08-17 10:00:21 -070075}
76
77#endif