GpuRectanizerTest.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #include "include/core/SkSize.h"
  8. #include "include/private/SkTDArray.h"
  9. #include "include/utils/SkRandom.h"
  10. #include "src/gpu/GrRectanizer_pow2.h"
  11. #include "src/gpu/GrRectanizer_skyline.h"
  12. #include "tests/Test.h"
  13. static const int kWidth = 1024;
  14. static const int kHeight = 1024;
  15. // Basic test of a GrRectanizer-derived class' functionality
  16. static void test_rectanizer_basic(skiatest::Reporter* reporter, GrRectanizer* rectanizer) {
  17. REPORTER_ASSERT(reporter, kWidth == rectanizer->width());
  18. REPORTER_ASSERT(reporter, kHeight == rectanizer->height());
  19. SkIPoint16 loc;
  20. REPORTER_ASSERT(reporter, rectanizer->addRect(50, 50, &loc));
  21. REPORTER_ASSERT(reporter, rectanizer->percentFull() > 0.0f);
  22. rectanizer->reset();
  23. REPORTER_ASSERT(reporter, rectanizer->percentFull() == 0.0f);
  24. }
  25. static void test_rectanizer_inserts(skiatest::Reporter*,
  26. GrRectanizer* rectanizer,
  27. const SkTDArray<SkISize>& rects) {
  28. int i;
  29. for (i = 0; i < rects.count(); ++i) {
  30. SkIPoint16 loc;
  31. if (!rectanizer->addRect(rects[i].fWidth, rects[i].fHeight, &loc)) {
  32. break;
  33. }
  34. }
  35. //SkDebugf("\n***%d %f\n", i, rectanizer->percentFull());
  36. }
  37. static void test_skyline(skiatest::Reporter* reporter, const SkTDArray<SkISize>& rects) {
  38. GrRectanizerSkyline skylineRectanizer(kWidth, kHeight);
  39. test_rectanizer_basic(reporter, &skylineRectanizer);
  40. test_rectanizer_inserts(reporter, &skylineRectanizer, rects);
  41. }
  42. static void test_pow2(skiatest::Reporter* reporter, const SkTDArray<SkISize>& rects) {
  43. GrRectanizerPow2 pow2Rectanizer(kWidth, kHeight);
  44. test_rectanizer_basic(reporter, &pow2Rectanizer);
  45. test_rectanizer_inserts(reporter, &pow2Rectanizer, rects);
  46. }
  47. DEF_GPUTEST(GpuRectanizer, reporter, factory) {
  48. SkTDArray<SkISize> rects;
  49. SkRandom rand;
  50. for (int i = 0; i < 50; i++) {
  51. rects.push_back(SkISize::Make(rand.nextRangeU(1, kWidth / 2),
  52. rand.nextRangeU(1, kHeight / 2)));
  53. }
  54. test_skyline(reporter, rects);
  55. test_pow2(reporter, rects);
  56. }