blob: 9fc3708ba128dce672939484cb9ddfea94cb6c34 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001#include "SampleCode.h"
2#include "SkView.h"
3#include "SkCanvas.h"
4#include "Sk64.h"
5#include "SkGradientShader.h"
6#include "SkGraphics.h"
7#include "SkImageDecoder.h"
8#include "SkKernel33MaskFilter.h"
9#include "SkPath.h"
10#include "SkRandom.h"
11#include "SkRegion.h"
12#include "SkShader.h"
13#include "SkUtils.h"
14#include "SkShaderExtras.h"
15#include "SkColorPriv.h"
16#include "SkColorFilter.h"
17#include "SkTime.h"
18#include "SkTypeface.h"
19#include "SkXfermode.h"
20
21#include "SkStream.h"
22#include "SkXMLParser.h"
23
24static const int gKernel[3][3] = {
25// { -1, -2, -1 }, { -2, 12, -2 }, { -1, -2, -1 }
26 { 1, 2, 1 }, { 2, 64-12, 2 }, { 1, 2, 1 }
27};
28static const int gShift = 6;
29
30class ReduceNoise : public SkKernel33ProcMaskFilter {
31public:
32 ReduceNoise(int percent256) : SkKernel33ProcMaskFilter(percent256) {}
33 virtual uint8_t computeValue(uint8_t* const* srcRows)
34 {
35 int c = srcRows[1][1];
36 int min = 255, max = 0;
37 for (int i = 0; i < 3; i++)
38 for (int j = 0; j < 3; j++)
39 if (i != 1 || j != 1)
40 {
41 int v = srcRows[i][j];
42 if (max < v)
43 max = v;
44 if (min > v)
45 min = v;
46 }
47 if (c > max) c = max;
48 // if (c < min) c = min;
49 return c;
50 }
51 virtual Factory getFactory() { return Create; }
52private:
53 ReduceNoise(SkFlattenableReadBuffer& rb) : SkKernel33ProcMaskFilter(rb) {}
54 static SkFlattenable* Create(SkFlattenableReadBuffer& rb)
55 {
56 return new ReduceNoise(rb);
57 }
58};
59
60class Darken : public SkKernel33ProcMaskFilter {
61public:
62 Darken(int percent256) : SkKernel33ProcMaskFilter(percent256) {}
63 virtual uint8_t computeValue(uint8_t* const* srcRows)
64 {
65 int c = srcRows[1][1];
66 float f = c / 255.f;
67
68 if (c >= 0)
69 {
70 f = sqrtf(f);
71 }
72 else
73 {
74 f *= f;
75 }
76 SkASSERT(f >= 0 && f <= 1);
77 return (int)(f * 255);
78 }
79 virtual Factory getFactory() { return Create; }
80private:
81 Darken(SkFlattenableReadBuffer& rb) : SkKernel33ProcMaskFilter(rb) {}
82 static SkFlattenable* Create(SkFlattenableReadBuffer& rb)
83 {
84 return new Darken(rb);
85 }
86};
87
88static SkMaskFilter* makemf() { return new Darken(0x30); }
89
90//#ifdef TEST_CLICKX
91
92static void test_typefaceCache()
93{
94 SkTypeface* t0 = SkTypeface::Create("sans-serif", SkTypeface::kNormal);
95 SkTypeface* t1 = SkTypeface::Create(NULL, SkTypeface::kNormal);
96 SkTypeface* t2 = SkTypeface::Create("arial", SkTypeface::kNormal);
97 SkTypeface* t3 = SkTypeface::Create("helvetica", SkTypeface::kItalic);
98
99 SkASSERT(t0 == t1);
100 SkASSERT(t0 == t2);
101 SkASSERT(t0 == t3);
102}
103
104static void test_breakText()
105{
106 SkPaint paint;
107 const char* text = "sdfkljAKLDFJKEWkldfjlk#$%&sdfs.dsj";
108 size_t length = strlen(text);
109 SkScalar width = paint.measureText(text, length);
110
111 SkScalar mm = 0;
112 SkScalar nn = 0;
113 for (SkScalar w = 0; w <= width; w += SK_Scalar1)
114 {
115 SkScalar m;
116 size_t n = paint.breakText(text, length, w, &m,
117 SkPaint::kBackward_TextBufferDirection);
118
119 SkASSERT(n <= length);
120 SkASSERT(m <= width);
121
122 if (n == 0)
123 SkASSERT(m == 0);
124 else
125 {
126 // now assert that we're monotonic
127 if (n == nn)
128 SkASSERT(m == mm);
129 else
130 {
131 SkASSERT(n > nn);
132 SkASSERT(m > mm);
133 }
134 }
135 nn = n;
136 mm = m;
137 }
138
139 nn = paint.breakText(text, length, width, &mm);
140 SkASSERT(nn == length);
141 SkASSERT(mm == width);
142}
143
144static SkRandom gRand;
145
146class SkPowerMode : public SkXfermode {
147public:
148 SkPowerMode(SkScalar exponent) { this->init(exponent); }
149
150 virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count, const SkAlpha aa[]);
151
152 typedef SkFlattenable* (*Factory)(SkFlattenableReadBuffer&);
153
154 // overrides for SkFlattenable
155 virtual Factory getFactory() { return Create; }
156 virtual void flatten(SkFlattenableWriteBuffer& b)
157 {
158 // this->INHERITED::flatten(b); How can we know if this is legal????
159 b.write32(SkScalarToFixed(fExp));
160 }
161
162private:
163 SkScalar fExp; // user's value
164 uint8_t fTable[256]; // cache
165
166 void init(SkScalar exponent);
167 SkPowerMode(SkFlattenableReadBuffer& b) : SkXfermode(b)
168 {
169 // read the exponent
170 this->init(SkFixedToScalar(b.readS32()));
171 }
172 static SkFlattenable* Create(SkFlattenableReadBuffer& b)
173 {
174 return SkNEW_ARGS(SkPowerMode, (b));
175 }
176
177 typedef SkXfermode INHERITED;
178};
179
180void SkPowerMode::init(SkScalar e)
181{
182 fExp = e;
183 float ee = SkScalarToFloat(e);
184
185 printf("------ %g\n", ee);
186 for (int i = 0; i < 256; i++)
187 {
188 float x = i / 255.f;
189 // printf(" %d %g", i, x);
190 x = powf(x, ee);
191 // printf(" %g", x);
192 int xx = SkScalarRound(SkFloatToScalar(x * 255));
193 // printf(" %d\n", xx);
194 fTable[i] = SkToU8(xx);
195 }
196}
197
198void SkPowerMode::xfer16(uint16_t dst[], const SkPMColor src[], int count, const SkAlpha aa[])
199{
200 for (int i = 0; i < count; i++)
201 {
202 SkPMColor c = src[i];
203 int r = SkGetPackedR32(c);
204 int g = SkGetPackedG32(c);
205 int b = SkGetPackedB32(c);
206 r = fTable[r];
207 g = fTable[g];
208 b = fTable[b];
209 dst[i] = SkPack888ToRGB16(r, g, b);
210 }
211}
212
213static const struct {
214 const char* fName;
215 uint32_t fFlags;
216 bool fFlushCache;
217} gHints[] = {
218 { "Linear", SkPaint::kLinearText_Flag, false },
219 { "Normal", 0, true },
220 { "Subpixel", SkPaint::kSubpixelText_Flag, true }
221};
222
223#ifdef SK_DEBUG
224 #define REPEAT_COUNT 1
225#else
226 #define REPEAT_COUNT 5000
227#endif
228
229static int count_char_points(const SkPaint& paint, char c)
230{
231 SkPath path;
232
233 paint.getTextPath(&c, 1, 0, 0, &path);
234 return path.getPoints(NULL, 0);
235}
236
237static int gOld, gNew, gCount;
238
239static void dump(int c, int oldc, int newc)
240{
241 if (oldc != newc)
242 {
243 gOld += oldc;
244 gNew += newc;
245 gCount += 1;
246 printf("char %c: old = %3d, new = %3d, reduction %g%%\n", c, oldc, newc, 100. * (oldc - newc) / oldc);
247 }
248}
249
250static void tab(int n)
251{
252// printf("[%d] ", n); return;
253 SkASSERT(n >= 0);
254 for (int i = 0; i < n; i++)
255 printf(" ");
256}
257
258#if 0
259#include "badrects.cpp"
260
261static void make_badrgn(SkRegion* rgn, int insetAmount)
262{
263 SkRect16 r, bounds;
264 int i;
265
266 rgn->setEmpty();
267 bounds.setEmpty();
268
269 for (i = 0; i < SK_ARRAY_COUNT(badrects); i++)
270 {
271 SkASSERT(badrects[i].width > 0 && badrects[i].height > 0);
272
273 r.set(badrects[i].x, badrects[i].y, badrects[i].x + badrects[i].width, badrects[i].y + badrects[i].height);
274 r.inset(insetAmount, insetAmount);
275 rgn->op(r, SkRegion::kUnion_Op);
276 bounds.join(r);
277 }
278 SkASSERT(bounds == rgn->getBounds());
279
280 for (i = 0; i < SK_ARRAY_COUNT(badrects); i++)
281 {
282 r.set(badrects[i].x, badrects[i].y, badrects[i].x + badrects[i].width, badrects[i].y + badrects[i].height);
283 SkASSERT(rgn->contains(r));
284 }
285}
286#endif
287
288static void draw_rgn(const SkRegion& rgn, SkCanvas* canvas, const SkPaint& paint)
289{
290 SkRect r;
291 SkRegion::Iterator iter(rgn);
292
293 for (; !iter.done(); iter.next())
294 {
295 r.set(iter.rect());
296 canvas->drawRect(r, paint);
297 }
298}
299
300static void test_break(SkCanvas* canvas, const char text[], size_t length,
301 SkScalar x, SkScalar y, const SkPaint& paint,
302 SkScalar clickX)
303{
304 SkPaint linePaint;
305
306 linePaint.setAntiAlias(true);
307
308 SkScalar measured;
309
310 if (paint.breakText(text, length, clickX - x, &measured, SkPaint::kForward_TextBufferDirection))
311 {
312 linePaint.setColor(SK_ColorRED);
313 canvas->drawLine(x, y, x + measured, y, linePaint);
314 }
315
316 x += paint.measureText(text, length);
317 if (paint.breakText(text, length, x - clickX, &measured, SkPaint::kBackward_TextBufferDirection))
318 {
319 linePaint.setColor(SK_ColorBLUE);
320 canvas->drawLine(x - measured, y, x, y, linePaint);
321 }
322}
323
324static void test_poly()
325{
326 static const SkPoint dst[] = {
327 SkIntToScalar(2), SkIntToScalar(1),
328 SkIntToScalar(5), SkIntToScalar(1),
329 SkIntToScalar(5), SkIntToScalar(3),
330 SkIntToScalar(2), SkIntToScalar(3)
331 };
332
333 static const SkPoint src[] = {
334 SkIntToScalar(0), SkIntToScalar(0),
335 SkIntToScalar(1), SkIntToScalar(0),
336 SkIntToScalar(1), SkIntToScalar(1),
337 SkIntToScalar(0), SkIntToScalar(1)
338 };
339
340 SkMatrix matrix;
341
342 if (matrix.setPolyToPoly(src, dst, 4))
343 {
344 SkPoint pt = { SK_Scalar1/2, SK_Scalar1/2 };
345 matrix.mapPoints(&pt, 1);
346 printf("---- x = %g y = %g\n", SkScalarToFloat(pt.fX), SkScalarToFloat(pt.fY));
347 }
348 else
349 printf("---- setPolyToPoly failed\n");
350}
351
352#include "SkColorShader.h"
353
354static void DrawTheText(SkCanvas* canvas, const char text[], size_t length,
355 SkScalar x, SkScalar y, const SkPaint& paint,
356 SkScalar clickX, SkMaskFilter* mf)
357{
358 SkPaint p(paint);
359
360#if 0
361 canvas->drawText(text, length, x, y, paint);
362#else
363 {
364 SkPoint pts[1000];
365 SkScalar xpos = x;
366 SkASSERT(length <= SK_ARRAY_COUNT(pts));
367 for (size_t i = 0; i < length; i++)
368 pts[i].set(xpos, y), xpos += paint.getTextSize();
369 canvas->drawPosText(text, length, pts, paint);
370 }
371#endif
372
373 p.setSubpixelText(true);
374 x += SkIntToScalar(180);
375 canvas->drawText(text, length, x, y, p);
376
377#ifdef TEST_CLICKX
378 test_break(canvas, text, length, x, y, p, clickX);
379#endif
380
381#ifdef SK_DEBUG
382 if (false)
383 {
384 SkColorShader shader;
385 p.setShader(&shader);
386 x += SkIntToScalar(180);
387 canvas->drawText(text, length, x, y, p);
388 p.setShader(NULL);
389 }
390
391 if (true)
392 {
393 // p.setMaskFilter(mf);
394 p.setSubpixelText(false);
395 p.setLinearText(true);
396 x += SkIntToScalar(180);
397 canvas->drawText(text, length, x, y, p);
398 }
399#endif
400}
401
402class TextSpeedView : public SkView {
403public:
404 TextSpeedView()
405 {
406 fMF = makemf();
407
408 fHints = 0;
409
410 if (false)
411 {
412 static const char extra[] = { '.', ',', ':', ';', '!' };
413 SkPaint paint, paint2;
414
415 paint2.setTypeface(SkTypeface::Create(NULL, SkTypeface::kItalic))->unref();
416
417 for (int i = 0; i < 26; i++)
418 ::dump('a' + i, count_char_points(paint, 'a' + i), count_char_points(paint2, 'a' + i));
419 for (int j = 0; j < SK_ARRAY_COUNT(extra); j++)
420 ::dump(extra[j], count_char_points(paint, extra[j]), count_char_points(paint2, extra[j]));
421
422 printf("--- ave reduction = %g%%\n", 100. * (gOld - gNew) / gOld);
423 }
424
425 if (true)
426 {
427 SkPoint pts[] = { SkIntToScalar(20), 0, SkIntToScalar(256+20), 0 };
428 SkColor colors[] = { SkColorSetARGB(0, 255, 255, 255), SkColorSetARGB(255, 255, 255, 255) };
429 fGradient = SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader::kClamp_TileMode);
430 }
431
432 fClickX = 0;
433
434 test_breakText();
435 test_typefaceCache();
436 test_poly();
437 }
438
439 virtual ~TextSpeedView()
440 {
441 fGradient->unref();
442 fMF->safeUnref();
443 }
444
445protected:
446 // overrides from SkEventSink
447 virtual bool onQuery(SkEvent* evt)
448 {
449 if (SampleCode::TitleQ(*evt))
450 {
451 SampleCode::TitleR(evt, "Text");
452 return true;
453 }
454 return this->INHERITED::onQuery(evt);
455 }
456
457 void drawBG(SkCanvas* canvas)
458 {
459// canvas->drawColor(0xFFDDDDDD);
460 canvas->drawColor(SK_ColorWHITE);
461 // canvas->drawColor(SK_ColorBLACK);
462 }
463
464 static void make_textstrip(SkBitmap* bm)
465 {
466 bm->setConfig(SkBitmap::kRGB_565_Config, 200, 18);
467 bm->allocPixels();
468 bm->eraseColor(SK_ColorWHITE);
469
470 SkCanvas canvas(*bm);
471 SkPaint paint;
472 const char* s = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit";
473
474 paint.setFlags(paint.getFlags() | SkPaint::kAntiAlias_Flag
475 | SkPaint::kDevKernText_Flag);
476 paint.setTextSize(SkIntToScalar(14));
477 canvas.drawText(s, strlen(s), SkIntToScalar(8), SkIntToScalar(14), paint);
478 }
479
480 static void fill_pts(SkPoint pts[], size_t n, SkRandom* rand)
481 {
482 for (size_t i = 0; i < n; i++)
483 pts[i].set(rand->nextUScalar1() * 640, rand->nextUScalar1() * 480);
484 }
485
486 virtual void onDraw(SkCanvas* canvas)
487 {
488 if (false)
489 {
490 canvas->translate(SkIntToScalar(480), 0);
491 canvas->rotate(SkIntToScalar(90));
492 }
493
494 this->drawBG(canvas);
495
496 if (false)
497 {
498 SkPaint p;
499
500 p.setAntiAlias(true);
501 p.setSubpixelText(true);
502 // p.setLinearText(true);
503
504 SkScalar size = SkIntToScalar(6);
505 SkMSec dur = 0;
506 const int LOOP = 16;
507 const int TIMES = 10;
508
509 for (int times = 0; times < TIMES; times++)
510 {
511 SkMSec now = SkTime::GetMSecs();
512 for (int loop = 0; loop < LOOP; loop++)
513 {
514 p.setTextSize(size);
515 size += SK_Scalar1/5;
516 canvas->drawText("Hamburgefons", 12, SkIntToScalar(10), SkIntToScalar(50), p);
517 }
518 dur += SkTime::GetMSecs() - now;
519 SkGraphics::SetFontCacheUsed(0);
520 }
521
522 printf("----- duration = %g\n", dur * 1.0 / TIMES);
523 this->inval(NULL);
524 return;
525 }
526
527 if (false)
528 {
529 SkPaint p;
530 p.setAntiAlias(true);
531 for (int i = 6; i <= 36; i++)
532 {
533 SkRect r;
534 SkPaint::FontMetrics m;
535 p.setTextSize(SkIntToScalar(i));
536 p.getFontMetrics(&m);
537 int ascent = SkScalarRound(m.fAscent);
538 int descent = SkScalarRound(m.fDescent);
539 for (uint8_t c = ' '; c <= 127; c++)
540 {
541 p.getTextWidths(&c, 1, NULL, &r);
542 if (SkScalarRound(r.fTop) < ascent)
543 printf("PS %d --- %c [%d] top=%g, ascent=%g ymax=%g\n", i, c, c,
544 SkScalarToFloat(r.fTop), SkScalarToFloat(m.fAscent), SkScalarToFloat(m.fTop));
545 if (SkScalarRound(r.fBottom) > descent)
546 printf("PS %d --- %c [%d] bottom=%g, descent=%g ymin=%g\n", i, c, c,
547 SkScalarToFloat(r.fBottom), SkScalarToFloat(m.fDescent), SkScalarToFloat(m.fBottom));
548 }
549 }
550 }
551
552 if (false)
553 {
554 SkPaint p;
555 p.setShader(fGradient);
556
557#ifdef SK_RELEASE
558 SkMSec now = SkTime::GetMSecs();
559 for (int i = 0; i < 100; i++)
560#endif
561 canvas->drawPaint(p);
562#ifdef SK_RELEASE
563 printf("----- %d ms\n", SkTime::GetMSecs() - now);
564 this->inval(NULL);
565#endif
566 return;
567 }
568
569 if (false)
570 {
571 SkBitmap bm;
572
573 make_textstrip(&bm);
574 canvas->translate(0, SkIntToScalar(50));
575 for (int i = 0; i < 10; i++)
576 {
577 float gamma = 1 + i * 0.2f;
578 SkPowerMode mode(SkFloatToScalar(1 / gamma));
579 SkPaint p;
580 p.setXfermode(&mode);
581
582 canvas->drawBitmap(bm, 0, SkIntToScalar(i) * bm.height(), &p);
583 }
584 return;
585 }
586
587 if (false)
588 {
589 SkPaint paint;
590
591 paint.setAntiAlias(true);
592 paint.setDevKernText(true);
593 SkMSec now = SkTime::GetMSecs();
594 for (int i = 0; i < 1000000; i++)
595 {
596 paint.measureText("Hamburgefons", 15, NULL, NULL);
597 }
598 printf("--------- measure %d\n", SkTime::GetMSecs() - now);
599 this->inval(NULL);
600 return;
601 }
602
603 if (false)
604 {
605 SkRegion rgn;
606 SkPath path;
607 SkPaint paint;
608
609 // make_badrgn(&rgn, -2);
610
611 if (false)
612 {
613 paint.setColor(SK_ColorBLUE);
614 canvas->drawIRect(rgn.getBounds(), paint);
615 }
616 paint.setColor(SK_ColorRED);
617 draw_rgn(rgn, canvas, paint);
618
619 rgn.getBoundaryPath(&path);
620 paint.setARGB(0x80, 0, 0, 0xFF);
621 canvas->drawPath(path, paint);
622 return;
623 }
624
625 if (false)
626 {
627 SkRect r = { SkIntToScalar(50), SkIntToScalar(50), SkIntToScalar(300), SkIntToScalar(300) };
628 SkPaint p;
629
630 p.setStyle(SkPaint::kStroke_Style);
631 p.setAlpha(0x80);
632 p.setStrokeWidth(SkIntToScalar(20));
633 canvas->drawRect(r, p);
634 }
635
636 if (false)
637 {
638 SkPaint p;
639 SkRect r = { SkIntToScalar(100), SkIntToScalar(100), SkIntToScalar(104), SkIntToScalar(104) };
640 // r.offset(SK_ScalarHalf, SK_ScalarHalf);
641 p.setStyle(SkPaint::kStroke_Style);
642 p.setStrokeWidth(SK_Scalar1*2);
643 // p.setAntiAliasOn(true);
644 canvas->drawRect(r, p);
645 return;
646 }
647
648 if (false)
649 {
650 Sk64 aa, bb;
651 int64_t a = (int64_t)6062080 * -30596;
652 int64_t b = (int64_t)4816896 * 57957;
653 aa.setMul(6062080, -30596);
654 bb.setMul(4816896, 57957);
655
656 a += b;
657 b = a >> 16;
658
659// SkFixed c = aa.addGetFixed(bb);
660
661 printf("%d %d\n", (int)a, a >> 32);
662
663 SkBitmap bm;
664 SkPaint paint;
665 SkScalar scale = SkFloatToScalar(0.5625f);
666 SkScalar x = SkIntToScalar(100);
667 SkScalar y = SkIntToScalar(100);
668
669 //paint.setFilterType(SkPaint::kBilinear_FilterType);
670
671 SkImageDecoder::DecodeFile("/app_web_browser.png", &bm);
672
673 // canvas->drawBitmap(bm, x, y, paint);
674 x += SkIntToScalar(100);
675 canvas->save();
676 canvas->translate(x, y);
677 canvas->scale(SkIntToScalar(2)/1, SkIntToScalar(2)/1);
678 canvas->translate(-x, -y);
679 canvas->drawBitmap(bm, x, y, &paint);
680 canvas->restore();
681 x += SkIntToScalar(100);
682 canvas->save();
683 canvas->translate(x, y);
684 canvas->scale(scale, scale);
685 canvas->translate(-x, -y);
686 // canvas->drawBitmap(bm, x, y, paint);
687 canvas->restore();
688 return;
689 }
690
691 SkAutoCanvasRestore restore(canvas, false);
692 {
693 SkRect r;
694 r.set(0, 0, SkIntToScalar(1000), SkIntToScalar(20));
695 // canvas->saveLayer(&r, NULL, SkCanvas::kHasAlphaLayer_SaveFlag);
696 }
697
698 SkPaint paint;
699// const uint16_t glyphs[] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19 };
700 int index = fHints % SK_ARRAY_COUNT(gHints);
701 index = 1;
702// const char* style = gHints[index].fName;
703
704// canvas->translate(0, SkIntToScalar(50));
705
706 // canvas->drawText(style, strlen(style), SkIntToScalar(20), SkIntToScalar(20), paint);
707
708// paint.setTypeface(SkTypeface::Create(NULL, SkTypeface::kItalic))->unref();
709 paint.setAntiAlias(true);
710 paint.setFlags(paint.getFlags() | gHints[index].fFlags);
711
712 SkMSec now = 0;
713 if (REPEAT_COUNT > 1)
714 now = SkTime::GetMSecs();
715
716 SkRect clip;
717 clip.set(SkIntToScalar(25), SkIntToScalar(34), SkIntToScalar(88), SkIntToScalar(155));
718
719 if (0) {
720 canvas->clipRect(clip);
721 }
722
723 if (0) {
724 SkPath clipPath;
725 clipPath.addOval(clip);
726 canvas->clipPath(clipPath);
727 }
728
729 const char* text = "Hamburgefons";
730 size_t length = strlen(text);
731
732#ifdef TEST_CLICKX
733 {
734 SkPaint p;
735
736 p.setColor(SK_ColorGREEN);
737 p.setAntiAlias(true);
738 canvas->drawLine(fClickX, 0, fClickX, SkIntToScalar(1000), p);
739 }
740#endif
741
742 for (int j = 0; j < REPEAT_COUNT; j++)
743 {
744 SkScalar y = SkIntToScalar(0);
745 for (int i = 9; i <= 24; i++) {
746 paint.setTextSize(SkIntToScalar(i) /*+ (gRand.nextU() & 0xFFFF)*/);
747 for (SkScalar dx = 0; dx <= SkIntToScalar(3)/4; dx += SkIntToScalar(1) /* /4 */)
748 {
749 y += paint.getFontSpacing();
750 DrawTheText(canvas, text, length, SkIntToScalar(20) + dx, y, paint, fClickX, fMF);
751 }
752 }
753 if (gHints[index].fFlushCache) {
754 SkGraphics::SetFontCacheUsed(0);
755 }
756 }
757
758 if (REPEAT_COUNT > 1)
759 {
760 printf("--------- FPS = %g\n", REPEAT_COUNT * 1000. / (SkTime::GetMSecs() - now));
761 this->inval(NULL);
762 }
763 }
764
765 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y)
766 {
767 fClickX = x;
768 this->inval(NULL);
769 return this->INHERITED::onFindClickHandler(x, y);
770 }
771
772 virtual bool onClick(Click* click)
773 {
774 return this->INHERITED::onClick(click);
775 }
776
777private:
778 int fHints;
779 SkScalar fClickX;
780 SkMaskFilter* fMF;
781 SkShader* fGradient;
782
783 typedef SkView INHERITED;
784};
785
786//////////////////////////////////////////////////////////////////////////////
787
788static SkView* MyFactory() { return new TextSpeedView; }
789static SkViewRegister reg(MyFactory);
790