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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 {64, 129, 7}, | 143 {64, 129, 7}, |
144 {255, 32, 7}, | 144 {255, 32, 7}, |
145 {500, 1000, 9} | 145 {500, 1000, 9} |
146 }; | 146 }; |
147 | 147 |
148 for (auto& currentTest : tests) { | 148 for (auto& currentTest : tests) { |
149 int levelCount = SkMipMap::ComputeLevelCount(currentTest.fWidth, current
Test.fHeight); | 149 int levelCount = SkMipMap::ComputeLevelCount(currentTest.fWidth, current
Test.fHeight); |
150 REPORTER_ASSERT(reporter, currentTest.fExpectedLevelCount == levelCount)
; | 150 REPORTER_ASSERT(reporter, currentTest.fExpectedLevelCount == levelCount)
; |
151 } | 151 } |
152 } | 152 } |
| 153 |
| 154 struct LevelSizeScenario { |
| 155 int fBaseWidth; |
| 156 int fBaseHeight; |
| 157 int fLevel; |
| 158 SkSize fExpectedMipMapLevelSize; |
| 159 }; |
| 160 |
| 161 DEF_TEST(MipMap_ComputeLevelSize, reporter) { |
| 162 const LevelSizeScenario tests[] = { |
| 163 // Test mipmaps with negative sizes |
| 164 {-100, 100, 1, SkSize::Make(0, 0)}, |
| 165 {100, -100, 1, SkSize::Make(0, 0)}, |
| 166 {-100, -100, 1, SkSize::Make(0, 0)}, |
| 167 |
| 168 // Test mipmaps with 0, 1, 2 as dimensions |
| 169 // (SkMipMap::Build requires a min size of 1) |
| 170 // |
| 171 // 0 |
| 172 {0, 100, 1, SkSize::Make(0, 0)}, |
| 173 {100, 0, 1, SkSize::Make(0, 0)}, |
| 174 {0, 0, 1, SkSize::Make(0, 0)}, |
| 175 // 1 |
| 176 |
| 177 {1, 100, 1, SkSize::Make(1, 50)}, |
| 178 {100, 1, 1, SkSize::Make(50, 1)}, |
| 179 {1, 1, 1, SkSize::Make(0, 0)}, |
| 180 // 2 |
| 181 {2, 100, 1, SkSize::Make(1, 50)}, |
| 182 {100, 2, 2, SkSize::Make(25, 1)}, |
| 183 {2, 2, 1, SkSize::Make(1, 1)}, |
| 184 |
| 185 // Test a handful of cases |
| 186 {63, 63, 3, SkSize::Make(7, 7)}, |
| 187 {64, 64, 3, SkSize::Make(8, 8)}, |
| 188 {127, 127, 3, SkSize::Make(15, 15)}, |
| 189 {64, 129, 4, SkSize::Make(4, 8)}, |
| 190 {255, 32, 7, SkSize::Make(1, 1)}, |
| 191 {500, 1000, 2, SkSize::Make(125, 250)}, |
| 192 }; |
| 193 |
| 194 for (auto& currentTest : tests) { |
| 195 SkSize levelSize = SkMipMap::ComputeLevelSize(currentTest.fBaseWidth, |
| 196 currentTest.fBaseHeight, c
urrentTest.fLevel); |
| 197 REPORTER_ASSERT(reporter, currentTest.fExpectedMipMapLevelSize == levelS
ize); |
| 198 } |
| 199 } |
OLD | NEW |