item->setData(Qt::DisplayRole, (*command)[i].c_str());
item->setData(Qt::UserRole + 1, counter++);
- if (0 == strcmp("Restore", (*command)[i].c_str())) {
+ if (0 == strcmp("Restore", (*command)[i].c_str()) ||
+ 0 == strcmp("EndCommentGroup", (*command)[i].c_str())) {
indent -= 10;
}
item->setData(Qt::UserRole + 3, indent);
if (0 == strcmp("Save", (*command)[i].c_str()) ||
- 0 == strcmp("Save Layer", (*command)[i].c_str())) {
+ 0 == strcmp("Save Layer", (*command)[i].c_str()) ||
+ 0 == strcmp("BeginCommentGroup", (*command)[i].c_str())) {
indent += 10;
}
addDrawCommand(new DrawData(data, length));
}
+void SkDebugCanvas::beginCommentGroup(const char* description) {
+ addDrawCommand(new BeginCommentGroup(description));
+}
+
+void SkDebugCanvas::addComment(const char* kywd, const char* value) {
+ addDrawCommand(new Comment(kywd, value));
+}
+
+void SkDebugCanvas::endCommentGroup() {
+ addDrawCommand(new EndCommentGroup());
+}
+
void SkDebugCanvas::drawOval(const SkRect& oval, const SkPaint& paint) {
addDrawCommand(new DrawOval(oval, paint));
}
virtual void drawData(const void*, size_t) SK_OVERRIDE;
+ virtual void beginCommentGroup(const char* description) SK_OVERRIDE;
+
+ virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
+
+ virtual void endCommentGroup() SK_OVERRIDE;
+
virtual void drawOval(const SkRect& oval, const SkPaint&) SK_OVERRIDE;
virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
// TODO(chudy): Refactor into non subclass model.
+SkDrawCommand::SkDrawCommand(DrawType type)
+ : fDrawType(type)
+ , fVisible(true) {
+}
+
SkDrawCommand::SkDrawCommand() {
fVisible = true;
}
case SKEW: return "Skew";
case TRANSLATE: return "Translate";
case NOOP: return "NoOp";
+ case BEGIN_COMMENT_GROUP: return "BeginCommentGroup";
+ case COMMENT: return "Comment";
+ case END_COMMENT_GROUP: return "EndCommentGroup";
default:
SkDebugf("DrawType error 0x%08x\n", type);
SkASSERT(0);
canvas->drawData(fData, fLength);
}
+BeginCommentGroup::BeginCommentGroup(const char* description)
+ : INHERITED(BEGIN_COMMENT_GROUP)
+ , fDescription(description) {
+ SkString* temp = new SkString;
+ temp->appendf("Description: %s", description);
+ fInfo.push(temp);
+}
+
+Comment::Comment(const char* kywd, const char* value)
+ : INHERITED(COMMENT)
+ , fKywd(kywd)
+ , fValue(value) {
+ SkString* temp = new SkString;
+ temp->appendf("%s: %s", kywd, value);
+ fInfo.push(temp);
+}
+
+EndCommentGroup::EndCommentGroup() : INHERITED(END_COMMENT_GROUP) {
+}
+
DrawOval::DrawOval(const SkRect& oval, const SkPaint& paint) {
fOval = oval;
fPaint = paint;
#include "SkPictureFlat.h"
#include "SkCanvas.h"
+#include "SkString.h"
class SkDrawCommand {
public:
/* TODO(chudy): Remove subclasses. */
+ SkDrawCommand(DrawType drawType);
SkDrawCommand();
virtual ~SkDrawCommand();
typedef SkDrawCommand INHERITED;
};
+class BeginCommentGroup : public SkDrawCommand {
+public:
+ BeginCommentGroup(const char* description);
+ virtual void execute(SkCanvas* canvas) SK_OVERRIDE {
+ canvas->beginCommentGroup(fDescription.c_str());
+ };
+private:
+ SkString fDescription;
+
+ typedef SkDrawCommand INHERITED;
+};
+
+class Comment : public SkDrawCommand {
+public:
+ Comment(const char* kywd, const char* value);
+ virtual void execute(SkCanvas* canvas) SK_OVERRIDE {
+ canvas->addComment(fKywd.c_str(), fValue.c_str());
+ };
+private:
+ SkString fKywd;
+ SkString fValue;
+
+ typedef SkDrawCommand INHERITED;
+};
+
+class EndCommentGroup : public SkDrawCommand {
+public:
+ EndCommentGroup();
+ virtual void execute(SkCanvas* canvas) SK_OVERRIDE {
+ canvas->endCommentGroup();
+ };
+private:
+ typedef SkDrawCommand INHERITED;
+};
+
class DrawOval : public SkDrawCommand {
public:
DrawOval(const SkRect& oval, const SkPaint& paint);
}
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ SkAutoCommentBlock acb(canvas, "onDraw");
+
canvas->translate(20 * SK_Scalar1, 20 * SK_Scalar1);
int testCount = 0;
+ canvas->addComment("Test", "Various Paints");
+
for (int i = 0; i < fPaints.count(); ++i) {
for (int j = 0; j < fRects.count(); ++j, ++testCount) {
canvas->save();
}
}
+ canvas->addComment("Test", "Matrices");
+
SkPaint paint;
paint.setColor(SK_ColorWHITE);
paint.setAntiAlias(true);
subclasses like SkPicture's recording canvas, that can store the data
and then play it back later (via another call to drawData).
*/
- virtual void drawData(const void* data, size_t length);
+ virtual void drawData(const void* data, size_t length) {
+ // do nothing. Subclasses may do something with the data
+ }
+
+ /** Add comments. beginCommentGroup/endCommentGroup open/close a new group.
+ Each comment added via addComment is notionally attached to its
+ enclosing group. Top-level comments simply belong to no group.
+ */
+ virtual void beginCommentGroup(const char* description) {
+ // do nothing. Subclasses may do something
+ }
+ virtual void addComment(const char* kywd, const char* value) {
+ // do nothing. Subclasses may do something
+ }
+ virtual void endCommentGroup() {
+ // do nothing. Subclasses may do something
+ }
+
//////////////////////////////////////////////////////////////////////////
int fSaveCount;
};
+/** Stack helper class to automatically open and close a comment block
+ */
+class SkAutoCommentBlock : SkNoncopyable {
+public:
+ SkAutoCommentBlock(SkCanvas* canvas, const char* description) {
+ fCanvas = canvas;
+ if (NULL != fCanvas) {
+ fCanvas->beginCommentGroup(description);
+ }
+ }
+
+ ~SkAutoCommentBlock() {
+ if (NULL != fCanvas) {
+ fCanvas->endCommentGroup();
+ }
+ }
+
+private:
+ SkCanvas* fCanvas;
+};
+
#endif
kDrawText_Verb,
kDrawPicture_Verb,
kDrawVertices_Verb,
- kDrawData_Verb
+ kDrawData_Verb,
+
+ kBeginCommentGroup_Verb,
+ kAddComment_Verb,
+ kEndCommentGroup_Verb
};
/** Subclasses of this are installed on the DumpCanvas, and then called for
const uint16_t indices[], int indexCount,
const SkPaint& paint) SK_OVERRIDE;
virtual void drawData(const void*, size_t) SK_OVERRIDE;
+ virtual void beginCommentGroup(const char* description) SK_OVERRIDE;
+ virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
+ virtual void endCommentGroup() SK_OVERRIDE;
private:
Dumper* fDumper;
const SkPaint& paint) SK_OVERRIDE;
virtual void drawData(const void* data, size_t length) SK_OVERRIDE;
+ virtual void beginCommentGroup(const char* description) SK_OVERRIDE;
+ virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
+ virtual void endCommentGroup() SK_OVERRIDE;
+
virtual SkBounder* setBounder(SkBounder* bounder) SK_OVERRIDE;
virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter) SK_OVERRIDE;
LOOPER_END
}
-void SkCanvas::drawData(const void* data, size_t length) {
- // do nothing. Subclasses may do something with the data
-}
-
//////////////////////////////////////////////////////////////////////////////
// These methods are NOT virtual, and therefore must call back into virtual
// methods, rather than actually drawing themselves.
SKEW,
TRANSLATE,
NOOP,
+ BEGIN_COMMENT_GROUP,
+ COMMENT,
+ END_COMMENT_GROUP,
- LAST_DRAWTYPE_ENUM = NOOP
+ LAST_DRAWTYPE_ENUM = END_COMMENT_GROUP
};
// In the 'match' method, this constant will match any flavor of DRAW_BITMAP*
canvas.drawData(reader.skip(length), length);
// skip handles padding the read out to a multiple of 4
} break;
+ case BEGIN_COMMENT_GROUP: {
+ const char* desc = reader.readString();
+ canvas.beginCommentGroup(desc);
+ } break;
+ case COMMENT: {
+ const char* kywd = reader.readString();
+ const char* value = reader.readString();
+ canvas.addComment(kywd, value);
+ } break;
+ case END_COMMENT_GROUP: {
+ canvas.endCommentGroup();
+ } break;
case DRAW_OVAL: {
const SkPaint& paint = *getPaint(reader);
canvas.drawOval(reader.skipT<SkRect>(), paint);
0, // SKEW - no paint
0, // TRANSLATE - no paint
0, // NOOP - no paint
+ 0, // BEGIN_GROUP - no paint
+ 0, // COMMENT - no paint
+ 0, // END_GROUP - no paint
};
SkASSERT(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1);
validate(initialOffset, size);
}
+void SkPictureRecord::beginCommentGroup(const char* description) {
+ // op/size + length of string + \0 terminated chars
+ int length = strlen(description);
+ uint32_t size = 2 * kUInt32Size + SkAlign4(length + 1);
+ uint32_t initialOffset = this->addDraw(BEGIN_COMMENT_GROUP, &size);
+ fWriter.writeString(description, length);
+ validate(initialOffset, size);
+}
+
+void SkPictureRecord::addComment(const char* kywd, const char* value) {
+ // op/size + 2x length of string + 2x \0 terminated chars
+ int kywdLen = strlen(kywd);
+ int valueLen = strlen(value);
+ uint32_t size = 3 * kUInt32Size + SkAlign4(kywdLen + 1) + SkAlign4(valueLen + 1);
+ uint32_t initialOffset = this->addDraw(COMMENT, &size);
+ fWriter.writeString(kywd, kywdLen);
+ fWriter.writeString(value, valueLen);
+ validate(initialOffset, size);
+}
+
+void SkPictureRecord::endCommentGroup() {
+ // op/size
+ uint32_t size = 1 * kUInt32Size;
+ uint32_t initialOffset = this->addDraw(END_COMMENT_GROUP, &size);
+ validate(initialOffset, size);
+}
+
///////////////////////////////////////////////////////////////////////////////
void SkPictureRecord::addBitmap(const SkBitmap& bitmap) {
const uint16_t indices[], int indexCount,
const SkPaint&) SK_OVERRIDE;
virtual void drawData(const void*, size_t) SK_OVERRIDE;
+ virtual void beginCommentGroup(const char* description) SK_OVERRIDE;
+ virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
+ virtual void endCommentGroup() SK_OVERRIDE;
virtual bool isDrawingToLayer() const SK_OVERRIDE;
void addFontMetricsTopBottom(const SkPaint& paint, const SkFlatData&,
const uint16_t indices[], int indexCount,
const SkPaint&) SK_OVERRIDE;
virtual void drawData(const void*, size_t) SK_OVERRIDE;
+ virtual void beginCommentGroup(const char* description) SK_OVERRIDE;
+ virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
+ virtual void endCommentGroup() SK_OVERRIDE;
/**
* Flatten an SkBitmap to send to the reader, where it will be referenced
}
}
+void SkGPipeCanvas::beginCommentGroup(const char* description) {
+ // ignore for now
+}
+
+void SkGPipeCanvas::addComment(const char* kywd, const char* value) {
+ // ignore for now
+}
+
+void SkGPipeCanvas::endCommentGroup() {
+ // ignore for now
+}
+
void SkGPipeCanvas::flushRecording(bool detachCurrentBlock) {
doNotify();
if (detachCurrentBlock) {
SkMin32(length, 64), data);
}
+void SkDumpCanvas::beginCommentGroup(const char* description) {
+ this->dump(kBeginCommentGroup_Verb, NULL, "beginCommentGroup(%s)", description);
+}
+
+void SkDumpCanvas::addComment(const char* kywd, const char* value) {
+ this->dump(kAddComment_Verb, NULL, "addComment(%s, %s)", kywd, value);
+}
+
+void SkDumpCanvas::endCommentGroup() {
+ this->dump(kEndCommentGroup_Verb, NULL, "endCommentGroup()");
+}
+
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
fProxy->drawData(data, length);
}
+void SkProxyCanvas::beginCommentGroup(const char* description) {
+ fProxy->beginCommentGroup(description);
+}
+
+void SkProxyCanvas::addComment(const char* kywd, const char* value) {
+ fProxy->addComment(kywd, value);
+}
+
+void SkProxyCanvas::endCommentGroup() {
+ fProxy->endCommentGroup();
+}
+
SkBounder* SkProxyCanvas::setBounder(SkBounder* bounder) {
return fProxy->setBounder(bounder);
}
SIMPLE_TEST_STEP(DrawTextOnPathMatrix, drawTextOnPath(kTestText.c_str(),
kTestText.size(), kTestPath, &kTestMatrix, kTestPaint));
SIMPLE_TEST_STEP(DrawData, drawData(kTestText.c_str(), kTestText.size()));
+SIMPLE_TEST_STEP(BeginGroup, beginCommentGroup(kTestText.c_str()));
+SIMPLE_TEST_STEP(AddComment, addComment(kTestText.c_str(), kTestText.c_str()));
+SIMPLE_TEST_STEP(EndGroup, endCommentGroup());
///////////////////////////////////////////////////////////////////////////////
// Complex test steps