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 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPath.h" | 10 #include "SkPath.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 cgSetPaintForText(cg, paint); | 92 cgSetPaintForText(cg, paint); |
93 | 93 |
94 uint16_t glyphs[200]; | 94 uint16_t glyphs[200]; |
95 int count = paint.textToGlyphs(text, len, glyphs); | 95 int count = paint.textToGlyphs(text, len, glyphs); |
96 | 96 |
97 CGContextShowGlyphsAtPoint(cg, x, y, glyphs, count); | 97 CGContextShowGlyphsAtPoint(cg, x, y, glyphs, count); |
98 } | 98 } |
99 } | 99 } |
100 #endif | 100 #endif |
101 | 101 |
102 namespace skiagm { | |
103 | |
104 /** | 102 /** |
105 Test a set of clipping problems discovered while writing blitAntiRect, | 103 Test a set of clipping problems discovered while writing blitAntiRect, |
106 and test all the code paths through the clipping blitters. | 104 and test all the code paths through the clipping blitters. |
107 Each region should show as a blue center surrounded by a 2px green | 105 Each region should show as a blue center surrounded by a 2px green |
108 border, with no red. | 106 border, with no red. |
109 */ | 107 */ |
110 | 108 |
111 #define HEIGHT 480 | 109 #define HEIGHT 480 |
112 | 110 |
113 class GammaTextGM : public GM { | 111 class GammaTextGM : public skiagm::GM { |
114 public: | 112 public: |
115 GammaTextGM() { | 113 GammaTextGM() { |
116 | 114 |
117 } | 115 } |
118 | 116 |
119 protected: | 117 protected: |
120 virtual SkString onShortName() { | 118 virtual SkString onShortName() { |
121 return SkString("gammatext"); | 119 return SkString("gammatext"); |
122 } | 120 } |
123 | 121 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 y += paint.getTextSize() * 2; | 190 y += paint.getTextSize() * 2; |
193 } | 191 } |
194 x += SkIntToScalar(1024) / SK_ARRAY_COUNT(fg); | 192 x += SkIntToScalar(1024) / SK_ARRAY_COUNT(fg); |
195 } | 193 } |
196 #ifdef SK_BUILD_FOR_MAC | 194 #ifdef SK_BUILD_FOR_MAC |
197 CGContextRelease(cg); | 195 CGContextRelease(cg); |
198 #endif | 196 #endif |
199 } | 197 } |
200 | 198 |
201 private: | 199 private: |
202 typedef GM INHERITED; | 200 typedef skiagm::GM INHERITED; |
203 }; | 201 }; |
204 | 202 |
| 203 DEF_GM( return new GammaTextGM; ) |
| 204 |
205 ////////////////////////////////////////////////////////////////////////////// | 205 ////////////////////////////////////////////////////////////////////////////// |
206 | 206 |
207 static GM* MyFactory(void*) { return new GammaTextGM; } | 207 static SkShader* make_gradient(SkColor c) { |
208 static GMRegistry reg(MyFactory); | 208 const SkPoint pts[] = { { 0, 0 }, { 240, 0 } }; |
| 209 SkColor colors[2]; |
| 210 colors[0] = c; |
| 211 colors[1] = SkColorSetA(c, 0); |
| 212 return SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader::kClamp
_TileMode); |
| 213 } |
209 | 214 |
| 215 static void set_face(SkPaint* paint) { |
| 216 SkTypeface* face = SkTypeface::CreateFromName("serif", SkTypeface::kItalic); |
| 217 SkSafeUnref(paint->setTypeface(face)); |
210 } | 218 } |
| 219 |
| 220 static void draw_pair(SkCanvas* canvas, SkPaint* paint, SkShader* shader) { |
| 221 const char text[] = "Now is the time for all good"; |
| 222 const size_t len = strlen(text); |
| 223 |
| 224 paint->setShader(NULL); |
| 225 canvas->drawText(text, len, 10, 20, *paint); |
| 226 paint->setShader(SkShader::CreateColorShader(paint->getColor()))->unref(); |
| 227 canvas->drawText(text, len, 10, 40, *paint); |
| 228 paint->setShader(shader); |
| 229 canvas->drawText(text, len, 10, 60, *paint); |
| 230 } |
| 231 |
| 232 class GammaShaderTextGM : public skiagm::GM { |
| 233 SkShader* fShaders[3]; |
| 234 SkColor fColors[3]; |
| 235 |
| 236 public: |
| 237 GammaShaderTextGM() { |
| 238 const SkColor colors[] = { SK_ColorBLACK, SK_ColorRED, SK_ColorBLUE }; |
| 239 for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) { |
| 240 fShaders[i] = NULL; |
| 241 fColors[i] = colors[i]; |
| 242 } |
| 243 } |
| 244 |
| 245 virtual ~GammaShaderTextGM() { |
| 246 for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) { |
| 247 SkSafeUnref(fShaders[i]); |
| 248 } |
| 249 } |
| 250 |
| 251 protected: |
| 252 virtual SkString onShortName() { |
| 253 return SkString("gammagradienttext"); |
| 254 } |
| 255 |
| 256 virtual SkISize onISize() { |
| 257 return SkISize::Make(300, 300); |
| 258 } |
| 259 |
| 260 virtual void onOnceBeforeDraw() { |
| 261 for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) { |
| 262 fShaders[i] = make_gradient(fColors[i]); |
| 263 } |
| 264 } |
| 265 |
| 266 virtual void onDraw(SkCanvas* canvas) { |
| 267 SkPaint paint; |
| 268 paint.setAntiAlias(true); |
| 269 paint.setLCDRenderText(true); |
| 270 paint.setTextSize(18); |
| 271 set_face(&paint); |
| 272 |
| 273 for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) { |
| 274 paint.setColor(fColors[i]); |
| 275 draw_pair(canvas, &paint, fShaders[i]); |
| 276 canvas->translate(0, 80); |
| 277 } |
| 278 } |
| 279 |
| 280 private: |
| 281 typedef skiagm::GM INHERITED; |
| 282 }; |
| 283 |
| 284 DEF_GM( return new GammaShaderTextGM; ) |
| 285 |
OLD | NEW |