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