skia2/tests/MipMapTest.cpp
commit-bot@chromium.org 6485b0be74 Switch out random number generator for tests, benches, samples.
This change makes tests, benches and samples use the new SkMWCRandom PRNG. GMs will be saved for another time, as they'll require rebaselining.

R=reed@google.com, bsalomon@google.com

Author: jvanverth@google.com

Review URL: https://chromiumcodereview.appspot.com/23653018

git-svn-id: http://skia.googlecode.com/svn/trunk@11136 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-06 19:05:11 +00:00

60 lines
1.9 KiB
C++

/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "Test.h"
#include "SkMipMap.h"
#include "SkBitmap.h"
#include "SkRandom.h"
static void make_bitmap(SkBitmap* bm, SkMWCRandom& rand) {
// for now, Build needs a min size of 2, otherwise it will return NULL.
// should fix that to support 1 X N, where N > 1 to return non-null.
int w = 2 + rand.nextU() % 1000;
int h = 2 + rand.nextU() % 1000;
bm->setConfig(SkBitmap::kARGB_8888_Config, w, h);
bm->allocPixels();
bm->eraseColor(SK_ColorWHITE);
}
static void TestMipMap(skiatest::Reporter* reporter) {
SkBitmap bm;
SkMWCRandom rand;
for (int i = 0; i < 500; ++i) {
make_bitmap(&bm, rand);
SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm));
REPORTER_ASSERT(reporter, !mm->extractLevel(SK_Scalar1, NULL));
REPORTER_ASSERT(reporter, !mm->extractLevel(SK_Scalar1 * 2, NULL));
SkMipMap::Level prevLevel;
sk_bzero(&prevLevel, sizeof(prevLevel));
SkScalar scale = SK_Scalar1;
for (int j = 0; j < 30; ++j) {
scale = scale * 2 / 3;
SkMipMap::Level level;
if (mm->extractLevel(scale, &level)) {
REPORTER_ASSERT(reporter, level.fPixels);
REPORTER_ASSERT(reporter, level.fWidth > 0);
REPORTER_ASSERT(reporter, level.fHeight > 0);
REPORTER_ASSERT(reporter, level.fRowBytes >= level.fWidth * 4);
if (prevLevel.fPixels) {
REPORTER_ASSERT(reporter, level.fWidth <= prevLevel.fWidth);
REPORTER_ASSERT(reporter, level.fHeight <= prevLevel.fHeight);
}
prevLevel = level;
}
}
}
}
#include "TestClassDef.h"
DEFINE_TESTCLASS("MipMap", MipMapTestClass, TestMipMap)