change all patheffect methods to const, in preparation for marking its

subclasses as immutable/re-entrant safe.
Review URL: https://codereview.appspot.com/6949071

git-svn-id: http://skia.googlecode.com/svn/trunk@6877 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2012-12-18 16:12:09 +00:00
parent 78c0c30987
commit 548a1f3210
14 changed files with 70 additions and 65 deletions

View File

@ -48,13 +48,14 @@ public:
* If this method returns true, the caller will apply (as needed) the
* resulting stroke-rec to dst and then draw.
*/
virtual bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*) = 0;
virtual bool filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec*) const = 0;
/**
* Compute a conservative bounds for its effect, given the src bounds.
* The baseline implementation just assigns src to dst.
*/
virtual void computeFastBounds(SkRect* dst, const SkRect& src);
virtual void computeFastBounds(SkRect* dst, const SkRect& src) const;
/** \class PointData
@ -152,7 +153,8 @@ public:
SkComposePathEffect(SkPathEffect* outer, SkPathEffect* inner)
: INHERITED(outer, inner) {}
virtual bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*) SK_OVERRIDE;
virtual bool filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec*) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposePathEffect)
@ -182,7 +184,8 @@ public:
SkSumPathEffect(SkPathEffect* first, SkPathEffect* second)
: INHERITED(first, second) {}
virtual bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*) SK_OVERRIDE;
virtual bool filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec*) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSumPathEffect)

View File

@ -16,19 +16,20 @@ class SkPathMeasure;
// This class is not exported to java.
class SK_API Sk1DPathEffect : public SkPathEffect {
public:
virtual bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*) SK_OVERRIDE;
virtual bool filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec*) const SK_OVERRIDE;
protected:
/** Called at the start of each contour, returns the initial offset
into that contour.
*/
virtual SkScalar begin(SkScalar contourLength) = 0;
virtual SkScalar begin(SkScalar contourLength) const = 0;
/** Called with the current distance along the path, with the current matrix
for the point/tangent at the specified distance.
Return the distance to travel for the next call. If return <= 0, then that
contour is done.
*/
virtual SkScalar next(SkPath* dst, SkScalar distance, SkPathMeasure&) = 0;
virtual SkScalar next(SkPath* dst, SkScalar dist, SkPathMeasure&) const = 0;
private:
typedef SkPathEffect INHERITED;
@ -53,7 +54,8 @@ public:
*/
SkPath1DPathEffect(const SkPath& path, SkScalar advance, SkScalar phase, Style);
virtual bool filterPath(SkPath*, const SkPath&, SkStrokeRec*) SK_OVERRIDE;
virtual bool filterPath(SkPath*, const SkPath&,
SkStrokeRec*) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPath1DPathEffect)
@ -62,8 +64,8 @@ protected:
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
// overrides from Sk1DPathEffect
virtual SkScalar begin(SkScalar contourLength) SK_OVERRIDE;
virtual SkScalar next(SkPath*, SkScalar distance, SkPathMeasure&) SK_OVERRIDE;
virtual SkScalar begin(SkScalar contourLength) const SK_OVERRIDE;
virtual SkScalar next(SkPath*, SkScalar, SkPathMeasure&) const SK_OVERRIDE;
private:
SkPath fPath; // copied from constructor

View File

@ -16,8 +16,8 @@ class SK_API Sk2DPathEffect : public SkPathEffect {
public:
Sk2DPathEffect(const SkMatrix& mat);
// overrides
virtual bool filterPath(SkPath*, const SkPath&, SkStrokeRec*) SK_OVERRIDE;
virtual bool filterPath(SkPath*, const SkPath&,
SkStrokeRec*) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Sk2DPathEffect)
@ -28,15 +28,15 @@ protected:
next() will receive u and v values within these bounds,
and then a call to end() will signal the end of processing.
*/
virtual void begin(const SkIRect& uvBounds, SkPath* dst);
virtual void next(const SkPoint& loc, int u, int v, SkPath* dst);
virtual void end(SkPath* dst);
virtual void begin(const SkIRect& uvBounds, SkPath* dst) const;
virtual void next(const SkPoint& loc, int u, int v, SkPath* dst) const;
virtual void end(SkPath* dst) const;
/** Low-level virtual called per span of locations in the u-direction.
The default implementation calls next() repeatedly with each
location.
*/
virtual void nextSpan(int u, int v, int ucount, SkPath* dst);
virtual void nextSpan(int u, int v, int ucount, SkPath* dst) const;
const SkMatrix& getMatrix() const { return fMatrix; }
@ -61,12 +61,13 @@ public:
SkLine2DPathEffect(SkScalar width, const SkMatrix& matrix)
: Sk2DPathEffect(matrix), fWidth(width) {}
virtual bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec) SK_OVERRIDE;
virtual bool filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec*) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLine2DPathEffect)
protected:
virtual void nextSpan(int u, int v, int ucount, SkPath* dst) SK_OVERRIDE;
virtual void nextSpan(int u, int v, int ucount, SkPath*) const SK_OVERRIDE;
SkLine2DPathEffect(SkFlattenableReadBuffer&);
@ -92,7 +93,7 @@ protected:
SkPath2DPathEffect(SkFlattenableReadBuffer& buffer);
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
virtual void next(const SkPoint&, int u, int v, SkPath* dst) SK_OVERRIDE;
virtual void next(const SkPoint&, int u, int v, SkPath*) const SK_OVERRIDE;
private:
SkPath fPath;

View File

@ -23,9 +23,8 @@ public:
SkCornerPathEffect(SkScalar radius);
virtual ~SkCornerPathEffect();
// overrides for SkPathEffect
// This method is not exported to java.
virtual bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*) SK_OVERRIDE;
virtual bool filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec*) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkCornerPathEffect)

View File

@ -36,17 +36,18 @@ public:
Note: only affects stroked paths.
*/
SkDashPathEffect(const SkScalar intervals[], int count, SkScalar phase, bool scaleToFit = false);
SkDashPathEffect(const SkScalar intervals[], int count, SkScalar phase,
bool scaleToFit = false);
virtual ~SkDashPathEffect();
virtual bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*) SK_OVERRIDE;
virtual bool filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec*) const SK_OVERRIDE;
virtual bool asPoints(PointData* results, const SkPath& src,
const SkStrokeRec&, const SkMatrix&) const SK_OVERRIDE;
// overrides for SkFlattenable
// This method is not exported to java.
virtual Factory getFactory();
virtual Factory getFactory() SK_OVERRIDE;
static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
protected:

View File

@ -22,7 +22,8 @@ public:
*/
SkDiscretePathEffect(SkScalar segLength, SkScalar deviation);
virtual bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*) SK_OVERRIDE;
virtual bool filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec*) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiscretePathEffect)

View File

@ -74,26 +74,26 @@ public:
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Dot2DPathEffect)
protected:
virtual void begin(const SkIRect& uvBounds, SkPath* dst) {
virtual void begin(const SkIRect& uvBounds, SkPath* dst) const SK_OVERRIDE {
if (fPts) {
fPts->reset();
}
this->INHERITED::begin(uvBounds, dst);
}
// virtual void end(SkPath* dst) {}
virtual void next(const SkPoint& loc, int u, int v, SkPath* dst)
{
virtual void next(const SkPoint& loc, int u, int v,
SkPath* dst) const SK_OVERRIDE {
if (fPts) {
*fPts->append() = loc;
}
dst->addCircle(loc.fX, loc.fY, fRadius);
}
Dot2DPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer)
{
Dot2DPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
fRadius = buffer.readScalar();
fPts = NULL;
}
virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE {
this->INHERITED::flatten(buffer);
buffer.writeScalar(fRadius);
@ -109,7 +109,8 @@ private:
class InverseFillPE : public SkPathEffect {
public:
InverseFillPE() {}
virtual bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*) SK_OVERRIDE {
virtual bool filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec*) const SK_OVERRIDE {
*dst = src;
dst->setFillType(SkPath::kInverseWinding_FillType);
return true;

View File

@ -94,8 +94,7 @@ public:
SK_DECLARE_UNFLATTENABLE_OBJECT()
protected:
virtual SkScalar begin(SkScalar contourLength)
{
virtual SkScalar begin(SkScalar contourLength) const {
SkScriptValue value;
SkAnimatorScript engine(*fMaker, NULL, SkType_Float);
engine.propertyCallBack(GetContourLength, &contourLength);
@ -104,8 +103,7 @@ protected:
return value.fOperand.fScalar;
}
virtual SkScalar next(SkPath* dst, SkScalar distance, SkPathMeasure& )
{
virtual SkScalar next(SkPath* dst, SkScalar distance, SkPathMeasure&) const {
fMaker->setExtraPropertyCallBack(fDraw->fType, GetDistance, &distance);
SkDrawPath* drawPath = NULL;
if (fDraw->addPath->isPath()) {

View File

@ -14,7 +14,7 @@
SK_DEFINE_INST_COUNT(SkPathEffect)
void SkPathEffect::computeFastBounds(SkRect* dst, const SkRect& src) {
void SkPathEffect::computeFastBounds(SkRect* dst, const SkRect& src) const {
*dst = src;
}
@ -56,7 +56,7 @@ SkPairPathEffect::SkPairPathEffect(SkFlattenableReadBuffer& buffer) {
///////////////////////////////////////////////////////////////////////////////
bool SkComposePathEffect::filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec* rec) {
SkStrokeRec* rec) const {
// we may have failed to unflatten these, so we have to check
if (!fPE0 || !fPE1) {
return false;
@ -74,7 +74,7 @@ bool SkComposePathEffect::filterPath(SkPath* dst, const SkPath& src,
///////////////////////////////////////////////////////////////////////////////
bool SkSumPathEffect::filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec* rec) {
SkStrokeRec* rec) const {
// use bit-or so that we always call both, even if the first one succeeds
return fPE0->filterPath(dst, src, rec) | fPE1->filterPath(dst, src, rec);
}

View File

@ -11,7 +11,8 @@
#include "SkFlattenableBuffers.h"
#include "SkPathMeasure.h"
bool Sk1DPathEffect::filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*) {
bool Sk1DPathEffect::filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec*) const {
SkPathMeasure meas(src, false);
do {
SkScalar length = meas.getLength();
@ -68,7 +69,7 @@ SkPath1DPathEffect::SkPath1DPathEffect(const SkPath& path, SkScalar advance,
}
bool SkPath1DPathEffect::filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec* rec) {
SkStrokeRec* rec) const {
if (fAdvance > 0) {
rec->setFillStyle();
return this->INHERITED::filterPath(dst, src, rec);
@ -159,7 +160,7 @@ SkPath1DPathEffect::SkPath1DPathEffect(SkFlattenableReadBuffer& buffer) {
}
}
SkScalar SkPath1DPathEffect::begin(SkScalar contourLength) {
SkScalar SkPath1DPathEffect::begin(SkScalar contourLength) const {
return fInitialOffset;
}
@ -174,7 +175,7 @@ void SkPath1DPathEffect::flatten(SkFlattenableWriteBuffer& buffer) const {
}
SkScalar SkPath1DPathEffect::next(SkPath* dst, SkScalar distance,
SkPathMeasure& meas) {
SkPathMeasure& meas) const {
switch (fStyle) {
case kTranslate_Style: {
SkPoint pos;

View File

@ -16,7 +16,8 @@ Sk2DPathEffect::Sk2DPathEffect(const SkMatrix& mat) : fMatrix(mat) {
fMatrixIsInvertible = mat.invert(&fInverse);
}
bool Sk2DPathEffect::filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*) {
bool Sk2DPathEffect::filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec*) const {
if (!fMatrixIsInvertible) {
return false;
}
@ -44,7 +45,7 @@ bool Sk2DPathEffect::filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*) {
return true;
}
void Sk2DPathEffect::nextSpan(int x, int y, int count, SkPath* path) {
void Sk2DPathEffect::nextSpan(int x, int y, int count, SkPath* path) const {
if (!fMatrixIsInvertible) {
return;
}
@ -60,9 +61,9 @@ void Sk2DPathEffect::nextSpan(int x, int y, int count, SkPath* path) {
} while (--count > 0);
}
void Sk2DPathEffect::begin(const SkIRect& uvBounds, SkPath* dst) {}
void Sk2DPathEffect::next(const SkPoint& loc, int u, int v, SkPath* dst) {}
void Sk2DPathEffect::end(SkPath* dst) {}
void Sk2DPathEffect::begin(const SkIRect& uvBounds, SkPath* dst) const {}
void Sk2DPathEffect::next(const SkPoint& loc, int u, int v, SkPath* dst) const {}
void Sk2DPathEffect::end(SkPath* dst) const {}
///////////////////////////////////////////////////////////////////////////////
@ -78,7 +79,8 @@ Sk2DPathEffect::Sk2DPathEffect(SkFlattenableReadBuffer& buffer) {
///////////////////////////////////////////////////////////////////////////////
bool SkLine2DPathEffect::filterPath(SkPath *dst, const SkPath &src, SkStrokeRec *rec) {
bool SkLine2DPathEffect::filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec* rec) const {
if (this->INHERITED::filterPath(dst, src, rec)) {
rec->setStrokeStyle(fWidth);
return true;
@ -86,7 +88,7 @@ bool SkLine2DPathEffect::filterPath(SkPath *dst, const SkPath &src, SkStrokeRec
return false;
}
void SkLine2DPathEffect::nextSpan(int u, int v, int ucount, SkPath *dst) {
void SkLine2DPathEffect::nextSpan(int u, int v, int ucount, SkPath* dst) const {
if (ucount > 1) {
SkPoint src[2], dstP[2];
@ -124,6 +126,7 @@ void SkPath2DPathEffect::flatten(SkFlattenableWriteBuffer& buffer) const {
buffer.writePath(fPath);
}
void SkPath2DPathEffect::next(const SkPoint& loc, int u, int v, SkPath* dst) {
void SkPath2DPathEffect::next(const SkPoint& loc, int u, int v,
SkPath* dst) const {
dst->addPath(fPath, loc.fX, loc.fY);
}

View File

@ -12,13 +12,8 @@
#include "SkPoint.h"
#include "SkFlattenableBuffers.h"
SkCornerPathEffect::SkCornerPathEffect(SkScalar radius) : fRadius(radius)
{
}
SkCornerPathEffect::~SkCornerPathEffect()
{
}
SkCornerPathEffect::SkCornerPathEffect(SkScalar radius) : fRadius(radius) {}
SkCornerPathEffect::~SkCornerPathEffect() {}
static bool ComputeStep(const SkPoint& a, const SkPoint& b, SkScalar radius,
SkPoint* step) {
@ -36,8 +31,8 @@ static bool ComputeStep(const SkPoint& a, const SkPoint& b, SkScalar radius,
}
bool SkCornerPathEffect::filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec*) {
if (fRadius == 0) {
SkStrokeRec*) const {
if (0 == fRadius) {
return false;
}

View File

@ -156,7 +156,7 @@ private:
};
bool SkDashPathEffect::filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec* rec) {
SkStrokeRec* rec) const {
// we do nothing if the src wants to be filled, or if our dashlength is 0
if (rec->isFillStyle() || fInitialDashLength < 0) {
return false;

View File

@ -26,7 +26,7 @@ SkDiscretePathEffect::SkDiscretePathEffect(SkScalar segLength, SkScalar deviatio
}
bool SkDiscretePathEffect::filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec* rec) {
SkStrokeRec* rec) const {
bool doFill = rec->isFillStyle();
SkPathMeasure meas(src, doFill);