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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 for (int i = 0; i < mipLevelCount; ++i) { | 67 for (int i = 0; i < mipLevelCount; ++i) { |
68 SkMipMap::Level level; | 68 SkMipMap::Level level; |
69 REPORTER_ASSERT(reporter, mm->getLevel(i, &level)); | 69 REPORTER_ASSERT(reporter, mm->getLevel(i, &level)); |
70 // Make sure the mipmaps contain valid data and that the sizes are corre ct | 70 // Make sure the mipmaps contain valid data and that the sizes are corre ct |
71 REPORTER_ASSERT(reporter, level.fPixmap.addr()); | 71 REPORTER_ASSERT(reporter, level.fPixmap.addr()); |
72 | 72 |
reed1
2016/06/09 10:31:26
Here would be an interesting place to call Compute
cblume
2016/06/09 16:23:06
Done.
| |
73 // + 1 because SkMipMap does not include the base mipmap level. | 73 // + 1 because SkMipMap does not include the base mipmap level. |
74 int twoToTheMipLevel = 1 << (i + 1); | 74 int twoToTheMipLevel = 1 << (i + 1); |
75 int currentWidth = width / twoToTheMipLevel; | 75 int currentWidth = width / twoToTheMipLevel; |
76 int currentHeight = height / twoToTheMipLevel; | 76 int currentHeight = height / twoToTheMipLevel; |
77 REPORTER_ASSERT(reporter, level.fPixmap.width() == currentWidth); | 77 REPORTER_ASSERT(reporter, level.fPixmap.width() == currentWidth); |
78 REPORTER_ASSERT(reporter, level.fPixmap.height() == currentHeight); | 78 REPORTER_ASSERT(reporter, level.fPixmap.height() == currentHeight); |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 DEF_TEST(MipMap_DirectLevelAccess, reporter) { | 82 DEF_TEST(MipMap_DirectLevelAccess, reporter) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 struct LevelSizeScenario { | 154 struct LevelSizeScenario { |
155 int fBaseWidth; | 155 int fBaseWidth; |
156 int fBaseHeight; | 156 int fBaseHeight; |
157 int fLevel; | 157 int fLevel; |
158 SkISize fExpectedMipMapLevelSize; | 158 SkISize fExpectedMipMapLevelSize; |
159 }; | 159 }; |
160 | 160 |
161 DEF_TEST(MipMap_ComputeLevelSize, reporter) { | 161 DEF_TEST(MipMap_ComputeLevelSize, reporter) { |
162 const LevelSizeScenario tests[] = { | 162 const LevelSizeScenario tests[] = { |
163 // Test mipmaps with negative sizes | 163 // Test mipmaps with negative sizes |
164 {-100, 100, 1, SkISize::Make(0, 0)}, | 164 {-100, 100, 0, SkISize::Make(0, 0)}, |
165 {100, -100, 1, SkISize::Make(0, 0)}, | 165 {100, -100, 0, SkISize::Make(0, 0)}, |
166 {-100, -100, 1, SkISize::Make(0, 0)}, | 166 {-100, -100, 0, SkISize::Make(0, 0)}, |
167 | 167 |
168 // Test mipmaps with 0, 1, 2 as dimensions | 168 // Test mipmaps with 0, 1, 2 as dimensions |
169 // (SkMipMap::Build requires a min size of 1) | 169 // (SkMipMap::Build requires a min size of 1) |
170 // | 170 // |
171 // 0 | 171 // 0 |
172 {0, 100, 1, SkISize::Make(0, 0)}, | 172 {0, 100, 0, SkISize::Make(0, 0)}, |
173 {100, 0, 1, SkISize::Make(0, 0)}, | 173 {100, 0, 0, SkISize::Make(0, 0)}, |
174 {0, 0, 1, SkISize::Make(0, 0)}, | 174 {0, 0, 0, SkISize::Make(0, 0)}, |
175 // 1 | 175 // 1 |
176 | 176 |
177 {1, 100, 1, SkISize::Make(1, 50)}, | 177 {1, 100, 0, SkISize::Make(1, 50)}, |
178 {100, 1, 1, SkISize::Make(50, 1)}, | 178 {100, 1, 0, SkISize::Make(50, 1)}, |
179 {1, 1, 1, SkISize::Make(0, 0)}, | 179 {1, 1, 0, SkISize::Make(0, 0)}, |
180 // 2 | 180 // 2 |
181 {2, 100, 1, SkISize::Make(1, 50)}, | 181 {2, 100, 0, SkISize::Make(1, 50)}, |
182 {100, 2, 2, SkISize::Make(25, 1)}, | 182 {100, 2, 1, SkISize::Make(25, 1)}, |
183 {2, 2, 1, SkISize::Make(1, 1)}, | 183 {2, 2, 0, SkISize::Make(1, 1)}, |
184 | 184 |
185 // Test a handful of cases | 185 // Test a handful of cases |
186 {63, 63, 3, SkISize::Make(7, 7)}, | 186 {63, 63, 2, SkISize::Make(7, 7)}, |
187 {64, 64, 3, SkISize::Make(8, 8)}, | 187 {64, 64, 2, SkISize::Make(8, 8)}, |
188 {127, 127, 3, SkISize::Make(15, 15)}, | 188 {127, 127, 2, SkISize::Make(15, 15)}, |
189 {64, 129, 4, SkISize::Make(4, 8)}, | 189 {64, 129, 3, SkISize::Make(4, 8)}, |
190 {255, 32, 7, SkISize::Make(1, 1)}, | 190 {255, 32, 6, SkISize::Make(1, 1)}, |
191 {500, 1000, 2, SkISize::Make(125, 250)}, | 191 {500, 1000, 1, SkISize::Make(125, 250)}, |
192 }; | 192 }; |
193 | 193 |
194 for (auto& currentTest : tests) { | 194 for (auto& currentTest : tests) { |
195 SkISize levelSize = SkMipMap::ComputeLevelSize(currentTest.fBaseWidth, | 195 SkISize levelSize = SkMipMap::ComputeLevelSize(currentTest.fBaseWidth, |
196 currentTest.fBaseHeight, | 196 currentTest.fBaseHeight, |
197 currentTest.fLevel); | 197 currentTest.fLevel); |
198 REPORTER_ASSERT(reporter, currentTest.fExpectedMipMapLevelSize == levelS ize); | 198 REPORTER_ASSERT(reporter, currentTest.fExpectedMipMapLevelSize == levelS ize); |
199 } | 199 } |
200 } | 200 } |
OLD | NEW |