| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkMipMap.h" | 9 #include "SkMipMap.h" |
| 10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 static void test_mipmap_generation(int width, int height, int expectedMipLevelCo
unt, | 58 static void test_mipmap_generation(int width, int height, int expectedMipLevelCo
unt, |
| 59 skiatest::Reporter* reporter) { | 59 skiatest::Reporter* reporter) { |
| 60 SkBitmap bm; | 60 SkBitmap bm; |
| 61 bm.allocN32Pixels(width, height); | 61 bm.allocN32Pixels(width, height); |
| 62 bm.eraseColor(SK_ColorWHITE); | 62 bm.eraseColor(SK_ColorWHITE); |
| 63 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, nullptr)); | 63 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, nullptr)); |
| 64 | 64 |
| 65 const int mipLevelCount = mm->countLevels(); | 65 const int mipLevelCount = mm->countLevels(); |
| 66 REPORTER_ASSERT(reporter, mipLevelCount == expectedMipLevelCount); | 66 REPORTER_ASSERT(reporter, mipLevelCount == expectedMipLevelCount); |
| 67 REPORTER_ASSERT(reporter, mipLevelCount == SkMipMap::ComputeLevelCount(width
, height)); |
| 67 for (int i = 0; i < mipLevelCount; ++i) { | 68 for (int i = 0; i < mipLevelCount; ++i) { |
| 68 SkMipMap::Level level; | 69 SkMipMap::Level level; |
| 69 REPORTER_ASSERT(reporter, mm->getLevel(i, &level)); | 70 REPORTER_ASSERT(reporter, mm->getLevel(i, &level)); |
| 70 // Make sure the mipmaps contain valid data and that the sizes are corre
ct | 71 // Make sure the mipmaps contain valid data and that the sizes are corre
ct |
| 71 REPORTER_ASSERT(reporter, level.fPixmap.addr()); | 72 REPORTER_ASSERT(reporter, level.fPixmap.addr()); |
| 73 SkISize size = SkMipMap::ComputeLevelSize(width, height, i); |
| 74 REPORTER_ASSERT(reporter, level.fPixmap.width() == size.width()); |
| 75 REPORTER_ASSERT(reporter, level.fPixmap.height() == size.height()); |
| 72 | 76 |
| 73 // + 1 because SkMipMap does not include the base mipmap level. | 77 // + 1 because SkMipMap does not include the base mipmap level. |
| 74 int twoToTheMipLevel = 1 << (i + 1); | 78 int twoToTheMipLevel = 1 << (i + 1); |
| 75 int currentWidth = width / twoToTheMipLevel; | 79 int currentWidth = width / twoToTheMipLevel; |
| 76 int currentHeight = height / twoToTheMipLevel; | 80 int currentHeight = height / twoToTheMipLevel; |
| 77 REPORTER_ASSERT(reporter, level.fPixmap.width() == currentWidth); | 81 REPORTER_ASSERT(reporter, level.fPixmap.width() == currentWidth); |
| 78 REPORTER_ASSERT(reporter, level.fPixmap.height() == currentHeight); | 82 REPORTER_ASSERT(reporter, level.fPixmap.height() == currentHeight); |
| 79 } | 83 } |
| 80 } | 84 } |
| 81 | 85 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 struct LevelSizeScenario { | 158 struct LevelSizeScenario { |
| 155 int fBaseWidth; | 159 int fBaseWidth; |
| 156 int fBaseHeight; | 160 int fBaseHeight; |
| 157 int fLevel; | 161 int fLevel; |
| 158 SkISize fExpectedMipMapLevelSize; | 162 SkISize fExpectedMipMapLevelSize; |
| 159 }; | 163 }; |
| 160 | 164 |
| 161 DEF_TEST(MipMap_ComputeLevelSize, reporter) { | 165 DEF_TEST(MipMap_ComputeLevelSize, reporter) { |
| 162 const LevelSizeScenario tests[] = { | 166 const LevelSizeScenario tests[] = { |
| 163 // Test mipmaps with negative sizes | 167 // Test mipmaps with negative sizes |
| 164 {-100, 100, 1, SkISize::Make(0, 0)}, | 168 {-100, 100, 0, SkISize::Make(0, 0)}, |
| 165 {100, -100, 1, SkISize::Make(0, 0)}, | 169 {100, -100, 0, SkISize::Make(0, 0)}, |
| 166 {-100, -100, 1, SkISize::Make(0, 0)}, | 170 {-100, -100, 0, SkISize::Make(0, 0)}, |
| 167 | 171 |
| 168 // Test mipmaps with 0, 1, 2 as dimensions | 172 // Test mipmaps with 0, 1, 2 as dimensions |
| 169 // (SkMipMap::Build requires a min size of 1) | 173 // (SkMipMap::Build requires a min size of 1) |
| 170 // | 174 // |
| 171 // 0 | 175 // 0 |
| 172 {0, 100, 1, SkISize::Make(0, 0)}, | 176 {0, 100, 0, SkISize::Make(0, 0)}, |
| 173 {100, 0, 1, SkISize::Make(0, 0)}, | 177 {100, 0, 0, SkISize::Make(0, 0)}, |
| 174 {0, 0, 1, SkISize::Make(0, 0)}, | 178 {0, 0, 0, SkISize::Make(0, 0)}, |
| 175 // 1 | 179 // 1 |
| 176 | 180 |
| 177 {1, 100, 1, SkISize::Make(1, 50)}, | 181 {1, 100, 0, SkISize::Make(1, 50)}, |
| 178 {100, 1, 1, SkISize::Make(50, 1)}, | 182 {100, 1, 0, SkISize::Make(50, 1)}, |
| 179 {1, 1, 1, SkISize::Make(0, 0)}, | 183 {1, 1, 0, SkISize::Make(0, 0)}, |
| 180 // 2 | 184 // 2 |
| 181 {2, 100, 1, SkISize::Make(1, 50)}, | 185 {2, 100, 0, SkISize::Make(1, 50)}, |
| 182 {100, 2, 2, SkISize::Make(25, 1)}, | 186 {100, 2, 1, SkISize::Make(25, 1)}, |
| 183 {2, 2, 1, SkISize::Make(1, 1)}, | 187 {2, 2, 0, SkISize::Make(1, 1)}, |
| 184 | 188 |
| 185 // Test a handful of cases | 189 // Test a handful of cases |
| 186 {63, 63, 3, SkISize::Make(7, 7)}, | 190 {63, 63, 2, SkISize::Make(7, 7)}, |
| 187 {64, 64, 3, SkISize::Make(8, 8)}, | 191 {64, 64, 2, SkISize::Make(8, 8)}, |
| 188 {127, 127, 3, SkISize::Make(15, 15)}, | 192 {127, 127, 2, SkISize::Make(15, 15)}, |
| 189 {64, 129, 4, SkISize::Make(4, 8)}, | 193 {64, 129, 3, SkISize::Make(4, 8)}, |
| 190 {255, 32, 7, SkISize::Make(1, 1)}, | 194 {255, 32, 6, SkISize::Make(1, 1)}, |
| 191 {500, 1000, 2, SkISize::Make(125, 250)}, | 195 {500, 1000, 1, SkISize::Make(125, 250)}, |
| 192 }; | 196 }; |
| 193 | 197 |
| 194 for (auto& currentTest : tests) { | 198 for (auto& currentTest : tests) { |
| 195 SkISize levelSize = SkMipMap::ComputeLevelSize(currentTest.fBaseWidth, | 199 SkISize levelSize = SkMipMap::ComputeLevelSize(currentTest.fBaseWidth, |
| 196 currentTest.fBaseHeight, | 200 currentTest.fBaseHeight, |
| 197 currentTest.fLevel); | 201 currentTest.fLevel); |
| 198 REPORTER_ASSERT(reporter, currentTest.fExpectedMipMapLevelSize == levelS
ize); | 202 REPORTER_ASSERT(reporter, currentTest.fExpectedMipMapLevelSize == levelS
ize); |
| 199 } | 203 } |
| 200 } | 204 } |
| OLD | NEW |