blob: e592d47018a14f74912f46ba9b884d8bacd8d2e7 [file] [log] [blame]
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +00001/*
2* Copyright 2014 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/SkSize.h"
9#include "include/private/SkTDArray.h"
10#include "include/utils/SkRandom.h"
Herb Derby73c75872020-01-22 18:09:16 -050011#include "src/gpu/GrRectanizerSkyline.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "tests/Test.h"
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +000013
robertphillipsc2fce562014-06-05 07:18:03 -070014static const int kWidth = 1024;
15static const int kHeight = 1024;
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +000016
17// Basic test of a GrRectanizer-derived class' functionality
Herb Derby73c75872020-01-22 18:09:16 -050018static void test_rectanizer_basic(skiatest::Reporter* reporter, GrRectanizerSkyline* rectanizer) {
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +000019 REPORTER_ASSERT(reporter, kWidth == rectanizer->width());
20 REPORTER_ASSERT(reporter, kHeight == rectanizer->height());
21
robertphillipsd5373412014-06-02 10:20:14 -070022 SkIPoint16 loc;
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +000023
24 REPORTER_ASSERT(reporter, rectanizer->addRect(50, 50, &loc));
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +000025 rectanizer->reset();
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +000026}
27
28static void test_rectanizer_inserts(skiatest::Reporter*,
Herb Derby73c75872020-01-22 18:09:16 -050029 GrRectanizerSkyline* rectanizer,
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +000030 const SkTDArray<SkISize>& rects) {
31 int i;
32 for (i = 0; i < rects.count(); ++i) {
robertphillipsd5373412014-06-02 10:20:14 -070033 SkIPoint16 loc;
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +000034 if (!rectanizer->addRect(rects[i].fWidth, rects[i].fHeight, &loc)) {
35 break;
36 }
37 }
38
39 //SkDebugf("\n***%d %f\n", i, rectanizer->percentFull());
40}
41
42static void test_skyline(skiatest::Reporter* reporter, const SkTDArray<SkISize>& rects) {
43 GrRectanizerSkyline skylineRectanizer(kWidth, kHeight);
44
45 test_rectanizer_basic(reporter, &skylineRectanizer);
46 test_rectanizer_inserts(reporter, &skylineRectanizer, rects);
47}
48
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +000049DEF_GPUTEST(GpuRectanizer, reporter, factory) {
robertphillipsc2fce562014-06-05 07:18:03 -070050 SkTDArray<SkISize> rects;
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +000051 SkRandom rand;
52
53 for (int i = 0; i < 50; i++) {
Mike Reed5edcd312018-08-08 11:23:41 -040054 rects.push_back(SkISize::Make(rand.nextRangeU(1, kWidth / 2),
55 rand.nextRangeU(1, kHeight / 2)));
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +000056 }
57
robertphillipsc2fce562014-06-05 07:18:03 -070058 test_skyline(reporter, rects);
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +000059}