Added toString to SkMaskFilter-derived classes
authorrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 18 Mar 2013 17:53:38 +0000 (17:53 +0000)
committerrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 18 Mar 2013 17:53:38 +0000 (17:53 +0000)
https://codereview.appspot.com/7889043/

git-svn-id: http://skia.googlecode.com/svn/trunk@8194 2bbb7eff-a529-9590-31e7-b0007b416f81

12 files changed:
include/core/SkMaskFilter.h
include/effects/SkEmbossMaskFilter.h
include/effects/SkKernel33MaskFilter.h
include/effects/SkStippleMaskFilter.h
include/effects/SkTableMaskFilter.h
samplecode/SampleText.cpp
src/core/SkPaint.cpp
src/effects/SkBlurMaskFilter.cpp
src/effects/SkEmbossMaskFilter.cpp
src/effects/SkKernel33MaskFilter.cpp
src/effects/SkStippleMaskFilter.cpp
src/effects/SkTableMaskFilter.cpp

index a874e62b48af10e8d3e012227f1bd056be61b225..aa499ecd2399a3a44250e07e78af4258fba4f156 100644 (file)
@@ -93,6 +93,8 @@ public:
      */
     virtual void computeFastBounds(const SkRect& src, SkRect* dest) const;
 
+    SkDEVCODE(virtual void toString(SkString* str) const = 0;)
+
 protected:
     // empty for now, but lets get our subclass to remember to init us for the future
     SkMaskFilter(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
index ce6447371f682d0707092b5f434e43e834b05802..c6679200b3e9c3c46dcbd2afc9c96bfec423d5a0 100644 (file)
@@ -32,6 +32,7 @@ public:
     virtual bool filterMask(SkMask* dst, const SkMask& src, const SkMatrix&,
                             SkIPoint* margin) const SK_OVERRIDE;
 
+    SkDEVCODE(virtual void toString(SkString* str) const SK_OVERRIDE;)
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkEmbossMaskFilter)
 
 protected:
index 9fcbb6afa7a633eb0c2508780e7951c278caf21d..3404b73b1773a71350892c4e40897de3483f402f 100644 (file)
@@ -21,6 +21,8 @@ public:
     virtual bool filterMask(SkMask*, const SkMask&, const SkMatrix&,
                             SkIPoint*) const SK_OVERRIDE;
 
+    SkDEVCODE(virtual void toString(SkString* str) const SK_OVERRIDE;)
+
 protected:
     SkKernel33ProcMaskFilter(SkFlattenableReadBuffer& rb);
     virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
@@ -44,6 +46,7 @@ public:
     // override from SkKernel33ProcMaskFilter
     virtual uint8_t computeValue(uint8_t* const* srcRows) const SK_OVERRIDE;
 
+    SkDEVCODE(virtual void toString(SkString* str) const SK_OVERRIDE;)
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkKernel33MaskFilter)
 
 private:
index be03c4590e62bed53d3acc59dd61e7134e33398b..8f6d20d9ca87024b44acdfe1de93497c96bf5684 100644 (file)
@@ -27,6 +27,7 @@ public:
         return SkMask::kA8_Format;
     }
 
+    SkDEVCODE(virtual void toString(SkString* str) const SK_OVERRIDE;)
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkStippleMaskFilter);
 
 protected:
index feb3b13847b876cae67aac31dec21cc18f26840b..ac33266f80c04d089df8631dd2880c9e5df5834a 100644 (file)
@@ -47,6 +47,7 @@ public:
     virtual bool filterMask(SkMask*, const SkMask&, const SkMatrix&,
                             SkIPoint*) const SK_OVERRIDE;
 
+    SkDEVCODE(virtual void toString(SkString* str) const SK_OVERRIDE;)
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTableMaskFilter)
 
 protected:
index ee447d30666ae48fe923cdd9ed20ff4aa3315bbb..5873091836a2a7b9aea5eb69b6d234be375f758d 100644 (file)
@@ -48,10 +48,21 @@ public:
     //    if (c < min) c = min;
         return c;
     }
+
+#ifdef SK_DEVELOPER
+    virtual void toString(SkString* str) const SK_OVERRIDE {
+        str->append("ReduceNoise: (");
+        this->INHERITED::toString(str);
+        str->append(")");
+    }
+#endif
+
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(ReduceNoise)
 
 private:
     ReduceNoise(SkFlattenableReadBuffer& rb) : SkKernel33ProcMaskFilter(rb) {}
