Added print out of SkShader information to debugger
authorrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 15 Jan 2013 20:17:47 +0000 (20:17 +0000)
committerrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 15 Jan 2013 20:17:47 +0000 (20:17 +0000)
https://codereview.appspot.com/7105045/

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

40 files changed:
debugger/SkObjectParser.cpp
experimental/Debugger/DebuggerContentView.cpp
experimental/Debugger/SkDebugDumper.cpp
experimental/Debugger/SkDebugDumper.h
include/core/SkBitmap.h
include/core/SkColorShader.h
include/core/SkComposeShader.h
include/core/SkEmptyShader.h
include/core/SkMatrix.h
include/core/SkShader.h
include/core/SkTypes.h
include/effects/SkTransparentShader.h
include/utils/SkDumpCanvas.h
samplecode/SamplePicture.cpp
samplecode/SampleSkLayer.cpp
src/core/SkBitmap.cpp
src/core/SkBitmapProcShader.cpp
src/core/SkBitmapProcShader.h
src/core/SkBlitter.cpp
src/core/SkColorFilter.cpp
src/core/SkComposeShader.cpp
src/core/SkDraw.cpp
src/core/SkFilterShader.h
src/core/SkMatrix.cpp
src/core/SkShader.cpp
src/effects/SkTransparentShader.cpp
src/effects/gradients/SkGradientShader.cpp
src/effects/gradients/SkGradientShaderPriv.h
src/effects/gradients/SkLinearGradient.cpp
src/effects/gradients/SkLinearGradient.h
src/effects/gradients/SkRadialGradient.cpp
src/effects/gradients/SkRadialGradient.h
src/effects/gradients/SkSweepGradient.cpp
src/effects/gradients/SkSweepGradient.h
src/effects/gradients/SkTwoPointConicalGradient.cpp
src/effects/gradients/SkTwoPointConicalGradient.h
src/effects/gradients/SkTwoPointRadialGradient.cpp
src/effects/gradients/SkTwoPointRadialGradient.h
src/utils/SkDumpCanvas.cpp
tools/pinspect.cpp

index aea54249552d333d5762f59b7b58f8c3c695ff08..d777631755237beeda40cae8bc3da00c33db4e35 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "SkObjectParser.h"
 #include "SkRRect.h"
+#include "SkShader.h"
 #include "SkTypeface.h"
 #include "SkStream.h"
 #include "SkData.h"
@@ -154,6 +155,7 @@ SkString* SkObjectParser::PaintToString(const SkPaint& paint) {
     SkShader* shader = paint.getShader();
     if (NULL != shader) {
         mPaint->append("<dt>Shader:</dt><dd>");
+        SkDEVCODE(shader->toString(mPaint);)
         mPaint->append("</dd>");
     }
 
index f079508643dfac35e5ed1ab8f8cdeae9317d8895..c928c2ea87b44d7793a5d51ae995117252cd39a3 100644 (file)
@@ -1,3 +1,6 @@
+
+#ifdef SK_DEVELOPER
+
 #include "SampleCode.h"
 #include "SkOSMenu.h"
 
@@ -271,3 +274,5 @@ bool is_debugger(SkView* view) {
     SkEvent isDebugger(gIsDebuggerQuery);
     return view->doQuery(&isDebugger);
 }
+
+#endif
\ No newline at end of file
index cfda184ebe4ca725706d52d28479f8f6f152434d..9f8afedae77d18edf55192c1a772077ac131beea 100644 (file)
@@ -6,6 +6,9 @@
  * found in the LICENSE file.
  */
 #include "SkDebugDumper.h"
+
+#ifdef SK_DEVELOPER
+
 #include "SkString.h"
 #include "SkPaint.h"
 #include "SkShader.h"
@@ -146,3 +149,5 @@ void SkDebugDumper::dump(SkDumpCanvas* canvas, SkDumpCanvas::Verb verb,
         }
     }
 }
+
+#endif
index e7d69562d5674bd07691c2c5159851cfb82843b0..16190c694d12a33b19cd616b90f61032c8420935 100644 (file)
@@ -7,6 +7,9 @@
  */
 #ifndef SkDebugDumper_DEFINED
 #define SkDebugDumper_DEFINED
+
+#ifdef SK_DEVELOPER
+
 #include "SkDumpCanvas.h"
 #include "SkEvent.h"
 
@@ -35,4 +38,7 @@ private:
 
     typedef SkDumpCanvas::Dumper INHERITED;
 };
+
+#endif
+
 #endif
index 7ea950bea25992bf9513b31b44a9065fecea97ff..4ec3ea41cb77d1147f4982cd8a670ba892383e22 100644 (file)
@@ -21,6 +21,7 @@ struct SkRect;
 class SkPaint;
 class SkPixelRef;
 class SkRegion;
+class SkString;
 
 // This is an opaque class, not interpreted by skia
 class SkGpuTexture;
