| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #include "gm.h" | 7 #include "gm.h" |
| 8 #include "SkColorFilter.h" | 8 #include "SkColorFilter.h" |
| 9 #include "SkMaskFilter.h" | 9 #include "SkMaskFilter.h" |
| 10 #include "SkPath.h" | 10 #include "SkPath.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode)); | 31 SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode)); |
| 32 canvas.drawPaint(paint); | 32 canvas.drawPaint(paint); |
| 33 } | 33 } |
| 34 | 34 |
| 35 static void setup(SkPaint* paint, const SkBitmap& bm, SkFilterQuality filter_lev
el, | 35 static void setup(SkPaint* paint, const SkBitmap& bm, SkFilterQuality filter_lev
el, |
| 36 SkShader::TileMode tmx, SkShader::TileMode tmy) { | 36 SkShader::TileMode tmx, SkShader::TileMode tmy) { |
| 37 paint->setShader(SkShader::MakeBitmapShader(bm, tmx, tmy)); | 37 paint->setShader(SkShader::MakeBitmapShader(bm, tmx, tmy)); |
| 38 paint->setFilterQuality(filter_level); | 38 paint->setFilterQuality(filter_level); |
| 39 } | 39 } |
| 40 | 40 |
| 41 static const SkColorType gColorTypes[] = { | 41 constexpr SkColorType gColorTypes[] = { |
| 42 kN32_SkColorType, | 42 kN32_SkColorType, |
| 43 kRGB_565_SkColorType, | 43 kRGB_565_SkColorType, |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class ScaledTilingGM : public skiagm::GM { | 46 class ScaledTilingGM : public skiagm::GM { |
| 47 public: | 47 public: |
| 48 ScaledTilingGM(bool powerOfTwoSize) | 48 ScaledTilingGM(bool powerOfTwoSize) |
| 49 : fPowerOfTwoSize(powerOfTwoSize) { | 49 : fPowerOfTwoSize(powerOfTwoSize) { |
| 50 } | 50 } |
| 51 | 51 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 void onDraw(SkCanvas* canvas) override { | 77 void onDraw(SkCanvas* canvas) override { |
| 78 float scale = 32.f/kPOTSize; | 78 float scale = 32.f/kPOTSize; |
| 79 | 79 |
| 80 int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize; | 80 int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize; |
| 81 | 81 |
| 82 SkRect r = { 0, 0, SkIntToScalar(size*2), SkIntToScalar(size*2) }; | 82 SkRect r = { 0, 0, SkIntToScalar(size*2), SkIntToScalar(size*2) }; |
| 83 | 83 |
| 84 static const char* gColorTypeNames[] = { "8888" , "565", "4444" }; | 84 const char* gColorTypeNames[] = { "8888" , "565", "4444" }; |
| 85 | 85 |
| 86 static const SkFilterQuality gFilterQualitys[] = | 86 constexpr SkFilterQuality gFilterQualitys[] = |
| 87 { kNone_SkFilterQuality, | 87 { kNone_SkFilterQuality, |
| 88 kLow_SkFilterQuality, | 88 kLow_SkFilterQuality, |
| 89 kMedium_SkFilterQuality, | 89 kMedium_SkFilterQuality, |
| 90 kHigh_SkFilterQuality }; | 90 kHigh_SkFilterQuality }; |
| 91 static const char* gFilterNames[] = { "None", "Low", "Medium", "High" }; | 91 const char* gFilterNames[] = { "None", "Low", "Medium", "High" }; |
| 92 | 92 |
| 93 static const SkShader::TileMode gModes[] = { SkShader::kClamp_TileMode,
SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode }; | 93 constexpr SkShader::TileMode gModes[] = { |
| 94 static const char* gModeNames[] = { "C",
"R", "M" }; | 94 SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMi
rror_TileMode }; |
| 95 const char* gModeNames[] = { "C", "R", "M" }; |
| 95 | 96 |
| 96 SkScalar y = SkIntToScalar(24); | 97 SkScalar y = SkIntToScalar(24); |
| 97 SkScalar x = SkIntToScalar(10)/scale; | 98 SkScalar x = SkIntToScalar(10)/scale; |
| 98 | 99 |
| 99 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { | 100 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { |
| 100 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { | 101 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { |
| 101 SkPaint p; | 102 SkPaint p; |
| 102 SkString str; | 103 SkString str; |
| 103 p.setAntiAlias(true); | 104 p.setAntiAlias(true); |
| 104 sk_tool_utils::set_portable_typeface(&p); | 105 sk_tool_utils::set_portable_typeface(&p); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 y += r.height() * 4 / 3; | 150 y += r.height() * 4 / 3; |
| 150 } | 151 } |
| 151 } | 152 } |
| 152 } | 153 } |
| 153 | 154 |
| 154 private: | 155 private: |
| 155 bool fPowerOfTwoSize; | 156 bool fPowerOfTwoSize; |
| 156 typedef skiagm::GM INHERITED; | 157 typedef skiagm::GM INHERITED; |
| 157 }; | 158 }; |
| 158 | 159 |
| 159 static const int gWidth = 32; | 160 constexpr int gWidth = 32; |
| 160 static const int gHeight = 32; | 161 constexpr int gHeight = 32; |
| 161 | 162 |
| 162 static sk_sp<SkShader> make_bm(SkShader::TileMode tx, SkShader::TileMode ty) { | 163 static sk_sp<SkShader> make_bm(SkShader::TileMode tx, SkShader::TileMode ty) { |
| 163 SkBitmap bm; | 164 SkBitmap bm; |
| 164 makebm(&bm, kN32_SkColorType, gWidth, gHeight); | 165 makebm(&bm, kN32_SkColorType, gWidth, gHeight); |
| 165 return SkShader::MakeBitmapShader(bm, tx, ty); | 166 return SkShader::MakeBitmapShader(bm, tx, ty); |
| 166 } | 167 } |
| 167 | 168 |
| 168 static sk_sp<SkShader> make_grad(SkShader::TileMode tx, SkShader::TileMode ty) { | 169 static sk_sp<SkShader> make_grad(SkShader::TileMode tx, SkShader::TileMode ty) { |
| 169 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)}
}; | 170 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)}
}; |
| 170 SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 }; | 171 SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 }; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 | 203 |
| 203 SkISize onISize() override { return SkISize::Make(650, 610); } | 204 SkISize onISize() override { return SkISize::Make(650, 610); } |
| 204 | 205 |
| 205 void onDraw(SkCanvas* canvas) override { | 206 void onDraw(SkCanvas* canvas) override { |
| 206 canvas->scale(SkIntToScalar(3)/2, SkIntToScalar(3)/2); | 207 canvas->scale(SkIntToScalar(3)/2, SkIntToScalar(3)/2); |
| 207 | 208 |
| 208 const SkScalar w = SkIntToScalar(gWidth); | 209 const SkScalar w = SkIntToScalar(gWidth); |
| 209 const SkScalar h = SkIntToScalar(gHeight); | 210 const SkScalar h = SkIntToScalar(gHeight); |
| 210 SkRect r = { -w, -h, w*2, h*2 }; | 211 SkRect r = { -w, -h, w*2, h*2 }; |
| 211 | 212 |
| 212 static const SkShader::TileMode gModes[] = { | 213 constexpr SkShader::TileMode gModes[] = { |
| 213 SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMi
rror_TileMode | 214 SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMi
rror_TileMode |
| 214 }; | 215 }; |
| 215 static const char* gModeNames[] = { | 216 const char* gModeNames[] = { |
| 216 "Clamp", "Repeat", "Mirror" | 217 "Clamp", "Repeat", "Mirror" |
| 217 }; | 218 }; |
| 218 | 219 |
| 219 SkScalar y = SkIntToScalar(24); | 220 SkScalar y = SkIntToScalar(24); |
| 220 SkScalar x = SkIntToScalar(66); | 221 SkScalar x = SkIntToScalar(66); |
| 221 | 222 |
| 222 SkPaint p; | 223 SkPaint p; |
| 223 p.setAntiAlias(true); | 224 p.setAntiAlias(true); |
| 224 sk_tool_utils::set_portable_typeface(&p); | 225 sk_tool_utils::set_portable_typeface(&p); |
| 225 p.setTextAlign(SkPaint::kCenter_Align); | 226 p.setTextAlign(SkPaint::kCenter_Align); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 private: | 259 private: |
| 259 typedef skiagm::GM INHERITED; | 260 typedef skiagm::GM INHERITED; |
| 260 }; | 261 }; |
| 261 | 262 |
| 262 ////////////////////////////////////////////////////////////////////////////// | 263 ////////////////////////////////////////////////////////////////////////////// |
| 263 | 264 |
| 264 DEF_GM( return new ScaledTilingGM(true); ) | 265 DEF_GM( return new ScaledTilingGM(true); ) |
| 265 DEF_GM( return new ScaledTilingGM(false); ) | 266 DEF_GM( return new ScaledTilingGM(false); ) |
| 266 DEF_GM( return new ScaledTiling2GM(make_bm, "bitmap"); ) | 267 DEF_GM( return new ScaledTiling2GM(make_bm, "bitmap"); ) |
| 267 DEF_GM( return new ScaledTiling2GM(make_grad, "gradient"); ) | 268 DEF_GM( return new ScaledTiling2GM(make_grad, "gradient"); ) |
| OLD | NEW |