SkMipMap::ComputeLevelSize to return SkISize

This previously returned SkSize, which had scalar components.
That doesn't make sense for a mipmap size.

R=bsalomon@google.com
BUG=578304
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2036313002

Review-Url: https://codereview.chromium.org/2036313002
This commit is contained in:
cblume 2016-06-03 11:59:50 -07:00 committed by Commit bot
parent 87fee2380c
commit 44e09ec810
3 changed files with 29 additions and 28 deletions

View File

@ -373,7 +373,7 @@ SkMipMap* SkMipMap::Build(const SkPixmap& src, SkDiscardableFactoryProc fact) {
size_t size = 0;
int countLevels = ComputeLevelCount(src.width(), src.height());
for (int currentMipLevel = countLevels; currentMipLevel > 0; currentMipLevel--) {
SkSize mipSize = ComputeLevelSize(src.width(), src.height(), currentMipLevel);
SkISize mipSize = ComputeLevelSize(src.width(), src.height(), currentMipLevel);
size += SkColorTypeMinRowBytes(ct, mipSize.fWidth) * mipSize.fHeight;
}
@ -496,17 +496,17 @@ int SkMipMap::ComputeLevelCount(int baseWidth, int baseHeight) {
return mipLevelCount;
}
SkSize SkMipMap::ComputeLevelSize(int baseWidth, int baseHeight, int level) {
SkISize SkMipMap::ComputeLevelSize(int baseWidth, int baseHeight, int level) {
if (baseWidth < 1 || baseHeight < 1) {
return SkSize::Make(0, 0);
return SkISize::Make(0, 0);
}
int maxLevelCount = ComputeLevelCount(baseWidth, baseHeight);
if (level > maxLevelCount || level < 0) {
return SkSize::Make(0, 0);
return SkISize::Make(0, 0);
}
if (level == 0) {
return SkSize::Make(baseWidth, baseHeight);
return SkISize::Make(baseWidth, baseHeight);
}
// OpenGL's spec requires that each mipmap level have height/width equal to
@ -516,7 +516,7 @@ SkSize SkMipMap::ComputeLevelSize(int baseWidth, int baseHeight, int level) {
int width = SkTMax(1, baseWidth >> level);
int height = SkTMax(1, baseHeight >> level);
return SkSize::Make(width, height);
return SkISize::Make(width, height);
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -27,7 +27,7 @@ public:
static int ComputeLevelCount(int baseWidth, int baseHeight);
// Determines the size of a given mipmap level.
static SkSize ComputeLevelSize(int baseWidth, int baseHeight, int level);
static SkISize ComputeLevelSize(int baseWidth, int baseHeight, int level);
struct Level {
SkPixmap fPixmap;

View File

@ -155,45 +155,46 @@ struct LevelSizeScenario {
int fBaseWidth;
int fBaseHeight;
int fLevel;
SkSize fExpectedMipMapLevelSize;
SkISize fExpectedMipMapLevelSize;
};
DEF_TEST(MipMap_ComputeLevelSize, reporter) {
const LevelSizeScenario tests[] = {
// Test mipmaps with negative sizes
{-100, 100, 1, SkSize::Make(0, 0)},
{100, -100, 1, SkSize::Make(0, 0)},
{-100, -100, 1, SkSize::Make(0, 0)},
{-100, 100, 1, SkISize::Make(0, 0)},
{100, -100, 1, SkISize::Make(0, 0)},
{-100, -100, 1, SkISize::Make(0, 0)},
// Test mipmaps with 0, 1, 2 as dimensions
// (SkMipMap::Build requires a min size of 1)
//
// 0
{0, 100, 1, SkSize::Make(0, 0)},
{100, 0, 1, SkSize::Make(0, 0)},
{0, 0, 1, SkSize::Make(0, 0)},
{0, 100, 1, SkISize::Make(0, 0)},
{100, 0, 1, SkISize::Make(0, 0)},
{0, 0, 1, SkISize::Make(0, 0)},
// 1
{1, 100, 1, SkSize::Make(1, 50)},
{100, 1, 1, SkSize::Make(50, 1)},
{1, 1, 1, SkSize::Make(0, 0)},
{1, 100, 1, SkISize::Make(1, 50)},
{100, 1, 1, SkISize::Make(50, 1)},
{1, 1, 1, SkISize::Make(0, 0)},
// 2
{2, 100, 1, SkSize::Make(1, 50)},
{100, 2, 2, SkSize::Make(25, 1)},
{2, 2, 1, SkSize::Make(1, 1)},
{2, 100, 1, SkISize::Make(1, 50)},
{100, 2, 2, SkISize::Make(25, 1)},
{2, 2, 1, SkISize::Make(1, 1)},
// Test a handful of cases
{63, 63, 3, SkSize::Make(7, 7)},
{64, 64, 3, SkSize::Make(8, 8)},
{127, 127, 3, SkSize::Make(15, 15)},
{64, 129, 4, SkSize::Make(4, 8)},
{255, 32, 7, SkSize::Make(1, 1)},
{500, 1000, 2, SkSize::Make(125, 250)},
{63, 63, 3, SkISize::Make(7, 7)},
{64, 64, 3, SkISize::Make(8, 8)},
{127, 127, 3, SkISize::Make(15, 15)},
{64, 129, 4, SkISize::Make(4, 8)},
{255, 32, 7, SkISize::Make(1, 1)},
{500, 1000, 2, SkISize::Make(125, 250)},
};
for (auto& currentTest : tests) {
SkSize levelSize = SkMipMap::ComputeLevelSize(currentTest.fBaseWidth,
currentTest.fBaseHeight, currentTest.fLevel);
SkISize levelSize = SkMipMap::ComputeLevelSize(currentTest.fBaseWidth,
currentTest.fBaseHeight,
currentTest.fLevel);
REPORTER_ASSERT(reporter, currentTest.fExpectedMipMapLevelSize == levelSize);
}
}