2014-05-29 18:46:38 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/private/SkTDArray.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
2020-05-19 17:57:53 +00:00
|
|
|
#include "src/gpu/GrRectanizerPow2.h"
|
2020-01-22 23:09:16 +00:00
|
|
|
#include "src/gpu/GrRectanizerSkyline.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
2014-05-29 18:46:38 +00:00
|
|
|
|
2014-06-05 14:18:03 +00:00
|
|
|
static const int kWidth = 1024;
|
|
|
|
static const int kHeight = 1024;
|
2014-05-29 18:46:38 +00:00
|
|
|
|
|
|
|
// Basic test of a GrRectanizer-derived class' functionality
|
2020-05-19 17:57:53 +00:00
|
|
|
static void test_rectanizer_basic(skiatest::Reporter* reporter, GrRectanizer* rectanizer) {
|
2014-05-29 18:46:38 +00:00
|
|
|
REPORTER_ASSERT(reporter, kWidth == rectanizer->width());
|
|
|
|
REPORTER_ASSERT(reporter, kHeight == rectanizer->height());
|
|
|
|
|
2014-06-02 17:20:14 +00:00
|
|
|
SkIPoint16 loc;
|
2014-05-29 18:46:38 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, rectanizer->addRect(50, 50, &loc));
|
2020-05-19 17:57:53 +00:00
|
|
|
REPORTER_ASSERT(reporter, rectanizer->percentFull() > 0.0f);
|
2014-05-29 18:46:38 +00:00
|
|
|
rectanizer->reset();
|
2020-05-19 17:57:53 +00:00
|
|
|
REPORTER_ASSERT(reporter, rectanizer->percentFull() == 0.0f);
|
2014-05-29 18:46:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_rectanizer_inserts(skiatest::Reporter*,
|
2020-05-19 17:57:53 +00:00
|
|
|
GrRectanizer* rectanizer,
|
2014-05-29 18:46:38 +00:00
|
|
|
const SkTDArray<SkISize>& rects) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < rects.count(); ++i) {
|
2014-06-02 17:20:14 +00:00
|
|
|
SkIPoint16 loc;
|
2014-05-29 18:46:38 +00:00
|
|
|
if (!rectanizer->addRect(rects[i].fWidth, rects[i].fHeight, &loc)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//SkDebugf("\n***%d %f\n", i, rectanizer->percentFull());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_skyline(skiatest::Reporter* reporter, const SkTDArray<SkISize>& rects) {
|
|
|
|
GrRectanizerSkyline skylineRectanizer(kWidth, kHeight);
|
|
|
|
|
|
|
|
test_rectanizer_basic(reporter, &skylineRectanizer);
|
|
|
|
test_rectanizer_inserts(reporter, &skylineRectanizer, rects);
|
|
|
|
}
|
|
|
|
|
2020-05-19 17:57:53 +00:00
|
|
|
static void test_pow2(skiatest::Reporter* reporter, const SkTDArray<SkISize>& rects) {
|
|
|
|
GrRectanizerPow2 pow2Rectanizer(kWidth, kHeight);
|
|
|
|
|
|
|
|
test_rectanizer_basic(reporter, &pow2Rectanizer);
|
|
|
|
test_rectanizer_inserts(reporter, &pow2Rectanizer, rects);
|
|
|
|
}
|
|
|
|
|
2014-05-29 18:46:38 +00:00
|
|
|
DEF_GPUTEST(GpuRectanizer, reporter, factory) {
|
2014-06-05 14:18:03 +00:00
|
|
|
SkTDArray<SkISize> rects;
|
2014-05-29 18:46:38 +00:00
|
|
|
SkRandom rand;
|
|
|
|
|
|
|
|
for (int i = 0; i < 50; i++) {
|
2018-08-08 15:23:41 +00:00
|
|
|
rects.push_back(SkISize::Make(rand.nextRangeU(1, kWidth / 2),
|
|
|
|
rand.nextRangeU(1, kHeight / 2)));
|
2014-05-29 18:46:38 +00:00
|
|
|
}
|
|
|
|
|
2014-06-05 14:18:03 +00:00
|
|
|
test_skyline(reporter, rects);
|
2020-05-19 17:57:53 +00:00
|
|
|
test_pow2(reporter, rects);
|
2014-05-29 18:46:38 +00:00
|
|
|
}
|