1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2016 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#include "include/core/SkTypes.h" 9cb93a386Sopenharmony_ci#include "tests/Test.h" 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ci#include "include/utils/SkRandom.h" 12cb93a386Sopenharmony_ci#include "src/core/SkRectPriv.h" 13cb93a386Sopenharmony_ci#include "src/gpu/GrWindowRectangles.h" 14cb93a386Sopenharmony_ci 15cb93a386Sopenharmony_cistatic SkIRect next_irect(SkRandom& r) { 16cb93a386Sopenharmony_ci return {r.nextS(), r.nextS(), r.nextS(), r.nextS()}; 17cb93a386Sopenharmony_ci} 18cb93a386Sopenharmony_ci 19cb93a386Sopenharmony_ciDEF_TEST(WindowRectangles, reporter) { 20cb93a386Sopenharmony_ci SkRandom r; 21cb93a386Sopenharmony_ci 22cb93a386Sopenharmony_ci SkIRect windowData[GrWindowRectangles::kMaxWindows]; 23cb93a386Sopenharmony_ci for (int i = 0; i < GrWindowRectangles::kMaxWindows; ++i) { 24cb93a386Sopenharmony_ci windowData[i] = next_irect(r); 25cb93a386Sopenharmony_ci } 26cb93a386Sopenharmony_ci 27cb93a386Sopenharmony_ci GrWindowRectangles wr; 28cb93a386Sopenharmony_ci for (int i = 0; i < GrWindowRectangles::kMaxWindows - 1; ++i) { 29cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, wr.count() == i); 30cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !memcmp(wr.data(), windowData, i * sizeof(SkIRect))); 31cb93a386Sopenharmony_ci 32cb93a386Sopenharmony_ci GrWindowRectangles wr2(wr); 33cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, wr2 == wr); 34cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, wr2.count() == wr.count()); 35cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !memcmp(wr2.data(), wr.data(), i * sizeof(SkIRect))); 36cb93a386Sopenharmony_ci 37cb93a386Sopenharmony_ci wr.addWindow(windowData[i]); 38cb93a386Sopenharmony_ci } 39cb93a386Sopenharmony_ci 40cb93a386Sopenharmony_ci SkASSERT(wr.count() == GrWindowRectangles::kMaxWindows - 1); 41cb93a386Sopenharmony_ci { 42cb93a386Sopenharmony_ci GrWindowRectangles A(wr), B(wr); 43cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, B == A); 44cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, B.data() == A.data()); // Should use copy-on-write. 45cb93a386Sopenharmony_ci 46cb93a386Sopenharmony_ci A.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]); 47cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, B.data() != A.data()); 48cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, B != A); 49cb93a386Sopenharmony_ci 50cb93a386Sopenharmony_ci B.addWindow(SkRectPriv::MakeILarge()); 51cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, B != A); 52cb93a386Sopenharmony_ci 53cb93a386Sopenharmony_ci for (int i = 0; i < GrWindowRectangles::kMaxWindows - 1; i++) { 54cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, A.data()[i] == windowData[i]); 55cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, B.data()[i] == windowData[i]); 56cb93a386Sopenharmony_ci } 57cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, A.data()[GrWindowRectangles::kMaxWindows - 1] 58cb93a386Sopenharmony_ci == windowData[GrWindowRectangles::kMaxWindows - 1]); 59cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, B.data()[GrWindowRectangles::kMaxWindows - 1] 60cb93a386Sopenharmony_ci == SkRectPriv::MakeILarge()); 61cb93a386Sopenharmony_ci } 62cb93a386Sopenharmony_ci { 63cb93a386Sopenharmony_ci GrWindowRectangles A(wr), B(wr); 64cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, B == A); 65cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, B.data() == A.data()); // Should use copy-on-write. 66cb93a386Sopenharmony_ci 67cb93a386Sopenharmony_ci A.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]); 68cb93a386Sopenharmony_ci B.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]); 69cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, B == A); 70cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, B.data() != A.data()); 71cb93a386Sopenharmony_ci 72cb93a386Sopenharmony_ci for (int i = 0; i < GrWindowRectangles::kMaxWindows; i++) { 73cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, B.data()[i] == A.data()[i]); 74cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, A.data()[i] == windowData[i]); 75cb93a386Sopenharmony_ci } 76cb93a386Sopenharmony_ci } 77cb93a386Sopenharmony_ci} 78