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 | |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 8 | #include "SkBitmap.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 9 | #include "SkMipMap.h" |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 10 | #include "SkRandom.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 11 | #include "Test.h" |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 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; |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 18 | bm->allocN32Pixels(w, h); |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 19 | bm->eraseColor(SK_ColorWHITE); |
| 20 | } |
| 21 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 22 | DEF_TEST(MipMap, reporter) { |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 23 | SkBitmap bm; |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 24 | SkRandom rand; |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 25 | |
| 26 | for (int i = 0; i < 500; ++i) { |
| 27 | make_bitmap(&bm, rand); |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 28 | SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, NULL)); |
skia.committer@gmail.com | a799198 | 2013-07-19 07:00:57 +0000 | [diff] [blame] | 29 | |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 30 | REPORTER_ASSERT(reporter, !mm->extractLevel(SK_Scalar1, NULL)); |
| 31 | REPORTER_ASSERT(reporter, !mm->extractLevel(SK_Scalar1 * 2, NULL)); |
skia.committer@gmail.com | a799198 | 2013-07-19 07:00:57 +0000 | [diff] [blame] | 32 | |
reed@google.com | 2c38fed | 2013-07-24 14:55:00 +0000 | [diff] [blame] | 33 | SkMipMap::Level prevLevel; |
| 34 | sk_bzero(&prevLevel, sizeof(prevLevel)); |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 35 | |
| 36 | SkScalar scale = SK_Scalar1; |
| 37 | for (int j = 0; j < 30; ++j) { |
| 38 | scale = scale * 2 / 3; |
| 39 | |
| 40 | SkMipMap::Level level; |
| 41 | if (mm->extractLevel(scale, &level)) { |
| 42 | REPORTER_ASSERT(reporter, level.fPixels); |
| 43 | REPORTER_ASSERT(reporter, level.fWidth > 0); |
| 44 | REPORTER_ASSERT(reporter, level.fHeight > 0); |
| 45 | REPORTER_ASSERT(reporter, level.fRowBytes >= level.fWidth * 4); |
skia.committer@gmail.com | a799198 | 2013-07-19 07:00:57 +0000 | [diff] [blame] | 46 | |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 47 | if (prevLevel.fPixels) { |
| 48 | REPORTER_ASSERT(reporter, level.fWidth <= prevLevel.fWidth); |
| 49 | REPORTER_ASSERT(reporter, level.fHeight <= prevLevel.fHeight); |
| 50 | } |
| 51 | prevLevel = level; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | } |