aboutsummaryrefslogtreecommitdiffstats
path: root/gm
diff options
context:
space:
mode:
Diffstat (limited to 'gm')
-rw-r--r--gm/Android.mk2
-rw-r--r--gm/gm_files.mk16
-rw-r--r--gm/gmmain.cpp5
-rw-r--r--gm/pathfill.cpp143
-rw-r--r--gm/strokerects.cpp88
5 files changed, 253 insertions, 1 deletions
diff --git a/gm/Android.mk b/gm/Android.mk
index e7960d4..b3aeadf 100644
--- a/gm/Android.mk
+++ b/gm/Android.mk
@@ -8,11 +8,13 @@ LOCAL_SRC_FILES := \
complexclip.cpp \
filltypes.cpp \
gradients.cpp \
+ pathfill.cpp \
points.cpp \
poly2poly.cpp \
shadertext.cpp \
shadows.cpp \
shapes.cpp \
+ strokerects.cpp \
tilemodes.cpp \
xfermodes.cpp \
gmmain.cpp
diff --git a/gm/gm_files.mk b/gm/gm_files.mk
new file mode 100644
index 0000000..e867820
--- /dev/null
+++ b/gm/gm_files.mk
@@ -0,0 +1,16 @@
+SOURCE := \
+ bitmapfilters.cpp \
+ blurs.cpp \
+ filltypes.cpp \
+ gradients.cpp \
+ pathfill.cpp \
+ points.cpp \
+ poly2poly.cpp \
+ shadows.cpp \
+ shapes.cpp \
+ strokerects.cpp \
+ tilemodes.cpp \
+ xfermodes.cpp \
+ shadertext.cpp \
+ complexclip.cpp \
+ gmmain.cpp
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index 357a54e..cb4e036 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -261,7 +261,10 @@ int main (int argc, char * const argv[]) {
if (gRec[i].fBackend == kPDF_Backend && writePath) {
#ifdef SK_SUPPORT_PDF
SkISize size = gm->getISize();
- SkPDFDevice* dev = new SkPDFDevice(size.width(), size.height());
+ SkMatrix identity;
+ identity.reset();
+ SkPDFDevice* dev = new SkPDFDevice(size.width(), size.height(),
+ identity);
SkAutoUnref aur(dev);
SkCanvas c(dev);
diff --git a/gm/pathfill.cpp b/gm/pathfill.cpp
new file mode 100644
index 0000000..ec56942
--- /dev/null
+++ b/gm/pathfill.cpp
@@ -0,0 +1,143 @@
+#include "gm.h"
+#include "SkPicture.h"
+#include "SkRectShape.h"
+#include "SkGroupShape.h"
+
+typedef SkScalar (*MakePathProc)(SkPath*);
+
+static SkScalar make_frame(SkPath* path) {
+ SkRect r = { 10, 10, 630, 470 };
+ path->addRoundRect(r, 15, 15);
+
+ SkPaint paint;
+ paint.setStyle(SkPaint::kStroke_Style);
+ paint.setStrokeWidth(5);
+ paint.getFillPath(*path, path);
+ return 15;
+}
+
+static SkScalar make_triangle(SkPath* path) {
+ static const int gCoord[] = {
+ 10, 20, 15, 5, 30, 30
+ };
+ path->moveTo(SkIntToScalar(gCoord[0]), SkIntToScalar(gCoord[1]));
+ path->lineTo(SkIntToScalar(gCoord[2]), SkIntToScalar(gCoord[3]));
+ path->lineTo(SkIntToScalar(gCoord[4]), SkIntToScalar(gCoord[5]));
+ path->close();
+ path->offset(10, 0);
+ return SkIntToScalar(30);
+}
+
+static SkScalar make_rect(SkPath* path) {
+ SkRect r = { 10, 10, 30, 30 };
+ path->addRect(r);
+ path->offset(10, 0);
+ return SkIntToScalar(30);
+}
+
+static SkScalar make_oval(SkPath* path) {
+ SkRect r = { 10, 10, 30, 30 };
+ path->addOval(r);
+ path->offset(10, 0);
+ return SkIntToScalar(30);
+}
+
+static SkScalar make_sawtooth(SkPath* path) {
+ SkScalar x = SkIntToScalar(20);
+ SkScalar y = SkIntToScalar(20);
+ const SkScalar x0 = x;
+ const SkScalar dx = SK_Scalar1 * 5;
+ const SkScalar dy = SK_Scalar1 * 10;
+
+ path->moveTo(x, y);
+ for (int i = 0; i < 32; i++) {
+ x += dx;
+ path->lineTo(x, y - dy);
+ x += dx;
+ path->lineTo(x, y + dy);
+ }
+ path->lineTo(x, y + 2 * dy);
+ path->lineTo(x0, y + 2 * dy);
+ path->close();
+ return SkIntToScalar(30);
+}
+
+static SkScalar make_star(SkPath* path, int n) {
+ const SkScalar c = SkIntToScalar(45);
+ const SkScalar r = SkIntToScalar(20);
+
+ SkScalar rad = -SK_ScalarPI / 2;
+ const SkScalar drad = (n >> 1) * SK_ScalarPI * 2 / n;
+
+ path->moveTo(c, c - r);
+ for (int i = 1; i < n; i++) {
+ rad += drad;
+ SkScalar cosV, sinV = SkScalarSinCos(rad, &cosV);
+ path->lineTo(c + SkScalarMul(cosV, r), c + SkScalarMul(sinV, r));
+ }
+ path->close();
+ return r * 2 * 6 / 5;
+}
+
+static SkScalar make_star_5(SkPath* path) { return make_star(path, 5); }
+static SkScalar make_star_13(SkPath* path) { return make_star(path, 13); }
+
+static const MakePathProc gProcs[] = {
+ make_frame,
+ make_triangle,
+ make_rect,
+ make_oval,
+ make_sawtooth,
+ make_star_5,
+ make_star_13
+};
+
+#define N SK_ARRAY_COUNT(gProcs)
+
+namespace skiagm {
+
+class PathFillGM : public GM {
+ SkPath fPath[N];
+ SkScalar fDY[N];
+public:
+ PathFillGM() {
+ for (size_t i = 0; i < N; i++) {
+ fDY[i] = gProcs[i](&fPath[i]);
+ }
+ }
+
+protected:
+ virtual SkString onShortName() {
+ return SkString("pathfill");
+ }
+
+ virtual SkISize onISize() {
+ return make_isize(640, 480);
+ }
+
+ void drawBG(SkCanvas* canvas) {
+ canvas->drawColor(SK_ColorWHITE);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ this->drawBG(canvas);
+
+ SkPaint paint;
+ paint.setAntiAlias(true);
+
+ for (size_t i = 0; i < N; i++) {
+ canvas->drawPath(fPath[i], paint);
+ canvas->translate(0, fDY[i]);
+ }
+ }
+
+private:
+ typedef GM INHERITED;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+static GM* MyFactory(void*) { return new PathFillGM; }
+static GMRegistry reg(MyFactory);
+
+}
diff --git a/gm/strokerects.cpp b/gm/strokerects.cpp
new file mode 100644
index 0000000..b716407
--- /dev/null
+++ b/gm/strokerects.cpp
@@ -0,0 +1,88 @@
+/*
+ Copyright 2011 Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+
+#include "gm.h"
+#include "SkRandom.h"
+
+namespace skiagm {
+
+#define W 400
+#define H 400
+#define N 100
+
+static const SkScalar SW = SkIntToScalar(W);
+static const SkScalar SH = SkIntToScalar(H);
+
+class StrokeRectGM : public GM {
+public:
+ StrokeRectGM() {}
+
+protected:
+ virtual SkString onShortName() {
+ return SkString("strokerects");
+ }
+
+ virtual SkISize onISize() {
+ return make_isize(W*2, H*2);
+ }
+
+ static void rnd_rect(SkRect* r, SkRandom& rand) {
+ SkScalar x = rand.nextUScalar1() * W;
+ SkScalar y = rand.nextUScalar1() * H;
+ SkScalar w = rand.nextUScalar1() * (W >> 2);
+ SkScalar h = rand.nextUScalar1() * (H >> 2);
+
+ r->set(x, y, x + w, y + h);
+ r->offset(-w/2 + rand.nextSScalar1(), -h/2 + + rand.nextSScalar1());
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ canvas->drawColor(SK_ColorWHITE);
+
+ SkPaint paint;
+ paint.setStyle(SkPaint::kStroke_Style);
+
+ for (int y = 0; y < 2; y++) {
+ paint.setAntiAlias(!!y);
+ for (int x = 0; x < 2; x++) {
+ paint.setStrokeWidth(x * SkIntToScalar(3));
+
+ SkAutoCanvasRestore acr(canvas, true);
+ canvas->translate(SW * x, SH * y);
+ canvas->clipRect(SkRect::MakeLTRB(2, 2, SW - 2, SH - 2));
+
+ SkRandom rand;
+ for (int i = 0; i < N; i++) {
+ SkRect r;
+ rnd_rect(&r, rand);
+ canvas->drawRect(r, paint);
+ }
+ }
+ }
+ }
+
+private:
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static GM* MyFactory(void*) { return new StrokeRectGM; }
+static GMRegistry reg(MyFactory);
+
+}
+