c7ad40f76f
Most of this is (obviously) not necessary to do, but once I started, I figured I'd just get it all. Tools (nanobench, DM, skiaserve), all GMs, benches, and unit tests, plus support code (command line parsing and config stuff). This is almost entirely mechanical. Bug: skia: Change-Id: I209500f8df8c5bd43f8298ff26440d1c4d7425fb Reviewed-on: https://skia-review.googlesource.com/131153 Reviewed-by: Mike Klein <mtklein@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
71 lines
2.2 KiB
C++
71 lines
2.2 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 "GrRectanizer_pow2.h"
|
|
#include "GrRectanizer_skyline.h"
|
|
#include "SkRandom.h"
|
|
#include "SkSize.h"
|
|
#include "SkTDArray.h"
|
|
#include "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, GrRectanizer* rectanizer) {
|
|
REPORTER_ASSERT(reporter, kWidth == rectanizer->width());
|
|
REPORTER_ASSERT(reporter, kHeight == rectanizer->height());
|
|
|
|
SkIPoint16 loc;
|
|
|
|
REPORTER_ASSERT(reporter, rectanizer->addRect(50, 50, &loc));
|
|
REPORTER_ASSERT(reporter, rectanizer->percentFull() > 0.0f);
|
|
rectanizer->reset();
|
|
REPORTER_ASSERT(reporter, rectanizer->percentFull() == 0.0f);
|
|
}
|
|
|
|
static void test_rectanizer_inserts(skiatest::Reporter*,
|
|
GrRectanizer* 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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
DEF_GPUTEST(GpuRectanizer, reporter, factory) {
|
|
SkTDArray<SkISize> rects;
|
|
SkRandom rand;
|
|
|
|
for (int i = 0; i < 50; i++) {
|
|
rects.push(SkISize::Make(rand.nextRangeU(1, kWidth / 2),
|
|
rand.nextRangeU(1, kHeight / 2)));
|
|
}
|
|
|
|
test_skyline(reporter, rects);
|
|
test_pow2(reporter, rects);
|
|
}
|