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

Side by Side Diff: gm/showmiplevels.cpp

Issue 1594613002: add GM to show miplevels for all colortypes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 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 | « no previous file | 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 2016 Google Inc. 2 * Copyright 2016 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 "gm.h" 8 #include "gm.h"
9 9
10 #include "Resources.h" 10 #include "Resources.h"
11 #include "SkBitmapScaler.h" 11 #include "SkBitmapScaler.h"
12 #include "SkGradientShader.h" 12 #include "SkGradientShader.h"
13 #include "SkTypeface.h" 13 #include "SkTypeface.h"
14 #include "SkImageDecoder.h" 14 #include "SkImageDecoder.h"
15 #include "SkStream.h" 15 #include "SkStream.h"
16 #include "SkPaint.h" 16 #include "SkPaint.h"
17 #include "SkMipMap.h" 17 #include "SkMipMap.h"
18 #include "Resources.h" 18 #include "Resources.h"
19 #include "sk_tool_utils.h" 19 #include "sk_tool_utils.h"
20 20
21 static SkBitmap make_bitmap(int size) { 21 static SkBitmap make_bitmap(int w, int h) {
22 SkBitmap bm; 22 SkBitmap bm;
23 bm.allocN32Pixels(size, size); 23 bm.allocN32Pixels(w, h);
24 SkCanvas canvas(bm); 24 SkCanvas canvas(bm);
25 canvas.clear(0xFFFFFFFF); 25 canvas.clear(0xFFFFFFFF);
26 SkPaint paint; 26 SkPaint paint;
27 paint.setStyle(SkPaint::kStroke_Style); 27 paint.setStyle(SkPaint::kStroke_Style);
28 paint.setStrokeWidth(size / 16.0f); 28 paint.setStrokeWidth(w / 16.0f);
29 canvas.drawCircle(size/2.0f, size/2.0f, size/3.0f, paint); 29 canvas.drawCircle(w/2.0f, h/2.0f, w/3.0f, paint);
30 return bm; 30 return bm;
31 } 31 }
32 32
33 static SkBitmap make_bitmap2(int size) { 33 static SkBitmap make_bitmap2(int w, int h) {
34 SkBitmap bm; 34 SkBitmap bm;
35 bm.allocN32Pixels(size, size); 35 bm.allocN32Pixels(w, h);
36 SkCanvas canvas(bm); 36 SkCanvas canvas(bm);
37 canvas.clear(0xFFFFFFFF); 37 canvas.clear(0xFFFFFFFF);
38 SkPaint paint; 38 SkPaint paint;
39 paint.setStyle(SkPaint::kStroke_Style); 39 paint.setStyle(SkPaint::kStroke_Style);
40 40
41 SkScalar inset = 2; 41 SkScalar inset = 2;
42 SkRect r = SkRect::MakeIWH(size, size).makeInset(0.5f, 0.5f); 42 SkRect r = SkRect::MakeIWH(w, h).makeInset(0.5f, 0.5f);
43 while (r.width() > 4) { 43 while (r.width() > 4) {
44 canvas.drawRect(r, paint); 44 canvas.drawRect(r, paint);
45 r.inset(inset, inset); 45 r.inset(inset, inset);
46 inset += 1; 46 inset += 1;
47 } 47 }
48 return bm; 48 return bm;
49 } 49 }
50 50
51 #include "SkNx.h" 51 #include "SkNx.h"
52 static SkBitmap make_bitmap3(int size) { 52 static SkBitmap make_bitmap3(int w, int h) {
53 SkBitmap bm; 53 SkBitmap bm;
54 bm.allocN32Pixels(size, size); 54 bm.allocN32Pixels(w, h);
55 SkCanvas canvas(bm); 55 SkCanvas canvas(bm);
56 canvas.clear(0xFFFFFFFF); 56 canvas.clear(0xFFFFFFFF);
57 SkPaint paint; 57 SkPaint paint;
58 paint.setStyle(SkPaint::kStroke_Style); 58 paint.setStyle(SkPaint::kStroke_Style);
59 paint.setStrokeWidth(2.1f); 59 paint.setStrokeWidth(2.1f);
60 60
61 SkScalar s = SkIntToScalar(size); 61 SkScalar s = SkIntToScalar(w);
62 Sk4f p(s, -s, -s, s); 62 Sk4f p(s, -s, -s, s);
63 Sk4f d(5); 63 Sk4f d(5);
64 while (p.kth<1>() < s) { 64 while (p.kth<1>() < s) {
65 canvas.drawLine(p.kth<0>(),p.kth<1>(), p.kth<2>(), p.kth<3>(), paint); 65 canvas.drawLine(p.kth<0>(),p.kth<1>(), p.kth<2>(), p.kth<3>(), paint);
66 p = p + d; 66 p = p + d;
67 } 67 }
68 return bm; 68 return bm;
69 } 69 }
70 70
71 class ShowMipLevels : public skiagm::GM { 71 class ShowMipLevels : public skiagm::GM {
(...skipping 24 matching lines...) Expand all
96 unsigned r = gamma(SkGetPackedR32(c)); 96 unsigned r = gamma(SkGetPackedR32(c));
97 unsigned g = gamma(SkGetPackedG32(c)); 97 unsigned g = gamma(SkGetPackedG32(c));
98 unsigned b = gamma(SkGetPackedB32(c)); 98 unsigned b = gamma(SkGetPackedB32(c));
99 *bm.getAddr32(x, y) = SkPackARGB32(0xFF, r, g, b); 99 *bm.getAddr32(x, y) = SkPackARGB32(0xFF, r, g, b);
100 } 100 }
101 } 101 }
102 } 102 }
103 103
104 ShowMipLevels(int N) : fN(N) { 104 ShowMipLevels(int N) : fN(N) {
105 fBM[0] = sk_tool_utils::create_checkerboard_bitmap(N, N, SK_ColorBLACK, SK_ColorWHITE, 2); 105 fBM[0] = sk_tool_utils::create_checkerboard_bitmap(N, N, SK_ColorBLACK, SK_ColorWHITE, 2);
106 fBM[1] = make_bitmap(N); 106 fBM[1] = make_bitmap(N, N);
107 fBM[2] = make_bitmap2(N); 107 fBM[2] = make_bitmap2(N, N);
108 fBM[3] = make_bitmap3(N); 108 fBM[3] = make_bitmap3(N, N);
109 } 109 }
110 110
111 protected: 111 protected:
112 112
113 SkString onShortName() override { 113 SkString onShortName() override {
114 SkString str; 114 SkString str;
115 str.printf("showmiplevels_%d", fN); 115 str.printf("showmiplevels_%d", fN);
116 return str; 116 return str;
117 } 117 }
118 118
(...skipping 20 matching lines...) Expand all
139 SkPixmap prevPM; 139 SkPixmap prevPM;
140 baseBM.lockPixels(); 140 baseBM.lockPixels();
141 baseBM.peekPixels(&prevPM); 141 baseBM.peekPixels(&prevPM);
142 142
143 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(baseBM, nullptr)); 143 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(baseBM, nullptr));
144 144
145 int index = 0; 145 int index = 0;
146 SkMipMap::Level level; 146 SkMipMap::Level level;
147 SkScalar scale = 0.5f; 147 SkScalar scale = 0.5f;
148 while (mm->extractLevel(scale, &level)) { 148 while (mm->extractLevel(scale, &level)) {
149 SkImageInfo info = SkImageInfo::MakeN32Premul(level.fWidth, level.fH eight); 149 SkImageInfo info = SkImageInfo::Make(level.fWidth, level.fHeight,
150 baseBM.colorType(), baseBM.alph aType());
150 SkPixmap levelPM{ info, level.fPixels, level.fRowBytes }; 151 SkPixmap levelPM{ info, level.fPixels, level.fRowBytes };
151 152
152 SkBitmap bm = func(prevPM, levelPM); 153 SkBitmap bm = func(prevPM, levelPM);
153 DrawAndFrame(canvas, bm, x, y); 154 DrawAndFrame(canvas, bm, x, y);
154 155
155 if (info.width() <= 2 || info.height() <= 2) { 156 if (info.width() <= 2 || info.height() <= 2) {
156 break; 157 break;
157 } 158 }
158 if (index & 1) { 159 if (index & 1) {
159 x += info.width() + 4; 160 x += info.width() + 4;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 canvas->translate(0, bm.height() * 0.85f); 204 canvas->translate(0, bm.height() * 0.85f);
204 } 205 }
205 } 206 }
206 207
207 private: 208 private:
208 typedef skiagm::GM INHERITED; 209 typedef skiagm::GM INHERITED;
209 }; 210 };
210 DEF_GM( return new ShowMipLevels(255); ) 211 DEF_GM( return new ShowMipLevels(255); )
211 DEF_GM( return new ShowMipLevels(256); ) 212 DEF_GM( return new ShowMipLevels(256); )
212 213
214 //////////////////////////////////////////////////////////////////////////////// ///////////////////
215
216 /**
217 * Show mip levels that were built, for all supported colortypes
218 */
219 class ShowMipLevels2 : public skiagm::GM {
220 const int fW, fH;
221 SkBitmap fBM[4];
222
223 public:
224 ShowMipLevels2(int w, int h) : fW(w), fH(h) {
225 fBM[0] = sk_tool_utils::create_checkerboard_bitmap(w, h, SK_ColorBLACK, SK_ColorWHITE, 2);
226 fBM[1] = make_bitmap(w, h);
227 fBM[2] = make_bitmap2(w, h);
228 fBM[3] = make_bitmap3(w, h);
229 }
230
231 protected:
232
233 SkString onShortName() override {
234 SkString str;
235 str.printf("showmiplevels2_%dx%d", fW, fH);
236 return str;
237 }
238
239 SkISize onISize() override {
240 return { 824, 862 };
241 }
242
243 static void DrawAndFrame(SkCanvas* canvas, const SkBitmap& bm, SkScalar x, S kScalar y) {
244 canvas->drawBitmap(bm, x, y, nullptr);
245 SkPaint paint;
246 paint.setStyle(SkPaint::kStroke_Style);
247 paint.setColor(0xFFFFCCCC);
248 canvas->drawRect(SkRect::MakeIWH(bm.width(), bm.height()).makeOffset(x, y).makeOutset(0.5f, 0.5f), paint);
249 }
250
251 void drawLevels(SkCanvas* canvas, const SkBitmap& baseBM) {
252 SkScalar x = 4;
253 SkScalar y = 4;
254
255 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(baseBM, nullptr));
256
257 int index = 0;
258 SkMipMap::Level level;
259 SkScalar scale = 0.5f;
260 while (mm->extractLevel(scale, &level)) {
261 SkImageInfo info = SkImageInfo::Make(level.fWidth, level.fHeight,
262 baseBM.colorType(), baseBM.alph aType());
263
264 SkBitmap bm;
265 bm.installPixels(info, level.fPixels, level.fRowBytes);
266 DrawAndFrame(canvas, bm, x, y);
267
268 if (info.width() <= 2 || info.height() <= 2) {
269 break;
270 }
271 if (index & 1) {
272 x += info.width() + 4;
273 } else {
274 y += info.height() + 4;
275 }
276 scale /= 2;
277 index += 1;
278 }
279 }
280
281 void drawSet(SkCanvas* canvas, const SkBitmap& orig) {
282 const SkColorType ctypes[] = {
283 kN32_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kGra y_8_SkColorType
284 };
285
286 SkAutoCanvasRestore acr(canvas, true);
287
288 for (auto ctype : ctypes) {
289 SkBitmap bm;
290 orig.copyTo(&bm, ctype);
291 drawLevels(canvas, bm);
292 canvas->translate(orig.width()/2 + 8.0f, 0);
293 }
294 }
295
296 void onDraw(SkCanvas* canvas) override {
297 canvas->translate(4, 4);
298 for (const auto& bm : fBM) {
299 this->drawSet(canvas, bm);
300 // round so we always produce an integral translate, so the GOLD too l won't show
301 // unimportant diffs if this is drawn on a GPU with different roundi ng rules
302 // since we draw the bitmaps using nearest-neighbor
303 canvas->translate(0, SkScalarRoundToScalar(bm.height() * 0.85f));
304 }
305 }
306
307 private:
308 typedef skiagm::GM INHERITED;
309 };
310 DEF_GM( return new ShowMipLevels2(255, 255); )
311 DEF_GM( return new ShowMipLevels2(256, 255); )
312 DEF_GM( return new ShowMipLevels2(255, 256); )
313 DEF_GM( return new ShowMipLevels2(256, 256); )
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698