| 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 | 14 |
| 17 // effects | 15 // effects |
| 18 #include "SkGradientShader.h" | 16 #include "SkGradientShader.h" |
| 19 #include "SkBlurDrawLooper.h" | 17 #include "SkBlurDrawLooper.h" |
| 20 | 18 |
| 21 static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) { | 19 static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) { |
| 22 bm->allocPixels(SkImageInfo::Make(w, h, ct, kPremul_SkAlphaType)); | 20 bm->allocPixels(SkImageInfo::Make(w, h, ct, kPremul_SkAlphaType)); |
| 23 bm->eraseColor(SK_ColorTRANSPARENT); | 21 bm->eraseColor(SK_ColorTRANSPARENT); |
| 24 | 22 |
| 25 SkCanvas canvas(*bm); | 23 SkCanvas canvas(*bm); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 static const char* gModeNames[] = { "C",
"R", "M" }; | 91 static const char* gModeNames[] = { "C",
"R", "M" }; |
| 94 | 92 |
| 95 SkScalar y = SkIntToScalar(24); | 93 SkScalar y = SkIntToScalar(24); |
| 96 SkScalar x = SkIntToScalar(10); | 94 SkScalar x = SkIntToScalar(10); |
| 97 | 95 |
| 98 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { | 96 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { |
| 99 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { | 97 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { |
| 100 SkPaint p; | 98 SkPaint p; |
| 101 SkString str; | 99 SkString str; |
| 102 p.setAntiAlias(true); | 100 p.setAntiAlias(true); |
| 103 sk_tool_utils::set_portable_typeface(&p); | 101 sk_tool_utils::set_portable_typeface_always(&p); |
| 104 p.setDither(true); | 102 p.setDither(true); |
| 105 str.printf("[%s,%s]", gModeNames[kx], gModeNames[ky]); | 103 str.printf("[%s,%s]", gModeNames[kx], gModeNames[ky]); |
| 106 | 104 |
| 107 p.setTextAlign(SkPaint::kCenter_Align); | 105 p.setTextAlign(SkPaint::kCenter_Align); |
| 108 canvas->drawText(str.c_str(), str.size(), x + r.width()/2, y, p)
; | 106 canvas->drawText(str.c_str(), str.size(), x + r.width()/2, y, p)
; |
| 109 | 107 |
| 110 x += r.width() * 4 / 3; | 108 x += r.width() * 4 / 3; |
| 111 } | 109 } |
| 112 } | 110 } |
| 113 | 111 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 133 canvas->drawRect(r, paint); | 131 canvas->drawRect(r, paint); |
| 134 canvas->restore(); | 132 canvas->restore(); |
| 135 | 133 |
| 136 x += r.width() * 4 / 3; | 134 x += r.width() * 4 / 3; |
| 137 } | 135 } |
| 138 } | 136 } |
| 139 { | 137 { |
| 140 SkPaint p; | 138 SkPaint p; |
| 141 SkString str; | 139 SkString str; |
| 142 p.setAntiAlias(true); | 140 p.setAntiAlias(true); |
| 143 sk_tool_utils::set_portable_typeface(&p); | 141 sk_tool_utils::set_portable_typeface_always(&p); |
| 144 str.printf("%s, %s", gConfigNames[i], gFilterNames[j]); | 142 str.printf("%s, %s", gConfigNames[i], gFilterNames[j]); |
| 145 canvas->drawText(str.c_str(), str.size(), x, y + r.height()
* 2 / 3, p); | 143 canvas->drawText(str.c_str(), str.size(), x, y + r.height()
* 2 / 3, p); |
| 146 } | 144 } |
| 147 | 145 |
| 148 y += r.height() * 4 / 3; | 146 y += r.height() * 4 / 3; |
| 149 } | 147 } |
| 150 } | 148 } |
| 151 } | 149 } |
| 152 | 150 |
| 153 private: | 151 private: |
| 154 bool fPowerOfTwoSize; | 152 bool fPowerOfTwoSize; |
| 155 typedef skiagm::GM INHERITED; | 153 typedef skiagm::GM INHERITED; |
| 156 }; | 154 }; |
| 157 | 155 |
| 158 static const int gWidth = 32; | 156 static const int gWidth = 32; |
| 159 static const int gHeight = 32; | 157 static const int gHeight = 32; |
| 160 | 158 |
| 161 static SkShader* make_bm(SkShader::TileMode tx, SkShader::TileMode ty) { | 159 static SkShader* make_bm(SkShader::TileMode tx, SkShader::TileMode ty) { |
| 162 SkBitmap bm; | 160 SkBitmap bm; |
| 163 makebm(&bm, kN32_SkColorType, gWidth, gHeight); | 161 makebm(&bm, kN32_SkColorType, gWidth, gHeight); |
| 164 return SkShader::CreateBitmapShader(bm, tx, ty); | 162 return SkShader::CreateBitmapShader(bm, tx, ty); |
| 165 } | 163 } |
| 166 | 164 |
| 167 static SkShader* make_grad(SkShader::TileMode tx, SkShader::TileMode ty) { | 165 static SkShader* make_grad(SkShader::TileMode tx, SkShader::TileMode ty) { |
| 168 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)}
}; | 166 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)}
}; |
| 169 SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 }; | 167 SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 }; |
| 170 SkScalar rad = SkIntToScalar(gWidth)/2; | 168 SkScalar rad = SkIntToScalar(gWidth)/2; |
| 171 SkColor colors[] = { 0xFFFF0000, 0xFF0044FF }; | 169 SkColor colors[] = { 0xFFFF0000, sk_tool_utils::color_to_565(0xFF0044FF) }; |
| 172 | 170 |
| 173 int index = (int)ty; | 171 int index = (int)ty; |
| 174 switch (index % 3) { | 172 switch (index % 3) { |
| 175 case 0: | 173 case 0: |
| 176 return SkGradientShader::CreateLinear(pts, colors, NULL, SK_ARRAY_CO
UNT(colors), tx); | 174 return SkGradientShader::CreateLinear(pts, colors, NULL, SK_ARRAY_CO
UNT(colors), tx); |
| 177 case 1: | 175 case 1: |
| 178 return SkGradientShader::CreateRadial(center, rad, colors, NULL, SK_
ARRAY_COUNT(colors), tx); | 176 return SkGradientShader::CreateRadial(center, rad, colors, NULL, SK_
ARRAY_COUNT(colors), tx); |
| 179 case 2: | 177 case 2: |
| 180 return SkGradientShader::CreateSweep(center.fX, center.fY, colors, N
ULL, SK_ARRAY_COUNT(colors)); | 178 return SkGradientShader::CreateSweep(center.fX, center.fY, colors, N
ULL, SK_ARRAY_COUNT(colors)); |
| 181 } | 179 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 }; | 211 }; |
| 214 static const char* gModeNames[] = { | 212 static const char* gModeNames[] = { |
| 215 "Clamp", "Repeat", "Mirror" | 213 "Clamp", "Repeat", "Mirror" |
| 216 }; | 214 }; |
| 217 | 215 |
| 218 SkScalar y = SkIntToScalar(24); | 216 SkScalar y = SkIntToScalar(24); |
| 219 SkScalar x = SkIntToScalar(66); | 217 SkScalar x = SkIntToScalar(66); |
| 220 | 218 |
| 221 SkPaint p; | 219 SkPaint p; |
| 222 p.setAntiAlias(true); | 220 p.setAntiAlias(true); |
| 223 sk_tool_utils::set_portable_typeface(&p); | 221 sk_tool_utils::set_portable_typeface_always(&p); |
| 224 p.setTextAlign(SkPaint::kCenter_Align); | 222 p.setTextAlign(SkPaint::kCenter_Align); |
| 225 | 223 |
| 226 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { | 224 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { |
| 227 SkString str(gModeNames[kx]); | 225 SkString str(gModeNames[kx]); |
| 228 canvas->drawText(str.c_str(), str.size(), x + r.width()/2, y, p); | 226 canvas->drawText(str.c_str(), str.size(), x + r.width()/2, y, p); |
| 229 x += r.width() * 4 / 3; | 227 x += r.width() * 4 / 3; |
| 230 } | 228 } |
| 231 | 229 |
| 232 y += SkIntToScalar(16) + h; | 230 y += SkIntToScalar(16) + h; |
| 233 p.setTextAlign(SkPaint::kRight_Align); | 231 p.setTextAlign(SkPaint::kRight_Align); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 257 private: | 255 private: |
| 258 typedef skiagm::GM INHERITED; | 256 typedef skiagm::GM INHERITED; |
| 259 }; | 257 }; |
| 260 | 258 |
| 261 ////////////////////////////////////////////////////////////////////////////// | 259 ////////////////////////////////////////////////////////////////////////////// |
| 262 | 260 |
| 263 DEF_GM( return new TilingGM(true); ) | 261 DEF_GM( return new TilingGM(true); ) |
| 264 DEF_GM( return new TilingGM(false); ) | 262 DEF_GM( return new TilingGM(false); ) |
| 265 DEF_GM( return new Tiling2GM(make_bm, "bitmap"); ) | 263 DEF_GM( return new Tiling2GM(make_bm, "bitmap"); ) |
| 266 DEF_GM( return new Tiling2GM(make_grad, "gradient"); ) | 264 DEF_GM( return new Tiling2GM(make_grad, "gradient"); ) |
| OLD | NEW |