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) {
|
2015-08-27 14:41:13 +00:00
|
|
|
// for now, Build needs a min size of 2, otherwise it will return nullptr.
|
2013-07-18 19:53:31 +00:00
|
|
|
// 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);
|
2015-08-27 14:41:13 +00:00
|
|
|
SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, nullptr));
|
2013-07-19 07:00:57 +00:00
|
|
|
|
2016-02-09 16:20:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, !mm->extractLevel(SkSize::Make(SK_Scalar1, SK_Scalar1),
|
|
|
|
nullptr));
|
|
|
|
REPORTER_ASSERT(reporter, !mm->extractLevel(SkSize::Make(SK_Scalar1 * 2, SK_Scalar1 * 2),
|
|
|
|
nullptr));
|
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;
|
2016-02-09 16:20:18 +00:00
|
|
|
if (mm->extractLevel(SkSize::Make(scale, scale), &level)) {
|
2016-01-17 02:50:35 +00:00
|
|
|
REPORTER_ASSERT(reporter, level.fPixmap.addr());
|
|
|
|
REPORTER_ASSERT(reporter, level.fPixmap.width() > 0);
|
|
|
|
REPORTER_ASSERT(reporter, level.fPixmap.height() > 0);
|
|
|
|
REPORTER_ASSERT(reporter, (int)level.fPixmap.rowBytes() >= level.fPixmap.width() * 4);
|
|
|
|
|
|
|
|
if (prevLevel.fPixmap.addr()) {
|
|
|
|
REPORTER_ASSERT(reporter, level.fPixmap.width() <= prevLevel.fPixmap.width());
|
|
|
|
REPORTER_ASSERT(reporter, level.fPixmap.height() <= prevLevel.fPixmap.height());
|
2013-07-18 19:53:31 +00:00
|
|
|
}
|
|
|
|
prevLevel = level;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|