diff options
author | 2014-02-20 20:40:19 +0000 | |
---|---|---|
committer | 2014-02-20 20:40:19 +0000 | |
commit | 0a2bf90dccba3bde188e0386a7f0c60e6dde1ae9 (patch) | |
tree | aa5c4198b4a200d6efe87d1a81964c8c219c1091 /samplecode/SampleAll.cpp | |
parent | 4012ba51a218883daef6c9be142f970b8ef5d0d2 (diff) |
Factory methods for heap-allocated SkPathEffect and SkXfermode objects.
This is part of an effort to ensure that all SkPaint effects can only be
allocated on the heap.
This patch makes the constructors of SkPathEffect, SkXfermode and
their subclasses non-public and instead provides factory methods for
creating these objects on the heap. We temporarily keep the constructors
of the following classes public to not break Chrome/Blink:
SkXfermode
SkCornerPathEffect
SkDashPathEffect
BUG=skia:2187
R=scroggo@google.com, reed@google.com, mtklein@google.com, bungeman@google.com
Author: dominikg@chromium.org
Review URL: https://codereview.chromium.org/166583002
git-svn-id: http://skia.googlecode.com/svn/trunk@13519 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'samplecode/SampleAll.cpp')
-rw-r--r-- | samplecode/SampleAll.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/samplecode/SampleAll.cpp b/samplecode/SampleAll.cpp index 6410670fed..bb5aadd1d8 100644 --- a/samplecode/SampleAll.cpp +++ b/samplecode/SampleAll.cpp @@ -144,7 +144,7 @@ static void r4(SkLayerRasterizer* rast, SkPaint& p) { static void r5(SkLayerRasterizer* rast, SkPaint& p) { rast->addLayer(p); - p.setPathEffect(new SkDiscretePathEffect(SK_Scalar1*4, SK_Scalar1*3))->unref(); + p.setPathEffect(SkDiscretePathEffect::Create(SK_Scalar1*4, SK_Scalar1*3))->unref(); p.setXfermodeMode(SkXfermode::kSrcOut_Mode); rast->addLayer(p); } @@ -217,7 +217,7 @@ static void r9(SkLayerRasterizer* rast, SkPaint& p) { SkMatrix lattice; lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0); lattice.postRotate(SkIntToScalar(30), 0, 0); - p.setPathEffect(new SkLine2DPathEffect(SK_Scalar1*2, lattice))->unref(); + p.setPathEffect(SkLine2DPathEffect::Create(SK_Scalar1*2, lattice))->unref(); p.setXfermodeMode(SkXfermode::kClear_Mode); rast->addLayer(p); @@ -550,11 +550,11 @@ SkCornerPathEffect.h:28:class SkCornerPathEffect : public SkPathEffect { path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); path.close(); path.offset(SkIntToScalar(-6), 0); - SkPathEffect* outer = new SkPath1DPathEffect(path, SkIntToScalar(12), + SkPathEffect* outer = SkPath1DPathEffect::Create(path, SkIntToScalar(12), gPhase, SkPath1DPathEffect::kRotate_Style); - SkPathEffect* inner = new SkDiscretePathEffect(SkIntToScalar(2), + SkPathEffect* inner = SkDiscretePathEffect::Create(SkIntToScalar(2), SkIntToScalar(1)/10); // SkCornerPathEffect(SkIntToScalar(2)); - SkPathEffect* result = new SkComposePathEffect(outer, inner); + SkPathEffect* result = SkComposePathEffect::Create(outer, inner); outer->unref(); inner->unref(); return result; @@ -627,12 +627,12 @@ SkCornerPathEffect.h:28:class SkCornerPathEffect : public SkPathEffect { canvas->restore(); if (1) { - SkAvoidXfermode mode(SK_ColorWHITE, 0xFF, - SkAvoidXfermode::kTargetColor_Mode); + SkAutoTUnref<SkAvoidXfermode> mode(SkAvoidXfermode::Create(SK_ColorWHITE, 0xFF, + SkAvoidXfermode::kTargetColor_Mode)); SkPaint paint; x += SkIntToScalar(20); SkRect r = { x, 0, x + SkIntToScalar(360), SkIntToScalar(700) }; - paint.setXfermode(&mode); + paint.setXfermode(mode); paint.setColor(SK_ColorGREEN); paint.setAntiAlias(true); canvas->drawOval(r, paint); |