commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkSize.h" |
| 9 | #include "include/private/SkTDArray.h" |
| 10 | #include "include/utils/SkRandom.h" |
Herb Derby | 73c7587 | 2020-01-22 18:09:16 -0500 | [diff] [blame] | 11 | #include "src/gpu/GrRectanizerSkyline.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "tests/Test.h" |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 13 | |
robertphillips | c2fce56 | 2014-06-05 07:18:03 -0700 | [diff] [blame] | 14 | static const int kWidth = 1024; |
| 15 | static const int kHeight = 1024; |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 16 | |
| 17 | // Basic test of a GrRectanizer-derived class' functionality |
Herb Derby | 73c7587 | 2020-01-22 18:09:16 -0500 | [diff] [blame] | 18 | static void test_rectanizer_basic(skiatest::Reporter* reporter, GrRectanizerSkyline* rectanizer) { |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 19 | REPORTER_ASSERT(reporter, kWidth == rectanizer->width()); |
| 20 | REPORTER_ASSERT(reporter, kHeight == rectanizer->height()); |
| 21 | |
robertphillips | d537341 | 2014-06-02 10:20:14 -0700 | [diff] [blame] | 22 | SkIPoint16 loc; |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 23 | |
| 24 | REPORTER_ASSERT(reporter, rectanizer->addRect(50, 50, &loc)); |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 25 | rectanizer->reset(); |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | static void test_rectanizer_inserts(skiatest::Reporter*, |
Herb Derby | 73c7587 | 2020-01-22 18:09:16 -0500 | [diff] [blame] | 29 | GrRectanizerSkyline* rectanizer, |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 30 | const SkTDArray<SkISize>& rects) { |
| 31 | int i; |
| 32 | for (i = 0; i < rects.count(); ++i) { |
robertphillips | d537341 | 2014-06-02 10:20:14 -0700 | [diff] [blame] | 33 | SkIPoint16 loc; |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 34 | 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 | |
| 42 | static 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.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 49 | DEF_GPUTEST(GpuRectanizer, reporter, factory) { |
robertphillips | c2fce56 | 2014-06-05 07:18:03 -0700 | [diff] [blame] | 50 | SkTDArray<SkISize> rects; |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 51 | SkRandom rand; |
| 52 | |
| 53 | for (int i = 0; i < 50; i++) { |
Mike Reed | 5edcd31 | 2018-08-08 11:23:41 -0400 | [diff] [blame] | 54 | rects.push_back(SkISize::Make(rand.nextRangeU(1, kWidth / 2), |
| 55 | rand.nextRangeU(1, kHeight / 2))); |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 56 | } |
| 57 | |
robertphillips | c2fce56 | 2014-06-05 07:18:03 -0700 | [diff] [blame] | 58 | test_skyline(reporter, rects); |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 59 | } |