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" |
| 11 | #include "src/gpu/GrRectanizer_pow2.h" |
| 12 | #include "src/gpu/GrRectanizer_skyline.h" |
| 13 | #include "tests/Test.h" |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 14 | |
robertphillips | c2fce56 | 2014-06-05 07:18:03 -0700 | [diff] [blame] | 15 | static const int kWidth = 1024; |
| 16 | static const int kHeight = 1024; |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 17 | |
| 18 | // Basic test of a GrRectanizer-derived class' functionality |
| 19 | static void test_rectanizer_basic(skiatest::Reporter* reporter, GrRectanizer* rectanizer) { |
| 20 | REPORTER_ASSERT(reporter, kWidth == rectanizer->width()); |
| 21 | REPORTER_ASSERT(reporter, kHeight == rectanizer->height()); |
| 22 | |
robertphillips | d537341 | 2014-06-02 10:20:14 -0700 | [diff] [blame] | 23 | SkIPoint16 loc; |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 24 | |
| 25 | REPORTER_ASSERT(reporter, rectanizer->addRect(50, 50, &loc)); |
| 26 | REPORTER_ASSERT(reporter, rectanizer->percentFull() > 0.0f); |
| 27 | rectanizer->reset(); |
| 28 | REPORTER_ASSERT(reporter, rectanizer->percentFull() == 0.0f); |
| 29 | } |
| 30 | |
| 31 | static void test_rectanizer_inserts(skiatest::Reporter*, |
| 32 | GrRectanizer* rectanizer, |
| 33 | const SkTDArray<SkISize>& rects) { |
| 34 | int i; |
| 35 | for (i = 0; i < rects.count(); ++i) { |
robertphillips | d537341 | 2014-06-02 10:20:14 -0700 | [diff] [blame] | 36 | SkIPoint16 loc; |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 37 | if (!rectanizer->addRect(rects[i].fWidth, rects[i].fHeight, &loc)) { |
| 38 | break; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | //SkDebugf("\n***%d %f\n", i, rectanizer->percentFull()); |
| 43 | } |
| 44 | |
| 45 | static void test_skyline(skiatest::Reporter* reporter, const SkTDArray<SkISize>& rects) { |
| 46 | GrRectanizerSkyline skylineRectanizer(kWidth, kHeight); |
| 47 | |
| 48 | test_rectanizer_basic(reporter, &skylineRectanizer); |
| 49 | test_rectanizer_inserts(reporter, &skylineRectanizer, rects); |
| 50 | } |
| 51 | |
| 52 | static void test_pow2(skiatest::Reporter* reporter, const SkTDArray<SkISize>& rects) { |
| 53 | GrRectanizerPow2 pow2Rectanizer(kWidth, kHeight); |
| 54 | |
| 55 | test_rectanizer_basic(reporter, &pow2Rectanizer); |
| 56 | test_rectanizer_inserts(reporter, &pow2Rectanizer, rects); |
| 57 | } |
| 58 | |
| 59 | DEF_GPUTEST(GpuRectanizer, reporter, factory) { |
robertphillips | c2fce56 | 2014-06-05 07:18:03 -0700 | [diff] [blame] | 60 | SkTDArray<SkISize> rects; |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 61 | SkRandom rand; |
| 62 | |
| 63 | for (int i = 0; i < 50; i++) { |
Mike Reed | 5edcd31 | 2018-08-08 11:23:41 -0400 | [diff] [blame] | 64 | rects.push_back(SkISize::Make(rand.nextRangeU(1, kWidth / 2), |
| 65 | rand.nextRangeU(1, kHeight / 2))); |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 66 | } |
| 67 | |
robertphillips | c2fce56 | 2014-06-05 07:18:03 -0700 | [diff] [blame] | 68 | test_skyline(reporter, rects); |
| 69 | test_pow2(reporter, rects); |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 70 | } |