@@ -625,6 +626,8 @@ public:
         int       fHeight;
     };
 
+    SkDEVCODE(void toString(SkString* str) const;)
+
 private:
     struct MipMap;
     mutable MipMap* fMipMap;
index 0823b70b6958bbd3a52ac5088f2871d3faefac73..c3790682e4b06c527ff0d4f9dc489ec2e72394d4 100644 (file)
@@ -48,6 +48,7 @@ public:
 
     virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
 
+    SK_DEVELOPER_TO_STRING()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorShader)
 
 protected:
index b0790bf393eeee13cd5a5f8b0fd174275966bb4e..524161b785b1f5b2e03bfc1b861be82cca7c2d6e 100644 (file)
@@ -39,6 +39,7 @@ public:
     virtual void endContext() SK_OVERRIDE;
     virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE;
 
+    SK_DEVELOPER_TO_STRING()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposeShader)
 
 protected:
index 13da457ad481b692f01cf65328c30a81ce911f3b..08c131db1bc18b9fca53da6b892318e8a186f355 100644 (file)
@@ -30,6 +30,7 @@ public:
     virtual void shadeSpan16(int x, int y, uint16_t span[], int count) SK_OVERRIDE;
     virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) SK_OVERRIDE;
 
+    SK_DEVELOPER_TO_STRING()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkEmptyShader)
 
 protected:
index 2d3786cf3141efde1a63fb81f82560ef5f3f7c7f..f9b72d7aeb4794c6f62dbbb68a78e2e39ffb6bd8 100644 (file)
@@ -527,8 +527,8 @@ public:
     // return the number of bytes read
     uint32_t readFromMemory(const void* buffer);
 
