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
This commit is contained in:
chudy@google.com 2012-08-07 20:41:37 +00:00
parent 21830d9009
commit 97cee97353
9 changed files with 267 additions and 290 deletions

View File

@ -293,18 +293,17 @@ void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
if (!fPause) {
fCanvasWidget.drawTo(currentRow);
}
std::vector<std::string> *cuffInfo = fDebugger.getCommandInfo(
SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(
currentRow);
/* TODO(chudy): Add command type before parameters. Rename v
* to something more informative. */
if (cuffInfo) {
std::vector<std::string>::iterator it;
if (currInfo) {
QString info;
info.append("<b>Parameters: </b><br/>");
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("<br/>");
}
fInspectorWidget.setDetailText(info);
@ -576,7 +575,8 @@ void SkDebuggerGUI::loadPicture(QString fileName) {
SkSafeUnref(stream);
SkSafeUnref(picture);
std::vector<std::string> *cv = fDebugger.getDrawCommands();
// Will this automatically clear out due to nature of refcnt?
SkTDArray<SkString*>* 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<std::string>* cv) {
void SkDebuggerGUI::setupListWidget(SkTDArray<SkString*>* 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<std::string>* cv) {
void SkDebuggerGUI::setupComboBox(SkTDArray<SkString*>* command) {
fFilter.clear();
fFilter.addItem("--Filter By Available Commands--");
std::map<std::string, int> 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;

View File

@ -278,12 +278,12 @@ private:
/**
Populates the list widget with the vector of strings passed in.
*/
void setupListWidget(std::vector<std::string>* cv);
void setupListWidget(SkTDArray<SkString*>* command);
/**
Populates the combo box widget with the vector of strings passed in.
*/
void setupComboBox(std::vector<std::string>* cv);
void setupComboBox(SkTDArray<SkString*>* command);
/**
Updates the directory widget with the latest directory path stored in

View File

@ -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<std::string>* SkDebugCanvas::getCommandInfo(int index) {
SkASSERT(index < (int)commandVector.size());
SkTDArray<SkString*>* 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<SkDrawCommand*> SkDebugCanvas::getDrawCommands() {
SkTDArray <SkDrawCommand*> SkDebugCanvas::getDrawCommands() {
return commandVector;
}
// TODO(chudy): Free command string memory.
std::vector<std::string>* SkDebugCanvas::getDrawCommandsAsStrings() {
std::vector<std::string>* commandString = new std::vector<std::string>();
if (!commandVector.empty()) {
for(it = commandVector.begin(); it != commandVector.end(); ++it) {
commandString->push_back((*it)->toString());
SkTDArray<SkString*>* SkDebugCanvas::getDrawCommandsAsStrings() {
SkTDArray<SkString*>* commandString = new SkTDArray<SkString*>();
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);
}

View File

@ -13,7 +13,8 @@
#include "SkCanvas.h"
#include "SkDrawCommand.h"
#include "SkPicture.h"
#include <vector>
#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<std::string>* getCommandInfo(int index);
SkTDArray<SkString*>* 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<SkDrawCommand*> getDrawCommands();
SkTDArray<SkDrawCommand*> getDrawCommands();
/**
* Returns the string vector of draw commands
*/
std::vector<std::string>* getDrawCommandsAsStrings();
SkTDArray<SkString*>* 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<SkDrawCommand*> commandVector;
std::vector<SkDrawCommand*>::const_iterator it;
SkTDArray<SkDrawCommand*> commandVector;
int fHeight;
int fWidth;
SkBitmap fBm;

View File

@ -41,8 +41,7 @@ public:
fDebugCanvas->toggleCommand(index, isVisible);
}
// TODO(chudy): Replace with SkTDArray
std::vector<std::string>* getDrawCommands() {
SkTDArray<SkString*>* getDrawCommands() {
return fDebugCanvas->getDrawCommandsAsStrings();
}
@ -75,7 +74,7 @@ public:
return fDebugCanvas->getCommandAtPoint(x, y, index);
}
std::vector<std::string>* getCommandInfo(int index) {
SkTDArray<SkString*>* getCommandInfo(int index) {
return fDebugCanvas->getCommandInfo(index);
}

View File

@ -7,9 +7,6 @@
*/
#include <cstring>
#include <iostream>
#include <string>
#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) {

View File

@ -9,11 +9,8 @@
#ifndef SKDRAWCOMMAND_H_
#define SKDRAWCOMMAND_H_
#include <iostream>
#include "SkPictureFlat.h"
#include "SkCanvas.h"
#include <sstream>
#include <vector>
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<std::string>* Info() {return &fInfo; };
SkTDArray<SkString*>* Info() {return &fInfo; };
virtual void execute(SkCanvas* canvas)=0;
DrawType getType() { return fDrawType; };
protected:
DrawType fDrawType;
std::vector<std::string> fInfo;
SkTDArray<SkString*> fInfo;
private:
bool fVisible;

View File

@ -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();
SkString* SkObjectParser::CustomTextToString(const char* text) {
SkString* mText = new SkString(text);
return mText;
}
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();
SkString* SkObjectParser::IntToString(int x, const char* text) {
SkString* mInt = new SkString(text);
mInt->append(" ");
mInt->appendScalar(SkIntToScalar(x));
return mInt;
}
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:<br/>(";
ss << matrix.get(0) << "), (";
ss << matrix.get(1) << "), (";
ss << matrix.get(2) << "), <br/>(";
ss << matrix.get(3) << "), (";
ss << matrix.get(4) << "), (";
ss << matrix.get(5) << "), <br/>(";
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();
}
std::string SkObjectParser::PathToString(const SkPath& path) {
std::string mPath;
std::stringstream ss;
mPath.append("SkPath: ");
for (int i=0; i<path.countPoints(); i++) {
ss << "(" << path.getPoint(i).fX << ", " << path.getPoint(i).fY << ") ";
mPath.append(ss.str());
ss.str("");
}
return mPath;
}
std::string SkObjectParser::PointsToString(const SkPoint pts[], size_t count) {
std::stringstream ss;
ss << "SkPoint pts[]: ";
for (unsigned int i = 0; i < count; i++) {
ss << "(" << pts[i].fX << "," << pts[i].fY << ") ";
}
return ss.str();
}
std::string SkObjectParser::PointModeToString(SkCanvas::PointMode mode) {
std::string mMode("SkCanvas::PointMode: ");
if (mode == SkCanvas::kPoints_PointMode) {
mMode.append("kPoints_PointMode");
} else if (mode == SkCanvas::kLines_PointMode) {
mMode.append("kLines_Mode");
} else if (mode == SkCanvas::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::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;
}
std::string SkObjectParser::RegionOpToString(SkRegion::Op op) {
std::string mOp("SkRegion::Op: ");
if (op == SkRegion::kDifference_Op) {
mOp.append("kDifference_Op");
} else if (op == SkRegion::kIntersect_Op) {
mOp.append("kIntersect_Op");
} else if (op == SkRegion::kUnion_Op) {
mOp.append("kUnion_Op");
} else if (op == SkRegion::kXOR_Op) {
mOp.append("kXOR_Op");
} else if (op == SkRegion::kReverseDifference_Op) {
mOp.append("kReverseDifference_Op");
} else if (op == SkRegion::kReplace_Op) {
mOp.append("kReplace_Op");
} else {
mOp.append("Unknown Type");
SkString* SkObjectParser::MatrixToString(const SkMatrix& matrix) {
SkString* mMatrix = new SkString("SkMatrix: (");
for (int i = 0; i < 8; i++) {
mMatrix->appendScalar(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;
}
SkString* SkObjectParser::PointsToString(const SkPoint pts[], size_t count) {
SkString* mPoints = new SkString("SkPoints pts[]: ");
for (unsigned int i = 0; i < count; i++) {
mPoints->append("(");
mPoints->appendScalar(pts[i].fX);
mPoints->append(",");
mPoints->appendScalar(pts[i].fY);
mPoints->append(")");
}
return mPoints;
}
SkString* SkObjectParser::PointModeToString(SkCanvas::PointMode mode) {
SkString* mMode = new SkString("SkCanvas::PointMode: ");
if (mode == SkCanvas::kPoints_PointMode) {
mMode->append("kPoints_PointMode");
} else if (mode == SkCanvas::kLines_PointMode) {
mMode->append("kLines_Mode");
} else if (mode == SkCanvas::kPolygon_PointMode) {
mMode->append("kPolygon_PointMode");
}
return mMode;
}
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;
}
SkString* SkObjectParser::RegionOpToString(SkRegion::Op op) {
SkString* mOp = new SkString("SkRegion::Op: ");
if (op == SkRegion::kDifference_Op) {
mOp->append("kDifference_Op");
} else if (op == SkRegion::kIntersect_Op) {
mOp->append("kIntersect_Op");
} else if (op == SkRegion::kUnion_Op) {
mOp->append("kUnion_Op");
} else if (op == SkRegion::kXOR_Op) {
mOp->append("kXOR_Op");
} else if (op == SkRegion::kReverseDifference_Op) {
mOp->append("kReverseDifference_Op");
} else if (op == SkRegion::kReplace_Op) {
mOp->append("kReplace_Op");
} else {
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;
}

View File

@ -10,9 +10,8 @@
#ifndef SKOBJECTPARSER_H_
#define SKOBJECTPARSER_H_
#include <iostream>
#include <sstream>
#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