Added toString to SkDrawLooper-derived classes

https://codereview.appspot.com/7195054/



git-svn-id: http://skia.googlecode.com/svn/trunk@7422 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
robertphillips@google.com 2013-01-28 20:21:59 +00:00
parent 85ec74ca54
commit 4991b8f234
10 changed files with 214 additions and 34 deletions

View File

@ -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("<dl><dt>SkPaint:</dt><dd><dl>");
@ -187,6 +178,7 @@ SkString* SkObjectParser::PaintToString(const SkPaint& paint) {
SkDrawLooper* looper = paint.getLooper();
if (NULL != looper) {
mPaint->append("<dt>DrawLooper:</dt><dd>");
SkDEVCODE(looper->toString(mPaint);)
mPaint->append("</dd>");
}
@ -218,22 +210,22 @@ SkString* SkObjectParser::PaintToString(const SkPaint& paint) {
mPaint->append("<dt>Flags:</dt><dd>(");
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");
}

View File

@ -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',

View File

@ -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) {}

View File

@ -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

View File

@ -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:

View File

@ -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:

View File

@ -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;
}
}

View File

@ -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

View File

@ -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

View File

@ -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()
};