reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | #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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 14 | #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 | |
| 23 | static SkRandom gRand; |
| 24 | |
| 25 | static const struct { |
| 26 | const char* fName; |
| 27 | uint32_t fFlags; |
| 28 | bool fFlushCache; |
| 29 | } gHints[] = { |
| 30 | { "Linear", SkPaint::kLinearText_Flag, false }, |
| 31 | { "Normal", 0, true }, |
| 32 | { "Subpixel", SkPaint::kSubpixelText_Flag, true } |
| 33 | }; |
| 34 | |
| 35 | #ifdef SK_DEBUG |
| 36 | #define REPEAT_COUNT 1 |
| 37 | #else |
| 38 | #define REPEAT_COUNT 5000 |
| 39 | #endif |
| 40 | |
| 41 | class PointsView : public SkView { |
| 42 | bool fAA; |
| 43 | public: |
| 44 | PointsView() : fAA(false) {} |
| 45 | |
| 46 | protected: |
| 47 | // overrides from SkEventSink |
| 48 | virtual bool onQuery(SkEvent* evt) |
| 49 | { |
| 50 | if (SampleCode::TitleQ(*evt)) |
| 51 | { |
| 52 | SampleCode::TitleR(evt, "Points"); |
| 53 | return true; |
| 54 | } |
| 55 | return this->INHERITED::onQuery(evt); |
| 56 | } |
| 57 | |
| 58 | void drawBG(SkCanvas* canvas) |
| 59 | { |
| 60 | // canvas->drawColor(0xFFDDDDDD); |
| 61 | canvas->drawColor(SK_ColorWHITE); |
| 62 | // canvas->drawColor(SK_ColorBLACK); |
| 63 | } |
| 64 | |
| 65 | static void fill_pts(SkPoint pts[], size_t n, SkRandom* rand) |
| 66 | { |
| 67 | for (size_t i = 0; i < n; i++) |
| 68 | pts[i].set(rand->nextUScalar1() * 640, rand->nextUScalar1() * 480); |
| 69 | } |
| 70 | |
| 71 | virtual void onDraw(SkCanvas* canvas) |
| 72 | { |
| 73 | this->drawBG(canvas); |
| 74 | |
| 75 | canvas->translate(SK_Scalar1, SK_Scalar1); |
| 76 | |
| 77 | SkRandom rand; |
| 78 | SkPaint p0, p1, p2, p3; |
| 79 | const size_t n = 99; |
| 80 | const int TIMES = 1; |
| 81 | |
| 82 | p0.setColor(SK_ColorRED); |
| 83 | p1.setColor(SK_ColorGREEN); |
| 84 | p2.setColor(SK_ColorBLUE); |
| 85 | p3.setColor(SK_ColorWHITE); |
| 86 | |
| 87 | // fAA = !fAA; |
| 88 | |
| 89 | p0.setAntiAlias(fAA); |
| 90 | p1.setAntiAlias(fAA); |
| 91 | p2.setAntiAlias(fAA); |
| 92 | p3.setAntiAlias(fAA); |
| 93 | |
| 94 | p0.setStrokeWidth(SkIntToScalar(4)); |
| 95 | p2.setStrokeWidth(SkIntToScalar(6)); |
| 96 | |
| 97 | SkPoint* pts = new SkPoint[n]; |
| 98 | fill_pts(pts, n, &rand); |
| 99 | |
| 100 | // SkMSec now = SkTime::GetMSecs(); |
| 101 | for (int times = 0; times < TIMES; times++) |
| 102 | { |
| 103 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, n, pts, p0); |
| 104 | canvas->drawPoints(SkCanvas::kLines_PointMode, n, pts, p1); |
| 105 | canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p2); |
| 106 | canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p3); |
| 107 | } |
| 108 | // printf("----- msecs %d\n", SkTime::GetMSecs() - now); |
| 109 | delete[] pts; |
| 110 | } |
| 111 | |
| 112 | private: |
| 113 | |
| 114 | typedef SkView INHERITED; |
| 115 | }; |
| 116 | |
| 117 | ////////////////////////////////////////////////////////////////////////////// |
| 118 | |
| 119 | static SkView* MyFactory() { return new PointsView; } |
| 120 | static SkViewRegister reg(MyFactory); |
| 121 | |