add new tests
authorcaryclark <caryclark@google.com>
Sat, 30 Jan 2016 18:11:21 +0000 (10:11 -0800)
committerCommit bot <commit-bot@chromium.org>
Sat, 30 Jan 2016 18:11:21 +0000 (10:11 -0800)
These tests are for upcoming changes to optimize
the path edge list.

TBR=reed@google.com
BUG=573166
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1651573002

Review URL: https://codereview.chromium.org/1651573002

gm/dashing.cpp
gyp/SampleApp.gyp
samplecode/SampleMegaStroke.cpp [new file with mode: 0644]

index aed4c00..e44e356 100644 (file)
@@ -502,6 +502,32 @@ DEF_SIMPLE_GM(longpathdash, canvas, 512, 512) {
     canvas->drawPath(lines, p);
 }
 
+DEF_SIMPLE_GM(longlinedash, canvas, 512, 512) {
+    SkPaint p;
+    p.setAntiAlias(true);
+    p.setStyle(SkPaint::kStroke_Style);
+    p.setStrokeWidth(80);
+
+    const SkScalar intervals[] = { 2, 2 };
+    p.setPathEffect(SkDashPathEffect::Create(intervals, SK_ARRAY_COUNT(intervals), 0))->unref();
+    canvas->drawRect(SkRect::MakeXYWH(-10000, 100, 20000, 20), p);
+}
+
+DEF_SIMPLE_GM(longwavyline, canvas, 512, 512) {
+    SkPaint p;
+    p.setAntiAlias(true);
+    p.setStyle(SkPaint::kStroke_Style);
+    p.setStrokeWidth(2);
+
+    SkPath wavy;
+    wavy.moveTo(-10000, 100);
+    for (SkScalar i = -10000; i < 10000; i += 20) {
+        wavy.quadTo(i + 5, 95, i + 10, 100);
+        wavy.quadTo(i + 15, 105, i + 20, 100);
+    }
+    canvas->drawPath(wavy, p);
+}
+
 //////////////////////////////////////////////////////////////////////////////
 
 DEF_GM(return new DashingGM;)
index 7409b76..1cd78b7 100644 (file)
@@ -85,6 +85,7 @@
         '../samplecode/SampleLua.cpp',
         '../samplecode/SampleManyRects.cpp',
         '../samplecode/SampleMeasure.cpp',
+        '../samplecode/SampleMegaStroke.cpp',
         '../samplecode/SamplePatch.cpp',
         '../samplecode/SamplePath.cpp',
         '../samplecode/SamplePathClip.cpp',
diff --git a/samplecode/SampleMegaStroke.cpp b/samplecode/SampleMegaStroke.cpp
new file mode 100644 (file)
index 0000000..d859156
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SampleCode.h"
+#include "SkCanvas.h"
+#include "SkPath.h"
+#include "SkRandom.h"
+
+class MegaStrokeView : public SampleView {
+public:
+    MegaStrokeView() {
+        fClip.set(0, 0, 950, 600);
+        fAngle = 0;
+        fPlusMinus = 0;
+        SkRandom rand;
+        fMegaPath.reset();
+        for (int index = 0; index < 921; ++index) {
+            for (int segs = 0; segs < 40; ++segs) {
+                fMegaPath.lineTo(SkIntToScalar(index), SkIntToScalar(rand.nextRangeU(500, 600)));
+            }
+        }
+    }
+
+protected:
+    // overrides from SkEventSink
+    bool onQuery(SkEvent* evt) override {
+        if (SampleCode::TitleQ(*evt)) {
+            SampleCode::TitleR(evt, "MegaStroke");
+            return true;
+        }
+
+        SkUnichar uni;
+        if (SampleCode::CharQ(*evt, &uni)) {
+           fClip.set(0, 0, 950, 600);
+        }
+        SkString str;
+        evt->getType(&str);
+        if (str == SkString("SampleCode_Key_Event")) {
+           fClip.set(0, 0, 950, 600);
+        }
+        return this->INHERITED::onQuery(evt);
+    }
+
+    void onDrawBackground(SkCanvas* canvas) override {
+    }
+
+    void onDrawContent(SkCanvas* canvas) override {
+        SkPaint paint;
+        paint.setAntiAlias(true);
+        paint.setARGB(255,255,153,0);
+        paint.setStyle(SkPaint::kStroke_Style);
+        paint.setStrokeWidth(1);
+
+        canvas->save();
+        canvas->clipRect(fClip);
+        canvas->clear(SK_ColorWHITE);
+        canvas->drawPath(fMegaPath, paint);
+        canvas->restore();
+
+        SkPaint divSimPaint;
+        divSimPaint.setColor(SK_ColorBLUE);
+           SkScalar x = SkScalarSin(fAngle * SK_ScalarPI / 180) * 200 + 250;
+           SkScalar y = SkScalarCos(fAngle * SK_ScalarPI / 180) * 200 + 250;
+
+        if ((fPlusMinus ^= 1)) {
+            fAngle += 5;
+        } else {
+            fAngle -= 5;
+        }
+        SkRect divSim = SkRect::MakeXYWH(x, y, 100, 100);
+        divSim.outset(30, 30);
+        canvas->drawRect(divSim, divSimPaint);
+        fClip = divSim;
+    }
+
+    void onSizeChange() override {
+        fClip.set(0, 0, 950, 600);
+    }
+
+    bool onAnimate(const SkAnimTimer& ) override {
+        return true;
+    }
+
+private:
+    SkPath      fMegaPath;
+    SkRect      fClip;
+    int         fAngle;
+    int         fPlusMinus;
+    typedef SampleView INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static SkView* MyFactory() { return new MegaStrokeView; }
+static SkViewRegister reg(MyFactory);