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