+
+    typedef SkKernel33ProcMaskFilter INHERITED;
 };
 
 class Darken : public SkKernel33ProcMaskFilter {
@@ -69,10 +80,21 @@ public:
         SkASSERT(f >= 0 && f <= 1);
         return (int)(f * 255);
     }
+
+#ifdef SK_DEVELOPER
+    virtual void toString(SkString* str) const SK_OVERRIDE { 
+        str->append("Darken: ("); 
+        this->INHERITED::toString(str);
+        str->append(")");
+    }
+#endif
+
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Darken)
 
 private:
     Darken(SkFlattenableReadBuffer& rb) : SkKernel33ProcMaskFilter(rb) {}
+
+    typedef SkKernel33ProcMaskFilter INHERITED;
 };
 
 static SkMaskFilter* makemf() { return new Darken(0x30); }
index b9dc5e5d0e27d440048ef87c3a2317f2299f5363..c7ad933dd1a42ccdce29e7376670e9440b3526c2 100644 (file)
@@ -2295,6 +2295,7 @@ void SkPaint::toString(SkString* str) const {
     SkMaskFilter* maskFilter = this->getMaskFilter();
     if (NULL != maskFilter) {
         str->append("<dt>MaskFilter:</dt><dd>");
+        SkDEVCODE(maskFilter->toString(str);)
         str->append("</dd>");
     }
 
index 88043ff6feb671e4ad9765b22c8aaeebce6e9e0b..2329b0f685ab5a8d61a471e281a046e5431aa988 100644 (file)
@@ -13,6 +13,7 @@
 #include "SkBounder.h"
 #include "SkRasterClip.h"
 #include "SkRTConf.h"
+#include "SkStringUtils.h"
 
 class SkBlurMaskFilterImpl : public SkMaskFilter {
 public:
@@ -27,6 +28,7 @@ public:
     virtual BlurType asABlur(BlurInfo*) const SK_OVERRIDE;
     virtual void computeFastBounds(const SkRect&, SkRect*) const SK_OVERRIDE;
 
+    SkDEVCODE(virtual void toString(SkString* str) const SK_OVERRIDE;)
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurMaskFilterImpl)
 
 protected:
@@ -339,6 +341,35 @@ SkMaskFilter::BlurType SkBlurMaskFilterImpl::asABlur(BlurInfo* info) const {
     return gBlurStyle2BlurType[fBlurStyle];
 }
 
+#ifdef SK_DEVELOPER
+void SkBlurMaskFilterImpl::toString(SkString* str) const {
+    str->append("SkBlurMaskFilterImpl: (");
+
+    str->append("radius: ");
+    str->appendScalar(fRadius);
+    str->append(" ");
+
+    static const char* gStyleName[SkBlurMaskFilter::kBlurStyleCount] = {
+        "normal", "solid", "outer", "inner"
+    };
+
+    str->appendf("style: %s ", gStyleName[fBlurStyle]);
+    str->append("flags: (");
+    if (fBlurFlags) {
+        bool needSeparator = false;
+        SkAddFlagToString(str, 
+                          SkToBool(fBlurFlags & SkBlurMaskFilter::kIgnoreTransform_BlurFlag), 
+                          "IgnoreXform", &needSeparator);
+        SkAddFlagToString(str, 
+                          SkToBool(fBlurFlags & SkBlurMaskFilter::kHighQuality_BlurFlag), 
+                          "HighQuality", &needSeparator);
+    } else {
+        str->append("None");
+    }
+    str->append("))");
+}
+#endif
+
 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter)
     SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl)
 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
index 0c9158586fa40aa714535ede79bce94730151782..a205fccf155a7f387354887216c59c3e24d5a794 100644 (file)
@@ -12,6 +12,7 @@
 #include "SkBlurMask.h"
 #include "SkEmbossMask.h"
 #include "SkFlattenableBuffers.h"
