diff --git a/debugger/SkObjectParser.cpp b/debugger/SkObjectParser.cpp index efa801ce98..c53d3b5a31 100644 --- a/debugger/SkObjectParser.cpp +++ b/debugger/SkObjectParser.cpp @@ -7,12 +7,13 @@ */ #include "SkObjectParser.h" -#include "SkRRect.h" -#include "SkShader.h" -#include "SkTypeface.h" -#include "SkStream.h" #include "SkData.h" #include "SkFontDescriptor.h" +#include "SkRRect.h" +#include "SkShader.h" +#include "SkStream.h" +#include "SkStringUtils.h" +#include "SkTypeface.h" /* TODO(chudy): Replace all std::strings with char */ @@ -101,16 +102,6 @@ SkString* SkObjectParser::MatrixToString(const SkMatrix& matrix) { return mMatrix; } -static void add_flag_to_string(SkString* string, bool flag, const char* flagStr, bool* needSeparator) { - if (flag) { - if (*needSeparator) { - string->append("|"); - } - string->append(flagStr); - *needSeparator = true; - } -} - SkString* SkObjectParser::PaintToString(const SkPaint& paint) { SkString* mPaint = new SkString("
SkPaint:
"); @@ -187,6 +178,7 @@ SkString* SkObjectParser::PaintToString(const SkPaint& paint) { SkDrawLooper* looper = paint.getLooper(); if (NULL != looper) { mPaint->append("
DrawLooper:
"); + SkDEVCODE(looper->toString(mPaint);) mPaint->append("
"); } @@ -218,22 +210,22 @@ SkString* SkObjectParser::PaintToString(const SkPaint& paint) { mPaint->append("
Flags:
("); if (paint.getFlags()) { bool needSeparator = false; - add_flag_to_string(mPaint, paint.isAntiAlias(), "AntiAlias", &needSeparator); - add_flag_to_string(mPaint, paint.isFilterBitmap(), "FilterBitmap", &needSeparator); - add_flag_to_string(mPaint, paint.isDither(), "Dither", &needSeparator); - add_flag_to_string(mPaint, paint.isUnderlineText(), "UnderlineText", &needSeparator); - add_flag_to_string(mPaint, paint.isStrikeThruText(), "StrikeThruText", &needSeparator); - add_flag_to_string(mPaint, paint.isFakeBoldText(), "FakeBoldText", &needSeparator); - add_flag_to_string(mPaint, paint.isLinearText(), "LinearText", &needSeparator); - add_flag_to_string(mPaint, paint.isSubpixelText(), "SubpixelText", &needSeparator); - add_flag_to_string(mPaint, paint.isDevKernText(), "DevKernText", &needSeparator); - add_flag_to_string(mPaint, paint.isLCDRenderText(), "LCDRenderText", &needSeparator); - add_flag_to_string(mPaint, paint.isEmbeddedBitmapText(), - "EmbeddedBitmapText", &needSeparator); - add_flag_to_string(mPaint, paint.isAutohinted(), "Autohinted", &needSeparator); - add_flag_to_string(mPaint, paint.isVerticalText(), "VerticalText", &needSeparator); - add_flag_to_string(mPaint, SkToBool(paint.getFlags() & SkPaint::kGenA8FromLCD_Flag), - "GenA8FromLCD", &needSeparator); + SkAddFlagToString(mPaint, paint.isAntiAlias(), "AntiAlias", &needSeparator); + SkAddFlagToString(mPaint, paint.isFilterBitmap(), "FilterBitmap", &needSeparator); + SkAddFlagToString(mPaint, paint.isDither(), "Dither", &needSeparator); + SkAddFlagToString(mPaint, paint.isUnderlineText(), "UnderlineText", &needSeparator); + SkAddFlagToString(mPaint, paint.isStrikeThruText(), "StrikeThruText", &needSeparator); + SkAddFlagToString(mPaint, paint.isFakeBoldText(), "FakeBoldText", &needSeparator); + SkAddFlagToString(mPaint, paint.isLinearText(), "LinearText", &needSeparator); + SkAddFlagToString(mPaint, paint.isSubpixelText(), "SubpixelText", &needSeparator); + SkAddFlagToString(mPaint, paint.isDevKernText(), "DevKernText", &needSeparator); + SkAddFlagToString(mPaint, paint.isLCDRenderText(), "LCDRenderText", &needSeparator); + SkAddFlagToString(mPaint, paint.isEmbeddedBitmapText(), + "EmbeddedBitmapText", &needSeparator); + SkAddFlagToString(mPaint, paint.isAutohinted(), "Autohinted", &needSeparator); + SkAddFlagToString(mPaint, paint.isVerticalText(), "VerticalText", &needSeparator); + SkAddFlagToString(mPaint, SkToBool(paint.getFlags() & SkPaint::kGenA8FromLCD_Flag), + "GenA8FromLCD", &needSeparator); } else { mPaint->append("None"); } diff --git a/gyp/core.gypi b/gyp/core.gypi index 82b9623c08..8c75c1f87d 100644 --- a/gyp/core.gypi +++ b/gyp/core.gypi @@ -157,6 +157,7 @@ '<(skia_src_path)/core/SkSpriteBlitterTemplate.h', '<(skia_src_path)/core/SkStream.cpp', '<(skia_src_path)/core/SkString.cpp', + '<(skia_src_path)/core/SkStringUtils.cpp', '<(skia_src_path)/core/SkStroke.h', '<(skia_src_path)/core/SkStroke.cpp', '<(skia_src_path)/core/SkStrokeRec.cpp', @@ -253,6 +254,7 @@ '<(skia_include_path)/core/SkShader.h', '<(skia_include_path)/core/SkStream.h', '<(skia_include_path)/core/SkString.h', + '<(skia_include_path)/core/SkStringUtils.h', '<(skia_include_path)/core/SkStrokeRec.h', '<(skia_include_path)/core/SkTArray.h', '<(skia_include_path)/core/SkTDArray.h', diff --git a/include/core/SkDrawLooper.h b/include/core/SkDrawLooper.h index 8a218c331d..2faf28b399 100644 --- a/include/core/SkDrawLooper.h +++ b/include/core/SkDrawLooper.h @@ -15,6 +15,7 @@ class SkCanvas; class SkPaint; struct SkRect; +class SkString; /** \class SkDrawLooper Subclasses of SkDrawLooper can be attached to a SkPaint. Where they are, @@ -62,6 +63,8 @@ public: virtual void computeFastBounds(const SkPaint& paint, const SkRect& src, SkRect* dst); + SkDEVCODE(virtual void toString(SkString* str) const = 0;) + protected: SkDrawLooper() {} SkDrawLooper(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {} diff --git a/include/core/SkStringUtils.h b/include/core/SkStringUtils.h new file mode 100644 index 0000000000..eea0b5143b --- /dev/null +++ b/include/core/SkStringUtils.h @@ -0,0 +1,23 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkStringUtils_DEFINED +#define SkStringUtils_DEFINED + +class SkString; + +/** + * Add 'flagStr' to 'string' and set 'needSeparator' to true only if 'flag' is + * true. If 'needSeparator' is true append a '|' before 'flagStr'. This method + * is used to streamline the creation of ASCII flag strings within the toString + * methods. + */ +void SkAddFlagToString(SkString* string, bool flag, + const char* flagStr, bool* needSeparator); + + +#endif \ No newline at end of file diff --git a/include/effects/SkBlurDrawLooper.h b/include/effects/SkBlurDrawLooper.h index c4107612cb..e968857889 100644 --- a/include/effects/SkBlurDrawLooper.h +++ b/include/effects/SkBlurDrawLooper.h @@ -43,6 +43,7 @@ public: virtual void init(SkCanvas*); virtual bool next(SkCanvas*, SkPaint* paint); + SK_DEVELOPER_TO_STRING() SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurDrawLooper) protected: diff --git a/include/effects/SkLayerDrawLooper.h b/include/effects/SkLayerDrawLooper.h index 5196af0798..cec78b7466 100644 --- a/include/effects/SkLayerDrawLooper.h +++ b/include/effects/SkLayerDrawLooper.h @@ -90,7 +90,7 @@ public: SkPaint* addLayer(const LayerInfo&); /** - * This layer will draw with the original paint, ad the specified offset + * This layer will draw with the original paint, at the specified offset */ void addLayer(SkScalar dx, SkScalar dy); @@ -103,6 +103,7 @@ public: virtual void init(SkCanvas*); virtual bool next(SkCanvas*, SkPaint* paint); + SK_DEVELOPER_TO_STRING() SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLayerDrawLooper) protected: diff --git a/src/core/SkStringUtils.cpp b/src/core/SkStringUtils.cpp new file mode 100644 index 0000000000..689a6eecaf --- /dev/null +++ b/src/core/SkStringUtils.cpp @@ -0,0 +1,20 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkString.h" +#include "SkStringUtils.h" + +void SkAddFlagToString(SkString* string, bool flag, const char* flagStr, bool* needSeparator) { + if (flag) { + if (*needSeparator) { + string->append("|"); + } + string->append(flagStr); + *needSeparator = true; + } +} + diff --git a/src/effects/SkBlurDrawLooper.cpp b/src/effects/SkBlurDrawLooper.cpp index e6e2ffdd8c..dda20638a3 100644 --- a/src/effects/SkBlurDrawLooper.cpp +++ b/src/effects/SkBlurDrawLooper.cpp @@ -8,10 +8,12 @@ #include "SkBlurDrawLooper.h" #include "SkBlurMaskFilter.h" #include "SkCanvas.h" -#include "SkFlattenableBuffers.h" -#include "SkPaint.h" -#include "SkMaskFilter.h" #include "SkColorFilter.h" +#include "SkFlattenableBuffers.h" +#include "SkMaskFilter.h" +#include "SkPaint.h" +#include "SkString.h" +#include "SkStringUtils.h" SkBlurDrawLooper::SkBlurDrawLooper(SkScalar radius, SkScalar dx, SkScalar dy, SkColor color, uint32_t flags) @@ -115,3 +117,35 @@ bool SkBlurDrawLooper::next(SkCanvas* canvas, SkPaint* paint) { return false; } } + +#ifdef SK_DEVELOPER +void SkBlurDrawLooper::toString(SkString* str) const { + str->append("SkBlurDrawLooper: "); + + str->append("dx: "); + str->appendScalar(fDx); + + str->append(" dy: "); + str->appendScalar(fDy); + + str->append(" color: "); + str->appendHex(fBlurColor); + + str->append(" flags: ("); + if (kNone_BlurFlag == fBlurFlags) { + str->append("None"); + } else { + bool needsSeparator = false; + SkAddFlagToString(str, SkToBool(kIgnoreTransform_BlurFlag & fBlurFlags), "IgnoreTransform", + &needsSeparator); + SkAddFlagToString(str, SkToBool(kOverrideColor_BlurFlag & fBlurFlags), "OverrideColor", + &needsSeparator); + SkAddFlagToString(str, SkToBool(kHighQuality_BlurFlag & fBlurFlags), "HighQuality", + &needsSeparator); + } + str->append(")"); + + // TODO: add optional "fBlurFilter->toString(str);" when SkMaskFilter::toString is added + // alternatively we could cache the radius in SkBlurDrawLooper and just add it here +} +#endif diff --git a/src/effects/SkLayerDrawLooper.cpp b/src/effects/SkLayerDrawLooper.cpp index c27908f250..6d03eae84d 100644 --- a/src/effects/SkLayerDrawLooper.cpp +++ b/src/effects/SkLayerDrawLooper.cpp @@ -10,6 +10,8 @@ #include "SkFlattenableBuffers.h" #include "SkLayerDrawLooper.h" #include "SkPaint.h" +#include "SkString.h" +#include "SkStringUtils.h" #include "SkUnPreMultiply.h" SK_DEFINE_INST_COUNT(SkLayerDrawLooper) @@ -245,3 +247,99 @@ SkLayerDrawLooper::SkLayerDrawLooper(SkFlattenableReadBuffer& buffer) } #endif } + +#ifdef SK_DEVELOPER +void SkLayerDrawLooper::toString(SkString* str) const { + str->appendf("SkLayerDrawLooper (%d): ", fCount); + + Rec* rec = fRecs; + for (int i = 0; i < fCount; i++) { + str->appendf("%d: ", i); + + str->append("flagsMask: ("); + if (0 == rec->fInfo.fFlagsMask) { + str->append("None"); + } else { + bool needSeparator = false; + SkAddFlagToString(str, SkToBool(SkPaint::kAntiAlias_Flag & rec->fInfo.fFlagsMask), + "AntiAlias", &needSeparator); + SkAddFlagToString(str, SkToBool(SkPaint::kFilterBitmap_Flag & rec->fInfo.fFlagsMask), + "FilterBitmap", &needSeparator); + SkAddFlagToString(str, SkToBool(SkPaint::kDither_Flag & rec->fInfo.fFlagsMask), + "Dither", &needSeparator); + SkAddFlagToString(str, SkToBool(SkPaint::kUnderlineText_Flag & rec->fInfo.fFlagsMask), + "UnderlineText", &needSeparator); + SkAddFlagToString(str, SkToBool(SkPaint::kStrikeThruText_Flag & rec->fInfo.fFlagsMask), + "StrikeThruText", &needSeparator); + SkAddFlagToString(str, SkToBool(SkPaint::kFakeBoldText_Flag & rec->fInfo.fFlagsMask), + "FakeBoldText", &needSeparator); + SkAddFlagToString(str, SkToBool(SkPaint::kLinearText_Flag & rec->fInfo.fFlagsMask), + "LinearText", &needSeparator); + SkAddFlagToString(str, SkToBool(SkPaint::kSubpixelText_Flag & rec->fInfo.fFlagsMask), + "SubpixelText", &needSeparator); + SkAddFlagToString(str, SkToBool(SkPaint::kDevKernText_Flag & rec->fInfo.fFlagsMask), + "DevKernText", &needSeparator); + SkAddFlagToString(str, SkToBool(SkPaint::kLCDRenderText_Flag & rec->fInfo.fFlagsMask), + "LCDRenderText", &needSeparator); + SkAddFlagToString(str, SkToBool(SkPaint::kEmbeddedBitmapText_Flag & rec->fInfo.fFlagsMask), + "EmbeddedBitmapText", &needSeparator); + SkAddFlagToString(str, SkToBool(SkPaint::kAutoHinting_Flag & rec->fInfo.fFlagsMask), + "Autohinted", &needSeparator); + SkAddFlagToString(str, SkToBool(SkPaint::kVerticalText_Flag & rec->fInfo.fFlagsMask), + "VerticalText", &needSeparator); + SkAddFlagToString(str, SkToBool(SkPaint::kGenA8FromLCD_Flag & rec->fInfo.fFlagsMask), + "GenA8FromLCD", &needSeparator); + } + str->append(") "); + + str->append("paintBits: ("); + if (0 == rec->fInfo.fPaintBits) { + str->append("None"); + } else if (kEntirePaint_Bits == rec->fInfo.fPaintBits) { + str->append("EntirePaint"); + } else { + bool needSeparator = false; + SkAddFlagToString(str, SkToBool(kStyle_Bit & rec->fInfo.fPaintBits), "Style", + &needSeparator); + SkAddFlagToString(str, SkToBool(kTextSkewX_Bit & rec->fInfo.fPaintBits), "TextSkewX", + &needSeparator); + SkAddFlagToString(str, SkToBool(kPathEffect_Bit & rec->fInfo.fPaintBits), "PathEffect", + &needSeparator); + SkAddFlagToString(str, SkToBool(kMaskFilter_Bit & rec->fInfo.fPaintBits), "MaskFilter", + &needSeparator); + SkAddFlagToString(str, SkToBool(kShader_Bit & rec->fInfo.fPaintBits), "Shader", + &needSeparator); + SkAddFlagToString(str, SkToBool(kColorFilter_Bit & rec->fInfo.fPaintBits), "ColorFilter", + &needSeparator); + SkAddFlagToString(str, SkToBool(kXfermode_Bit & rec->fInfo.fPaintBits), "Xfermode", + &needSeparator); + } + str->append(") "); + + static const char* gModeStrings[SkXfermode::kLastMode+1] = { + "kClear", "kSrc", "kDst", "kSrcOver", "kDstOver", "kSrcIn", "kDstIn", + "kSrcOut", "kDstOut", "kSrcATop", "kDstATop", "kXor", "kPlus", + "kMultiply", "kScreen", "kOverlay", "kDarken", "kLighten", "kColorDodge", + "kColorBurn", "kHardLight", "kSoftLight", "kDifference", "kExclusion" + }; + + str->appendf("mode: %s ", gModeStrings[rec->fInfo.fColorMode]); + + str->append("offset: ("); + str->appendScalar(rec->fInfo.fOffset.fX); + str->append(", "); + str->appendScalar(rec->fInfo.fOffset.fY); + str->append(") "); + + str->append("postTranslate: "); + if (rec->fInfo.fPostTranslate) { + str->append("true "); + } else { + str->append("false "); + } + + // TODO: add "rec->fPaint.toString(str);" when SkPaint::toString is added + rec = rec->fNext; + } +} +#endif diff --git a/tests/QuickRejectTest.cpp b/tests/QuickRejectTest.cpp index 00008330eb..9d87bffebc 100644 --- a/tests/QuickRejectTest.cpp +++ b/tests/QuickRejectTest.cpp @@ -29,6 +29,12 @@ public: return false; } +#ifdef SK_DEVELOPER + virtual void toString(SkString* str) const SK_OVERRIDE { + str->append("TestLooper:"); + } +#endif + SK_DECLARE_UNFLATTENABLE_OBJECT() };