Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: tests/MipMapTest.cpp

Issue 1686563002: Relocate anisotropic mipmap logic to SkMipMap::extractLevel() (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkMipMap.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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, SkRandom& rand) { 13 static void make_bitmap(SkBitmap* bm, SkRandom& rand) {
14 // for now, Build needs a min size of 2, otherwise it will return nullptr. 14 // for now, Build needs a min size of 2, otherwise it will return nullptr.
15 // should fix that to support 1 X N, where N > 1 to return non-null. 15 // should fix that to support 1 X N, where N > 1 to return non-null.
16 int w = 2 + rand.nextU() % 1000; 16 int w = 2 + rand.nextU() % 1000;
17 int h = 2 + rand.nextU() % 1000; 17 int h = 2 + rand.nextU() % 1000;
18 bm->allocN32Pixels(w, h); 18 bm->allocN32Pixels(w, h);
19 bm->eraseColor(SK_ColorWHITE); 19 bm->eraseColor(SK_ColorWHITE);
20 } 20 }
21 21
22 DEF_TEST(MipMap, reporter) { 22 DEF_TEST(MipMap, reporter) {
23 SkBitmap bm; 23 SkBitmap bm;
24 SkRandom rand; 24 SkRandom rand;
25 25
26 for (int i = 0; i < 500; ++i) { 26 for (int i = 0; i < 500; ++i) {
27 make_bitmap(&bm, rand); 27 make_bitmap(&bm, rand);
28 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, nullptr)); 28 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, nullptr));
29 29
30 REPORTER_ASSERT(reporter, !mm->extractLevel(SK_Scalar1, nullptr)); 30 REPORTER_ASSERT(reporter, !mm->extractLevel(SkSize::Make(SK_Scalar1, SK_ Scalar1),
31 REPORTER_ASSERT(reporter, !mm->extractLevel(SK_Scalar1 * 2, nullptr)); 31 nullptr));
32 REPORTER_ASSERT(reporter, !mm->extractLevel(SkSize::Make(SK_Scalar1 * 2, SK_Scalar1 * 2),
33 nullptr));
32 34
33 SkMipMap::Level prevLevel; 35 SkMipMap::Level prevLevel;
34 sk_bzero(&prevLevel, sizeof(prevLevel)); 36 sk_bzero(&prevLevel, sizeof(prevLevel));
35 37
36 SkScalar scale = SK_Scalar1; 38 SkScalar scale = SK_Scalar1;
37 for (int j = 0; j < 30; ++j) { 39 for (int j = 0; j < 30; ++j) {
38 scale = scale * 2 / 3; 40 scale = scale * 2 / 3;
39 41
40 SkMipMap::Level level; 42 SkMipMap::Level level;
41 if (mm->extractLevel(scale, &level)) { 43 if (mm->extractLevel(SkSize::Make(scale, scale), &level)) {
42 REPORTER_ASSERT(reporter, level.fPixmap.addr()); 44 REPORTER_ASSERT(reporter, level.fPixmap.addr());
43 REPORTER_ASSERT(reporter, level.fPixmap.width() > 0); 45 REPORTER_ASSERT(reporter, level.fPixmap.width() > 0);
44 REPORTER_ASSERT(reporter, level.fPixmap.height() > 0); 46 REPORTER_ASSERT(reporter, level.fPixmap.height() > 0);
45 REPORTER_ASSERT(reporter, (int)level.fPixmap.rowBytes() >= level .fPixmap.width() * 4); 47 REPORTER_ASSERT(reporter, (int)level.fPixmap.rowBytes() >= level .fPixmap.width() * 4);
46 48
47 if (prevLevel.fPixmap.addr()) { 49 if (prevLevel.fPixmap.addr()) {
48 REPORTER_ASSERT(reporter, level.fPixmap.width() <= prevLevel .fPixmap.width()); 50 REPORTER_ASSERT(reporter, level.fPixmap.width() <= prevLevel .fPixmap.width());
49 REPORTER_ASSERT(reporter, level.fPixmap.height() <= prevLeve l.fPixmap.height()); 51 REPORTER_ASSERT(reporter, level.fPixmap.height() <= prevLeve l.fPixmap.height());
50 } 52 }
51 prevLevel = level; 53 prevLevel = level;
52 } 54 }
53 } 55 }
54 } 56 }
55 } 57 }
OLDNEW
« no previous file with comments | « src/core/SkMipMap.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698