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
This commit is contained in:
robertphillips@google.com 2013-01-15 20:17:47 +00:00
parent 06b8a19b56
commit 76f9e938df
40 changed files with 386 additions and 80 deletions

View File

@ -8,6 +8,7 @@
#include "SkObjectParser.h" #include "SkObjectParser.h"
#include "SkRRect.h" #include "SkRRect.h"
#include "SkShader.h"
#include "SkTypeface.h" #include "SkTypeface.h"
#include "SkStream.h" #include "SkStream.h"
#include "SkData.h" #include "SkData.h"
@ -154,6 +155,7 @@ SkString* SkObjectParser::PaintToString(const SkPaint& paint) {
SkShader* shader = paint.getShader(); SkShader* shader = paint.getShader();
if (NULL != shader) { if (NULL != shader) {
mPaint->append("<dt>Shader:</dt><dd>"); mPaint->append("<dt>Shader:</dt><dd>");
SkDEVCODE(shader->toString(mPaint);)
mPaint->append("</dd>"); mPaint->append("</dd>");
} }

View File

@ -1,3 +1,6 @@
#ifdef SK_DEVELOPER
#include "SampleCode.h" #include "SampleCode.h"
#include "SkOSMenu.h" #include "SkOSMenu.h"
@ -271,3 +274,5 @@ bool is_debugger(SkView* view) {
SkEvent isDebugger(gIsDebuggerQuery); SkEvent isDebugger(gIsDebuggerQuery);
return view->doQuery(&isDebugger); return view->doQuery(&isDebugger);
} }
#endif

View File

@ -6,6 +6,9 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
#include "SkDebugDumper.h" #include "SkDebugDumper.h"
#ifdef SK_DEVELOPER
#include "SkString.h" #include "SkString.h"
#include "SkPaint.h" #include "SkPaint.h"
#include "SkShader.h" #include "SkShader.h"
@ -146,3 +149,5 @@ void SkDebugDumper::dump(SkDumpCanvas* canvas, SkDumpCanvas::Verb verb,
} }
} }
} }
#endif

View File

@ -7,6 +7,9 @@
*/ */
#ifndef SkDebugDumper_DEFINED #ifndef SkDebugDumper_DEFINED
#define SkDebugDumper_DEFINED #define SkDebugDumper_DEFINED
#ifdef SK_DEVELOPER
#include "SkDumpCanvas.h" #include "SkDumpCanvas.h"
#include "SkEvent.h" #include "SkEvent.h"
@ -35,4 +38,7 @@ private:
typedef SkDumpCanvas::Dumper INHERITED; typedef SkDumpCanvas::Dumper INHERITED;
}; };
#endif
#endif #endif

View File

@ -21,6 +21,7 @@ struct SkRect;
class SkPaint; class SkPaint;
class SkPixelRef; class SkPixelRef;
class SkRegion; class SkRegion;
class SkString;
// This is an opaque class, not interpreted by skia // This is an opaque class, not interpreted by skia
class SkGpuTexture; class SkGpuTexture;
@ -625,6 +626,8 @@ public:
int fHeight; int fHeight;
}; };
SkDEVCODE(void toString(SkString* str) const;)
private: private:
struct MipMap; struct MipMap;
mutable MipMap* fMipMap; mutable MipMap* fMipMap;

View File

@ -48,6 +48,7 @@ public:
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE; virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
SK_DEVELOPER_TO_STRING()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorShader) SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorShader)
protected: protected:

View File

@ -39,6 +39,7 @@ public:
virtual void endContext() SK_OVERRIDE; virtual void endContext() SK_OVERRIDE;
virtual void shadeSpan(int x, int y, SkPMColor[], int count) 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) SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposeShader)
protected: protected:

View File

@ -30,6 +30,7 @@ public:
virtual void shadeSpan16(int x, int y, uint16_t span[], int count) SK_OVERRIDE; 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; 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) SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkEmptyShader)
protected: protected:

View File

