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 "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkBlurMask.h" | 9 #include "SkBlurMask.h" |
10 #include "SkBlurMaskFilter.h" | 10 #include "SkBlurMaskFilter.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 /////////////////////////////////////////////////////////////////////////////// | 24 /////////////////////////////////////////////////////////////////////////////// |
25 | 25 |
26 #include "Sk1DPathEffect.h" | 26 #include "Sk1DPathEffect.h" |
27 #include "Sk2DPathEffect.h" | 27 #include "Sk2DPathEffect.h" |
28 #include "SkCornerPathEffect.h" | 28 #include "SkCornerPathEffect.h" |
29 #include "SkDashPathEffect.h" | 29 #include "SkDashPathEffect.h" |
30 #include "SkDiscretePathEffect.h" | 30 #include "SkDiscretePathEffect.h" |
31 | 31 |
32 static void compose_pe(SkPaint* paint) { | 32 static void compose_pe(SkPaint* paint) { |
33 SkPathEffect* pe = paint->getPathEffect(); | 33 SkPathEffect* pe = paint->getPathEffect(); |
34 SkPathEffect* corner = new SkCornerPathEffect(25); | 34 SkPathEffect* corner = SkCornerPathEffect::Create(25); |
35 SkPathEffect* compose; | 35 SkPathEffect* compose; |
36 if (pe) { | 36 if (pe) { |
37 compose = new SkComposePathEffect(pe, corner); | 37 compose = SkComposePathEffect::Create(pe, corner); |
38 corner->unref(); | 38 corner->unref(); |
39 } else { | 39 } else { |
40 compose = corner; | 40 compose = corner; |
41 } | 41 } |
42 paint->setPathEffect(compose)->unref(); | 42 paint->setPathEffect(compose)->unref(); |
43 } | 43 } |
44 | 44 |
45 static void hair_pe(SkPaint* paint) { | 45 static void hair_pe(SkPaint* paint) { |
46 paint->setStrokeWidth(0); | 46 paint->setStrokeWidth(0); |
47 } | 47 } |
48 | 48 |
49 static void hair2_pe(SkPaint* paint) { | 49 static void hair2_pe(SkPaint* paint) { |
50 paint->setStrokeWidth(0); | 50 paint->setStrokeWidth(0); |
51 compose_pe(paint); | 51 compose_pe(paint); |
52 } | 52 } |
53 | 53 |
54 static void stroke_pe(SkPaint* paint) { | 54 static void stroke_pe(SkPaint* paint) { |
55 paint->setStrokeWidth(12); | 55 paint->setStrokeWidth(12); |
56 compose_pe(paint); | 56 compose_pe(paint); |
57 } | 57 } |
58 | 58 |
59 static void dash_pe(SkPaint* paint) { | 59 static void dash_pe(SkPaint* paint) { |
60 SkScalar inter[] = { 20, 10, 10, 10 }; | 60 SkScalar inter[] = { 20, 10, 10, 10 }; |
61 paint->setStrokeWidth(12); | 61 paint->setStrokeWidth(12); |
62 paint->setPathEffect(new SkDashPathEffect(inter, SK_ARRAY_COUNT(inter), | 62 paint->setPathEffect(SkDashPathEffect::Create(inter, SK_ARRAY_COUNT(inter), |
63 0))->unref(); | 63 0))->unref(); |
64 compose_pe(paint); | 64 compose_pe(paint); |
65 } | 65 } |
66 | 66 |
67 static const int gXY[] = { | 67 static const int gXY[] = { |
68 4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4 | 68 4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4 |
69 }; | 69 }; |
70 | 70 |
71 static void scale(SkPath* path, SkScalar scale) { | 71 static void scale(SkPath* path, SkScalar scale) { |
72 SkMatrix m; | 72 SkMatrix m; |
73 m.setScale(scale, scale); | 73 m.setScale(scale, scale); |
74 path->transform(m); | 74 path->transform(m); |
75 } | 75 } |
76 | 76 |
77 static void one_d_pe(SkPaint* paint) { | 77 static void one_d_pe(SkPaint* paint) { |
78 SkPath path; | 78 SkPath path; |
79 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); | 79 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); |
80 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) | 80 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) |
81 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); | 81 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); |
82 path.close(); | 82 path.close(); |
83 path.offset(SkIntToScalar(-6), 0); | 83 path.offset(SkIntToScalar(-6), 0); |
84 scale(&path, 1.5f); | 84 scale(&path, 1.5f); |
85 | 85 |
86 paint->setPathEffect(new SkPath1DPathEffect(path, SkIntToScalar(21), 0, | 86 paint->setPathEffect(SkPath1DPathEffect::Create(path, SkIntToScalar(21), 0, |
87 SkPath1DPathEffect::kRotate_Style))->unref(); | 87 SkPath1DPathEffect::kRotate_
Style))->unref(); |
88 compose_pe(paint); | 88 compose_pe(paint); |
89 } | 89 } |
90 | 90 |
91 typedef void (*PE_Proc)(SkPaint*); | 91 typedef void (*PE_Proc)(SkPaint*); |
92 static const PE_Proc gPE[] = { hair_pe, hair2_pe, stroke_pe, dash_pe, one_d_pe }
; | 92 static const PE_Proc gPE[] = { hair_pe, hair2_pe, stroke_pe, dash_pe, one_d_pe }
; |
93 | 93 |
94 static void fill_pe(SkPaint* paint) { | 94 static void fill_pe(SkPaint* paint) { |
95 paint->setStyle(SkPaint::kFill_Style); | 95 paint->setStyle(SkPaint::kFill_Style); |
96 paint->setPathEffect(NULL); | 96 paint->setPathEffect(NULL); |
97 } | 97 } |
98 | 98 |
99 static void discrete_pe(SkPaint* paint) { | 99 static void discrete_pe(SkPaint* paint) { |
100 paint->setPathEffect(new SkDiscretePathEffect(10, 4))->unref(); | 100 paint->setPathEffect(SkDiscretePathEffect::Create(10, 4))->unref(); |
101 } | 101 } |
102 | 102 |
103 static SkPathEffect* MakeTileEffect() { | 103 static SkPathEffect* MakeTileEffect() { |
104 SkMatrix m; | 104 SkMatrix m; |
105 m.setScale(SkIntToScalar(12), SkIntToScalar(12)); | 105 m.setScale(SkIntToScalar(12), SkIntToScalar(12)); |
106 | 106 |
107 SkPath path; | 107 SkPath path; |
108 path.addCircle(0, 0, SkIntToScalar(5)); | 108 path.addCircle(0, 0, SkIntToScalar(5)); |
109 | 109 |
110 return new SkPath2DPathEffect(m, path); | 110 return SkPath2DPathEffect::Create(m, path); |
111 } | 111 } |
112 | 112 |
113 static void tile_pe(SkPaint* paint) { | 113 static void tile_pe(SkPaint* paint) { |
114 paint->setPathEffect(MakeTileEffect())->unref(); | 114 paint->setPathEffect(MakeTileEffect())->unref(); |
115 } | 115 } |
116 | 116 |
117 static const PE_Proc gPE2[] = { fill_pe, discrete_pe, tile_pe }; | 117 static const PE_Proc gPE2[] = { fill_pe, discrete_pe, tile_pe }; |
118 | 118 |
119 static void patheffect_slide(SkCanvas* canvas) { | 119 static void patheffect_slide(SkCanvas* canvas) { |
120 SkPaint paint; | 120 SkPaint paint; |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 p.setXfermode(NULL); | 540 p.setXfermode(NULL); |
541 rast->addLayer(p); | 541 rast->addLayer(p); |
542 } | 542 } |
543 | 543 |
544 #include "SkDiscretePathEffect.h" | 544 #include "SkDiscretePathEffect.h" |
545 | 545 |
546 static void r5(SkLayerRasterizer* rast, SkPaint& p) | 546 static void r5(SkLayerRasterizer* rast, SkPaint& p) |
547 { | 547 { |
548 rast->addLayer(p); | 548 rast->addLayer(p); |
549 | 549 |
550 p.setPathEffect(new SkDiscretePathEffect(SK_Scalar1*4, SK_Scalar1*3))->unref
(); | 550 p.setPathEffect(SkDiscretePathEffect::Create(SK_Scalar1*4, SK_Scalar1*3))->u
nref(); |
551 p.setXfermodeMode(SkXfermode::kSrcOut_Mode); | 551 p.setXfermodeMode(SkXfermode::kSrcOut_Mode); |
552 rast->addLayer(p); | 552 rast->addLayer(p); |
553 } | 553 } |
554 | 554 |
555 static void r6(SkLayerRasterizer* rast, SkPaint& p) | 555 static void r6(SkLayerRasterizer* rast, SkPaint& p) |
556 { | 556 { |
557 rast->addLayer(p); | 557 rast->addLayer(p); |
558 | 558 |
559 p.setAntiAlias(false); | 559 p.setAntiAlias(false); |
560 SkLayerRasterizer* rast2 = new SkLayerRasterizer; | 560 SkLayerRasterizer* rast2 = new SkLayerRasterizer; |
561 r5(rast2, p); | 561 r5(rast2, p); |
562 p.setRasterizer(rast2)->unref(); | 562 p.setRasterizer(rast2)->unref(); |
563 p.setXfermodeMode(SkXfermode::kClear_Mode); | 563 p.setXfermodeMode(SkXfermode::kClear_Mode); |
564 rast->addLayer(p); | 564 rast->addLayer(p); |
565 } | 565 } |
566 | 566 |
567 #include "Sk2DPathEffect.h" | 567 #include "Sk2DPathEffect.h" |
568 | 568 |
569 static SkPathEffect* MakeDotEffect(SkScalar radius, const SkMatrix& matrix) { | 569 static SkPathEffect* MakeDotEffect(SkScalar radius, const SkMatrix& matrix) { |
570 SkPath path; | 570 SkPath path; |
571 path.addCircle(0, 0, radius); | 571 path.addCircle(0, 0, radius); |
572 return new SkPath2DPathEffect(matrix, path); | 572 return SkPath2DPathEffect::Create(matrix, path); |
573 } | 573 } |
574 | 574 |
575 static void r7(SkLayerRasterizer* rast, SkPaint& p) | 575 static void r7(SkLayerRasterizer* rast, SkPaint& p) |
576 { | 576 { |
577 SkMatrix lattice; | 577 SkMatrix lattice; |
578 lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); | 578 lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); |
579 lattice.postSkew(SK_Scalar1/3, 0, 0, 0); | 579 lattice.postSkew(SK_Scalar1/3, 0, 0, 0); |
580 p.setPathEffect(MakeDotEffect(SK_Scalar1*4, lattice))->unref(); | 580 p.setPathEffect(MakeDotEffect(SK_Scalar1*4, lattice))->unref(); |
581 rast->addLayer(p); | 581 rast->addLayer(p); |
582 } | 582 } |
(...skipping 16 matching lines...) Expand all Loading... |
599 rast->addLayer(p); | 599 rast->addLayer(p); |
600 } | 600 } |
601 | 601 |
602 static void r9(SkLayerRasterizer* rast, SkPaint& p) | 602 static void r9(SkLayerRasterizer* rast, SkPaint& p) |
603 { | 603 { |
604 rast->addLayer(p); | 604 rast->addLayer(p); |
605 | 605 |
606 SkMatrix lattice; | 606 SkMatrix lattice; |
607 lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0); | 607 lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0); |
608 lattice.postRotate(SkIntToScalar(30), 0, 0); | 608 lattice.postRotate(SkIntToScalar(30), 0, 0); |
609 p.setPathEffect(new SkLine2DPathEffect(SK_Scalar1*2, lattice))->unref(); | 609 p.setPathEffect(SkLine2DPathEffect::Create(SK_Scalar1*2, lattice))->unref(); |
610 p.setXfermodeMode(SkXfermode::kClear_Mode); | 610 p.setXfermodeMode(SkXfermode::kClear_Mode); |
611 rast->addLayer(p); | 611 rast->addLayer(p); |
612 | 612 |
613 p.setPathEffect(NULL); | 613 p.setPathEffect(NULL); |
614 p.setXfermode(NULL); | 614 p.setXfermode(NULL); |
615 p.setStyle(SkPaint::kStroke_Style); | 615 p.setStyle(SkPaint::kStroke_Style); |
616 p.setStrokeWidth(SK_Scalar1); | 616 p.setStrokeWidth(SK_Scalar1); |
617 rast->addLayer(p); | 617 rast->addLayer(p); |
618 } | 618 } |
619 | 619 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 } | 725 } |
726 | 726 |
727 private: | 727 private: |
728 typedef SampleView INHERITED; | 728 typedef SampleView INHERITED; |
729 }; | 729 }; |
730 | 730 |
731 ////////////////////////////////////////////////////////////////////////////// | 731 ////////////////////////////////////////////////////////////////////////////// |
732 | 732 |
733 static SkView* MyFactory() { return new SlideView; } | 733 static SkView* MyFactory() { return new SlideView; } |
734 static SkViewRegister reg(MyFactory); | 734 static SkViewRegister reg(MyFactory); |
OLD | NEW |