-    void dump() const;
-    void toDumpString(SkString*) const;
+    SkDEVCODE(void dump() const;)
+    SkDEVCODE(void toString(SkString*) const;)
 
     /**
      * Calculates the maximum stretching factor of the matrix. If the matrix has
index d5945afdd7a219e4fac4c4d573ebf2def5e835b7..899e3b6122aaf191fcb9044479d269c366b3fb1c 100644 (file)
@@ -341,6 +341,8 @@ public:
     static SkShader* CreateBitmapShader(const SkBitmap& src,
                                         TileMode tmx, TileMode tmy);
 
+    SkDEVCODE(virtual void toString(SkString* str) const;)
+
 protected:
     enum MatrixClass {
         kLinear_MatrixClass,            // no perspective
index 113fd00e6b45db0e6e226381c24f17f931f96676..cbba50cc1b5de87f62173702b3257a7a91171b55 100644 (file)
@@ -112,6 +112,16 @@ inline void operator delete(void* p) {
     #define SkAssertResult(cond)        cond
 #endif
 
+#ifdef SK_DEVELOPER
+    #define SkDEVCODE(code)             code
+    // the 'toString' helper functions convert Sk* objects to human-readable
+    // form in developer mode
+    #define SK_DEVELOPER_TO_STRING()    virtual void toString(SkString* str) const SK_OVERRIDE;
+#else
+    #define SkDEVCODE(code)
+    #define SK_DEVELOPER_TO_STRING()
+#endif
+
 template <bool>
 struct SkCompileAssert {
 };
index 74187f791225f4617e69c35853bd1714436172d7..bee9a02d2d9f0af99b71fb2b2ab56ebbf66265e4 100644 (file)
@@ -21,6 +21,7 @@ public:
     virtual void    shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE;
     virtual void    shadeSpan16(int x, int y, uint16_t span[], int count) SK_OVERRIDE;
 
+    SK_DEVELOPER_TO_STRING()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTransparentShader)
 
 private:
index 608ab01334a0320d87a718bdf11a01a49f2b07f3..8d9c67d50dd681449202a4ffe7da17e64ebd63f5 100644 (file)
@@ -10,6 +10,8 @@
 
 #include "SkCanvas.h"
 
+#ifdef SK_DEVELOPER
+
 /** This class overrides all the draw methods on SkCanvas, and formats them
     as text, and then sends that to a Dumper helper object.
 
@@ -155,3 +157,5 @@ private:
 };
 
 #endif
+
+#endif
index 17a0d7580a2a9993baf1add6057fa14cad60c565..7134a1f2fc10d3927d34ef8690050c351984d597 100644 (file)
@@ -153,11 +153,13 @@ protected:
         canvas->drawPicture(*pict);
         canvas->restore();
 
+#ifdef SK_DEVELOPER
         if (false) {
             SkDebugfDumper dumper;
             SkDumpCanvas dumpCanvas(&dumper);
             dumpCanvas.drawPicture(*pict);
         }
+#endif
 
         // test that we can re-record a subpicture, and see the results
 
index e7c0ddbe577e712bd6d3fe7c6ee0d1d7ad50bcdf..7d7451f62a8e42308ec49e034dc08e25eb790b42 100644 (file)
@@ -56,7 +56,7 @@ static void test_33(const SkMatrix44& mat,
     if (dst[0] != x0 || dst[1] != x1 || dst[2] != x2 ||
         dst[3] != y0 || dst[4] != y1 || dst[5] != y2) {
         SkString str;
-        dst.toDumpString(&str);
+        dst.toString(&str);
         SkDebugf("3x3: expected 3x3 [%g %g %g] [%g %g %g] bug got %s\n",
                  x0, x1, x2, y0, y1, y2, str.c_str());
     }
@@ -116,7 +116,7 @@ static void dump_layers(const SkLayer* layer, int tab = 0) {
     SkString matrixStr;
 
     layer->getLocalTransform(&matrix);
-    matrix.toDumpString(&matrixStr);
+    matrix.toString(&matrixStr);
 
     for (int j = 0; j < tab; j++) {
         SkDebugf(" ");
index f0dafc17fa250b969bc07f79f99b905cb5b0bf09..9692a71be20684b0735b6cea65ba825dc1baee42 100644 (file)
@@ -1638,3 +1638,44 @@ void SkBitmap::validate() const {
 #endif
 }
 #endif
+
+#ifdef SK_DEVELOPER
+void SkBitmap::toString(SkString* str) const {
+
+    static const char* gConfigNames[kConfigCount] = {
+        "NONE", "A1", "A8", "INDEX8", "565", "4444", "8888", "RLE"
+    };
+
+    str->appendf("bitmap: ((%d, %d) %s", this->width(), this->height(),
+                 gConfigNames[this->config()]);
+
+    str->append(" (");
+    if (this->isOpaque()) {
+        str->append("opaque");
+    } else {
+        str->append("transparent");
+    }
+    if (this->isImmutable()) {
+        str->append(", immutable");
+    } else {
+        str->append(", not-immutable");
+    }
+    str->append(")");
+
+    SkPixelRef* pr = this->pixelRef();
+    if (NULL == pr) {
+        // show null or the explicit pixel address (rare)
+        str->appendf(" pixels:%p", this->getPixels());
+    } else {
+        const char* uri = pr->getURI();
+        if (NULL != uri) {
+            str->appendf(" uri:\"%s\"", uri);
+        } else {
+            str->appendf(" pixelref:%p", pr);
+        }
+    }
+
+    str->append(")");
+}
+#endif
+
index c3b9b263ed4693e8acaef77c267cb3e9ce312c94..aa790717a16a12b13575fb0e0ac8c7ce075abe7d 100644 (file)
@@ -127,7 +127,7 @@ bool SkBitmapProcShader::setContext(const SkBitmap& device,
         flags &= ~kHasSpan16_Flag;
     }
 
-    // if we're only 1-pixel heigh, and we don't rotate, then we can claim this
+    // if we're only 1-pixel high, and we don't rotate, then we can claim this
     if (1 == bitmap.height() &&
             only_scale_and_translate(this->getTotalInverse())) {
         flags |= kConstInY32_Flag;
@@ -306,38 +306,27 @@ SkShader* SkShader::CreateBitmapShader(const SkBitmap& src,
 
 ///////////////////////////////////////////////////////////////////////////////
 
-static const char* gTileModeName[] = {
-    "clamp", "repeat", "mirror"
-};
-
-bool SkBitmapProcShader::toDumpString(SkString* str) const {
-    str->printf("BitmapShader: [%d %d %d",
-                fRawBitmap.width(), fRawBitmap.height(),
-                fRawBitmap.bytesPerPixel());
-
-    // add the pixelref
-    SkPixelRef* pr = fRawBitmap.pixelRef();
-    if (pr) {
-        const char* uri = pr->getURI();
-        if (uri) {
-            str->appendf(" \"%s\"", uri);
-        }
-    }
+#ifdef SK_DEVELOPER
+void SkBitmapProcShader::toString(SkString* str) const {
+    static const char* gTileModeName[SkShader::kTileModeCount] = {
+        "clamp", "repeat", "mirror"
+    };
 
-    // add the (optional) matrix
-    {
-        if (this->hasLocalMatrix()) {
-            SkString info;
-            this->getLocalMatrix().toDumpString(&info);
-            str->appendf(" %s", info.c_str());
-        }
-    }
+    str->append("BitmapShader: (");
 
-    str->appendf(" [%s %s]]",
+    str->appendf("(%s, %s)",
                  gTileModeName[fState.fTileModeX],
                  gTileModeName[fState.fTileModeY]);
-    return true;
+
+    str->append(" ");
+    fRawBitmap.toString(str);
+
+    this->INHERITED::toString(str);
+
+    str->append(")");
 }
+#endif
+
 ///////////////////////////////////////////////////////////////////////////////
 
 #if SK_SUPPORT_GPU
index fb7ff0bcb2168d1878450271d69d2d0da99780dd..e5f7b91c7939ce18a598ac8ae582a418a5303224 100644 (file)
@@ -19,18 +19,17 @@ public:
 
     // overrides from SkShader
     virtual bool isOpaque() const SK_OVERRIDE;
-    virtual bool setContext(const SkBitmap&, const SkPaint&, const SkMatrix&);
-    virtual void endContext();
-    virtual uint32_t getFlags() { return fFlags; }
-    virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count);
+    virtual bool setContext(const SkBitmap&, const SkPaint&, const SkMatrix&) SK_OVERRIDE;
+    virtual void endContext() SK_OVERRIDE;
+    virtual uint32_t getFlags() SK_OVERRIDE { return fFlags; }
+    virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE;
     virtual ShadeProc asAShadeProc(void** ctx) SK_OVERRIDE;
-    virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count);
-    virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const;
+    virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OVERRIDE;
+    virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const SK_OVERRIDE;
 
     static bool CanDo(const SkBitmap&, TileMode tx, TileMode ty);
-
-    // override from flattenable
-    virtual bool toDumpString(SkString* str) const;
+    
+    SK_DEVELOPER_TO_STRING()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader)
 
 #if SK_SUPPORT_GPU
index efe9d11a9d7ede27a7256a67c7c6a6dc456a061f..e3b3c3471aaabf66e2d654713347a8fd1fa61af1 100644 (file)
@@ -19,6 +19,7 @@
 #include "SkTLazy.h"
 #include "SkUtils.h"
 #include "SkXfermode.h"
+#include "SkString.h"
 
 SkBlitter::~SkBlitter() {}
 
@@ -663,6 +664,21 @@ public:
         }
     }
 
+#ifdef SK_DEVELOPER
+    virtual void toString(SkString* str) const SK_OVERRIDE {
+        str->append("Sk3DShader: (");
+
+        if (NULL != fProxy) {
+            str->append("Proxy: ");
+            fProxy->toString(str);
+        }
+
+        this->INHERITED::toString(str);
+
+        str->append(")");
+    }
+#endif
+
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Sk3DShader)
 
 protected:
index 747b2fff6c65875cd5e95526a27bcb973e1d4505..5bfca46478c7bd6220fb3aaba4331a12bef872a4 100644 (file)
@@ -10,6 +10,7 @@
 #include "SkFlattenableBuffers.h"
 #include "SkShader.h"
 #include "SkUnPreMultiply.h"
+#include "SkString.h"
 
 SK_DEFINE_INST_COUNT(SkColorFilter)
 
@@ -117,3 +118,17 @@ void SkFilterShader::shadeSpan16(int x, int y, uint16_t result[], int count) {
     fFilter->filterSpan16(result, count, result);
 }
 
+#ifdef SK_DEVELOPER
+void SkFilterShader::toString(SkString* str) const {
+    str->append("SkFilterShader: (");
+
+    str->append("Shader: ");
+    fShader->toString(str);
+    str->append(" Filter: ");
+    // TODO: add "fFilter->toString(str);" once SkColorFilter::toString is added
+
+    this->INHERITED::toString(str);
+
+    str->append(")");
+}
+#endif
\ No newline at end of file
index 92ffaf7d91bd9276a3aa262c403915108197300b..fd3b21e2ac5b6967a68cbd5ff7482f9c58878a9e 100644 (file)
@@ -13,6 +13,7 @@
 #include "SkColorShader.h"
 #include "SkFlattenableBuffers.h"
 #include "SkXfermode.h"
+#include "SkString.h"
 
 ///////////////////////////////////////////////////////////////////////////////
 
@@ -172,3 +173,20 @@ void SkComposeShader::shadeSpan(int x, int y, SkPMColor result[], int count) {
         } while (count > 0);
     }
 }
+
+#ifdef SK_DEVELOPER
+void SkComposeShader::toString(SkString* str) const {
+    str->append("SkComposeShader: (");
+
+    str->append("ShaderA: ");
+    fShaderA->toString(str);
+    str->append(" ShaderB: ");
+    fShaderB->toString(str);
+    str->append(" Xfermode: ");
+    // TODO: add "fMode->toString(str);" once SkXfermode::toString is added
+
+    this->INHERITED::toString(str);
+
+    str->append(")");
+}
+#endif
index d6ee66fa0d94ac9fe37b6457e6fc4f4e7e5e2920..cf638e9b4c2e06290e6a7e49c62b7f276ece2c73 100644 (file)
@@ -20,6 +20,7 @@
 #include "SkRasterizer.h"
 #include "SkScan.h"
 #include "SkShader.h"
+#include "SkString.h"
 #include "SkStroke.h"
 #include "SkTemplatesPriv.h"
 #include "SkTLazy.h"
@@ -2331,6 +2332,7 @@ public:
 
     virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE;
 
+    SK_DEVELOPER_TO_STRING()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTriColorShader)
 
 protected:
@@ -2403,6 +2405,16 @@ void SkTriColorShader::shadeSpan(int x, int y, SkPMColor dstC[], int count) {
     }
 }
 
+#ifdef SK_DEVELOPER
+void SkTriColorShader::toString(SkString* str) const {
+    str->append("SkTriColorShader: (");
+
+    this->INHERITED::toString(str);
+
+    str->append(")");
+}
+#endif
+
 void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count,
                           const SkPoint vertices[], const SkPoint textures[],
                           const SkColor colors[], SkXfermode* xmode,
index ded3125adca7cbb43f070db7b7db778d4f58fe41..be19640d0e29f240fb68d016da493ef234f4234b 100644 (file)
@@ -24,6 +24,7 @@ public:
     virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE;
     virtual void shadeSpan16(int x, int y, uint16_t[], int count) SK_OVERRIDE;
 
+    SK_DEVELOPER_TO_STRING()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkFilterShader)
 
 protected:
index d7b2ff6e2b37003865f41b01a5a6ad3b211198a9..532a53449b09efa7f74f08de0d40c2ff4d8a9117 100644 (file)
@@ -1820,14 +1820,15 @@ uint32_t SkMatrix::readFromMemory(const void* buffer) {
     return 9 * sizeof(SkScalar);
 }
 
+#ifdef SK_DEVELOPER
 void SkMatrix::dump() const {
     SkString str;
-    this->toDumpString(&str);
+    this->toString(&str);
     SkDebugf("%s\n", str.c_str());
 }
 
-void SkMatrix::toDumpString(SkString* str) const {
-    str->printf("[%8.4f %8.4f %8.4f][%8.4f %8.4f %8.4f][%8.4f %8.4f %8.4f]",
+void SkMatrix::toString(SkString* str) const {
+    str->appendf("[%8.4f %8.4f %8.4f][%8.4f %8.4f %8.4f][%8.4f %8.4f %8.4f]",
 #ifdef SK_SCALAR_IS_FLOAT
              fMat[0], fMat[1], fMat[2], fMat[3], fMat[4], fMat[5],
              fMat[6], fMat[7], fMat[8]);
@@ -1837,6 +1838,7 @@ void SkMatrix::toDumpString(SkString* str) const {
     SkFractToFloat(fMat[6]), SkFractToFloat(fMat[7]), SkFractToFloat(fMat[8]));
 #endif
 }
+#endif
 
 ///////////////////////////////////////////////////////////////////////////////
 
index 41de8020e35d44c455fbac1dceb61115974a48ce..d895801ba422b4fedd271f0726ecfb5f2eb8a963 100644 (file)
@@ -182,6 +182,15 @@ SkShader* SkShader::CreateBitmapShader(const SkBitmap& src,
     return SkShader::CreateBitmapShader(src, tmx, tmy, NULL, 0);
 }
 
+#ifdef SK_DEVELOPER
+void SkShader::toString(SkString* str) const {
+    if (this->hasLocalMatrix()) {
+        str->append(" ");
+        this->getLocalMatrix().toString(str);
+    }
+}
+#endif
+
 //////////////////////////////////////////////////////////////////////////////
 
 #include "SkColorShader.h"
@@ -303,6 +312,23 @@ SkShader::GradientType SkColorShader::asAGradient(GradientInfo* info) const {
     return kColor_GradientType;
 }
 
+#ifdef SK_DEVELOPER
+void SkColorShader::toString(SkString* str) const {
+    str->append("SkColorShader: (");
+
+    if (fInheritColor) {
+        str->append("Color: inherited from paint");
+    } else {
+        str->append("Color: ");
+        str->appendHex(fColor);
+    }
+
+    this->INHERITED::toString(str);
+
+    str->append(")");
+}
+#endif
+
 ///////////////////////////////////////////////////////////////////////////////
 
 #include "SkEmptyShader.h"
@@ -324,3 +350,13 @@ void SkEmptyShader::shadeSpan16(int x, int y, uint16_t span[], int count) {
 void SkEmptyShader::shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) {
     SkDEBUGFAIL("should never get called, since setContext() returned false");
 }
+
+#ifdef SK_DEVELOPER
+void SkEmptyShader::toString(SkString* str) const {
+    str->append("SkEmptyShader: (");
+
+    this->INHERITED::toString(str);
+
+    str->append(")");
+}
+#endif
index 28b075f4e2edf0c869218c591a03479f0b2679e6..2c7172f9b91df3d81597c5e2af95ff7d95f5cd00 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "SkTransparentShader.h"
 #include "SkColorPriv.h"
+#include "SkString.h"
 
 bool SkTransparentShader::setContext(const SkBitmap& device,
                                      const SkPaint& paint,
@@ -125,3 +126,13 @@ void SkTransparentShader::shadeSpan16(int x, int y, uint16_t span[], int count)
         memcpy(span, src, count << 1);
     }
 }
+
+#ifdef SK_DEVELOPER
+void SkTransparentShader::toString(SkString* str) const {
+    str->append("SkTransparentShader: (");
+    
+    this->INHERITED::toString(str);
+
+    str->append(")");
+}
+#endif
index 7d779708f66fe932d512faac54c5031e6f36f2da..ba72eeadd44bcb3e21642090bf7dfaf67839b17d 100644 (file)
@@ -546,16 +546,16 @@ void SkGradientShaderBase::commonAsAGradient(GradientInfo* info) const {
     if (info) {
         if (info->fColorCount >= fColorCount) {
             if (info->fColors) {
-                memcpy(info->fColors, fOrigColors,
-                       fColorCount * sizeof(SkColor));
+                memcpy(info->fColors, fOrigColors, fColorCount * sizeof(SkColor));
             }
             if (info->fColorOffsets) {
                 if (fColorCount == 2) {
                     info->fColorOffsets[0] = 0;
                     info->fColorOffsets[1] = SK_Scalar1;
                 } else if (fColorCount > 2) {
-                    for (int i = 0; i < fColorCount; i++)
+                    for (int i = 0; i < fColorCount; ++i) {
                         info->fColorOffsets[i] = SkFixedToScalar(fRecs[i].fPos);
+                    }
                 }
             }
         }
@@ -564,6 +564,42 @@ void SkGradientShaderBase::commonAsAGradient(GradientInfo* info) const {
     }
 }
 
+#ifdef SK_DEVELOPER
+void SkGradientShaderBase::toString(SkString* str) const {
+
+    str->appendf("%d colors: ", fColorCount);
+
+    for (int i = 0; i < fColorCount; ++i) {
+        str->appendHex(fOrigColors[i]);
+        if (i < fColorCount-1) {
+            str->append(", ");
+        }
+    }
+
+    if (fColorCount > 2) {
+        str->append(" points: (");
+        for (int i = 0; i < fColorCount; ++i) {
+            str->appendScalar(SkFixedToScalar(fRecs[i].fPos));
+            if (i < fColorCount-1) {
+                str->append(", ");
+            }
+        }
+        str->append(")");
+    }
+
+    static const char* gTileModeName[SkShader::kTileModeCount] = {
+        "clamp", "repeat", "mirror"
+    };
+
+    str->append(" ");
+    str->append(gTileModeName[fTileMode]);
+
+    // TODO: add "fMapper->toString(str);" when SkUnitMapper::toString is added
+
+    this->INHERITED::toString(str);
+}
+#endif
+
 ///////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
 
index b2b8c47a1c4447045341a851cc1b4c6ab20b399d..27c443814b00852a391beafd63735a2905c3644e 100644 (file)
@@ -139,6 +139,7 @@ public:
 protected:
     SkGradientShaderBase(SkFlattenableReadBuffer& );
     virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
+    SK_DEVELOPER_TO_STRING()
 
     SkUnitMapper* fMapper;
     SkMatrix    fPtsToUnit;     // set by subclass
index fc5653b6fdce9cdf80528244c9a365900353c45a..1788b7ada7473323f2ea48a31e1a0bf0b7986024 100644 (file)
@@ -564,3 +564,16 @@ GrEffect* SkLinearGradient::asNewEffect(GrContext* context, const SkPaint&) cons
 }
 
 #endif
+
+#ifdef SK_DEVELOPER
+void SkLinearGradient::toString(SkString* str) const {
+    str->append("SkLinearGradient (");
+
+    str->appendf("start: (%f, %f)", fStart.fX, fStart.fY);
+    str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY);
+
+    this->INHERITED::toString(str);
+
+    str->append(")");
+}
+#endif
index 29777c13ed24ebbbfb07f933f1db6f62556571fb..e7935e46d6f6a38fd2be0a81b0eef78ae626ad6d 100644 (file)
@@ -24,6 +24,7 @@ public:
     virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
     virtual GrEffect* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
 
+    SK_DEVELOPER_TO_STRING()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLinearGradient)
 
 protected:
index d31cebd6168b72e41069343a39694d7be65414d6..c0e745713a215b3e5820556ac1fd0834b7993e59 100644 (file)
@@ -588,3 +588,21 @@ GrEffect* SkRadialGradient::asNewEffect(GrContext* context, const SkPaint&) cons
 }
 
 #endif
+
+#ifdef SK_DEVELOPER
+void SkRadialGradient::toString(SkString* str) const {
+    str->append("SkRadialGradient: (");
+    
+    str->append("center: (");
+    str->appendScalar(fCenter.fX);
+    str->append(", ");
+    str->appendScalar(fCenter.fY);
+    str->append(") radius: ");
+    str->appendScalar(fRadius);
+    str->append(" ");
+
+    this->INHERITED::toString(str);
+
+    str->append(")");
+}
+#endif
index 9730df4f4d08d101df158da51fe5ccbedf217298..0bb75c57d76f3a54e9c9d739c82de50a73be019a 100644 (file)
@@ -26,6 +26,7 @@ public:
     virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
     virtual GrEffect* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
 
+    SK_DEVELOPER_TO_STRING()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkRadialGradient)
 
 protected:
index 8e7ef96a15f83ebb022cb492031089d98a63cb7d..493109e7ee48f4b5663c358160907da8c3c492fb 100644 (file)
@@ -489,3 +489,19 @@ GrEffect* SkSweepGradient::asNewEffect(GrContext* context, const SkPaint&) const
 }
 
 #endif
+
+#ifdef SK_DEVELOPER
+void SkSweepGradient::toString(SkString* str) const {
+    str->append("SkSweepGradient: (");
+
+    str->append("center: (");
+    str->appendScalar(fCenter.fX);
+    str->append(", ");
+    str->appendScalar(fCenter.fY);
+    str->append(") ");
+
+    this->INHERITED::toString(str);
+
+    str->append(")");
+}
+#endif
index 5034b8e4c65aaa0bfadce3caabf05ccba633e4ad..41489665902af49720d9ed352dd2b810c44d4509 100644 (file)
@@ -26,6 +26,7 @@ public:
 
     virtual GrEffect* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
 
+    SK_DEVELOPER_TO_STRING()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSweepGradient)
 
 protected:
index 37b8a5123325d1dbbc3eaa4dccad0f130dbd76db..23e4dcc295bb7f4a20881614abb834ecf4ba9353 100644 (file)
@@ -715,3 +715,29 @@ GrEffect* SkTwoPointConicalGradient::asNewEffect(GrContext* context, const SkPai
 }
 
 #endif
+
+#ifdef SK_DEVELOPER
+void SkTwoPointConicalGradient::toString(SkString* str) const {
+    str->append("SkTwoPointConicalGradient: (");
+
+    str->append("center1: (");
+    str->appendScalar(fCenter1.fX);
+    str->append(", ");
+    str->appendScalar(fCenter1.fY);
+    str->append(") radius1: ");
+    str->appendScalar(fRadius1);
+    str->append(" ");
+
+    str->append("center2: (");
+    str->appendScalar(fCenter2.fX);
+    str->append(", ");
+    str->appendScalar(fCenter2.fY);
+    str->append(") radius2: ");
+    str->appendScalar(fRadius2);
+    str->append(" ");
+
+    this->INHERITED::toString(str);
+
+    str->append(")");
+}
+#endif
index c4ccc05d3c7a99c34580ff3d22d102b4ac6c6ff3..44432cc6beb27c5a387833250702776870ac00e1 100644 (file)
@@ -67,6 +67,7 @@ public:
     SkScalar getStartRadius() const { return fRadius1; }
     SkScalar getDiffRadius() const { return fRadius2 - fRadius1; }
 
+    SK_DEVELOPER_TO_STRING()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointConicalGradient)
 
 protected:
index 075e940e13d98c640b1a4ff32cfee8d45afe83ca..2e458097d10d19ae21125ac461deae6169be29a5 100644 (file)
@@ -309,6 +309,32 @@ bool SkTwoPointRadialGradient::setContext( const SkBitmap& device,
     return true;
 }
 
+#ifdef SK_DEVELOPER
+void SkTwoPointRadialGradient::toString(SkString* str) const {
+    str->append("SkTwoPointRadialGradient: (");
+
+    str->append("center1: (");
+    str->appendScalar(fCenter1.fX);
+    str->append(", ");
+    str->appendScalar(fCenter1.fY);
+    str->append(") radius1: ");
+    str->appendScalar(fRadius1);
+    str->append(" ");
+
+    str->append("center2: (");
+    str->appendScalar(fCenter2.fX);
+    str->append(", ");
+    str->appendScalar(fCenter2.fY);
+    str->append(") radius2: ");
+    str->appendScalar(fRadius2);
+    str->append(" ");
+
+    this->INHERITED::toString(str);
+
+    str->append(")");
+}
+#endif
+
 SkTwoPointRadialGradient::SkTwoPointRadialGradient(
     SkFlattenableReadBuffer& buffer)
     : INHERITED(buffer),
index 2f9d66d3ef68e3159c9353b0d75685c174d5cc9b..e0b00827e1f626387f0c82332669020460525ea2 100644 (file)
@@ -35,6 +35,7 @@ public:
     SkScalar getStartRadius() const { return fStartRadius; }
     SkScalar getDiffRadius() const { return fDiffRadius; }
 
+    SK_DEVELOPER_TO_STRING()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointRadialGradient)
 
 protected:
index 2722fb4c045ce4ea6eb09f3d39904b45b2b323ab..46c414144cbbc5eeb53c304037405823799f7f61 100644 (file)
@@ -5,7 +5,10 @@
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
+
 #include "SkDumpCanvas.h"
+
+#ifdef SK_DEVELOPER
 #include "SkPicture.h"
 #include "SkPixelRef.h"
 #include "SkRRect.h"
@@ -130,31 +133,6 @@ static const char* toString(SkCanvas::PointMode pm) {
     return gPMNames[pm];
 }
 
-static const char* toString(SkBitmap::Config config) {
-    static const char* gConfigNames[] = {
-        "NONE", "A1", "A8", "INDEX8", "565", "4444", "8888", "RLE"
-    };
-    return gConfigNames[config];
-}
-
-static void toString(const SkBitmap& bm, SkString* str) {
-    str->appendf("bitmap:[%d %d] %s", bm.width(), bm.height(),
-                toString(bm.config()));
-
-    SkPixelRef* pr = bm.pixelRef();
-    if (NULL == pr) {
-        // show null or the explicit pixel address (rare)
-        str->appendf(" pixels:%p", bm.getPixels());
-    } else {
-        const char* uri = pr->getURI();
-        if (uri) {
-            str->appendf(" uri:\"%s\"", uri);
-        } else {
-            str->appendf(" pixelref:%p", pr);
-        }
-    }
-}
-
 static void toString(const void* text, size_t byteLen, SkPaint::TextEncoding enc,
                      SkString* str) {
     // FIXME: this code appears to be untested - and probably unused - and probably wrong
@@ -273,14 +251,14 @@ bool SkDumpCanvas::skew(SkScalar sx, SkScalar sy) {
 
 bool SkDumpCanvas::concat(const SkMatrix& matrix) {
     SkString str;
-    matrix.toDumpString(&str);
+    matrix.toString(&str);
     this->dump(kMatrix_Verb, NULL, "concat(%s)", str.c_str());
     return this->INHERITED::concat(matrix);
 }
 
 void SkDumpCanvas::setMatrix(const SkMatrix& matrix) {
     SkString str;
-    matrix.toDumpString(&str);
+    matrix.toString(&str);
     this->dump(kMatrix_Verb, NULL, "setMatrix(%s)", str.c_str());
     this->INHERITED::setMatrix(matrix);
 }
@@ -362,7 +340,7 @@ void SkDumpCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
 void SkDumpCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y,
                                const SkPaint* paint) {
     SkString str;
-    toString(bitmap, &str);
+    bitmap.toString(&str);
     this->dump(kDrawBitmap_Verb, paint, "drawBitmap(%s %g %g)", str.c_str(),
                SkScalarToFloat(x), SkScalarToFloat(y));
 }
@@ -370,7 +348,7 @@ void SkDumpCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y,
 void SkDumpCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
                                         const SkRect& dst, const SkPaint* paint) {
     SkString bs, rs;
-    toString(bitmap, &bs);
+    bitmap.toString(&bs);
     toString(dst, &rs);
     // show the src-rect only if its not everything
     if (src && (src->fLeft > 0 || src->fTop > 0 ||
@@ -388,8 +366,8 @@ void SkDumpCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* sr
 void SkDumpCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
                                      const SkPaint* paint) {
     SkString bs, ms;
-    toString(bitmap, &bs);
-    m.toDumpString(&ms);
+    bitmap.toString(&bs);
+    m.toString(&ms);
     this->dump(kDrawBitmap_Verb, paint, "drawBitmapMatrix(%s %s)",
                bs.c_str(), ms.c_str());
 }
@@ -397,7 +375,7 @@ void SkDumpCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
 void SkDumpCanvas::drawSprite(const SkBitmap& bitmap, int x, int y,
                                const SkPaint* paint) {
     SkString str;
-    toString(bitmap, &str);
+    bitmap.toString(&str);
     this->dump(kDrawBitmap_Verb, paint, "drawSprite(%s %d %d)", str.c_str(),
                x, y);
 }
@@ -525,4 +503,4 @@ static void dumpToDebugf(const char text[], void*) {
 
 SkDebugfDumper::SkDebugfDumper() : INHERITED(dumpToDebugf, NULL) {}
 
-
+#endif
index b82bd332c794111847ff5e8505ce22a00d31e431..b5a6727e96ed51fd92b5836bf25c18ebc67f549f 100644 (file)
@@ -39,9 +39,13 @@ static SkPicture* inspect(const char path[]) {
 }
 
 static void dumpOps(SkPicture* pic) {
+#ifdef SK_DEVELOPER
     SkDebugfDumper dumper;
     SkDumpCanvas canvas(&dumper);
     canvas.drawPicture(*pic);
+#else
+    printf("SK_DEVELOPER mode not enabled\n");
+#endif
 }
 
 int tool_main(int argc, char** argv);