diff options
author | 2011-06-16 20:49:55 +0000 | |
---|---|---|
committer | 2011-06-16 20:49:55 +0000 | |
commit | a8a42e20f0806fabac8e87b9d06421b93a225267 (patch) | |
tree | e185fa6e65bc8d305efc953b422bfb4b7888357b /experimental/CocoaDebugger/SkDebugDumper.cpp | |
parent | af951c9bc4cbb6e60b430194fe5127ebe99c53fb (diff) |
Added CocoaDebugger to experimental
git-svn-id: http://skia.googlecode.com/svn/trunk@1622 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'experimental/CocoaDebugger/SkDebugDumper.cpp')
-rw-r--r-- | experimental/CocoaDebugger/SkDebugDumper.cpp | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/experimental/CocoaDebugger/SkDebugDumper.cpp b/experimental/CocoaDebugger/SkDebugDumper.cpp new file mode 100644 index 0000000000..2afcd188ff --- /dev/null +++ b/experimental/CocoaDebugger/SkDebugDumper.cpp @@ -0,0 +1,161 @@ +#include "SkDebugDumper.h" +#include "SkString.h" +#include "SkPaint.h" +#include "SkShader.h" +#include "SkPathEffect.h" +#include "SkXfermode.h" +#include "SkColorFilter.h" +#include "SkPathEffect.h" +#include "SkMaskFilter.h" +#include "SkGradientShader.h" +#include "SkDebuggerViews.h" + +bool gNeverSetToTrueJustNeedToFoolLinker; +static void init_effects() { + if (gNeverSetToTrueJustNeedToFoolLinker) { + SkPoint p = SkPoint::Make(0,0); + SkPoint q = SkPoint::Make(100,100); + SkPoint pts[] = {p, q}; + SkColor colors[] = { SK_ColorRED, SK_ColorGREEN }; + SkScalar pos[] = { 0, 1.0}; + SkGradientShader::CreateLinear(pts, colors, pos, 2, + SkShader::kMirror_TileMode); + } +} + +SkDebugDumper::SkDebugDumper(SkEventSinkID cID, SkEventSinkID clID, + SkEventSinkID ipID) { + fContentID = cID; + fCommandListID = clID; + fInfoPanelID = ipID; + fInit = false; + fDisabled = false; + fCount = 0; + init_effects(); +} + +static void appendPtr(SkString* str, const void* ptr, const char name[]) { + if (ptr) { + str->appendf("$s: %p\t", name, ptr); + } +} + +static void appendFlattenable(SkString* str, const SkFlattenable* ptr, + const char name[]) { + if (ptr) { + SkString info; + if (ptr->toDumpString(&info)) { + str->appendf("%s", info.c_str()); + } else { + str->appendf("%s: %p", name, ptr); + } + } +} + +static SkString dumpMatrix(SkDumpCanvasM* canvas) { + SkString str; + SkMatrix m = canvas->getTotalMatrix(); + str.appendf("Matrix:"); + str.appendf("Translate (%0.4g, %0.4g) ", + SkScalarToFloat(m.get(SkMatrix::kMTransX)), + SkScalarToFloat(m.get(SkMatrix::kMTransY))); + str.appendf("Scale (%0.4g, %0.4g) ", + SkScalarToFloat(m.get(SkMatrix::kMScaleX)), + SkScalarToFloat(m.get(SkMatrix::kMScaleY))); + str.appendf("Skew (%0.4g, %0.4g) ", + SkScalarToFloat(m.get(SkMatrix::kMSkewX)), + SkScalarToFloat(m.get(SkMatrix::kMSkewY))); + str.appendf("Perspective (%0.4g, %0.4g, %0.4g) ", + SkScalarToFloat(m.get(SkMatrix::kMPersp0)), + SkScalarToFloat(m.get(SkMatrix::kMPersp1)), + SkScalarToFloat(m.get(SkMatrix::kMPersp2))); + return str; +} + +static SkString dumpClip(SkDumpCanvasM* canvas) { + SkString str; + SkPath p; + int maxPts = 50; + if (canvas->getTotalClip().getBoundaryPath(&p)) { + SkPoint pts[maxPts]; + int numPts = p.getPoints(pts, maxPts); + + str.appendf("Clip: [ "); + for (int i = 0; i < numPts; ++i) { + str.appendf("(%0.4g, %0.4g)", pts[i].x(), pts[i].y()); + if (i < numPts-1) + str.appendf(" , "); + } + str.appendf(" ]"); + } + return str; +} + +static const char* gPaintFlags[] = { + "AntiAliasing", + "Bitmap Filtering", + "Dithering", + "Underline Text", + "Strike-Through Text", + "Fake Bold Text", + "Linear Text", + "Subpixel Positioned Text", + "Device Kerning Text", + "LCD/Subpixel Glyph Rendering", + "Embedded Bitmap Text", + "Freetype Autohinting", + + "ALL" +}; + + +static SkString dumpPaint(SkDumpCanvasM* canvas, const SkPaint* p, + SkDumpCanvasM::Verb verb) { + SkString str; + str.appendf("Color: #%08X\n", p->getColor()); + str.appendf("Flags: %s\n", gPaintFlags[p->getFlags()]); + appendFlattenable(&str, p->getShader(), "shader"); + appendFlattenable(&str, p->getXfermode(), "xfermode"); + appendFlattenable(&str, p->getPathEffect(), "pathEffect"); + appendFlattenable(&str, p->getMaskFilter(), "maskFilter"); + appendFlattenable(&str, p->getPathEffect(), "pathEffect"); + appendFlattenable(&str, p->getColorFilter(), "filter"); + + if (SkDumpCanvasM::kDrawText_Verb == verb) { + str.appendf("Text Size:%0.4g\n", SkScalarToFloat(p->getTextSize())); + appendPtr(&str, p->getTypeface(), "typeface"); + } + + return str; +} + +void SkDebugDumper::dump(SkDumpCanvasM* canvas, SkDumpCanvasM::Verb verb, + const char str[], const SkPaint* p) { + if (!fDisabled) { + SkString msg, tab; + + const int level = canvas->getNestLevel() + canvas->getSaveCount() - 1; + SkASSERT(level >= 0); + for (int i = 0; i < level; i++) { + tab.append("| "); + } + + msg.appendf("%03d: %s%s\n", fCount, tab.c_str(), str); + ++fCount; + if (!fInit) { + SkEvent* cmd = new SkEvent(SkDebugger_CommandType); + cmd->setString(SkDebugger_Atom, msg); + cmd->post(fCommandListID, 100); + } + else { + SkEvent* state = new SkEvent(SkDebugger_StateType); + state->setString(SkDebugger_Matrix, dumpMatrix(canvas)); + state->setString(SkDebugger_Clip, dumpClip(canvas)); + if (p) { + state->setString(SkDebugger_PaintInfo, dumpPaint(canvas, p, verb)); + state->getMetaData().setPtr(SkDebugger_Paint, (void*)p, PaintProc); + } + state->post(fInfoPanelID); + } + } +}
\ No newline at end of file |