| OLD | NEW |
| 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 #define SHOW_MIP_COLOR 0xFF000000 |
| 22 |
| 21 static SkBitmap make_bitmap(int w, int h) { | 23 static SkBitmap make_bitmap(int w, int h) { |
| 22 SkBitmap bm; | 24 SkBitmap bm; |
| 23 bm.allocN32Pixels(w, h); | 25 bm.allocN32Pixels(w, h); |
| 24 SkCanvas canvas(bm); | 26 SkCanvas canvas(bm); |
| 25 canvas.clear(0xFFFFFFFF); | 27 canvas.clear(0xFFFFFFFF); |
| 26 SkPaint paint; | 28 SkPaint paint; |
| 27 paint.setStyle(SkPaint::kStroke_Style); | 29 paint.setStyle(SkPaint::kStroke_Style); |
| 28 paint.setStrokeWidth(w / 16.0f); | 30 paint.setStrokeWidth(w / 16.0f); |
| 31 paint.setColor(SHOW_MIP_COLOR); |
| 29 canvas.drawCircle(w/2.0f, h/2.0f, w/3.0f, paint); | 32 canvas.drawCircle(w/2.0f, h/2.0f, w/3.0f, paint); |
| 30 return bm; | 33 return bm; |
| 31 } | 34 } |
| 32 | 35 |
| 33 static SkBitmap make_bitmap2(int w, int h) { | 36 static SkBitmap make_bitmap2(int w, int h) { |
| 34 SkBitmap bm; | 37 SkBitmap bm; |
| 35 bm.allocN32Pixels(w, h); | 38 bm.allocN32Pixels(w, h); |
| 36 SkCanvas canvas(bm); | 39 SkCanvas canvas(bm); |
| 37 canvas.clear(0xFFFFFFFF); | 40 canvas.clear(0xFFFFFFFF); |
| 38 SkPaint paint; | 41 SkPaint paint; |
| 42 paint.setColor(SHOW_MIP_COLOR); |
| 39 paint.setStyle(SkPaint::kStroke_Style); | 43 paint.setStyle(SkPaint::kStroke_Style); |
| 40 | 44 |
| 41 SkScalar inset = 2; | 45 SkScalar inset = 2; |
| 42 SkRect r = SkRect::MakeIWH(w, h).makeInset(0.5f, 0.5f); | 46 SkRect r = SkRect::MakeIWH(w, h).makeInset(0.5f, 0.5f); |
| 43 while (r.width() > 4) { | 47 while (r.width() > 4) { |
| 44 canvas.drawRect(r, paint); | 48 canvas.drawRect(r, paint); |
| 45 r.inset(inset, inset); | 49 r.inset(inset, inset); |
| 46 inset += 1; | 50 inset += 1; |
| 47 } | 51 } |
| 48 return bm; | 52 return bm; |
| 49 } | 53 } |
| 50 | 54 |
| 51 #include "SkNx.h" | 55 #include "SkNx.h" |
| 52 static SkBitmap make_bitmap3(int w, int h) { | 56 static SkBitmap make_bitmap3(int w, int h) { |
| 53 SkBitmap bm; | 57 SkBitmap bm; |
| 54 bm.allocN32Pixels(w, h); | 58 bm.allocN32Pixels(w, h); |
| 55 SkCanvas canvas(bm); | 59 SkCanvas canvas(bm); |
| 56 canvas.clear(0xFFFFFFFF); | 60 canvas.clear(0xFFFFFFFF); |
| 57 SkPaint paint; | 61 SkPaint paint; |
| 58 paint.setStyle(SkPaint::kStroke_Style); | 62 paint.setStyle(SkPaint::kStroke_Style); |
| 59 paint.setStrokeWidth(2.1f); | 63 paint.setStrokeWidth(2.1f); |
| 64 paint.setColor(SHOW_MIP_COLOR); |
| 60 | 65 |
| 61 SkScalar s = SkIntToScalar(w); | 66 SkScalar s = SkIntToScalar(w); |
| 62 Sk4f p(s, -s, -s, s); | 67 Sk4f p(s, -s, -s, s); |
| 63 Sk4f d(5); | 68 Sk4f d(5); |
| 64 while (p.kth<1>() < s) { | 69 while (p.kth<1>() < s) { |
| 65 canvas.drawLine(p.kth<0>(),p.kth<1>(), p.kth<2>(), p.kth<3>(), paint); | 70 canvas.drawLine(p.kth<0>(),p.kth<1>(), p.kth<2>(), p.kth<3>(), paint); |
| 66 p = p + d; | 71 p = p + d; |
| 67 } | 72 } |
| 68 return bm; | 73 return bm; |
| 69 } | 74 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 220 |
| 216 /** | 221 /** |
| 217 * Show mip levels that were built, for all supported colortypes | 222 * Show mip levels that were built, for all supported colortypes |
| 218 */ | 223 */ |
| 219 class ShowMipLevels2 : public skiagm::GM { | 224 class ShowMipLevels2 : public skiagm::GM { |
| 220 const int fW, fH; | 225 const int fW, fH; |
| 221 SkBitmap fBM[4]; | 226 SkBitmap fBM[4]; |
| 222 | 227 |
| 223 public: | 228 public: |
| 224 ShowMipLevels2(int w, int h) : fW(w), fH(h) { | 229 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); | 230 fBM[0] = sk_tool_utils::create_checkerboard_bitmap(w, h, SHOW_MIP_COLOR,
SK_ColorWHITE, 2); |
| 226 fBM[1] = make_bitmap(w, h); | 231 fBM[1] = make_bitmap(w, h); |
| 227 fBM[2] = make_bitmap2(w, h); | 232 fBM[2] = make_bitmap2(w, h); |
| 228 fBM[3] = make_bitmap3(w, h); | 233 fBM[3] = make_bitmap3(w, h); |
| 229 } | 234 } |
| 230 | 235 |
| 231 protected: | 236 protected: |
| 232 | 237 |
| 233 SkString onShortName() override { | 238 SkString onShortName() override { |
| 234 SkString str; | 239 SkString str; |
| 235 str.printf("showmiplevels2_%dx%d", fW, fH); | 240 str.printf("showmiplevels2_%dx%d", fW, fH); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 } | 309 } |
| 305 } | 310 } |
| 306 | 311 |
| 307 private: | 312 private: |
| 308 typedef skiagm::GM INHERITED; | 313 typedef skiagm::GM INHERITED; |
| 309 }; | 314 }; |
| 310 DEF_GM( return new ShowMipLevels2(255, 255); ) | 315 DEF_GM( return new ShowMipLevels2(255, 255); ) |
| 311 DEF_GM( return new ShowMipLevels2(256, 255); ) | 316 DEF_GM( return new ShowMipLevels2(256, 255); ) |
| 312 DEF_GM( return new ShowMipLevels2(255, 256); ) | 317 DEF_GM( return new ShowMipLevels2(255, 256); ) |
| 313 DEF_GM( return new ShowMipLevels2(256, 256); ) | 318 DEF_GM( return new ShowMipLevels2(256, 256); ) |
| OLD | NEW |