aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2016-03-18 11:22:57 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-18 11:22:57 -0700
commita439334b6e758d38501e225e2e5d0ab73e2fb6eb (patch)
tree8f2919ed2f6dcae5c4d5dbaaf608b5c6d248f2fc /samplecode
parent0be9e806af72b3e029e691eef5c891c90d3fd320 (diff)
Reland of "switch patheffects over to sk_sp (patchset #5 id:80001 of https://codereview.chromium.org/1813553005/ )"
Diffstat (limited to 'samplecode')
-rw-r--r--samplecode/ClockFaceView.cpp11
-rw-r--r--samplecode/SampleAll.cpp21
-rw-r--r--samplecode/SampleFilterFuzz.cpp34
-rw-r--r--samplecode/SamplePath.cpp4
-rw-r--r--samplecode/SamplePathEffects.cpp37
-rw-r--r--samplecode/SampleSlides.cpp36
6 files changed, 64 insertions, 79 deletions
diff --git a/samplecode/ClockFaceView.cpp b/samplecode/ClockFaceView.cpp
index 11684e11ad..f5b43fb82f 100644
--- a/samplecode/ClockFaceView.cpp
+++ b/samplecode/ClockFaceView.cpp
@@ -132,16 +132,16 @@ private:
SkFlattenable* InverseFillPE::CreateProc(SkReadBuffer& buffer) { return new InverseFillPE; }
-static SkPathEffect* makepe(float interp, SkTDArray<SkPoint>* pts) {
+static sk_sp<SkPathEffect> makepe(float interp, SkTDArray<SkPoint>* pts) {
SkMatrix lattice;
SkScalar rad = 3 + SkIntToScalar(4) * (1 - interp);
lattice.setScale(rad*2, rad*2, 0, 0);
lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
- return new Dot2DPathEffect(rad, lattice, pts);
+ return sk_make_sp<Dot2DPathEffect>(rad, lattice, pts);
}
static void r7(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p, SkScalar interp) {
- p.setPathEffect(makepe(SkScalarToFloat(interp), nullptr))->unref();
+ p.setPathEffect(makepe(SkScalarToFloat(interp), nullptr));
rastBuilder->addLayer(p);
#if 0
p.setPathEffect(new InverseFillPE())->unref();
@@ -201,7 +201,7 @@ protected:
static void drawdots(SkCanvas* canvas, const SkPaint& orig) {
SkTDArray<SkPoint> pts;
- SkPathEffect* pe = makepe(0, &pts);
+ auto pe = makepe(0, &pts);
SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);
SkPath path, dstPath;
@@ -212,8 +212,7 @@ protected:
p.setAntiAlias(true);
p.setStrokeWidth(10);
p.setColor(SK_ColorRED);
- canvas->drawPoints(SkCanvas::kPoints_PointMode, pts.count(), pts.begin(),
- p);
+ canvas->drawPoints(SkCanvas::kPoints_PointMode, pts.count(), pts.begin(), p);
}
virtual void onDraw(SkCanvas* canvas) {
diff --git a/samplecode/SampleAll.cpp b/samplecode/SampleAll.cpp
index 90fc5bdb16..7c0557fc40 100644
--- a/samplecode/SampleAll.cpp
+++ b/samplecode/SampleAll.cpp
@@ -141,7 +141,7 @@ static void r4(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
static void r5(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
rastBuilder->addLayer(p);
- p.setPathEffect(SkDiscretePathEffect::Create(SK_Scalar1*4, SK_Scalar1*3))->unref();
+ p.setPathEffect(SkDiscretePathEffect::Make(SK_Scalar1*4, SK_Scalar1*3));
p.setXfermodeMode(SkXfermode::kSrcOut_Mode);
rastBuilder->addLayer(p);
}
@@ -184,7 +184,7 @@ static void r7(SkLayerRasterizer::Builder* rastBuilder, 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(sk_make_sp<Dot2DPathEffect>(SK_Scalar1*4, lattice));
rastBuilder->addLayer(p);
}
@@ -194,7 +194,7 @@ static void r8(SkLayerRasterizer::Builder* rastBuilder, 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(sk_make_sp<Dot2DPathEffect>(SK_Scalar1*2, lattice));
p.setXfermodeMode(SkXfermode::kClear_Mode);
rastBuilder->addLayer(p);
@@ -211,7 +211,7 @@ static void r9(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
SkMatrix lattice;
lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0);
lattice.postRotate(SkIntToScalar(30), 0, 0);
- p.setPathEffect(SkLine2DPathEffect::Create(SK_Scalar1*2, lattice))->unref();
+ p.setPathEffect(SkLine2DPathEffect::Make(SK_Scalar1*2, lattice));
p.setXfermodeMode(SkXfermode::kClear_Mode);
rastBuilder->addLayer(p);
@@ -416,7 +416,7 @@ protected:
canvas->translate(SkIntToScalar(50), 0);
paint.setColor(SK_ColorYELLOW);
paint.setShader(linear);
- paint.setPathEffect(pathEffectTest())->unref();
+ paint.setPathEffect(pathEffectTest());
canvas->drawRect(rect, paint);
paint.setPathEffect(nullptr);
@@ -481,7 +481,7 @@ protected:
return this->INHERITED::onFindClickHandler(x, y, modi);
}
- SkPathEffect* pathEffectTest() {
+ sk_sp<SkPathEffect> pathEffectTest() {
static const int gXY[] = { 1, 0, 0, -1, 2, -1, 3, 0, 2, 1, 0, 1 };
SkScalar gPhase = 0;
SkPath path;
@@ -490,14 +490,11 @@ protected:
path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1]));
path.close();
path.offset(SkIntToScalar(-6), 0);
- SkPathEffect* outer = SkPath1DPathEffect::Create(path, SkIntToScalar(12),
+ auto outer = SkPath1DPathEffect::Make(path, SkIntToScalar(12),
gPhase, SkPath1DPathEffect::kRotate_Style);
- SkPathEffect* inner = SkDiscretePathEffect::Create(SkIntToScalar(2),
+ auto inner = SkDiscretePathEffect::Make(SkIntToScalar(2),
SkIntToScalar(1)/10); // SkCornerPathEffect(SkIntToScalar(2));
- SkPathEffect* result = SkComposePathEffect::Create(outer, inner);
- outer->unref();
- inner->unref();
- return result;
+ return SkComposePathEffect::Make(outer, inner);
}
sk_sp<SkShader> shaderTest() {
diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp
index 0dd01e95b2..fe2fb0b2ff 100644
--- a/samplecode/SampleFilterFuzz.cpp
+++ b/samplecode/SampleFilterFuzz.cpp
@@ -422,22 +422,20 @@ static SkPath make_path() {
return path;
}
-static SkPathEffect* make_path_effect(bool canBeNull = true) {
- SkPathEffect* pathEffect = nullptr;
+static sk_sp<SkPathEffect> make_path_effect(bool canBeNull = true) {
+ sk_sp<SkPathEffect> pathEffect;
if (canBeNull && (R(3) == 1)) { return pathEffect; }
switch (R(9)) {
case 0:
- pathEffect = SkArcToPathEffect::Create(make_scalar(true));
+ pathEffect = SkArcToPathEffect::Make(make_scalar(true));
break;
- case 1: {
- SkAutoTUnref<SkPathEffect> outer(make_path_effect(false));
- SkAutoTUnref<SkPathEffect> inner(make_path_effect(false));
- pathEffect = SkComposePathEffect::Create(outer, inner);
+ case 1:
+ pathEffect = SkComposePathEffect::Make(make_path_effect(false),
+ make_path_effect(false));
break;
- }
case 2:
- pathEffect = SkCornerPathEffect::Create(make_scalar());
+ pathEffect = SkCornerPathEffect::Make(make_scalar());
break;
case 3: {
int count = R(10);
@@ -445,28 +443,26 @@ static SkPathEffect* make_path_effect(bool canBeNull = true) {
for (int i = 0; i < count; ++i) {
intervals[i] = make_scalar();
}
- pathEffect = SkDashPathEffect::Create(intervals, count, make_scalar());
+ pathEffect = SkDashPathEffect::Make(intervals, count, make_scalar());
break;
}
case 4:
- pathEffect = SkDiscretePathEffect::Create(make_scalar(), make_scalar());
+ pathEffect = SkDiscretePathEffect::Make(make_scalar(), make_scalar());
break;
case 5:
- pathEffect = SkPath1DPathEffect::Create(make_path(),
- make_scalar(),
- make_scalar(),
- make_path_1d_path_effect_style());
+ pathEffect = SkPath1DPathEffect::Make(make_path(), make_scalar(), make_scalar(),
+ make_path_1d_path_effect_style());
break;
case 6:
- pathEffect = SkLine2DPathEffect::Create(make_scalar(), make_matrix());
+ pathEffect = SkLine2DPathEffect::Make(make_scalar(), make_matrix());
break;
case 7:
- pathEffect = SkPath2DPathEffect::Create(make_matrix(), make_path());
+ pathEffect = SkPath2DPathEffect::Make(make_matrix(), make_path());
break;
case 8:
default:
- pathEffect = SkSumPathEffect::Create(make_path_effect(false),
- make_path_effect(false));
+ pathEffect = SkSumPathEffect::Make(make_path_effect(false),
+ make_path_effect(false));
break;
}
return pathEffect;
diff --git a/samplecode/SamplePath.cpp b/samplecode/SamplePath.cpp
index c977ca0dc2..9ef1c851d8 100644
--- a/samplecode/SamplePath.cpp
+++ b/samplecode/SamplePath.cpp
@@ -254,13 +254,13 @@ public:
fArcToPaint.setStyle(SkPaint::kStroke_Style);
fArcToPaint.setStrokeWidth(9);
fArcToPaint.setColor(0x800000FF);
- fArcToPaint.setPathEffect(SkArcToPathEffect::Create(rad))->unref();
+ fArcToPaint.setPathEffect(SkArcToPathEffect::Make(rad));
fCornerPaint.setAntiAlias(true);
fCornerPaint.setStyle(SkPaint::kStroke_Style);
fCornerPaint.setStrokeWidth(13);
fCornerPaint.setColor(SK_ColorGREEN);
- fCornerPaint.setPathEffect(SkCornerPathEffect::Create(rad*2))->unref();
+ fCornerPaint.setPathEffect(SkCornerPathEffect::Make(rad*2));
fSkeletonPaint.setAntiAlias(true);
fSkeletonPaint.setStyle(SkPaint::kStroke_Style);
diff --git a/samplecode/SamplePathEffects.cpp b/samplecode/SamplePathEffects.cpp
index a162cf33ad..10715f382a 100644
--- a/samplecode/SamplePathEffects.cpp
+++ b/samplecode/SamplePathEffects.cpp
@@ -26,9 +26,10 @@ static const int gXY[] = {
4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4
};
-static SkPathEffect* make_pe(int flags, SkScalar phase) {
- if (flags == 1)
- return SkCornerPathEffect::Create(SkIntToScalar(CORNER_RADIUS));
+static sk_sp<SkPathEffect> make_pe(int flags, SkScalar phase) {
+ if (flags == 1) {
+ return SkCornerPathEffect::Make(SkIntToScalar(CORNER_RADIUS));
+ }
SkPath path;
path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1]));
@@ -37,36 +38,30 @@ static SkPathEffect* make_pe(int flags, SkScalar phase) {
path.close();
path.offset(SkIntToScalar(-6), 0);
- SkPathEffect* outer = SkPath1DPathEffect::Create(path, 12, phase,
- SkPath1DPathEffect::kRotate_Style);
+ auto outer = SkPath1DPathEffect::Make(path, 12, phase, SkPath1DPathEffect::kRotate_Style);
if (flags == 2)
return outer;
- SkPathEffect* inner = SkCornerPathEffect::Create(SkIntToScalar(CORNER_RADIUS));
+ auto inner = SkCornerPathEffect::Make(SkIntToScalar(CORNER_RADIUS));
- SkPathEffect* pe = SkComposePathEffect::Create(outer, inner);
- outer->unref();
- inner->unref();
- return pe;
+ return SkComposePathEffect::Make(outer, inner);
}
-static SkPathEffect* make_warp_pe(SkScalar phase) {
+static sk_sp<SkPathEffect> make_warp_pe(SkScalar phase) {
SkPath path;
path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1]));
- for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2)
+ for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) {
path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1]));
+ }
path.close();
path.offset(SkIntToScalar(-6), 0);
- SkPathEffect* outer = SkPath1DPathEffect::Create(
+ auto outer = SkPath1DPathEffect::Make(
path, 12, phase, SkPath1DPathEffect::kMorph_Style);
- SkPathEffect* inner = SkCornerPathEffect::Create(SkIntToScalar(CORNER_RADIUS));
+ auto inner = SkCornerPathEffect::Make(SkIntToScalar(CORNER_RADIUS));
- SkPathEffect* pe = SkComposePathEffect::Create(outer, inner);
- outer->unref();
- inner->unref();
- return pe;
+ return SkComposePathEffect::Make(outer, inner);
}
///////////////////////////////////////////////////////////
@@ -143,19 +138,19 @@ protected:
canvas->translate(0, 50);
paint.setColor(SK_ColorBLUE);
- paint.setPathEffect(make_pe(2, fPhase))->unref();
+ paint.setPathEffect(make_pe(2, fPhase));
canvas->drawPath(fPath, paint);
canvas->translate(0, 50);
paint.setARGB(0xFF, 0, 0xBB, 0);
- paint.setPathEffect(make_pe(3, fPhase))->unref();
+ paint.setPathEffect(make_pe(3, fPhase));
canvas->drawPath(fPath, paint);
canvas->translate(0, 50);
paint.setARGB(0xFF, 0, 0, 0);
- paint.setPathEffect(make_warp_pe(fPhase))->unref();
+ paint.setPathEffect(make_warp_pe(fPhase));
TestRastBuilder testRastBuilder;
paint.setRasterizer(testRastBuilder.detachRasterizer())->unref();
canvas->drawPath(fPath, paint);
diff --git a/samplecode/SampleSlides.cpp b/samplecode/SampleSlides.cpp
index c3cc2bbd6f..38fd7402c7 100644
--- a/samplecode/SampleSlides.cpp
+++ b/samplecode/SampleSlides.cpp
@@ -31,15 +31,14 @@ typedef void (*SlideProc)(SkCanvas*);
static void compose_pe(SkPaint* paint) {
SkPathEffect* pe = paint->getPathEffect();
- SkPathEffect* corner = SkCornerPathEffect::Create(25);
- SkPathEffect* compose;
+ sk_sp<SkPathEffect> corner = SkCornerPathEffect::Make(25);
+ sk_sp<SkPathEffect> compose;
if (pe) {
- compose = SkComposePathEffect::Create(pe, corner);
- corner->unref();
+ compose = SkComposePathEffect::Make(sk_ref_sp(pe), corner);
} else {
compose = corner;
}
- paint->setPathEffect(compose)->unref();
+ paint->setPathEffect(compose);
}
static void hair_pe(SkPaint* paint) {
@@ -59,8 +58,7 @@ static void stroke_pe(SkPaint* paint) {
static void dash_pe(SkPaint* paint) {
SkScalar inter[] = { 20, 10, 10, 10 };
paint->setStrokeWidth(12);
- paint->setPathEffect(SkDashPathEffect::Create(inter, SK_ARRAY_COUNT(inter),
- 0))->unref();
+ paint->setPathEffect(SkDashPathEffect::Make(inter, SK_ARRAY_COUNT(inter), 0));
compose_pe(paint);
}
@@ -83,8 +81,8 @@ static void one_d_pe(SkPaint* paint) {
path.offset(SkIntToScalar(-6), 0);
scale(&path, 1.5f);
- paint->setPathEffect(SkPath1DPathEffect::Create(path, SkIntToScalar(21), 0,
- SkPath1DPathEffect::kRotate_Style))->unref();
+ paint->setPathEffect(SkPath1DPathEffect::Make(path, SkIntToScalar(21), 0,
+ SkPath1DPathEffect::kRotate_Style));
compose_pe(paint);
}
@@ -97,21 +95,21 @@ static void fill_pe(SkPaint* paint) {
}
static void discrete_pe(SkPaint* paint) {
- paint->setPathEffect(SkDiscretePathEffect::Create(10, 4))->unref();
+ paint->setPathEffect(SkDiscretePathEffect::Make(10, 4));
}
-static SkPathEffect* MakeTileEffect() {
+static sk_sp<SkPathEffect> MakeTileEffect() {
SkMatrix m;
m.setScale(SkIntToScalar(12), SkIntToScalar(12));
SkPath path;
path.addCircle(0, 0, SkIntToScalar(5));
- return SkPath2DPathEffect::Create(m, path);
+ return SkPath2DPathEffect::Make(m, path);
}
static void tile_pe(SkPaint* paint) {
- paint->setPathEffect(MakeTileEffect())->unref();
+ paint->setPathEffect(MakeTileEffect());
}
static const PE_Proc gPE2[] = { fill_pe, discrete_pe, tile_pe };
@@ -534,7 +532,7 @@ static void r5(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p)
{
rastBuilder->addLayer(p);
- p.setPathEffect(SkDiscretePathEffect::Create(SK_Scalar1*4, SK_Scalar1*3))->unref();
+ p.setPathEffect(SkDiscretePathEffect::Make(SK_Scalar1*4, SK_Scalar1*3));
p.setXfermodeMode(SkXfermode::kSrcOut_Mode);
rastBuilder->addLayer(p);
}
@@ -553,10 +551,10 @@ static void r6(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p)
#include "Sk2DPathEffect.h"
-static SkPathEffect* MakeDotEffect(SkScalar radius, const SkMatrix& matrix) {
+static sk_sp<SkPathEffect> MakeDotEffect(SkScalar radius, const SkMatrix& matrix) {
SkPath path;
path.addCircle(0, 0, radius);
- return SkPath2DPathEffect::Create(matrix, path);
+ return SkPath2DPathEffect::Make(matrix, path);
}
static void r7(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p)
@@ -564,7 +562,7 @@ static void r7(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p)
SkMatrix lattice;
lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0);
lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
- p.setPathEffect(MakeDotEffect(SK_Scalar1*4, lattice))->unref();
+ p.setPathEffect(MakeDotEffect(SK_Scalar1*4, lattice));
rastBuilder->addLayer(p);
}
@@ -575,7 +573,7 @@ static void r8(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p)
SkMatrix lattice;
lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0);
lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
- p.setPathEffect(MakeDotEffect(SK_Scalar1*2, lattice))->unref();
+ p.setPathEffect(MakeDotEffect(SK_Scalar1*2, lattice));
p.setXfermodeMode(SkXfermode::kClear_Mode);
rastBuilder->addLayer(p);
@@ -593,7 +591,7 @@ static void r9(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p)
SkMatrix lattice;
lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0);
lattice.postRotate(SkIntToScalar(30), 0, 0);
- p.setPathEffect(SkLine2DPathEffect::Create(SK_Scalar1*2, lattice))->unref();
+ p.setPathEffect(SkLine2DPathEffect::Make(SK_Scalar1*2, lattice));
p.setXfermodeMode(SkXfermode::kClear_Mode);
rastBuilder->addLayer(p);