+#include "SkString.h"
 
 static inline int pin2byte(int n) {
     if (n < 0) {
@@ -131,3 +132,24 @@ void SkEmbossMaskFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
     buffer.writeByteArray(&tmpLight, sizeof(tmpLight));
     buffer.writeScalar(fBlurRadius);
 }
+
+#ifdef SK_DEVELOPER
+void SkEmbossMaskFilter::toString(SkString* str) const {
+    str->append("SkEmbossMaskFilter: (");
+
+    str->append("direction: (");
+    str->appendScalar(fLight.fDirection[0]);
+    str->append(", ");
+    str->appendScalar(fLight.fDirection[1]);
+    str->append(", ");
+    str->appendScalar(fLight.fDirection[2]);
+    str->append(") ");
+
+    str->appendf("ambient: %d specular: %d ", 
+        fLight.fAmbient, fLight.fSpecular);
+
+    str->append("blurRadius: ");
+    str->appendScalar(fBlurRadius);
+    str->append(")");
+}
+#endif
index 9c42b398c73d9c60e6f29d6e17f275a0e4e3b758..485001bbe38fc865899819443c4c419d5e622833 100644 (file)
@@ -8,6 +8,7 @@
 #include "SkKernel33MaskFilter.h"
 #include "SkColorPriv.h"
 #include "SkFlattenableBuffers.h"
+#include "SkString.h"
 
 SkMask::Format SkKernel33ProcMaskFilter::getFormat() const {
     return SkMask::kA8_Format;
@@ -84,6 +85,12 @@ SkKernel33ProcMaskFilter::SkKernel33ProcMaskFilter(SkFlattenableReadBuffer& rb)
     fPercent256 = rb.readInt();
 }
 
+#ifdef SK_DEVELOPER
+void SkKernel33ProcMaskFilter::toString(SkString* str) const {
+    str->appendf("percent256: %d, ", fPercent256);
+}
+#endif
+
 ///////////////////////////////////////////////////////////////////////////////
 
 uint8_t SkKernel33MaskFilter::computeValue(uint8_t* const* srcRows) const {
@@ -117,3 +124,19 @@ SkKernel33MaskFilter::SkKernel33MaskFilter(SkFlattenableReadBuffer& rb)
     SkASSERT(9 == count);
     fShift = rb.readInt();
 }
+
+#ifdef SK_DEVELOPER
+void SkKernel33MaskFilter::toString(SkString* str) const {
+    str->append("SkKernel33MaskFilter: (");
+
+    str->appendf("kernel: (%d, %d, %d, %d, %d, %d, %d, %d, %d), ",
+            fKernel[0][0], fKernel[0][1], fKernel[0][2],
+            fKernel[1][0], fKernel[1][1], fKernel[1][2],
+            fKernel[2][0], fKernel[2][1], fKernel[2][2]);
+    str->appendf("shift: %d, ", fShift);
+
+    this->INHERITED::toString(str);
+
+    str->append(")");
+}
+#endif
index 24b911440097f0bf417aa1251697685395946011..14f30ec6510bd126b6ef2f8d288adf74c72a0bad 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #include "SkStippleMaskFilter.h"
-
+#include "SkString.h"
 
 bool SkStippleMaskFilter::filterMask(SkMask* dst,
                                      const SkMask& src,
@@ -44,3 +44,9 @@ bool SkStippleMaskFilter::filterMask(SkMask* dst,
 
     return true;
 }
+
+#ifdef SK_DEVELOPER
+void SkStippleMaskFilter::toString(SkString* str) const {
+    str->append("SkStippleMaskFilter: ()");
+}
+#endif
index ada5d012177dd78bc15e1c452a60162c9b9b41b2..5bff4def299ea343e5945dd9218863c03c51b136 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "SkTableMaskFilter.h"
 #include "SkFlattenableBuffers.h"
+#include "SkString.h"
 
 SkTableMaskFilter::SkTableMaskFilter() {
     for (int i = 0; i < 256; i++) {
@@ -126,3 +127,17 @@ void SkTableMaskFilter::MakeClipTable(uint8_t table[256], uint8_t min,
     SkDebugf("\n\n");
 #endif
 }
+
+#ifdef SK_DEVELOPER
+void SkTableMaskFilter::toString(SkString* str) const {
+    str->append("SkTableMaskFilter: (");
+
+    str->append("table: ");
+    for (int i = 0; i < 255; ++i) {
+        str->appendf("%d, ", fTable[i]);
+    }
+    str->appendf("%d", fTable[255]);
+
+    str->append(")");
+}
+#endif