| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "gm.h" | 8 #include "gm.h" |
| 9 #include "SkPath.h" | 9 #include "SkPath.h" |
| 10 #include "SkRegion.h" | 10 #include "SkRegion.h" |
| 11 #include "SkShader.h" | 11 #include "SkShader.h" |
| 12 #include "SkUtils.h" | 12 #include "SkUtils.h" |
| 13 #include "SkColorPriv.h" | |
| 14 #include "SkColorFilter.h" | 13 #include "SkColorFilter.h" |
| 15 #include "SkTypeface.h" | |
| 16 #include "SkBlurMask.h" | |
| 17 | 14 |
| 18 // effects | 15 // effects |
| 19 #include "SkGradientShader.h" | 16 #include "SkGradientShader.h" |
| 20 #include "SkBlurDrawLooper.h" | 17 #include "SkBlurDrawLooper.h" |
| 21 | 18 |
| 22 static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) { | 19 static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) { |
| 23 bm->allocPixels(SkImageInfo::Make(w, h, ct, kPremul_SkAlphaType)); | 20 bm->allocPixels(SkImageInfo::Make(w, h, ct, kPremul_SkAlphaType)); |
| 24 bm->eraseColor(SK_ColorTRANSPARENT); | 21 bm->eraseColor(SK_ColorTRANSPARENT); |
| 25 | 22 |
| 26 SkCanvas canvas(*bm); | 23 SkCanvas canvas(*bm); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 41 paint->setShader(shader)->unref(); | 38 paint->setShader(shader)->unref(); |
| 42 paint->setFilterQuality(filter_level); | 39 paint->setFilterQuality(filter_level); |
| 43 } | 40 } |
| 44 | 41 |
| 45 static const SkColorType gColorTypes[] = { | 42 static const SkColorType gColorTypes[] = { |
| 46 kN32_SkColorType, | 43 kN32_SkColorType, |
| 47 kRGB_565_SkColorType, | 44 kRGB_565_SkColorType, |
| 48 }; | 45 }; |
| 49 | 46 |
| 50 class ScaledTilingGM : public skiagm::GM { | 47 class ScaledTilingGM : public skiagm::GM { |
| 51 SkAutoTUnref<SkBlurDrawLooper> fLooper; | |
| 52 public: | 48 public: |
| 53 ScaledTilingGM(bool powerOfTwoSize) | 49 ScaledTilingGM(bool powerOfTwoSize) |
| 54 : fLooper(SkBlurDrawLooper::Create(0x88000000, | 50 : fPowerOfTwoSize(powerOfTwoSize) { |
| 55 SkBlurMask::ConvertRadiusToSigma(
SkIntToScalar(1)), | |
| 56 SkIntToScalar(2), SkIntToScalar(2
))) | |
| 57 , fPowerOfTwoSize(powerOfTwoSize) { | |
| 58 } | 51 } |
| 59 | 52 |
| 60 SkBitmap fTexture[SK_ARRAY_COUNT(gColorTypes)]; | 53 SkBitmap fTexture[SK_ARRAY_COUNT(gColorTypes)]; |
| 61 | 54 |
| 62 protected: | 55 protected: |
| 63 enum { | 56 enum { |
| 64 kPOTSize = 4, | 57 kPOTSize = 4, |
| 65 kNPOTSize = 3, | 58 kNPOTSize = 3, |
| 66 }; | 59 }; |
| 67 | 60 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 static const char* gModeNames[] = { "C",
"R", "M" }; | 95 static const char* gModeNames[] = { "C",
"R", "M" }; |
| 103 | 96 |
| 104 SkScalar y = SkIntToScalar(24); | 97 SkScalar y = SkIntToScalar(24); |
| 105 SkScalar x = SkIntToScalar(10)/scale; | 98 SkScalar x = SkIntToScalar(10)/scale; |
| 106 | 99 |
| 107 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { | 100 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { |
| 108 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { | 101 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { |
| 109 SkPaint p; | 102 SkPaint p; |
| 110 SkString str; | 103 SkString str; |
| 111 p.setAntiAlias(true); | 104 p.setAntiAlias(true); |
| 112 sk_tool_utils::set_portable_typeface(&p); | 105 sk_tool_utils::set_portable_typeface_always(&p); |
| 113 p.setDither(true); | |
| 114 p.setLooper(fLooper); | |
| 115 str.printf("[%s,%s]", gModeNames[kx], gModeNames[ky]); | 106 str.printf("[%s,%s]", gModeNames[kx], gModeNames[ky]); |
| 116 | 107 |
| 117 p.setTextAlign(SkPaint::kCenter_Align); | 108 p.setTextAlign(SkPaint::kCenter_Align); |
| 118 canvas->drawText(str.c_str(), str.size(), scale*(x + r.width()/2
), y, p); | 109 canvas->drawText(str.c_str(), str.size(), scale*(x + r.width()/2
), y, p); |
| 119 | 110 |
| 120 x += r.width() * 4 / 3; | 111 x += r.width() * 4 / 3; |
| 121 } | 112 } |
| 122 } | 113 } |
| 123 | 114 |
| 124 y = SkIntToScalar(40) / scale; | 115 y = SkIntToScalar(40) / scale; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 144 canvas->drawRect(r, paint); | 135 canvas->drawRect(r, paint); |
| 145 canvas->restore(); | 136 canvas->restore(); |
| 146 | 137 |
| 147 x += r.width() * 4 / 3; | 138 x += r.width() * 4 / 3; |
| 148 } | 139 } |
| 149 } | 140 } |
| 150 { | 141 { |
| 151 SkPaint p; | 142 SkPaint p; |
| 152 SkString str; | 143 SkString str; |
| 153 p.setAntiAlias(true); | 144 p.setAntiAlias(true); |
| 154 sk_tool_utils::set_portable_typeface(&p); | 145 sk_tool_utils::set_portable_typeface_always(&p); |
| 155 p.setLooper(fLooper); | |
| 156 str.printf("%s, %s", gColorTypeNames[i], gFilterNames[j]); | 146 str.printf("%s, %s", gColorTypeNames[i], gFilterNames[j]); |
| 157 canvas->drawText(str.c_str(), str.size(), scale*x, scale*(y
+ r.height() * 2 / 3), p); | 147 canvas->drawText(str.c_str(), str.size(), scale*x, scale*(y
+ r.height() * 2 / 3), p); |
| 158 } | 148 } |
| 159 | 149 |
| 160 y += r.height() * 4 / 3; | 150 y += r.height() * 4 / 3; |
| 161 } | 151 } |
| 162 } | 152 } |
| 163 } | 153 } |
| 164 | 154 |
| 165 private: | 155 private: |
| 166 bool fPowerOfTwoSize; | 156 bool fPowerOfTwoSize; |
| 167 typedef skiagm::GM INHERITED; | 157 typedef skiagm::GM INHERITED; |
| 168 }; | 158 }; |
| 169 | 159 |
| 170 static const int gWidth = 32; | 160 static const int gWidth = 32; |
| 171 static const int gHeight = 32; | 161 static const int gHeight = 32; |
| 172 | 162 |
| 173 static SkShader* make_bm(SkShader::TileMode tx, SkShader::TileMode ty) { | 163 static SkShader* make_bm(SkShader::TileMode tx, SkShader::TileMode ty) { |
| 174 SkBitmap bm; | 164 SkBitmap bm; |
| 175 makebm(&bm, kN32_SkColorType, gWidth, gHeight); | 165 makebm(&bm, kN32_SkColorType, gWidth, gHeight); |
| 176 return SkShader::CreateBitmapShader(bm, tx, ty); | 166 return SkShader::CreateBitmapShader(bm, tx, ty); |
| 177 } | 167 } |
| 178 | 168 |
| 179 static SkShader* make_grad(SkShader::TileMode tx, SkShader::TileMode ty) { | 169 static SkShader* make_grad(SkShader::TileMode tx, SkShader::TileMode ty) { |
| 180 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)}
}; | 170 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)}
}; |
| 181 SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 }; | 171 SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 }; |
| 182 SkScalar rad = SkIntToScalar(gWidth)/2; | 172 SkScalar rad = SkIntToScalar(gWidth)/2; |
| 183 SkColor colors[] = { 0xFFFF0000, 0xFF0044FF }; | 173 SkColor colors[] = { 0xFFFF0000, sk_tool_utils::color_to_565(0xFF0044FF) }; |
| 184 | 174 |
| 185 int index = (int)ty; | 175 int index = (int)ty; |
| 186 switch (index % 3) { | 176 switch (index % 3) { |
| 187 case 0: | 177 case 0: |
| 188 return SkGradientShader::CreateLinear(pts, colors, NULL, SK_ARRAY_CO
UNT(colors), tx); | 178 return SkGradientShader::CreateLinear(pts, colors, NULL, SK_ARRAY_CO
UNT(colors), tx); |
| 189 case 1: | 179 case 1: |
| 190 return SkGradientShader::CreateRadial(center, rad, colors, NULL, SK_
ARRAY_COUNT(colors), tx); | 180 return SkGradientShader::CreateRadial(center, rad, colors, NULL, SK_
ARRAY_COUNT(colors), tx); |
| 191 case 2: | 181 case 2: |
| 192 return SkGradientShader::CreateSweep(center.fX, center.fY, colors, N
ULL, SK_ARRAY_COUNT(colors)); | 182 return SkGradientShader::CreateSweep(center.fX, center.fY, colors, N
ULL, SK_ARRAY_COUNT(colors)); |
| 193 } | 183 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 }; | 215 }; |
| 226 static const char* gModeNames[] = { | 216 static const char* gModeNames[] = { |
| 227 "Clamp", "Repeat", "Mirror" | 217 "Clamp", "Repeat", "Mirror" |
| 228 }; | 218 }; |
| 229 | 219 |
| 230 SkScalar y = SkIntToScalar(24); | 220 SkScalar y = SkIntToScalar(24); |
| 231 SkScalar x = SkIntToScalar(66); | 221 SkScalar x = SkIntToScalar(66); |
| 232 | 222 |
| 233 SkPaint p; | 223 SkPaint p; |
| 234 p.setAntiAlias(true); | 224 p.setAntiAlias(true); |
| 235 sk_tool_utils::set_portable_typeface(&p); | 225 sk_tool_utils::set_portable_typeface_always(&p); |
| 236 p.setTextAlign(SkPaint::kCenter_Align); | 226 p.setTextAlign(SkPaint::kCenter_Align); |
| 237 | 227 |
| 238 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { | 228 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { |
| 239 SkString str(gModeNames[kx]); | 229 SkString str(gModeNames[kx]); |
| 240 canvas->drawText(str.c_str(), str.size(), x + r.width()/2, y, p); | 230 canvas->drawText(str.c_str(), str.size(), x + r.width()/2, y, p); |
| 241 x += r.width() * 4 / 3; | 231 x += r.width() * 4 / 3; |
| 242 } | 232 } |
| 243 | 233 |
| 244 y += SkIntToScalar(16) + h; | 234 y += SkIntToScalar(16) + h; |
| 245 p.setTextAlign(SkPaint::kRight_Align); | 235 p.setTextAlign(SkPaint::kRight_Align); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 269 private: | 259 private: |
| 270 typedef skiagm::GM INHERITED; | 260 typedef skiagm::GM INHERITED; |
| 271 }; | 261 }; |
| 272 | 262 |
| 273 ////////////////////////////////////////////////////////////////////////////// | 263 ////////////////////////////////////////////////////////////////////////////// |
| 274 | 264 |
| 275 DEF_GM( return new ScaledTilingGM(true); ) | 265 DEF_GM( return new ScaledTilingGM(true); ) |
| 276 DEF_GM( return new ScaledTilingGM(false); ) | 266 DEF_GM( return new ScaledTilingGM(false); ) |
| 277 DEF_GM( return new ScaledTiling2GM(make_bm, "bitmap"); ) | 267 DEF_GM( return new ScaledTiling2GM(make_bm, "bitmap"); ) |
| 278 DEF_GM( return new ScaledTiling2GM(make_grad, "gradient"); ) | 268 DEF_GM( return new ScaledTiling2GM(make_grad, "gradient"); ) |
| OLD | NEW |