reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "Test.h" |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame^] | 9 | #include "TestClassDef.h" |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 10 | #include "SkMipMap.h" |
| 11 | #include "SkBitmap.h" |
| 12 | #include "SkRandom.h" |
| 13 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 14 | static void make_bitmap(SkBitmap* bm, SkRandom& rand) { |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 15 | // for now, Build needs a min size of 2, otherwise it will return NULL. |
| 16 | // should fix that to support 1 X N, where N > 1 to return non-null. |
| 17 | int w = 2 + rand.nextU() % 1000; |
| 18 | int h = 2 + rand.nextU() % 1000; |
| 19 | bm->setConfig(SkBitmap::kARGB_8888_Config, w, h); |
| 20 | bm->allocPixels(); |
| 21 | bm->eraseColor(SK_ColorWHITE); |
| 22 | } |
| 23 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame^] | 24 | DEF_TEST(MipMap, reporter) { |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 25 | SkBitmap bm; |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 26 | SkRandom rand; |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 27 | |
| 28 | for (int i = 0; i < 500; ++i) { |
| 29 | make_bitmap(&bm, rand); |
| 30 | SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm)); |
skia.committer@gmail.com | a799198 | 2013-07-19 07:00:57 +0000 | [diff] [blame] | 31 | |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 32 | REPORTER_ASSERT(reporter, !mm->extractLevel(SK_Scalar1, NULL)); |
| 33 | REPORTER_ASSERT(reporter, !mm->extractLevel(SK_Scalar1 * 2, NULL)); |
skia.committer@gmail.com | a799198 | 2013-07-19 07:00:57 +0000 | [diff] [blame] | 34 | |
reed@google.com | 2c38fed | 2013-07-24 14:55:00 +0000 | [diff] [blame] | 35 | SkMipMap::Level prevLevel; |
| 36 | sk_bzero(&prevLevel, sizeof(prevLevel)); |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 37 | |
| 38 | SkScalar scale = SK_Scalar1; |
| 39 | for (int j = 0; j < 30; ++j) { |
| 40 | scale = scale * 2 / 3; |
| 41 | |
| 42 | SkMipMap::Level level; |
| 43 | if (mm->extractLevel(scale, &level)) { |
| 44 | REPORTER_ASSERT(reporter, level.fPixels); |
| 45 | REPORTER_ASSERT(reporter, level.fWidth > 0); |
| 46 | REPORTER_ASSERT(reporter, level.fHeight > 0); |
| 47 | REPORTER_ASSERT(reporter, level.fRowBytes >= level.fWidth * 4); |
skia.committer@gmail.com | a799198 | 2013-07-19 07:00:57 +0000 | [diff] [blame] | 48 | |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 49 | if (prevLevel.fPixels) { |
| 50 | REPORTER_ASSERT(reporter, level.fWidth <= prevLevel.fWidth); |
| 51 | REPORTER_ASSERT(reporter, level.fHeight <= prevLevel.fHeight); |
| 52 | } |
| 53 | prevLevel = level; |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | } |