change SkMaskFilter methods to const, in preparation for making the class as
immutable and re-entrant safe.
Review URL: https://codereview.appspot.com/6944069
git-svn-id: http://skia.googlecode.com/svn/trunk@6881 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkDraw.h b/include/core/SkDraw.h
index 5db4bf0..4ac7cf9 100644
--- a/include/core/SkDraw.h
+++ b/include/core/SkDraw.h
@@ -76,7 +76,7 @@
solely to assist in computing the mask's bounds (if the mode requests that).
*/
static bool DrawToMask(const SkPath& devPath, const SkIRect* clipBounds,
- SkMaskFilter* filter, const SkMatrix* filterMatrix,
+ const SkMaskFilter*, const SkMatrix* filterMatrix,
SkMask* mask, SkMask::CreateMode mode,
SkPaint::Style style);
diff --git a/include/core/SkMaskFilter.h b/include/core/SkMaskFilter.h
index 02f5855..245de29 100644
--- a/include/core/SkMaskFilter.h
+++ b/include/core/SkMaskFilter.h
@@ -40,7 +40,7 @@
/** Returns the format of the resulting mask that this subclass will return
when its filterMask() method is called.
*/
- virtual SkMask::Format getFormat() = 0;
+ virtual SkMask::Format getFormat() const = 0;
/** Create a new mask by filter the src mask.
If src.fImage == null, then do not allocate or create the dst image
@@ -56,7 +56,7 @@
@return true if the dst mask was correctly created.
*/
virtual bool filterMask(SkMask* dst, const SkMask& src, const SkMatrix&,
- SkIPoint* margin);
+ SkIPoint* margin) const;
enum BlurType {
kNone_BlurType, //!< this maskfilter is not a blur
@@ -91,7 +91,7 @@
* The default impl calls filterMask with the src mask having no image,
* but subclasses may override this if they can compute the rect faster.
*/
- virtual void computeFastBounds(const SkRect& src, SkRect* dest);
+ virtual void computeFastBounds(const SkRect& src, SkRect* dest) const;
protected:
// empty for now, but lets get our subclass to remember to init us for the future
@@ -127,7 +127,7 @@
virtual FilterReturn filterRectsToNine(const SkRect[], int count,
const SkMatrix&,
const SkIRect& clipBounds,
- NinePatch*);
+ NinePatch*) const;
private:
friend class SkDraw;
@@ -139,7 +139,7 @@
*/
bool filterPath(const SkPath& devPath, const SkMatrix& devMatrix,
const SkRasterClip&, SkBounder*, SkBlitter* blitter,
- SkPaint::Style style);
+ SkPaint::Style style) const;
typedef SkFlattenable INHERITED;
};
diff --git a/include/effects/SkEmbossMaskFilter.h b/include/effects/SkEmbossMaskFilter.h
index 96c25b2..ce64473 100644
--- a/include/effects/SkEmbossMaskFilter.h
+++ b/include/effects/SkEmbossMaskFilter.h
@@ -27,10 +27,10 @@
// overrides from SkMaskFilter
// This method is not exported to java.
- virtual SkMask::Format getFormat();
+ virtual SkMask::Format getFormat() const SK_OVERRIDE;
// This method is not exported to java.
virtual bool filterMask(SkMask* dst, const SkMask& src, const SkMatrix&,
- SkIPoint* margin);
+ SkIPoint* margin) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkEmbossMaskFilter)
diff --git a/include/effects/SkKernel33MaskFilter.h b/include/effects/SkKernel33MaskFilter.h
index 41e73c9..9fcbb6a 100644
--- a/include/effects/SkKernel33MaskFilter.h
+++ b/include/effects/SkKernel33MaskFilter.h
@@ -15,11 +15,11 @@
SkKernel33ProcMaskFilter(unsigned percent256 = 256)
: fPercent256(percent256) {}
- virtual uint8_t computeValue(uint8_t* const* srcRows) = 0;
+ virtual uint8_t computeValue(uint8_t* const* srcRows) const = 0;
- // overrides from SkMaskFilter
- virtual SkMask::Format getFormat();
- virtual bool filterMask(SkMask*, const SkMask&, const SkMatrix&, SkIPoint*);
+ virtual SkMask::Format getFormat() const SK_OVERRIDE;
+ virtual bool filterMask(SkMask*, const SkMask&, const SkMatrix&,
+ SkIPoint*) const SK_OVERRIDE;
protected:
SkKernel33ProcMaskFilter(SkFlattenableReadBuffer& rb);
@@ -42,7 +42,7 @@
}
// override from SkKernel33ProcMaskFilter
- virtual uint8_t computeValue(uint8_t* const* srcRows);
+ virtual uint8_t computeValue(uint8_t* const* srcRows) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkKernel33MaskFilter)
diff --git a/include/effects/SkStippleMaskFilter.h b/include/effects/SkStippleMaskFilter.h
index b5d162e..be03c45 100644
--- a/include/effects/SkStippleMaskFilter.h
+++ b/include/effects/SkStippleMaskFilter.h
@@ -20,10 +20,10 @@
virtual bool filterMask(SkMask* dst, const SkMask& src,
const SkMatrix& matrix,
- SkIPoint* margin) SK_OVERRIDE;
+ SkIPoint* margin) const SK_OVERRIDE;
// getFormat is from SkMaskFilter
- virtual SkMask::Format getFormat() SK_OVERRIDE {
+ virtual SkMask::Format getFormat() const SK_OVERRIDE {
return SkMask::kA8_Format;
}
diff --git a/include/effects/SkTableMaskFilter.h b/include/effects/SkTableMaskFilter.h
index c407b40..feb3b13 100644
--- a/include/effects/SkTableMaskFilter.h
+++ b/include/effects/SkTableMaskFilter.h
@@ -22,8 +22,6 @@
SkTableMaskFilter(const uint8_t table[256]);
virtual ~SkTableMaskFilter();
- void setTable(const uint8_t table[256]);
-
/** Utility that sets the gamma table
*/
static void MakeGammaTable(uint8_t table[256], SkScalar gamma);
@@ -45,9 +43,9 @@
return SkNEW_ARGS(SkTableMaskFilter, (table));
}
- // overrides from SkMaskFilter
- virtual SkMask::Format getFormat();
- virtual bool filterMask(SkMask*, const SkMask&, const SkMatrix&, SkIPoint*);
+ virtual SkMask::Format getFormat() const SK_OVERRIDE;
+ virtual bool filterMask(SkMask*, const SkMask&, const SkMatrix&,
+ SkIPoint*) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTableMaskFilter)
diff --git a/samplecode/SampleText.cpp b/samplecode/SampleText.cpp
index 8ff36e4..6483218 100644
--- a/samplecode/SampleText.cpp
+++ b/samplecode/SampleText.cpp
@@ -31,8 +31,7 @@
class ReduceNoise : public SkKernel33ProcMaskFilter {
public:
ReduceNoise(int percent256) : SkKernel33ProcMaskFilter(percent256) {}
- virtual uint8_t computeValue(uint8_t* const* srcRows)
- {
+ virtual uint8_t computeValue(uint8_t* const* srcRows) const {
int c = srcRows[1][1];
int min = 255, max = 0;
for (int i = 0; i < 3; i++)
@@ -58,8 +57,7 @@
class Darken : public SkKernel33ProcMaskFilter {
public:
Darken(int percent256) : SkKernel33ProcMaskFilter(percent256) {}
- virtual uint8_t computeValue(uint8_t* const* srcRows)
- {
+ virtual uint8_t computeValue(uint8_t* const* srcRows) const {
int c = srcRows[1][1];
float f = c / 255.f;
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index 3326b55..281c69c 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -1,4 +1,3 @@
-
/*
* Copyright 2006 The Android Open Source Project
*
@@ -2651,7 +2650,7 @@
#include "SkBlitter.h"
static bool compute_bounds(const SkPath& devPath, const SkIRect* clipBounds,
- SkMaskFilter* filter, const SkMatrix* filterMatrix,
+ const SkMaskFilter* filter, const SkMatrix* filterMatrix,
SkIRect* bounds) {
if (devPath.isEmpty()) {
return false;
@@ -2725,7 +2724,7 @@
}
bool SkDraw::DrawToMask(const SkPath& devPath, const SkIRect* clipBounds,
- SkMaskFilter* filter, const SkMatrix* filterMatrix,
+ const SkMaskFilter* filter, const SkMatrix* filterMatrix,
SkMask* mask, SkMask::CreateMode mode,
SkPaint::Style style) {
if (SkMask::kJustRenderImage_CreateMode != mode) {
diff --git a/src/core/SkMaskFilter.cpp b/src/core/SkMaskFilter.cpp
index eef2139..5de76c7 100644
--- a/src/core/SkMaskFilter.cpp
+++ b/src/core/SkMaskFilter.cpp
@@ -17,7 +17,7 @@
SK_DEFINE_INST_COUNT(SkMaskFilter)
bool SkMaskFilter::filterMask(SkMask*, const SkMask&, const SkMatrix&,
- SkIPoint*) {
+ SkIPoint*) const {
return false;
}
@@ -192,7 +192,7 @@
bool SkMaskFilter::filterPath(const SkPath& devPath, const SkMatrix& matrix,
const SkRasterClip& clip, SkBounder* bounder,
- SkBlitter* blitter, SkPaint::Style style) {
+ SkBlitter* blitter, SkPaint::Style style) const {
SkRect rects[2];
int rectCount = 0;
if (SkPaint::kFill_Style == style) {
@@ -254,7 +254,7 @@
SkMaskFilter::FilterReturn
SkMaskFilter::filterRectsToNine(const SkRect[], int count, const SkMatrix&,
- const SkIRect& clipBounds, NinePatch*) {
+ const SkIRect& clipBounds, NinePatch*) const {
return kUnimplemented_FilterReturn;
}
@@ -262,7 +262,7 @@
return kNone_BlurType;
}
-void SkMaskFilter::computeFastBounds(const SkRect& src, SkRect* dst) {
+void SkMaskFilter::computeFastBounds(const SkRect& src, SkRect* dst) const {
SkMask srcM, dstM;
srcM.fImage = NULL;
diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp
index a3991ca..c49a785 100644
--- a/src/effects/SkBlurMaskFilter.cpp
+++ b/src/effects/SkBlurMaskFilter.cpp
@@ -17,18 +17,18 @@
uint32_t flags);
// overrides from SkMaskFilter
- virtual SkMask::Format getFormat() SK_OVERRIDE;
+ virtual SkMask::Format getFormat() const SK_OVERRIDE;
virtual bool filterMask(SkMask* dst, const SkMask& src, const SkMatrix&,
- SkIPoint* margin) SK_OVERRIDE;
+ SkIPoint* margin) const SK_OVERRIDE;
virtual BlurType asABlur(BlurInfo*) const SK_OVERRIDE;
- virtual void computeFastBounds(const SkRect& src, SkRect* dst) SK_OVERRIDE;
+ virtual void computeFastBounds(const SkRect&, SkRect*) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurMaskFilterImpl)
protected:
virtual FilterReturn filterRectsToNine(const SkRect[], int count, const SkMatrix&,
const SkIRect& clipBounds,
- NinePatch*) SK_OVERRIDE;
+ NinePatch*) const SK_OVERRIDE;
private:
SkScalar fRadius;
@@ -74,12 +74,13 @@
SkASSERT(flags <= SkBlurMaskFilter::kAll_BlurFlag);
}
-SkMask::Format SkBlurMaskFilterImpl::getFormat() {
+SkMask::Format SkBlurMaskFilterImpl::getFormat() const {
return SkMask::kA8_Format;
}
bool SkBlurMaskFilterImpl::filterMask(SkMask* dst, const SkMask& src,
- const SkMatrix& matrix, SkIPoint* margin) {
+ const SkMatrix& matrix,
+ SkIPoint* margin) const{
SkScalar radius;
if (fBlurFlags & SkBlurMaskFilter::kIgnoreTransform_BlurFlag) {
radius = fRadius;
@@ -153,7 +154,7 @@
SkBlurMaskFilterImpl::filterRectsToNine(const SkRect rects[], int count,
const SkMatrix& matrix,
const SkIRect& clipBounds,
- NinePatch* patch) {
+ NinePatch* patch) const {
if (count < 1 || count > 2) {
return kUnimplemented_FilterReturn;
}
@@ -249,7 +250,8 @@
return kTrue_FilterReturn;
}
-void SkBlurMaskFilterImpl::computeFastBounds(const SkRect& src, SkRect* dst) {
+void SkBlurMaskFilterImpl::computeFastBounds(const SkRect& src,
+ SkRect* dst) const {
dst->set(src.fLeft - fRadius, src.fTop - fRadius,
src.fRight + fRadius, src.fBottom + fRadius);
}
diff --git a/src/effects/SkEmbossMaskFilter.cpp b/src/effects/SkEmbossMaskFilter.cpp
index 6480f50..0c91585 100644
--- a/src/effects/SkEmbossMaskFilter.cpp
+++ b/src/effects/SkEmbossMaskFilter.cpp
@@ -60,12 +60,12 @@
normalize(fLight.fDirection);
}
-SkMask::Format SkEmbossMaskFilter::getFormat() {
+SkMask::Format SkEmbossMaskFilter::getFormat() const {
return SkMask::k3D_Format;
}
bool SkEmbossMaskFilter::filterMask(SkMask* dst, const SkMask& src,
- const SkMatrix& matrix, SkIPoint* margin) {
+ const SkMatrix& matrix, SkIPoint* margin) const {
SkScalar radius = matrix.mapRadius(fBlurRadius);
if (!SkBlurMask::Blur(dst, src, radius, SkBlurMask::kInner_Style,
diff --git a/src/effects/SkKernel33MaskFilter.cpp b/src/effects/SkKernel33MaskFilter.cpp
index 1568a4f..0f198cd 100644
--- a/src/effects/SkKernel33MaskFilter.cpp
+++ b/src/effects/SkKernel33MaskFilter.cpp
@@ -9,12 +9,12 @@
#include "SkColorPriv.h"
#include "SkFlattenableBuffers.h"
-SkMask::Format SkKernel33ProcMaskFilter::getFormat() {
+SkMask::Format SkKernel33ProcMaskFilter::getFormat() const {
return SkMask::kA8_Format;
}
bool SkKernel33ProcMaskFilter::filterMask(SkMask* dst, const SkMask& src,
- const SkMatrix&, SkIPoint* margin) {
+ const SkMatrix&, SkIPoint* margin) const {
// margin???
dst->fImage = NULL;
dst->fBounds = src.fBounds;
@@ -86,7 +86,7 @@
///////////////////////////////////////////////////////////////////////////////
-uint8_t SkKernel33MaskFilter::computeValue(uint8_t* const* srcRows) {
+uint8_t SkKernel33MaskFilter::computeValue(uint8_t* const* srcRows) const {
int value = 0;
for (int i = 0; i < 3; i++) {
diff --git a/src/effects/SkStippleMaskFilter.cpp b/src/effects/SkStippleMaskFilter.cpp
index 434528e..24b9114 100644
--- a/src/effects/SkStippleMaskFilter.cpp
+++ b/src/effects/SkStippleMaskFilter.cpp
@@ -11,7 +11,7 @@
bool SkStippleMaskFilter::filterMask(SkMask* dst,
const SkMask& src,
const SkMatrix& matrix,
- SkIPoint* margin) {
+ SkIPoint* margin) const {
if (src.fFormat != SkMask::kA8_Format) {
return false;
diff --git a/src/effects/SkTableMaskFilter.cpp b/src/effects/SkTableMaskFilter.cpp
index d1fe134..73b7fa6 100644
--- a/src/effects/SkTableMaskFilter.cpp
+++ b/src/effects/SkTableMaskFilter.cpp
@@ -17,17 +17,13 @@
}
SkTableMaskFilter::SkTableMaskFilter(const uint8_t table[256]) {
- this->setTable(table);
+ memcpy(fTable, table, sizeof(fTable));
}
SkTableMaskFilter::~SkTableMaskFilter() {}
-void SkTableMaskFilter::setTable(const uint8_t table[256]) {
- memcpy(fTable, table, 256);
-}
-
bool SkTableMaskFilter::filterMask(SkMask* dst, const SkMask& src,
- const SkMatrix&, SkIPoint* margin) {
+ const SkMatrix&, SkIPoint* margin) const {
if (src.fFormat != SkMask::kA8_Format) {
return false;
}
@@ -68,7 +64,7 @@
return true;
}
-SkMask::Format SkTableMaskFilter::getFormat() {
+SkMask::Format SkTableMaskFilter::getFormat() const {
return SkMask::kA8_Format;
}