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