@ -527,8 +527,8 @@ public:
// return the number of bytes read // return the number of bytes read
uint32_t readFromMemory(const void* buffer); uint32_t readFromMemory(const void* buffer);
void dump() const; SkDEVCODE(void dump() const;)
void toDumpString(SkString*) const; SkDEVCODE(void toString(SkString*) const;)
/** /**
* Calculates the maximum stretching factor of the matrix. If the matrix has * Calculates the maximum stretching factor of the matrix. If the matrix has

View File

@ -341,6 +341,8 @@ public:
static SkShader* CreateBitmapShader(const SkBitmap& src, static SkShader* CreateBitmapShader(const SkBitmap& src,
TileMode tmx, TileMode tmy); TileMode tmx, TileMode tmy);
SkDEVCODE(virtual void toString(SkString* str) const;)
protected: protected:
enum MatrixClass { enum MatrixClass {
kLinear_MatrixClass, // no perspective kLinear_MatrixClass, // no perspective

View File

@ -112,6 +112,16 @@ inline void operator delete(void* p) {
#define SkAssertResult(cond) cond #define SkAssertResult(cond) cond
#endif #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> template <bool>
struct SkCompileAssert { struct SkCompileAssert {
}; };

View File

@ -21,6 +21,7 @@ public:
virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE; 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; 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) SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTransparentShader)
private: private:

View File

@ -10,6 +10,8 @@
#include "SkCanvas.h" #include "SkCanvas.h"
#ifdef SK_DEVELOPER
/** This class overrides all the draw methods on SkCanvas, and formats them /** This class overrides all the draw methods on SkCanvas, and formats them
as text, and then sends that to a Dumper helper object. as text, and then sends that to a Dumper helper object.
@ -155,3 +157,5 @@ private:
}; };
#endif #endif
#endif

View File

@ -153,11 +153,13 @@ protected:
canvas->drawPicture(*pict); canvas->drawPicture(*pict);
canvas->restore(); canvas->restore();
#ifdef SK_DEVELOPER
if (false) { if (false) {
SkDebugfDumper dumper; SkDebugfDumper dumper;
SkDumpCanvas dumpCanvas(&dumper); SkDumpCanvas dumpCanvas(&dumper);
dumpCanvas.drawPicture(*pict); dumpCanvas.drawPicture(*pict);
} }
#endif
// test that we can re-record a subpicture, and see the results // test that we can re-record a subpicture, and see the results

View File

@ -56,7 +56,7 @@ static void test_33(const SkMatrix44& mat,
if (dst[0] != x0 || dst[1] != x1 || dst[2] != x2 || if (dst[0] != x0 || dst[1] != x1 || dst[2] != x2 ||
dst[3] != y0 || dst[4] != y1 || dst[5] != y2) { dst[3] != y0 || dst[4] != y1 || dst[5] != y2) {
SkString str; SkString str;
dst.toDumpString(&str); dst.toString(&str);
SkDebugf("3x3: expected 3x3 [%g %g %g] [%g %g %g] bug got %s\n", SkDebugf("3x3: expected 3x3 [%g %g %g] [%g %g %g] bug got %s\n",
x0, x1, x2, y0, y1, y2, str.c_str()); 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; SkString matrixStr;
layer->getLocalTransform(&matrix); layer->getLocalTransform(&matrix);
matrix.toDumpString(&matrixStr); matrix.toString(&matrixStr);
for (int j = 0; j < tab; j++) { for (int j = 0; j < tab; j++) {
SkDebugf(" "); SkDebugf(" ");

View File

@ -1638,3 +1638,44 @@ void SkBitmap::validate() const {
#endif #endif
} }
#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

View File

@ -127,7 +127,7 @@ bool SkBitmapProcShader::setContext(const SkBitmap& device,
flags &= ~kHasSpan16_Flag; 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() && if (1 == bitmap.height() &&
only_scale_and_translate(this->getTotalInverse())) { only_scale_and_translate(this->getTotalInverse())) {
flags |= kConstInY32_Flag; flags |= kConstInY32_Flag;
@ -306,38 +306,27 @@ SkShader* SkShader::CreateBitmapShader(const SkBitmap& src,
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
static const char* gTileModeName[] = { #ifdef SK_DEVELOPER
"clamp", "repeat", "mirror" void SkBitmapProcShader::toString(SkString* str) const {
}; static const char* gTileModeName[SkShader::kTileModeCount] = {
"clamp", "repeat", "mirror"
};
bool SkBitmapProcShader::toDumpString(SkString* str) const { str->append("BitmapShader: (");
str->printf("BitmapShader: [%d %d %d",
fRawBitmap.width(), fRawBitmap.height(),
fRawBitmap.bytesPerPixel());
// add the pixelref str->appendf("(%s, %s)",
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]]",
gTileModeName[fState.fTileModeX], gTileModeName[fState.fTileModeX],
gTileModeName[fState.fTileModeY]); gTileModeName[fState.fTileModeY]);
return true;
str->append(" ");
fRawBitmap.toString(str);
this->INHERITED::toString(str);
str->append(")");
} }
#endif
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU

View File

@ -19,18 +19,17 @@ public:
// overrides from SkShader // overrides from SkShader
virtual bool isOpaque() const SK_OVERRIDE; virtual bool isOpaque() const SK_OVERRIDE;
virtual bool setContext(const SkBitmap&, const SkPaint&, const SkMatrix&); virtual bool setContext(const SkBitmap&, const SkPaint&, const SkMatrix&) SK_OVERRIDE;
virtual void endContext(); virtual void endContext() SK_OVERRIDE;
virtual uint32_t getFlags() { return fFlags; } virtual uint32_t getFlags() SK_OVERRIDE { return fFlags; }
virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count); virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE;
virtual ShadeProc asAShadeProc(void** ctx) SK_OVERRIDE; virtual ShadeProc asAShadeProc(void** ctx) SK_OVERRIDE;
virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count); virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OVERRIDE;
virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const; virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const SK_OVERRIDE;
static bool CanDo(const SkBitmap&, TileMode tx, TileMode ty); static bool CanDo(const SkBitmap&, TileMode tx, TileMode ty);
// override from flattenable SK_DEVELOPER_TO_STRING()
virtual bool toDumpString(SkString* str) const;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader) SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader)
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU

View File

@ -19,6 +19,7 @@
#include "SkTLazy.h" #include "SkTLazy.h"
#include "SkUtils.h" #include "SkUtils.h"
#include "SkXfermode.h" #include "SkXfermode.h"
#include "SkString.h"
SkBlitter::~SkBlitter() {} 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) SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Sk3DShader)
protected: protected:

View File

@ -10,6 +10,7 @@
#include "SkFlattenableBuffers.h" #include "SkFlattenableBuffers.h"
#include "SkShader.h" #include "SkShader.h"
#include "SkUnPreMultiply.h" #include "SkUnPreMultiply.h"
#include "SkString.h"
SK_DEFINE_INST_COUNT(SkColorFilter) 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); 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

View File

@ -13,6 +13,7 @@
#include "SkColorShader.h" #include "SkColorShader.h"
#include "SkFlattenableBuffers.h" #include "SkFlattenableBuffers.h"
#include "SkXfermode.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); } 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

View File

@ -20,6 +20,7 @@
#include "SkRasterizer.h" #include "SkRasterizer.h"
#include "SkScan.h" #include "SkScan.h"
#include "SkShader.h" #include "SkShader.h"
#include "SkString.h"
#include "SkStroke.h" #include "SkStroke.h"
#include "SkTemplatesPriv.h" #include "SkTemplatesPriv.h"
#include "SkTLazy.h" #include "SkTLazy.h"
@ -2331,6 +2332,7 @@ public:
virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE; virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE;
SK_DEVELOPER_TO_STRING()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTriColorShader) SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTriColorShader)
protected: 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, void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count,
const SkPoint vertices[], const SkPoint textures[], const SkPoint vertices[], const SkPoint textures[],
const SkColor colors[], SkXfermode* xmode, const SkColor colors[], SkXfermode* xmode,

View File

@ -24,6 +24,7 @@ public:
virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE; 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; virtual void shadeSpan16(int x, int y, uint16_t[], int count) SK_OVERRIDE;
SK_DEVELOPER_TO_STRING()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkFilterShader) SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkFilterShader)
protected: protected:

View File

@ -1820,14 +1820,15 @@ uint32_t SkMatrix::readFromMemory(const void* buffer) {
return 9 * sizeof(SkScalar); return 9 * sizeof(SkScalar);
} }
#ifdef SK_DEVELOPER
void SkMatrix::dump() const { void SkMatrix::dump() const {
SkString str; SkString str;
this->toDumpString(&str); this->toString(&str);
SkDebugf("%s\n", str.c_str()); SkDebugf("%s\n", str.c_str());
} }
void SkMatrix::toDumpString(SkString* str) const { void SkMatrix::toString(SkString* str) const {
str->printf("[%8.4f %8.4f %8.4f][%8.4f %8.4f %8.4f][%8.4f %8.4f %8.4f]", 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 #ifdef SK_SCALAR_IS_FLOAT
fMat[0], fMat[1], fMat[2], fMat[3], fMat[4], fMat[5], fMat[0], fMat[1], fMat[2], fMat[3], fMat[4], fMat[5],
fMat[6], fMat[7], fMat[8]); 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])); SkFractToFloat(fMat[6]), SkFractToFloat(fMat[7]), SkFractToFloat(fMat[8]));
#endif #endif
} }
#endif
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -182,6 +182,15 @@ SkShader* SkShader::CreateBitmapShader(const SkBitmap& src,
return SkShader::CreateBitmapShader(src, tmx, tmy, NULL, 0); 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" #include "SkColorShader.h"
@ -303,6 +312,23 @@ SkShader::GradientType SkColorShader::asAGradient(GradientInfo* info) const {
return kColor_GradientType; 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" #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) { void SkEmptyShader::shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) {
SkDEBUGFAIL("should never get called, since setContext() returned false"); 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

View File

@ -9,6 +9,7 @@
#include "SkTransparentShader.h" #include "SkTransparentShader.h"
#include "SkColorPriv.h" #include "SkColorPriv.h"
#include "SkString.h"
bool SkTransparentShader::setContext(const SkBitmap& device, bool SkTransparentShader::setContext(const SkBitmap& device,
const SkPaint& paint, const SkPaint& paint,
@ -125,3 +126,13 @@ void SkTransparentShader::shadeSpan16(int x, int y, uint16_t span[], int count)
memcpy(span, src, count << 1); memcpy(span, src, count << 1);
} }
} }
#ifdef SK_DEVELOPER
void SkTransparentShader::toString(SkString* str) const {
str->append("SkTransparentShader: (");
this->INHERITED::toString(str);
str->append(")");
}
#endif

View File

@ -546,16 +546,16 @@ void SkGradientShaderBase::commonAsAGradient(GradientInfo* info) const {
if (info) { if (info) {
if (info->fColorCount >= fColorCount) { if (info->fColorCount >= fColorCount) {
if (info->fColors) { if (info->fColors) {
memcpy(info->fColors, fOrigColors, memcpy(info->fColors, fOrigColors, fColorCount * sizeof(SkColor));
fColorCount * sizeof(SkColor));
} }
if (info->fColorOffsets) { if (info->fColorOffsets) {
if (fColorCount == 2) { if (fColorCount == 2) {
info->fColorOffsets[0] = 0; info->fColorOffsets[0] = 0;
info->fColorOffsets[1] = SK_Scalar1; info->fColorOffsets[1] = SK_Scalar1;
} else if (fColorCount > 2) { } 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); 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
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -139,6 +139,7 @@ public:
protected: protected:
SkGradientShaderBase(SkFlattenableReadBuffer& ); SkGradientShaderBase(SkFlattenableReadBuffer& );
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
SK_DEVELOPER_TO_STRING()
SkUnitMapper* fMapper; SkUnitMapper* fMapper;
SkMatrix fPtsToUnit; // set by subclass SkMatrix fPtsToUnit; // set by subclass

View File

@ -564,3 +564,16 @@ GrEffect* SkLinearGradient::asNewEffect(GrContext* context, const SkPaint&) cons
} }
#endif #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

View File

@ -24,6 +24,7 @@ public:
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE; virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
virtual GrEffect* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE; virtual GrEffect* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
SK_DEVELOPER_TO_STRING()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLinearGradient) SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLinearGradient)
protected: protected:

View File

@ -588,3 +588,21 @@ GrEffect* SkRadialGradient::asNewEffect(GrContext* context, const SkPaint&) cons
} }
#endif #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

View File

@ -26,6 +26,7 @@ public:
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE; virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
virtual GrEffect* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE; virtual GrEffect* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
SK_DEVELOPER_TO_STRING()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkRadialGradient) SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkRadialGradient)
protected: protected:

View File

@ -489,3 +489,19 @@ GrEffect* SkSweepGradient::asNewEffect(GrContext* context, const SkPaint&) const
} }
#endif #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

View File

@ -26,6 +26,7 @@ public:
virtual GrEffect* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE; virtual GrEffect* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
SK_DEVELOPER_TO_STRING()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSweepGradient) SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSweepGradient)
protected: protected:

View File

@ -715,3 +715,29 @@ GrEffect* SkTwoPointConicalGradient::asNewEffect(GrContext* context, const SkPai
} }
#endif #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

View File

@ -67,6 +67,7 @@ public:
SkScalar getStartRadius() const { return fRadius1; } SkScalar getStartRadius() const { return fRadius1; }
SkScalar getDiffRadius() const { return fRadius2 - fRadius1; } SkScalar getDiffRadius() const { return fRadius2 - fRadius1; }
SK_DEVELOPER_TO_STRING()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointConicalGradient) SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointConicalGradient)
protected: protected:

View File

@ -309,6 +309,32 @@ bool SkTwoPointRadialGradient::setContext( const SkBitmap& device,
return true; 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( SkTwoPointRadialGradient::SkTwoPointRadialGradient(
SkFlattenableReadBuffer& buffer) SkFlattenableReadBuffer& buffer)
: INHERITED(buffer), : INHERITED(buffer),

View File

@ -35,6 +35,7 @@ public:
SkScalar getStartRadius() const { return fStartRadius; } SkScalar getStartRadius() const { return fStartRadius; }
SkScalar getDiffRadius() const { return fDiffRadius; } SkScalar getDiffRadius() const { return fDiffRadius; }
SK_DEVELOPER_TO_STRING()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointRadialGradient) SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointRadialGradient)
protected: protected:

View File

@ -5,7 +5,10 @@
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
*/ */
#include "SkDumpCanvas.h" #include "SkDumpCanvas.h"
#ifdef SK_DEVELOPER
#include "SkPicture.h" #include "SkPicture.h"
#include "SkPixelRef.h" #include "SkPixelRef.h"
#include "SkRRect.h" #include "SkRRect.h"
@ -130,31 +133,6 @@ static const char* toString(SkCanvas::PointMode pm) {
return gPMNames[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, static void toString(const void* text, size_t byteLen, SkPaint::TextEncoding enc,
SkString* str) { SkString* str) {
// FIXME: this code appears to be untested - and probably unused - and probably wrong // 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) { bool SkDumpCanvas::concat(const SkMatrix& matrix) {
SkString str; SkString str;
matrix.toDumpString(&str); matrix.toString(&str);
this->dump(kMatrix_Verb, NULL, "concat(%s)", str.c_str()); this->dump(kMatrix_Verb, NULL, "concat(%s)", str.c_str());
return this->INHERITED::concat(matrix); return this->INHERITED::concat(matrix);
} }
void SkDumpCanvas::setMatrix(const SkMatrix& matrix) { void SkDumpCanvas::setMatrix(const SkMatrix& matrix) {
SkString str; SkString str;
matrix.toDumpString(&str); matrix.toString(&str);
this->dump(kMatrix_Verb, NULL, "setMatrix(%s)", str.c_str()); this->dump(kMatrix_Verb, NULL, "setMatrix(%s)", str.c_str());
this->INHERITED::setMatrix(matrix); 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, void SkDumpCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y,
const SkPaint* paint) { const SkPaint* paint) {
SkString str; SkString str;
toString(bitmap, &str); bitmap.toString(&str);
this->dump(kDrawBitmap_Verb, paint, "drawBitmap(%s %g %g)", str.c_str(), this->dump(kDrawBitmap_Verb, paint, "drawBitmap(%s %g %g)", str.c_str(),
SkScalarToFloat(x), SkScalarToFloat(y)); 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, void SkDumpCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
const SkRect& dst, const SkPaint* paint) { const SkRect& dst, const SkPaint* paint) {
SkString bs, rs; SkString bs, rs;
toString(bitmap, &bs); bitmap.toString(&bs);
toString(dst, &rs); toString(dst, &rs);
// show the src-rect only if its not everything // show the src-rect only if its not everything
if (src && (src->fLeft > 0 || src->fTop > 0 || 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, void SkDumpCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
const SkPaint* paint) { const SkPaint* paint) {
SkString bs, ms; SkString bs, ms;
toString(bitmap, &bs); bitmap.toString(&bs);
m.toDumpString(&ms); m.toString(&ms);
this->dump(kDrawBitmap_Verb, paint, "drawBitmapMatrix(%s %s)", this->dump(kDrawBitmap_Verb, paint, "drawBitmapMatrix(%s %s)",
bs.c_str(), ms.c_str()); 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, void SkDumpCanvas::drawSprite(const SkBitmap& bitmap, int x, int y,
const SkPaint* paint) { const SkPaint* paint) {
SkString str; SkString str;
toString(bitmap, &str); bitmap.toString(&str);
this->dump(kDrawBitmap_Verb, paint, "drawSprite(%s %d %d)", str.c_str(), this->dump(kDrawBitmap_Verb, paint, "drawSprite(%s %d %d)", str.c_str(),
x, y); x, y);
} }
@ -525,4 +503,4 @@ static void dumpToDebugf(const char text[], void*) {
SkDebugfDumper::SkDebugfDumper() : INHERITED(dumpToDebugf, NULL) {} SkDebugfDumper::SkDebugfDumper() : INHERITED(dumpToDebugf, NULL) {}
#endif

View File

@ -39,9 +39,13 @@ static SkPicture* inspect(const char path[]) {
} }
static void dumpOps(SkPicture* pic) { static void dumpOps(SkPicture* pic) {
#ifdef SK_DEVELOPER
SkDebugfDumper dumper; SkDebugfDumper dumper;
SkDumpCanvas canvas(&dumper); SkDumpCanvas canvas(&dumper);
canvas.drawPicture(*pic); canvas.drawPicture(*pic);
#else
printf("SK_DEVELOPER mode not enabled\n");
#endif
} }
int tool_main(int argc, char** argv); int tool_main(int argc, char** argv);