From 76f9e938df0b5826fd4c80b854ceafaf385cfbe1 Mon Sep 17 00:00:00 2001 From: "robertphillips@google.com" Date: Tue, 15 Jan 2013 20:17:47 +0000 Subject: [PATCH] Added print out of SkShader information to debugger https://codereview.appspot.com/7105045/ git-svn-id: http://skia.googlecode.com/svn/trunk@7201 2bbb7eff-a529-9590-31e7-b0007b416f81 --- debugger/SkObjectParser.cpp | 2 + experimental/Debugger/DebuggerContentView.cpp | 5 +++ experimental/Debugger/SkDebugDumper.cpp | 5 +++ experimental/Debugger/SkDebugDumper.h | 6 +++ include/core/SkBitmap.h | 3 ++ include/core/SkColorShader.h | 1 + include/core/SkComposeShader.h | 1 + include/core/SkEmptyShader.h | 1 + include/core/SkMatrix.h | 4 +- include/core/SkShader.h | 2 + include/core/SkTypes.h | 10 +++++ include/effects/SkTransparentShader.h | 1 + include/utils/SkDumpCanvas.h | 4 ++ samplecode/SamplePicture.cpp | 2 + samplecode/SampleSkLayer.cpp | 4 +- src/core/SkBitmap.cpp | 41 +++++++++++++++++ src/core/SkBitmapProcShader.cpp | 45 +++++++------------ src/core/SkBitmapProcShader.h | 17 ++++--- src/core/SkBlitter.cpp | 16 +++++++ src/core/SkColorFilter.cpp | 15 +++++++ src/core/SkComposeShader.cpp | 18 ++++++++ src/core/SkDraw.cpp | 12 +++++ src/core/SkFilterShader.h | 1 + src/core/SkMatrix.cpp | 8 ++-- src/core/SkShader.cpp | 36 +++++++++++++++ src/effects/SkTransparentShader.cpp | 11 +++++ src/effects/gradients/SkGradientShader.cpp | 42 +++++++++++++++-- src/effects/gradients/SkGradientShaderPriv.h | 1 + src/effects/gradients/SkLinearGradient.cpp | 13 ++++++ src/effects/gradients/SkLinearGradient.h | 1 + src/effects/gradients/SkRadialGradient.cpp | 18 ++++++++ src/effects/gradients/SkRadialGradient.h | 1 + src/effects/gradients/SkSweepGradient.cpp | 16 +++++++ src/effects/gradients/SkSweepGradient.h | 1 + .../gradients/SkTwoPointConicalGradient.cpp | 26 +++++++++++ .../gradients/SkTwoPointConicalGradient.h | 1 + .../gradients/SkTwoPointRadialGradient.cpp | 26 +++++++++++ .../gradients/SkTwoPointRadialGradient.h | 1 + src/utils/SkDumpCanvas.cpp | 44 +++++------------- tools/pinspect.cpp | 4 ++ 40 files changed, 386 insertions(+), 80 deletions(-) diff --git a/debugger/SkObjectParser.cpp b/debugger/SkObjectParser.cpp index aea5424955..d777631755 100644 --- a/debugger/SkObjectParser.cpp +++ b/debugger/SkObjectParser.cpp @@ -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("
Shader:
"); + SkDEVCODE(shader->toString(mPaint);) mPaint->append("
"); } diff --git a/experimental/Debugger/DebuggerContentView.cpp b/experimental/Debugger/DebuggerContentView.cpp index f079508643..c928c2ea87 100644 --- a/experimental/Debugger/DebuggerContentView.cpp +++ b/experimental/Debugger/DebuggerContentView.cpp @@ -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 diff --git a/experimental/Debugger/SkDebugDumper.cpp b/experimental/Debugger/SkDebugDumper.cpp index cfda184ebe..9f8afedae7 100644 --- a/experimental/Debugger/SkDebugDumper.cpp +++ b/experimental/Debugger/SkDebugDumper.cpp @@ -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 diff --git a/experimental/Debugger/SkDebugDumper.h b/experimental/Debugger/SkDebugDumper.h index e7d69562d5..16190c694d 100644 --- a/experimental/Debugger/SkDebugDumper.h +++ b/experimental/Debugger/SkDebugDumper.h @@ -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 diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h index 7ea950bea2..4ec3ea41cb 100644 --- a/include/core/SkBitmap.h +++ b/include/core/SkBitmap.h @@ -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; diff --git a/include/core/SkColorShader.h b/include/core/SkColorShader.h index 0823b70b69..c3790682e4 100644 --- a/include/core/SkColorShader.h +++ b/include/core/SkColorShader.h @@ -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: diff --git a/include/core/SkComposeShader.h b/include/core/SkComposeShader.h index b0790bf393..524161b785 100644 --- a/include/core/SkComposeShader.h +++ b/include/core/SkComposeShader.h @@ -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: diff --git a/include/core/SkEmptyShader.h b/include/core/SkEmptyShader.h index 13da457ad4..08c131db1b 100644 --- a/include/core/SkEmptyShader.h +++ b/include/core/SkEmptyShader.h @@ -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: diff --git a/include/core/SkMatrix.h b/include/core/SkMatrix.h index 2d3786cf31..f9b72d7aeb 100644 --- a/include/core/SkMatrix.h +++ b/include/core/SkMatrix.h @@ -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 diff --git a/include/core/SkShader.h b/include/core/SkShader.h index d5945afdd7..899e3b6122 100644 --- a/include/core/SkShader.h +++ b/include/core/SkShader.h @@ -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 diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h index 113fd00e6b..cbba50cc1b 100644 --- a/include/core/SkTypes.h +++ b/include/core/SkTypes.h @@ -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 struct SkCompileAssert { }; diff --git a/include/effects/SkTransparentShader.h b/include/effects/SkTransparentShader.h index 74187f7912..bee9a02d2d 100644 --- a/include/effects/SkTransparentShader.h +++ b/include/effects/SkTransparentShader.h @@ -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: diff --git a/include/utils/SkDumpCanvas.h b/include/utils/SkDumpCanvas.h index 608ab01334..8d9c67d50d 100644 --- a/include/utils/SkDumpCanvas.h +++ b/include/utils/SkDumpCanvas.h @@ -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 diff --git a/samplecode/SamplePicture.cpp b/samplecode/SamplePicture.cpp index 17a0d7580a..7134a1f2fc 100644 --- a/samplecode/SamplePicture.cpp +++ b/samplecode/SamplePicture.cpp @@ -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 diff --git a/samplecode/SampleSkLayer.cpp b/samplecode/SampleSkLayer.cpp index e7c0ddbe57..7d7451f62a 100644 --- a/samplecode/SampleSkLayer.cpp +++ b/samplecode/SampleSkLayer.cpp @@ -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(" "); diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index f0dafc17fa..9692a71be2 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -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 + diff --git a/src/core/SkBitmapProcShader.cpp b/src/core/SkBitmapProcShader.cpp index c3b9b263ed..aa790717a1 100644 --- a/src/core/SkBitmapProcShader.cpp +++ b/src/core/SkBitmapProcShader.cpp @@ -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" -}; +#ifdef SK_DEVELOPER +void SkBitmapProcShader::toString(SkString* str) const { + static const char* gTileModeName[SkShader::kTileModeCount] = { + "clamp", "repeat", "mirror" + }; -bool SkBitmapProcShader::toDumpString(SkString* str) const { - str->printf("BitmapShader: [%d %d %d", - fRawBitmap.width(), fRawBitmap.height(), - fRawBitmap.bytesPerPixel()); + str->append("BitmapShader: ("); - // add the pixelref - SkPixelRef* pr = fRawBitmap.pixelRef(); - if (pr) { - const char* uri = pr->getURI(); - if (uri) { - str->appendf(" \"%s\"", uri); - } - } - - // add the (optional) matrix - { - if (this->hasLocalMatrix()) { - SkString info; - this->getLocalMatrix().toDumpString(&info); - str->appendf(" %s", info.c_str()); - } - } - - 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 diff --git a/src/core/SkBitmapProcShader.h b/src/core/SkBitmapProcShader.h index fb7ff0bcb2..e5f7b91c79 100644 --- a/src/core/SkBitmapProcShader.h +++ b/src/core/SkBitmapProcShader.h @@ -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 diff --git a/src/core/SkBlitter.cpp b/src/core/SkBlitter.cpp index efe9d11a9d..e3b3c3471a 100644 --- a/src/core/SkBlitter.cpp +++ b/src/core/SkBlitter.cpp @@ -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: diff --git a/src/core/SkColorFilter.cpp b/src/core/SkColorFilter.cpp index 747b2fff6c..5bfca46478 100644 --- a/src/core/SkColorFilter.cpp +++ b/src/core/SkColorFilter.cpp @@ -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 diff --git a/src/core/SkComposeShader.cpp b/src/core/SkComposeShader.cpp index 92ffaf7d91..fd3b21e2ac 100644 --- a/src/core/SkComposeShader.cpp +++ b/src/core/SkComposeShader.cpp @@ -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 diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp index d6ee66fa0d..cf638e9b4c 100644 --- a/src/core/SkDraw.cpp +++ b/src/core/SkDraw.cpp @@ -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, diff --git a/src/core/SkFilterShader.h b/src/core/SkFilterShader.h index ded3125adc..be19640d0e 100644 --- a/src/core/SkFilterShader.h +++ b/src/core/SkFilterShader.h @@ -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: diff --git a/src/core/SkMatrix.cpp b/src/core/SkMatrix.cpp index d7b2ff6e2b..532a53449b 100644 --- a/src/core/SkMatrix.cpp +++ b/src/core/SkMatrix.cpp @@ -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 /////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp index 41de8020e3..d895801ba4 100644 --- a/src/core/SkShader.cpp +++ b/src/core/SkShader.cpp @@ -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 diff --git a/src/effects/SkTransparentShader.cpp b/src/effects/SkTransparentShader.cpp index 28b075f4e2..2c7172f9b9 100644 --- a/src/effects/SkTransparentShader.cpp +++ b/src/effects/SkTransparentShader.cpp @@ -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 diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index 7d779708f6..ba72eeadd4 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp @@ -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 + /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h index b2b8c47a1c..27c443814b 100644 --- a/src/effects/gradients/SkGradientShaderPriv.h +++ b/src/effects/gradients/SkGradientShaderPriv.h @@ -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 diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp index fc5653b6fd..1788b7ada7 100644 --- a/src/effects/gradients/SkLinearGradient.cpp +++ b/src/effects/gradients/SkLinearGradient.cpp @@ -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 diff --git a/src/effects/gradients/SkLinearGradient.h b/src/effects/gradients/SkLinearGradient.h index 29777c13ed..e7935e46d6 100644 --- a/src/effects/gradients/SkLinearGradient.h +++ b/src/effects/gradients/SkLinearGradient.h @@ -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: diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp index d31cebd616..c0e745713a 100644 --- a/src/effects/gradients/SkRadialGradient.cpp +++ b/src/effects/gradients/SkRadialGradient.cpp @@ -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 diff --git a/src/effects/gradients/SkRadialGradient.h b/src/effects/gradients/SkRadialGradient.h index 9730df4f4d..0bb75c57d7 100644 --- a/src/effects/gradients/SkRadialGradient.h +++ b/src/effects/gradients/SkRadialGradient.h @@ -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: diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp index 8e7ef96a15..493109e7ee 100644 --- a/src/effects/gradients/SkSweepGradient.cpp +++ b/src/effects/gradients/SkSweepGradient.cpp @@ -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 diff --git a/src/effects/gradients/SkSweepGradient.h b/src/effects/gradients/SkSweepGradient.h index 5034b8e4c6..4148966590 100644 --- a/src/effects/gradients/SkSweepGradient.h +++ b/src/effects/gradients/SkSweepGradient.h @@ -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: diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp index 37b8a51233..23e4dcc295 100644 --- a/src/effects/gradients/SkTwoPointConicalGradient.cpp +++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp @@ -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 diff --git a/src/effects/gradients/SkTwoPointConicalGradient.h b/src/effects/gradients/SkTwoPointConicalGradient.h index c4ccc05d3c..44432cc6be 100644 --- a/src/effects/gradients/SkTwoPointConicalGradient.h +++ b/src/effects/gradients/SkTwoPointConicalGradient.h @@ -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: diff --git a/src/effects/gradients/SkTwoPointRadialGradient.cpp b/src/effects/gradients/SkTwoPointRadialGradient.cpp index 075e940e13..2e458097d1 100644 --- a/src/effects/gradients/SkTwoPointRadialGradient.cpp +++ b/src/effects/gradients/SkTwoPointRadialGradient.cpp @@ -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), diff --git a/src/effects/gradients/SkTwoPointRadialGradient.h b/src/effects/gradients/SkTwoPointRadialGradient.h index 2f9d66d3ef..e0b00827e1 100644 --- a/src/effects/gradients/SkTwoPointRadialGradient.h +++ b/src/effects/gradients/SkTwoPointRadialGradient.h @@ -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: diff --git a/src/utils/SkDumpCanvas.cpp b/src/utils/SkDumpCanvas.cpp index 2722fb4c04..46c414144c 100644 --- a/src/utils/SkDumpCanvas.cpp +++ b/src/utils/SkDumpCanvas.cpp @@ -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 diff --git a/tools/pinspect.cpp b/tools/pinspect.cpp index b82bd332c7..b5a6727e96 100644 --- a/tools/pinspect.cpp +++ b/tools/pinspect.cpp @@ -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);