aboutsummaryrefslogtreecommitdiffstats
path: root/samplecode/SampleSlides.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'samplecode/SampleSlides.cpp')
-rw-r--r--samplecode/SampleSlides.cpp73
1 files changed, 23 insertions, 50 deletions
diff --git a/samplecode/SampleSlides.cpp b/samplecode/SampleSlides.cpp
index 3b7d05b..d39cee0 100644
--- a/samplecode/SampleSlides.cpp
+++ b/samplecode/SampleSlides.cpp
@@ -1,3 +1,10 @@
+
+/*
+ * Copyright 2011 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 "SkView.h"
#include "SkCanvas.h"
@@ -87,23 +94,18 @@ static void discrete_pe(SkPaint* paint) {
paint->setPathEffect(new SkDiscretePathEffect(10, 4))->unref();
}
-class TilePathEffect : public Sk2DPathEffect {
- static SkMatrix make_mat() {
- SkMatrix m;
- m.setScale(12, 12);
- return m;
- }
-public:
- TilePathEffect() : Sk2DPathEffect(make_mat()) {}
+static SkPathEffect* MakeTileEffect() {
+ SkMatrix m;
+ m.setScale(SkIntToScalar(12), SkIntToScalar(12));
-protected:
- virtual void next(const SkPoint& loc, int u, int v, SkPath* dst) {
- dst->addCircle(loc.fX, loc.fY, 5);
- }
-};
+ SkPath path;
+ path.addCircle(0, 0, SkIntToScalar(5));
+
+ return new SkPath2DPathEffect(m, path);
+}
static void tile_pe(SkPaint* paint) {
- paint->setPathEffect(new TilePathEffect)->unref();
+ paint->setPathEffect(MakeTileEffect())->unref();
}
static const PE_Proc gPE2[] = { fill_pe, discrete_pe, tile_pe };
@@ -312,7 +314,6 @@ static void textonpath_slide(SkCanvas* canvas) {
#include "SkOSFile.h"
#include "SkRandom.h"
#include "SkStream.h"
-#include "SkNinePatch.h"
static SkShader* make_shader0(SkIPoint* size) {
SkBitmap bm;
@@ -563,46 +564,18 @@ static void r6(SkLayerRasterizer* rast, SkPaint& p)
#include "Sk2DPathEffect.h"
-class Dot2DPathEffect : public Sk2DPathEffect {
-public:
- Dot2DPathEffect(SkScalar radius, const SkMatrix& matrix)
- : Sk2DPathEffect(matrix), fRadius(radius) {}
-
- virtual void flatten(SkFlattenableWriteBuffer& buffer)
- {
- this->INHERITED::flatten(buffer);
-
- buffer.writeScalar(fRadius);
- }
- virtual Factory getFactory() { return CreateProc; }
-
-protected:
- virtual void next(const SkPoint& loc, int u, int v, SkPath* dst)
- {
- dst->addCircle(loc.fX, loc.fY, fRadius);
- }
-
- Dot2DPathEffect(SkFlattenableReadBuffer& buffer) : Sk2DPathEffect(buffer)
- {
- fRadius = buffer.readScalar();
- }
-private:
- SkScalar fRadius;
-
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer)
- {
- return new Dot2DPathEffect(buffer);
- }
-
- typedef Sk2DPathEffect INHERITED;
-};
+static SkPathEffect* MakeDotEffect(SkScalar radius, const SkMatrix& matrix) {
+ SkPath path;
+ path.addCircle(0, 0, radius);
+ return new SkPath2DPathEffect(matrix, path);
+}
static void r7(SkLayerRasterizer* rast, SkPaint& p)
{
SkMatrix lattice;
lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0);
lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
- p.setPathEffect(new Dot2DPathEffect(SK_Scalar1*4, lattice))->unref();
+ p.setPathEffect(MakeDotEffect(SK_Scalar1*4, lattice))->unref();
rast->addLayer(p);
}
@@ -613,7 +586,7 @@ static void r8(SkLayerRasterizer* rast, SkPaint& p)
SkMatrix lattice;
lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0);
lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
- p.setPathEffect(new Dot2DPathEffect(SK_Scalar1*2, lattice))->unref();
+ p.setPathEffect(MakeDotEffect(SK_Scalar1*2, lattice))->unref();
p.setXfermodeMode(SkXfermode::kClear_Mode);
rast->addLayer(p);