From: chudy@google.com Date: Tue, 7 Aug 2012 20:41:37 +0000 (+0000) Subject: Replaced all instances of std strings and vectors in favor of SkStrings and SkTDArray... X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~15256 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=97cee9735350cb472249ce1a827ba1aa6b2a5f59;p=platform%2Fupstream%2FlibSkiaSharp.git Replaced all instances of std strings and vectors in favor of SkStrings and SkTDArrays within skia code Review URL: https://codereview.appspot.com/6445088 git-svn-id: http://skia.googlecode.com/svn/trunk@4995 2bbb7eff-a529-9590-31e7-b0007b416f81 --- diff --git a/debugger/QT/SkDebuggerGUI.cpp b/debugger/QT/SkDebuggerGUI.cpp index 9863cc0..e2d4bf9 100644 --- a/debugger/QT/SkDebuggerGUI.cpp +++ b/debugger/QT/SkDebuggerGUI.cpp @@ -293,18 +293,17 @@ void SkDebuggerGUI::registerListClick(QListWidgetItem *item) { if (!fPause) { fCanvasWidget.drawTo(currentRow); } - std::vector *cuffInfo = fDebugger.getCommandInfo( + SkTDArray *currInfo = fDebugger.getCommandInfo( currentRow); /* TODO(chudy): Add command type before parameters. Rename v * to something more informative. */ - if (cuffInfo) { - std::vector::iterator it; - + if (currInfo) { QString info; info.append("Parameters:
"); - for (it = cuffInfo->begin(); it != cuffInfo->end(); ++it) { - info.append(QString((*it).c_str())); + for (int i = 0; i < currInfo->count(); i++) { + + info.append(QString((*currInfo)[i]->c_str())); info.append("
"); } fInspectorWidget.setDetailText(info); @@ -576,7 +575,8 @@ void SkDebuggerGUI::loadPicture(QString fileName) { SkSafeUnref(stream); SkSafeUnref(picture); - std::vector *cv = fDebugger.getDrawCommands(); + // Will this automatically clear out due to nature of refcnt? + SkTDArray* commands = fDebugger.getDrawCommands(); /* fDebugCanvas is reinitialized every load picture. Need it to retain value * of the visibility filter. @@ -585,8 +585,8 @@ void SkDebuggerGUI::loadPicture(QString fileName) { * */ fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityButton()->isChecked()); - setupListWidget(cv); - setupComboBox(cv); + setupListWidget(commands); + setupComboBox(commands); fInspectorWidget.setDisabled(false); fSettingsWidget.setDisabled(false); fMenuEdit.setDisabled(false); @@ -598,24 +598,24 @@ void SkDebuggerGUI::loadPicture(QString fileName) { actionPlay(); } -void SkDebuggerGUI::setupListWidget(std::vector* cv) { +void SkDebuggerGUI::setupListWidget(SkTDArray* command) { fListWidget.clear(); int counter = 0; - for (unsigned int i = 0; i < cv->size(); i++) { + for (int i = 0; i < command->count(); i++) { QListWidgetItem *item = new QListWidgetItem(); - item->setData(Qt::DisplayRole, (*cv)[i].c_str()); + item->setData(Qt::DisplayRole, (*command)[i]->c_str()); item->setData(Qt::UserRole + 1, counter++); fListWidget.addItem(item); } } -void SkDebuggerGUI::setupComboBox(std::vector* cv) { +void SkDebuggerGUI::setupComboBox(SkTDArray* command) { fFilter.clear(); fFilter.addItem("--Filter By Available Commands--"); std::map map; - for (unsigned int i = 0; i < cv->size(); i++) { - map[(*cv)[i]]++; + for (int i = 0; i < command->count(); i++) { + map[(*command)[i]->c_str()]++; } QString overview; diff --git a/debugger/QT/SkDebuggerGUI.h b/debugger/QT/SkDebuggerGUI.h index 763f4be..f460067 100644 --- a/debugger/QT/SkDebuggerGUI.h +++ b/debugger/QT/SkDebuggerGUI.h @@ -278,12 +278,12 @@ private: /** Populates the list widget with the vector of strings passed in. */ - void setupListWidget(std::vector* cv); + void setupListWidget(SkTDArray* command); /** Populates the combo box widget with the vector of strings passed in. */ - void setupComboBox(std::vector* cv); + void setupComboBox(SkTDArray* command); /** Updates the directory widget with the latest directory path stored in diff --git a/debugger/SkDebugCanvas.cpp b/debugger/SkDebugCanvas.cpp index 64444bb..59f982a 100644 --- a/debugger/SkDebugCanvas.cpp +++ b/debugger/SkDebugCanvas.cpp @@ -24,25 +24,22 @@ SkDebugCanvas::SkDebugCanvas(int width, int height) { } SkDebugCanvas::~SkDebugCanvas() { - for (int i = 0; i < commandVector.size(); i++) { - delete(commandVector[i]); - } - commandVector.clear(); + commandVector.deleteAll(); } void SkDebugCanvas::addDrawCommand(SkDrawCommand* command) { - commandVector.push_back(command); + commandVector.push(command); } void SkDebugCanvas::draw(SkCanvas* canvas) { - if(!commandVector.empty()) { - for(it = commandVector.begin(); it != commandVector.end(); ++it) { - if ((*it)->isVisible()) { - (*it)->execute(canvas); + if(!commandVector.isEmpty()) { + for (int i = 0; i < commandVector.count(); i++) { + if (commandVector[i]->isVisible()) { + commandVector[i]->execute(canvas); } } } - fIndex = commandVector.size() - 1; + fIndex = commandVector.count() - 1; } void SkDebugCanvas::applyUserTransform(SkCanvas* canvas) { @@ -79,8 +76,8 @@ int SkDebugCanvas::getCommandAtPoint(int x, int y, int index) { void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) { int counter = 0; - SkASSERT(!commandVector.empty()); - SkASSERT(index < (int)commandVector.size()); + SkASSERT(!commandVector.isEmpty()); + SkASSERT(index < commandVector.count()); int i; // This only works assuming the canvas and device are the same ones that @@ -120,30 +117,30 @@ void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) { } SkDrawCommand* SkDebugCanvas::getDrawCommandAt(int index) { - SkASSERT(index < (int)commandVector.size()); + SkASSERT(index < commandVector.count()); return commandVector[index]; } -std::vector* SkDebugCanvas::getCommandInfo(int index) { - SkASSERT(index < (int)commandVector.size()); +SkTDArray* SkDebugCanvas::getCommandInfo(int index) { + SkASSERT(index < commandVector.count()); return commandVector[index]->Info(); } bool SkDebugCanvas::getDrawCommandVisibilityAt(int index) { - SkASSERT(index < (int)commandVector.size()); + SkASSERT(index < commandVector.count()); return commandVector[index]->isVisible(); } -std::vector SkDebugCanvas::getDrawCommands() { +SkTDArray SkDebugCanvas::getDrawCommands() { return commandVector; } // TODO(chudy): Free command string memory. -std::vector* SkDebugCanvas::getDrawCommandsAsStrings() { - std::vector* commandString = new std::vector(); - if (!commandVector.empty()) { - for(it = commandVector.begin(); it != commandVector.end(); ++it) { - commandString->push_back((*it)->toString()); +SkTDArray* SkDebugCanvas::getDrawCommandsAsStrings() { + SkTDArray* commandString = new SkTDArray(); + if (!commandVector.isEmpty()) { + for (int i = 0; i < commandVector.count(); i ++) { + commandString->push(new SkString(commandVector[i]->toString())); } } return commandString; @@ -296,6 +293,6 @@ bool SkDebugCanvas::translate(SkScalar dx, SkScalar dy) { } void SkDebugCanvas::toggleCommand(int index, bool toggle) { - SkASSERT(index < (int)commandVector.size()); + SkASSERT(index < commandVector.count()); commandVector[index]->setVisible(toggle); } diff --git a/debugger/SkDebugCanvas.h b/debugger/SkDebugCanvas.h index 7a83390..2834010 100644 --- a/debugger/SkDebugCanvas.h +++ b/debugger/SkDebugCanvas.h @@ -13,7 +13,8 @@ #include "SkCanvas.h" #include "SkDrawCommand.h" #include "SkPicture.h" -#include +#include "SkTDArray.h" +#include "SkString.h" class SkDebugCanvas : public SkCanvas { public: @@ -73,7 +74,7 @@ public: Returns information about the command at the given index. @param index The index of the command */ - std::vector* getCommandInfo(int index); + SkTDArray* getCommandInfo(int index); /** Returns the visibility of the command at the given index. @@ -84,18 +85,18 @@ public: /** Returns the vector of draw commands */ - std::vector getDrawCommands(); + SkTDArray getDrawCommands(); /** * Returns the string vector of draw commands */ - std::vector* getDrawCommandsAsStrings(); + SkTDArray* getDrawCommandsAsStrings(); /** Returns length of draw command vector. */ int getSize() { - return commandVector.size(); + return commandVector.count(); } /** @@ -196,8 +197,7 @@ public: private: typedef SkCanvas INHERITED; - std::vector commandVector; - std::vector::const_iterator it; + SkTDArray commandVector; int fHeight; int fWidth; SkBitmap fBm; diff --git a/debugger/SkDebugger.h b/debugger/SkDebugger.h index eb724f3..67fa6a0 100644 --- a/debugger/SkDebugger.h +++ b/debugger/SkDebugger.h @@ -41,8 +41,7 @@ public: fDebugCanvas->toggleCommand(index, isVisible); } - // TODO(chudy): Replace with SkTDArray - std::vector* getDrawCommands() { + SkTDArray* getDrawCommands() { return fDebugCanvas->getDrawCommandsAsStrings(); } @@ -75,7 +74,7 @@ public: return fDebugCanvas->getCommandAtPoint(x, y, index); } - std::vector* getCommandInfo(int index) { + SkTDArray* getCommandInfo(int index) { return fDebugCanvas->getCommandInfo(index); } diff --git a/debugger/SkDrawCommand.cpp b/debugger/SkDrawCommand.cpp index 5844049..83b0719 100644 --- a/debugger/SkDrawCommand.cpp +++ b/debugger/SkDrawCommand.cpp @@ -7,9 +7,6 @@ */ -#include -#include -#include #include "SkDrawCommand.h" #include "SkObjectParser.h" @@ -20,6 +17,7 @@ SkDrawCommand::SkDrawCommand() { } SkDrawCommand::~SkDrawCommand() { + fInfo.deleteAll(); } const char* SkDrawCommand::GetCommandString(DrawType type) { @@ -63,16 +61,14 @@ const char* SkDrawCommand::GetCommandString(DrawType type) { return NULL; } -std::string SkDrawCommand::toString() { - std::stringstream ss; - ss << GetCommandString(fDrawType); - return ss.str(); +SkString SkDrawCommand::toString() { + return SkString(GetCommandString(fDrawType)); } Clear::Clear(SkColor color) { this->fColor = color; this->fDrawType = DRAW_CLEAR; - this->fInfo.push_back(std::string("No Parameters")); + this->fInfo.push(SkObjectParser::CustomTextToString("No Parameters")); } void Clear::execute(SkCanvas* canvas) { @@ -85,9 +81,9 @@ ClipPath::ClipPath(const SkPath& path, SkRegion::Op op, bool doAA) { this->fDoAA = doAA; this->fDrawType = CLIP_PATH; - this->fInfo.push_back(SkObjectParser::PathToString(path)); - this->fInfo.push_back(SkObjectParser::RegionOpToString(op)); - this->fInfo.push_back(SkObjectParser::BoolToString(doAA)); + this->fInfo.push(SkObjectParser::PathToString(path)); + this->fInfo.push(SkObjectParser::RegionOpToString(op)); + this->fInfo.push(SkObjectParser::BoolToString(doAA)); } void ClipPath::execute(SkCanvas* canvas) { @@ -99,8 +95,8 @@ ClipRegion::ClipRegion(const SkRegion& region, SkRegion::Op op) { this->fOp = op; this->fDrawType = CLIP_REGION; - this->fInfo.push_back(SkObjectParser::RegionToString(region)); - this->fInfo.push_back(SkObjectParser::RegionOpToString(op)); + this->fInfo.push(SkObjectParser::RegionToString(region)); + this->fInfo.push(SkObjectParser::RegionOpToString(op)); } void ClipRegion::execute(SkCanvas* canvas) { @@ -113,9 +109,9 @@ ClipRect::ClipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { this->fDoAA = doAA; this->fDrawType = CLIP_RECT; - this->fInfo.push_back(SkObjectParser::RectToString(rect)); - this->fInfo.push_back(SkObjectParser::RegionOpToString(op)); - this->fInfo.push_back(SkObjectParser::BoolToString(doAA)); + this->fInfo.push(SkObjectParser::RectToString(rect)); + this->fInfo.push(SkObjectParser::RegionOpToString(op)); + this->fInfo.push(SkObjectParser::BoolToString(doAA)); } void ClipRect::execute(SkCanvas* canvas) { @@ -126,7 +122,7 @@ Concat::Concat(const SkMatrix& matrix) { this->fMatrix = &matrix; this->fDrawType = CONCAT; - this->fInfo.push_back(SkObjectParser::MatrixToString(matrix)); + this->fInfo.push(SkObjectParser::MatrixToString(matrix)); } void Concat::execute(SkCanvas* canvas) { @@ -141,9 +137,9 @@ DrawBitmap::DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, this->fPaint = paint; this->fDrawType = DRAW_BITMAP; - this->fInfo.push_back(SkObjectParser::BitmapToString(bitmap)); - this->fInfo.push_back(SkObjectParser::ScalarToString(left, "SkScalar left: ")); - this->fInfo.push_back(SkObjectParser::ScalarToString(top, "SkScalar top: ")); + this->fInfo.push(SkObjectParser::BitmapToString(bitmap)); + this->fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: ")); + this->fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: ")); } void DrawBitmap::execute(SkCanvas* canvas) { @@ -157,9 +153,9 @@ DrawBitmapMatrix::DrawBitmapMatrix(const SkBitmap& bitmap, this->fPaint = paint; this->fDrawType = DRAW_BITMAP_MATRIX; - this->fInfo.push_back(SkObjectParser::BitmapToString(bitmap)); - this->fInfo.push_back(SkObjectParser::MatrixToString(matrix)); - if (paint) this->fInfo.push_back(SkObjectParser::PaintToString(*paint)); + this->fInfo.push(SkObjectParser::BitmapToString(bitmap)); + this->fInfo.push(SkObjectParser::MatrixToString(matrix)); + if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint)); } void DrawBitmapMatrix::execute(SkCanvas* canvas) { @@ -174,10 +170,10 @@ DrawBitmapNine::DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, this->fPaint = paint; this->fDrawType = DRAW_BITMAP_NINE; - this->fInfo.push_back(SkObjectParser::BitmapToString(bitmap)); - this->fInfo.push_back(SkObjectParser::IRectToString(center)); - this->fInfo.push_back(SkObjectParser::RectToString(dst)); - if (paint) this->fInfo.push_back(SkObjectParser::PaintToString(*paint)); + this->fInfo.push(SkObjectParser::BitmapToString(bitmap)); + this->fInfo.push(SkObjectParser::IRectToString(center)); + this->fInfo.push(SkObjectParser::RectToString(dst)); + if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint)); } void DrawBitmapNine::execute(SkCanvas* canvas) { @@ -192,10 +188,10 @@ DrawBitmapRect::DrawBitmapRect(const SkBitmap& bitmap, const SkIRect* src, this->fPaint = paint; this->fDrawType = DRAW_BITMAP_RECT; - this->fInfo.push_back(SkObjectParser::BitmapToString(bitmap)); - if (src) this->fInfo.push_back(SkObjectParser::IRectToString(*src)); - this->fInfo.push_back(SkObjectParser::RectToString(dst)); - if (paint) this->fInfo.push_back(SkObjectParser::PaintToString(*paint)); + this->fInfo.push(SkObjectParser::BitmapToString(bitmap)); + if (src) this->fInfo.push(SkObjectParser::IRectToString(*src)); + this->fInfo.push(SkObjectParser::RectToString(dst)); + if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint)); } void DrawBitmapRect::execute(SkCanvas* canvas) { @@ -217,7 +213,7 @@ DrawPaint::DrawPaint(const SkPaint& paint) { this->fPaint = &paint; this->fDrawType = DRAW_PAINT; - this->fInfo.push_back(SkObjectParser::PaintToString(paint)); + this->fInfo.push(SkObjectParser::PaintToString(paint)); } void DrawPaint::execute(SkCanvas* canvas) { @@ -229,8 +225,8 @@ DrawPath::DrawPath(const SkPath& path, const SkPaint& paint) { this->fPaint = &paint; this->fDrawType = DRAW_PATH; - this->fInfo.push_back(SkObjectParser::PathToString(path)); - this->fInfo.push_back(SkObjectParser::PaintToString(paint)); + this->fInfo.push(SkObjectParser::PathToString(path)); + this->fInfo.push(SkObjectParser::PaintToString(paint)); } void DrawPath::execute(SkCanvas* canvas) { @@ -240,7 +236,7 @@ void DrawPath::execute(SkCanvas* canvas) { DrawPicture::DrawPicture(SkPicture& picture) { this->fPicture = &picture; this->fDrawType = DRAW_PICTURE; - this->fInfo.push_back(std::string("Data unavailable. To be implemented")); + this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented.")); } void DrawPicture::execute(SkCanvas* canvas) { @@ -255,9 +251,9 @@ DrawPoints::DrawPoints(SkCanvas::PointMode mode, size_t count, this->fPaint = &paint; this->fDrawType = DRAW_POINTS; - this->fInfo.push_back(SkObjectParser::PointsToString(pts, count)); - this->fInfo.push_back(SkObjectParser::ScalarToString(count, "Points: ")); - this->fInfo.push_back(SkObjectParser::PointModeToString(mode)); + this->fInfo.push(SkObjectParser::PointsToString(pts, count)); + this->fInfo.push(SkObjectParser::ScalarToString(count, "Points: ")); + this->fInfo.push(SkObjectParser::PointModeToString(mode)); } void DrawPoints::execute(SkCanvas* canvas) { @@ -272,10 +268,10 @@ DrawPosText::DrawPosText(const void* text, size_t byteLength, const SkPoint pos[ this->fPaint = &paint; this->fDrawType = DRAW_POS_TEXT; - this->fInfo.push_back(SkObjectParser::TextToString(text, byteLength)); + this->fInfo.push(SkObjectParser::TextToString(text, byteLength)); // TODO(chudy): Test that this works. - this->fInfo.push_back(SkObjectParser::PointsToString(pos, 1)); - this->fInfo.push_back(SkObjectParser::PaintToString(paint)); + this->fInfo.push(SkObjectParser::PointsToString(pos, 1)); + this->fInfo.push(SkObjectParser::PaintToString(paint)); } void DrawPosText::execute(SkCanvas* canvas) { @@ -292,10 +288,10 @@ DrawPosTextH::DrawPosTextH(const void* text, size_t byteLength, this->fPaint = &paint; this->fDrawType = DRAW_POS_TEXT_H; - this->fInfo.push_back(SkObjectParser::TextToString(text, byteLength)); - this->fInfo.push_back(SkObjectParser::ScalarToString(xpos[0], "XPOS: ")); - this->fInfo.push_back(SkObjectParser::ScalarToString(constY, "SkScalar constY: ")); - this->fInfo.push_back(SkObjectParser::PaintToString(paint)); + this->fInfo.push(SkObjectParser::TextToString(text, byteLength)); + this->fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: ")); + this->fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: ")); + this->fInfo.push(SkObjectParser::PaintToString(paint)); } void DrawPosTextH::execute(SkCanvas* canvas) { @@ -308,8 +304,8 @@ DrawRectC::DrawRectC(const SkRect& rect, const SkPaint& paint) { this->fPaint = &paint; this->fDrawType = DRAW_RECT; - this->fInfo.push_back(SkObjectParser::RectToString(rect)); - this->fInfo.push_back(SkObjectParser::PaintToString(paint)); + this->fInfo.push(SkObjectParser::RectToString(rect)); + this->fInfo.push(SkObjectParser::PaintToString(paint)); } void DrawRectC::execute(SkCanvas* canvas) { @@ -324,9 +320,9 @@ DrawSprite::DrawSprite(const SkBitmap& bitmap, int left, int top, this->fPaint = paint; this->fDrawType = DRAW_SPRITE; - this->fInfo.push_back(SkObjectParser::BitmapToString(bitmap)); - this->fInfo.push_back(SkObjectParser::IntToString(left, "Left: ")); - this->fInfo.push_back(SkObjectParser::IntToString(top, "Top: ")); + this->fInfo.push(SkObjectParser::BitmapToString(bitmap)); + this->fInfo.push(SkObjectParser::IntToString(left, "Left: ")); + this->fInfo.push(SkObjectParser::IntToString(top, "Top: ")); } void DrawSprite::execute(SkCanvas* canvas) { @@ -342,10 +338,10 @@ DrawTextC::DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y this->fPaint = &paint; this->fDrawType = DRAW_TEXT; - this->fInfo.push_back(SkObjectParser::TextToString(text, byteLength)); - this->fInfo.push_back(SkObjectParser::ScalarToString(x, "SkScalar x: ")); - this->fInfo.push_back(SkObjectParser::ScalarToString(y, "SkScalar y: ")); - this->fInfo.push_back(SkObjectParser::PaintToString(paint)); + this->fInfo.push(SkObjectParser::TextToString(text, byteLength)); + this->fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: ")); + this->fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: ")); + this->fInfo.push(SkObjectParser::PaintToString(paint)); } void DrawTextC::execute(SkCanvas* canvas) { @@ -361,10 +357,10 @@ DrawTextOnPath::DrawTextOnPath(const void* text, size_t byteLength, this->fPaint = &paint; this->fDrawType = DRAW_TEXT_ON_PATH; - this->fInfo.push_back(SkObjectParser::TextToString(text, byteLength)); - this->fInfo.push_back(SkObjectParser::PathToString(path)); - if (matrix) this->fInfo.push_back(SkObjectParser::MatrixToString(*matrix)); - this->fInfo.push_back(SkObjectParser::PaintToString(paint)); + this->fInfo.push(SkObjectParser::TextToString(text, byteLength)); + this->fInfo.push(SkObjectParser::PathToString(path)); + if (matrix) this->fInfo.push(SkObjectParser::MatrixToString(*matrix)); + this->fInfo.push(SkObjectParser::PaintToString(paint)); } void DrawTextOnPath::execute(SkCanvas* canvas) { @@ -386,7 +382,7 @@ DrawVertices::DrawVertices(SkCanvas::VertexMode vmode, int vertexCount, this->fPaint = &paint; this->fDrawType = DRAW_VERTICES; // TODO(chudy) - this->fInfo.push_back(std::string("To be implemented")); + this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented.")); } void DrawVertices::execute(SkCanvas* canvas) { @@ -397,7 +393,7 @@ void DrawVertices::execute(SkCanvas* canvas) { Restore::Restore() { this->fDrawType = RESTORE; - this->fInfo.push_back(std::string("No Parameters")); + this->fInfo.push(SkObjectParser::CustomTextToString("No Parameters")); } void Restore::execute(SkCanvas* canvas) { @@ -408,7 +404,7 @@ Rotate::Rotate(SkScalar degrees) { this->fDegrees = degrees; this->fDrawType = ROTATE; - this->fInfo.push_back(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: ")); + this->fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: ")); } void Rotate::execute(SkCanvas* canvas) { @@ -418,8 +414,7 @@ void Rotate::execute(SkCanvas* canvas) { Save::Save(SkCanvas::SaveFlags flags) { this->fFlags = flags; this->fDrawType = SAVE; - - this->fInfo.push_back(SkObjectParser::SaveFlagsToString(flags)); + this->fInfo.push(SkObjectParser::SaveFlagsToString(flags)); } void Save::execute(SkCanvas* canvas) { @@ -433,9 +428,9 @@ SaveLayer::SaveLayer(const SkRect* bounds, const SkPaint* paint, this->fFlags = flags; this->fDrawType = SAVE_LAYER; - if (bounds) this->fInfo.push_back(SkObjectParser::RectToString(*bounds)); - if (paint) this->fInfo.push_back(SkObjectParser::PaintToString(*paint)); - this->fInfo.push_back(SkObjectParser::SaveFlagsToString(flags)); + if (bounds) this->fInfo.push(SkObjectParser::RectToString(*bounds)); + if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint)); + this->fInfo.push(SkObjectParser::SaveFlagsToString(flags)); } void SaveLayer::execute(SkCanvas* canvas) { @@ -447,8 +442,8 @@ Scale::Scale(SkScalar sx, SkScalar sy) { this->fSy = sy; this->fDrawType = SCALE; - this->fInfo.push_back(SkObjectParser::ScalarToString(sx, "SkScalar sx: ")); - this->fInfo.push_back(SkObjectParser::ScalarToString(sy, "SkScalar sy: ")); + this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: ")); + this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: ")); } void Scale::execute(SkCanvas* canvas) { @@ -459,7 +454,7 @@ SetMatrix::SetMatrix(const SkMatrix& matrix) { this->fMatrix = &matrix; this->fDrawType = SET_MATRIX; - this->fInfo.push_back(SkObjectParser::MatrixToString(matrix)); + this->fInfo.push(SkObjectParser::MatrixToString(matrix)); } void SetMatrix::execute(SkCanvas* canvas) { @@ -471,8 +466,8 @@ Skew::Skew(SkScalar sx, SkScalar sy) { this->fSy = sy; this->fDrawType = SKEW; - this->fInfo.push_back(SkObjectParser::ScalarToString(sx, "SkScalar sx: ")); - this->fInfo.push_back(SkObjectParser::ScalarToString(sy, "SkScalar sy: ")); + this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: ")); + this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: ")); } void Skew::execute(SkCanvas* canvas) { @@ -484,8 +479,8 @@ Translate::Translate(SkScalar dx, SkScalar dy) { this->fDy = dy; this->fDrawType = TRANSLATE; - this->fInfo.push_back(SkObjectParser::ScalarToString(dx, "SkScalar dx: ")); - this->fInfo.push_back(SkObjectParser::ScalarToString(dy, "SkScalar dy: ")); + this->fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: ")); + this->fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: ")); } void Translate::execute(SkCanvas* canvas) { diff --git a/debugger/SkDrawCommand.h b/debugger/SkDrawCommand.h index f09dae9..33b735e 100644 --- a/debugger/SkDrawCommand.h +++ b/debugger/SkDrawCommand.h @@ -9,11 +9,8 @@ #ifndef SKDRAWCOMMAND_H_ #define SKDRAWCOMMAND_H_ -#include #include "SkPictureFlat.h" #include "SkCanvas.h" -#include -#include class SkDrawCommand { public: @@ -22,7 +19,7 @@ public: virtual ~SkDrawCommand(); - virtual std::string toString(); + virtual SkString toString(); virtual const char* toCString() { return GetCommandString(fDrawType); @@ -36,13 +33,13 @@ public: fVisible = toggle; } - std::vector* Info() {return &fInfo; }; + SkTDArray* Info() {return &fInfo; }; virtual void execute(SkCanvas* canvas)=0; DrawType getType() { return fDrawType; }; protected: DrawType fDrawType; - std::vector fInfo; + SkTDArray fInfo; private: bool fVisible; diff --git a/debugger/SkObjectParser.cpp b/debugger/SkObjectParser.cpp index 68774c2..af12083 100644 --- a/debugger/SkObjectParser.cpp +++ b/debugger/SkObjectParser.cpp @@ -10,189 +10,174 @@ /* TODO(chudy): Replace all std::strings with char */ -std::string SkObjectParser::BitmapToString(const SkBitmap& bitmap) { - const char* mBitmap("SkBitmap: Data unavailable"); +SkString* SkObjectParser::BitmapToString(const SkBitmap& bitmap) { + SkString* mBitmap = new SkString("SkBitmap: Data unavailable"); return mBitmap; } -std::string SkObjectParser::BoolToString(bool doAA) { +SkString* SkObjectParser::BoolToString(bool doAA) { + SkString* mBool = new SkString("Bool doAA: "); if (doAA) { - return "bool doAA: True"; + mBool->append("True"); } else { - return "bool doAA: False"; + mBool->append("False"); } + return mBool; } -std::string SkObjectParser::IntToString(int x, const char* text) { - std::stringstream ss; - ss << text << x; - return ss.str(); -} - -std::string SkObjectParser::IRectToString(const SkIRect& rect) { - std::stringstream ss; - ss << "SkIRect: "; - ss << "L: " << rect.left() << ","; - ss << "T: " << rect.top() << ","; - ss << "R: " << rect.right() << ","; - ss << "B: " << rect.bottom(); - return ss.str(); -} - -std::string SkObjectParser::MatrixToString(const SkMatrix& matrix) { - std::stringstream ss; - /* NOTE(chudy): Cleaner looking than loops. */ - /* TODO(chudy): Decide whether to remove html part in order to really - * seperate view / model. */ - ss << "SkMatrix:
("; - ss << matrix.get(0) << "), ("; - ss << matrix.get(1) << "), ("; - ss << matrix.get(2) << "),
("; - ss << matrix.get(3) << "), ("; - ss << matrix.get(4) << "), ("; - ss << matrix.get(5) << "),
("; - ss << matrix.get(6) << "), ("; - ss << matrix.get(7) << "), ("; - ss << matrix.get(8) << ")"; - return ss.str(); -} - -std::string SkObjectParser::PaintToString(const SkPaint& paint) { - std::stringstream ss; - SkColor color = paint.getColor(); - ss << "SkPaint: 0x" << std::hex << std::uppercase << color; - return ss.str(); +SkString* SkObjectParser::CustomTextToString(const char* text) { + SkString* mText = new SkString(text); + return mText; +} + +SkString* SkObjectParser::IntToString(int x, const char* text) { + SkString* mInt = new SkString(text); + mInt->append(" "); + mInt->appendScalar(SkIntToScalar(x)); + return mInt; } -std::string SkObjectParser::PathToString(const SkPath& path) { - std::string mPath; - std::stringstream ss; - mPath.append("SkPath: "); +SkString* SkObjectParser::IRectToString(const SkIRect& rect) { + SkString* mRect = new SkString("SkIRect: "); + mRect->append("L: "); + mRect->appendScalar(rect.left()); + mRect->append(", T: "); + mRect->appendScalar(rect.top()); + mRect->append(", R: "); + mRect->appendScalar(rect.right()); + mRect->append(", B: "); + mRect->appendScalar(rect.bottom()); + return mRect; +} - for (int i=0; iappendScalar(matrix.get(i)); + mMatrix->append("), ("); } + mMatrix->appendScalar(matrix.get(8)); + mMatrix->append(")"); + return mMatrix; +} +SkString* SkObjectParser::PaintToString(const SkPaint& paint) { + SkColor color = paint.getColor(); + SkString* mPaint = new SkString("SkPaint: 0x"); + mPaint->appendHex(color); + return mPaint; +} + +SkString* SkObjectParser::PathToString(const SkPath& path) { + SkString* mPath = new SkString("SkPath: "); + for (int i = 0; i < path.countPoints(); i++) { + mPath->append("("); + mPath->appendScalar(path.getPoint(i).fX); + mPath->append(", "); + mPath->appendScalar(path.getPoint(i).fY); + mPath->append(") "); + } return mPath; } -std::string SkObjectParser::PointsToString(const SkPoint pts[], size_t count) { - std::stringstream ss; - ss << "SkPoint pts[]: "; +SkString* SkObjectParser::PointsToString(const SkPoint pts[], size_t count) { + SkString* mPoints = new SkString("SkPoints pts[]: "); for (unsigned int i = 0; i < count; i++) { - ss << "(" << pts[i].fX << "," << pts[i].fY << ") "; + mPoints->append("("); + mPoints->appendScalar(pts[i].fX); + mPoints->append(","); + mPoints->appendScalar(pts[i].fY); + mPoints->append(")"); } - return ss.str(); + return mPoints; } -std::string SkObjectParser::PointModeToString(SkCanvas::PointMode mode) { - std::string mMode("SkCanvas::PointMode: "); +SkString* SkObjectParser::PointModeToString(SkCanvas::PointMode mode) { + SkString* mMode = new SkString("SkCanvas::PointMode: "); if (mode == SkCanvas::kPoints_PointMode) { - mMode.append("kPoints_PointMode"); + mMode->append("kPoints_PointMode"); } else if (mode == SkCanvas::kLines_PointMode) { - mMode.append("kLines_Mode"); + mMode->append("kLines_Mode"); } else if (mode == SkCanvas::kPolygon_PointMode) { - mMode.append("kPolygon_PointMode"); + mMode->append("kPolygon_PointMode"); } - return mMode; } -std::string SkObjectParser::RectToString(const SkRect& rect) { - std::string mRect("SkRect: "); - std::stringstream ss; - - mRect.append("("); - ss << rect.left(); - mRect.append(ss.str()); - - ss.str(""); - mRect.append(", "); - ss << rect.top(); - mRect.append(ss.str()); - - ss.str(""); - mRect.append(", "); - ss << rect.right(); - mRect.append(ss.str()); - - ss.str(""); - mRect.append(", "); - ss << rect.bottom(); - mRect.append(ss.str()); - mRect.append(")"); - +SkString* SkObjectParser::RectToString(const SkRect& rect) { + SkString* mRect = new SkString("SkRect: "); + mRect->append("("); + mRect->appendScalar(rect.left()); + mRect->append(", "); + mRect->appendScalar(rect.top()); + mRect->append(", "); + mRect->appendScalar(rect.right()); + mRect->append(", "); + mRect->appendScalar(rect.bottom()); + mRect->append(")"); return mRect; } -std::string SkObjectParser::RegionOpToString(SkRegion::Op op) { - std::string mOp("SkRegion::Op: "); - +SkString* SkObjectParser::RegionOpToString(SkRegion::Op op) { + SkString* mOp = new SkString("SkRegion::Op: "); if (op == SkRegion::kDifference_Op) { - mOp.append("kDifference_Op"); + mOp->append("kDifference_Op"); } else if (op == SkRegion::kIntersect_Op) { - mOp.append("kIntersect_Op"); + mOp->append("kIntersect_Op"); } else if (op == SkRegion::kUnion_Op) { - mOp.append("kUnion_Op"); + mOp->append("kUnion_Op"); } else if (op == SkRegion::kXOR_Op) { - mOp.append("kXOR_Op"); + mOp->append("kXOR_Op"); } else if (op == SkRegion::kReverseDifference_Op) { - mOp.append("kReverseDifference_Op"); + mOp->append("kReverseDifference_Op"); } else if (op == SkRegion::kReplace_Op) { - mOp.append("kReplace_Op"); + mOp->append("kReplace_Op"); } else { - mOp.append("Unknown Type"); + mOp->append("Unknown Type"); } - return mOp; } -std::string SkObjectParser::RegionToString(const SkRegion& region) { - return "SkRegion: Data unavailable."; +SkString* SkObjectParser::RegionToString(const SkRegion& region) { + SkString* mRegion = new SkString("SkRegion: Data unavailable."); + return mRegion; } -std::string SkObjectParser::SaveFlagsToString(SkCanvas::SaveFlags flags) { - std::string mFlags; - mFlags.append("SkCanvas::SaveFlags: "); - +SkString* SkObjectParser::SaveFlagsToString(SkCanvas::SaveFlags flags) { + SkString* mFlags = new SkString("SkCanvas::SaveFlags: "); if(flags == SkCanvas::kMatrixClip_SaveFlag) { - mFlags.append("kMatrixClip_SaveFlag"); + mFlags->append("kMatrixClip_SaveFlag"); } else if (flags == SkCanvas::kClip_SaveFlag) { - mFlags.append("kClip_SaveFlag"); + mFlags->append("kClip_SaveFlag"); } else if (flags == SkCanvas::kHasAlphaLayer_SaveFlag) { - mFlags.append("kHasAlphaLayer_SaveFlag"); + mFlags->append("kHasAlphaLayer_SaveFlag"); } else if (flags == SkCanvas::kFullColorLayer_SaveFlag) { - mFlags.append("kFullColorLayer_SaveFlag"); + mFlags->append("kFullColorLayer_SaveFlag"); } else if (flags == SkCanvas::kClipToLayer_SaveFlag) { - mFlags.append("kClipToLayer_SaveFlag"); + mFlags->append("kClipToLayer_SaveFlag"); } else if (flags == SkCanvas::kMatrixClip_SaveFlag) { - mFlags.append("kMatrixClip_SaveFlag"); + mFlags->append("kMatrixClip_SaveFlag"); } else if (flags == SkCanvas::kARGB_NoClipLayer_SaveFlag) { - mFlags.append("kARGB_NoClipLayer_SaveFlag"); + mFlags->append("kARGB_NoClipLayer_SaveFlag"); } else if (flags == SkCanvas::kARGB_ClipLayer_SaveFlag) { - mFlags.append("kARGB_ClipLayer_SaveFlag"); + mFlags->append("kARGB_ClipLayer_SaveFlag"); } else { - mFlags.append("Data Unavailable"); + mFlags->append("Data Unavailable"); } - return mFlags; } -std::string SkObjectParser::ScalarToString(SkScalar x, const char* text) { - std::string mScalar; - mScalar.append(text); - - std::stringstream ss; - ss << x; - mScalar.append(ss.str()); +SkString* SkObjectParser::ScalarToString(SkScalar x, const char* text) { + SkString* mScalar = new SkString(text); + mScalar->append(" "); + mScalar->appendScalar(x); return mScalar; } -std::string SkObjectParser::TextToString(const void* text, size_t byteLength) { +SkString* SkObjectParser::TextToString(const void* text, size_t byteLength) { char result[6+byteLength]; strcpy(result,"Text: "); strcat(result, (char*)text); - return result; + SkString* mText = new SkString(result); + return mText; } diff --git a/debugger/SkObjectParser.h b/debugger/SkObjectParser.h index f08ca08..16cd623 100644 --- a/debugger/SkObjectParser.h +++ b/debugger/SkObjectParser.h @@ -10,9 +10,8 @@ #ifndef SKOBJECTPARSER_H_ #define SKOBJECTPARSER_H_ -#include -#include #include "SkCanvas.h" +#include "SkString.h" /** \class SkObjectParser The ObjectParser is used to return string information about parameters @@ -26,13 +25,18 @@ public: Returns a string about a bitmaps bounds and config. @param bitmap SkBitmap */ - static std::string BitmapToString(const SkBitmap& bitmap); + static SkString* BitmapToString(const SkBitmap& bitmap); /** Returns a string representation of a boolean. @param doAA boolean */ - static std::string BoolToString(bool doAA); + static SkString* BoolToString(bool doAA); + + /** + Returns a string representation of the text pointer passed in. + */ + static SkString* CustomTextToString(const char* text); /** Returns a string representation of an integer with the text parameter @@ -40,66 +44,66 @@ public: @param x integer @param text */ - static std::string IntToString(int x, const char* text); + static SkString* IntToString(int x, const char* text); /** Returns a string representation of the SkIRects coordinates. @param rect SkIRect */ - static std::string IRectToString(const SkIRect& rect); + static SkString* IRectToString(const SkIRect& rect); /** Returns a string representation of an SkMatrix's contents @param matrix SkMatrix */ - static std::string MatrixToString(const SkMatrix& matrix); + static SkString* MatrixToString(const SkMatrix& matrix); /** Returns a string representation of an SkPaint's color @param paint SkPaint */ - static std::string PaintToString(const SkPaint& paint); + static SkString* PaintToString(const SkPaint& paint); /** Returns a string representation of a SkPath's points. @param path SkPath */ - static std::string PathToString(const SkPath& path); + static SkString* PathToString(const SkPath& path); /** Returns a string representation of the points in the point array. @param pts[] Array of SkPoints @param count */ - static std::string PointsToString(const SkPoint pts[], size_t count); + static SkString* PointsToString(const SkPoint pts[], size_t count); /** Returns a string representation of the SkCanvas PointMode enum. */ - static std::string PointModeToString(SkCanvas::PointMode mode); + static SkString* PointModeToString(SkCanvas::PointMode mode); /** Returns a string representation of the SkRects coordinates. @param rect SkRect */ - static std::string RectToString(const SkRect& rect); + static SkString* RectToString(const SkRect& rect); /** Returns a string representation of the SkRegion enum. @param op SkRegion::op enum */ - static std::string RegionOpToString(SkRegion::Op op); + static SkString* RegionOpToString(SkRegion::Op op); /** Returns a string representation of the SkRegion. @param region SkRegion */ - static std::string RegionToString(const SkRegion& region); + static SkString* RegionToString(const SkRegion& region); /** Returns a string representation of the SkCanvas::SaveFlags enum. @param flags SkCanvas::SaveFlags enum */ - static std::string SaveFlagsToString(SkCanvas::SaveFlags flags); + static SkString* SaveFlagsToString(SkCanvas::SaveFlags flags); /** Returns a string representation of an SkScalar with the text parameter @@ -107,13 +111,13 @@ public: @param x SkScalar @param text */ - static std::string ScalarToString(SkScalar x, const char* text); + static SkString* ScalarToString(SkScalar x, const char* text); /** Returns a string representation of the char pointer passed in. @param text const void* that will be cast to a char* */ - static std::string TextToString(const void* text, size_t byteLength); + static SkString* TextToString(const void* text, size_t byteLength); }; #endif