2013-07-18 19:53:31 +00:00
|
|
|
/*
|
|
|
|
* 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 "SkBitmap.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "SkMipMap.h"
|
2013-07-18 19:53:31 +00:00
|
|
|
#include "SkRandom.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "Test.h"
|
2013-07-18 19:53:31 +00:00
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
static void make_bitmap(SkBitmap* bm, SkRandom& rand) {
|
2013-07-18 19:53:31 +00:00
|
|
|
// 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;
|
2014-02-13 14:41:43 +00:00
|
|
|
bm->allocN32Pixels(w, h);
|
2013-07-18 19:53:31 +00:00
|
|
|
bm->eraseColor(SK_ColorWHITE);
|
|
|
|
}
|
|
|
|
|
2013-12-12 21:11:12 +00:00
|
|
|
DEF_TEST(MipMap, reporter) {
|
2013-07-18 19:53:31 +00:00
|
|
|
SkBitmap bm;
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2013-07-18 19:53:31 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 500; ++i) {
|
|
|
|
make_bitmap(&bm, rand);
|
2014-10-02 20:47:08 +00:00
|
|
|
SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, NULL));
|
2013-07-19 07:00:57 +00:00
|
|
|
|
2013-07-18 19:53:31 +00:00
|
|
|
REPORTER_ASSERT(reporter, !mm->extractLevel(SK_Scalar1, NULL));
|
|
|
|
REPORTER_ASSERT(reporter, !mm->extractLevel(SK_Scalar1 * 2, NULL));
|
2013-07-19 07:00:57 +00:00
|
|
|
|
2013-07-24 14:55:00 +00:00
|
|
|
SkMipMap::Level prevLevel;
|
|
|
|
sk_bzero(&prevLevel, sizeof(prevLevel));
|
2013-07-18 19:53:31 +00:00
|
|
|
|
|
|
|
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);
|
2013-07-19 07:00:57 +00:00
|
|
|
|
2013-07-18 19:53:31 +00:00
|
|
|
if (prevLevel.fPixels) {
|
|
|
|
REPORTER_ASSERT(reporter, level.fWidth <= prevLevel.fWidth);
|
|
|
|
REPORTER_ASSERT(reporter, level.fHeight <= prevLevel.fHeight);
|
|
|
|
}
|
|
|
|
prevLevel = level;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|