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" |
11 #include "Test.h" | 11 #include "Test.h" |
12 | 12 |
13 static void make_bitmap(SkBitmap* bm, int width, int height) { | 13 static void make_bitmap(SkBitmap* bm, int width, int height) { |
14 bm->allocN32Pixels(width, height); | 14 bm->allocN32Pixels(width, height); |
15 bm->eraseColor(SK_ColorWHITE); | 15 bm->eraseColor(SK_ColorWHITE); |
16 } | 16 } |
17 | 17 |
18 DEF_TEST(MipMap, reporter) { | 18 DEF_TEST(MipMap, reporter) { |
19 SkBitmap bm; | 19 SkBitmap bm; |
20 SkRandom rand; | 20 SkRandom rand; |
21 | 21 |
22 for (int i = 0; i < 500; ++i) { | 22 for (int i = 0; i < 500; ++i) { |
23 int width = 1 + rand.nextU() % 1000; | 23 int width = 1 + rand.nextU() % 1000; |
24 int height = 1 + rand.nextU() % 1000; | 24 int height = 1 + rand.nextU() % 1000; |
25 make_bitmap(&bm, width, height); | 25 make_bitmap(&bm, width, height); |
26 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, nullptr)); | 26 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, SkSourceGammaTreatment::kI
gnore, nullptr)); |
27 | 27 |
28 REPORTER_ASSERT(reporter, mm->countLevels() == SkMipMap::ComputeLevelCou
nt(width, height)); | 28 REPORTER_ASSERT(reporter, mm->countLevels() == SkMipMap::ComputeLevelCou
nt(width, height)); |
29 REPORTER_ASSERT(reporter, !mm->extractLevel(SkSize::Make(SK_Scalar1, SK_
Scalar1), | 29 REPORTER_ASSERT(reporter, !mm->extractLevel(SkSize::Make(SK_Scalar1, SK_
Scalar1), |
30 nullptr)); | 30 nullptr)); |
31 REPORTER_ASSERT(reporter, !mm->extractLevel(SkSize::Make(SK_Scalar1 * 2,
SK_Scalar1 * 2), | 31 REPORTER_ASSERT(reporter, !mm->extractLevel(SkSize::Make(SK_Scalar1 * 2,
SK_Scalar1 * 2), |
32 nullptr)); | 32 nullptr)); |
33 | 33 |
34 SkMipMap::Level prevLevel; | 34 SkMipMap::Level prevLevel; |
35 sk_bzero(&prevLevel, sizeof(prevLevel)); | 35 sk_bzero(&prevLevel, sizeof(prevLevel)); |
36 | 36 |
(...skipping 16 matching lines...) Expand all Loading... |
53 } | 53 } |
54 } | 54 } |
55 } | 55 } |
56 } | 56 } |
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, SkSourceGammaTreatment::kIgnor
e, 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 |
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) { |
83 // create mipmap with invalid size | 83 // create mipmap with invalid size |
84 { | 84 { |
85 // SkMipMap current requires the dimensions be greater than 2x2 | 85 // SkMipMap current requires the dimensions be greater than 2x2 |
86 SkBitmap bm; | 86 SkBitmap bm; |
87 bm.allocN32Pixels(1, 1); | 87 bm.allocN32Pixels(1, 1); |
88 bm.eraseColor(SK_ColorWHITE); | 88 bm.eraseColor(SK_ColorWHITE); |
89 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, nullptr)); | 89 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, SkSourceGammaTreatment::kI
gnore, nullptr)); |
90 | 90 |
91 REPORTER_ASSERT(reporter, mm == nullptr); | 91 REPORTER_ASSERT(reporter, mm == nullptr); |
92 } | 92 } |
93 | 93 |
94 // check small mipmap's count and levels | 94 // check small mipmap's count and levels |
95 // There should be 5 mipmap levels generated: | 95 // There should be 5 mipmap levels generated: |
96 // 16x16, 8x8, 4x4, 2x2, 1x1 | 96 // 16x16, 8x8, 4x4, 2x2, 1x1 |
97 test_mipmap_generation(32, 32, 5, reporter); | 97 test_mipmap_generation(32, 32, 5, reporter); |
98 | 98 |
99 // check large mipmap's count and levels | 99 // check large mipmap's count and levels |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 {500, 1000, 2, SkISize::Make(125, 250)}, | 191 {500, 1000, 2, 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 |