skia2/tests/GpuRectanizerTest.cpp
Herb Derby 73c75877bd Reland "Specialize SkRectanzier to SkRectanizerSkyline"
This is a reland of 77e1f84a84

Original change's description:
> Specialize SkRectanzier to SkRectanizerSkyline
> 
> It looks like the pow2 rectanizer has never been used. Remove
> the unneeded abstraction for rectanizer everywhere.
> 
> Change-Id: Iba33f1c6faf37201d03928ce8409751c212480a0
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/265983
> Commit-Queue: Herb Derby <herb@google.com>
> Reviewed-by: Mike Klein <mtklein@google.com>

Change-Id: I09729ba2b0e4b8b1a229fef4b95e65195b33fdc7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/266180
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
2020-01-23 15:28:26 +00:00

60 lines
1.8 KiB
C++

/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/core/SkSize.h"
#include "include/private/SkTDArray.h"
#include "include/utils/SkRandom.h"
#include "src/gpu/GrRectanizerSkyline.h"
#include "tests/Test.h"
static const int kWidth = 1024;
static const int kHeight = 1024;
// Basic test of a GrRectanizer-derived class' functionality
static void test_rectanizer_basic(skiatest::Reporter* reporter, GrRectanizerSkyline* rectanizer) {
REPORTER_ASSERT(reporter, kWidth == rectanizer->width());
REPORTER_ASSERT(reporter, kHeight == rectanizer->height());
SkIPoint16 loc;
REPORTER_ASSERT(reporter, rectanizer->addRect(50, 50, &loc));
rectanizer->reset();
}
static void test_rectanizer_inserts(skiatest::Reporter*,
GrRectanizerSkyline* rectanizer,
const SkTDArray<SkISize>& rects) {
int i;
for (i = 0; i < rects.count(); ++i) {
SkIPoint16 loc;
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);
}
DEF_GPUTEST(GpuRectanizer, reporter, factory) {
SkTDArray<SkISize> rects;
SkRandom rand;
for (int i = 0; i < 50; i++) {
rects.push_back(SkISize::Make(rand.nextRangeU(1, kWidth / 2),
rand.nextRangeU(1, kHeight / 2)));
}
test_skyline(reporter, rects);
}