Fixed debugger for addition of drawRRect, clipRRect & drawOval
https://codereview.appspot.com/7035051/ git-svn-id: http://skia.googlecode.com/svn/trunk@6975 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
ad51430215
commit
67baba4892
@ -34,22 +34,22 @@ SkDebugCanvas::SkDebugCanvas(int width, int height)
|
||||
}
|
||||
|
||||
SkDebugCanvas::~SkDebugCanvas() {
|
||||
commandVector.deleteAll();
|
||||
fCommandVector.deleteAll();
|
||||
}
|
||||
|
||||
void SkDebugCanvas::addDrawCommand(SkDrawCommand* command) {
|
||||
commandVector.push(command);
|
||||
fCommandVector.push(command);
|
||||
}
|
||||
|
||||
void SkDebugCanvas::draw(SkCanvas* canvas) {
|
||||
if(!commandVector.isEmpty()) {
|
||||
for (int i = 0; i < commandVector.count(); i++) {
|
||||
if (commandVector[i]->isVisible()) {
|
||||
commandVector[i]->execute(canvas);
|
||||
if(!fCommandVector.isEmpty()) {
|
||||
for (int i = 0; i < fCommandVector.count(); i++) {
|
||||
if (fCommandVector[i]->isVisible()) {
|
||||
fCommandVector[i]->execute(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
fIndex = commandVector.count() - 1;
|
||||
fIndex = fCommandVector.count() - 1;
|
||||
}
|
||||
|
||||
void SkDebugCanvas::applyUserTransform(SkCanvas* canvas) {
|
||||
@ -74,8 +74,8 @@ int SkDebugCanvas::getCommandAtPoint(int x, int y, int index) {
|
||||
int layer = 0;
|
||||
SkColor prev = bitmap.getColor(0,0);
|
||||
for (int i = 0; i < index; i++) {
|
||||
if (commandVector[i]->isVisible()) {
|
||||
commandVector[i]->execute(&canvas);
|
||||
if (fCommandVector[i]->isVisible()) {
|
||||
fCommandVector[i]->execute(&canvas);
|
||||
}
|
||||
if (prev != bitmap.getColor(0,0)) {
|
||||
layer = i;
|
||||
@ -87,8 +87,8 @@ int SkDebugCanvas::getCommandAtPoint(int x, int y, int index) {
|
||||
|
||||
void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) {
|
||||
int counter = 0;
|
||||
SkASSERT(!commandVector.isEmpty());
|
||||
SkASSERT(index < commandVector.count());
|
||||
SkASSERT(!fCommandVector.isEmpty());
|
||||
SkASSERT(index < fCommandVector.count());
|
||||
int i;
|
||||
|
||||
// This only works assuming the canvas and device are the same ones that
|
||||
@ -125,9 +125,9 @@ void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) {
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
if (commandVector[i]->isVisible()) {
|
||||
commandVector[i]->execute(canvas);
|
||||
commandVector[i]->trackSaveState(&fOutstandingSaveCount);
|
||||
if (fCommandVector[i]->isVisible()) {
|
||||
fCommandVector[i]->execute(canvas);
|
||||
fCommandVector[i]->trackSaveState(&fOutstandingSaveCount);
|
||||
}
|
||||
}
|
||||
fMatrix = canvas->getTotalMatrix();
|
||||
@ -136,30 +136,30 @@ void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) {
|
||||
}
|
||||
|
||||
SkDrawCommand* SkDebugCanvas::getDrawCommandAt(int index) {
|
||||
SkASSERT(index < commandVector.count());
|
||||
return commandVector[index];
|
||||
SkASSERT(index < fCommandVector.count());
|
||||
return fCommandVector[index];
|
||||
}
|
||||
|
||||
SkTDArray<SkString*>* SkDebugCanvas::getCommandInfo(int index) {
|
||||
SkASSERT(index < commandVector.count());
|
||||
return commandVector[index]->Info();
|
||||
SkASSERT(index < fCommandVector.count());
|
||||
return fCommandVector[index]->Info();
|
||||
}
|
||||
|
||||
bool SkDebugCanvas::getDrawCommandVisibilityAt(int index) {
|
||||
SkASSERT(index < commandVector.count());
|
||||
return commandVector[index]->isVisible();
|
||||
SkASSERT(index < fCommandVector.count());
|
||||
return fCommandVector[index]->isVisible();
|
||||
}
|
||||
|
||||
const SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() const {
|
||||
return commandVector;
|
||||
return fCommandVector;
|
||||
}
|
||||
|
||||
// TODO(chudy): Free command string memory.
|
||||
SkTArray<SkString>* SkDebugCanvas::getDrawCommandsAsStrings() const {
|
||||
SkTArray<SkString>* commandString = new SkTArray<SkString>(commandVector.count());
|
||||
if (!commandVector.isEmpty()) {
|
||||
for (int i = 0; i < commandVector.count(); i ++) {
|
||||
commandString->push_back() = commandVector[i]->toString();
|
||||
SkTArray<SkString>* commandString = new SkTArray<SkString>(fCommandVector.count());
|
||||
if (!fCommandVector.isEmpty()) {
|
||||
for (int i = 0; i < fCommandVector.count(); i ++) {
|
||||
commandString->push_back() = fCommandVector[i]->toString();
|
||||
}
|
||||
}
|
||||
return commandString;
|
||||
@ -258,6 +258,11 @@ bool SkDebugCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkDebugCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
|
||||
addDrawCommand(new ClipRRect(rrect, op, doAA));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkDebugCanvas::clipRegion(const SkRegion& region, SkRegion::Op op) {
|
||||
addDrawCommand(new ClipRegion(region, op));
|
||||
return true;
|
||||
@ -296,6 +301,10 @@ void SkDebugCanvas::drawData(const void* data, size_t length) {
|
||||
addDrawCommand(new DrawData(data, length));
|
||||
}
|
||||
|
||||
void SkDebugCanvas::drawOval(const SkRect& oval, const SkPaint& paint) {
|
||||
addDrawCommand(new DrawOval(oval, paint));
|
||||
}
|
||||
|
||||
void SkDebugCanvas::drawPaint(const SkPaint& paint) {
|
||||
addDrawCommand(new DrawPaint(paint));
|
||||
}
|
||||
@ -329,6 +338,10 @@ void SkDebugCanvas::drawRect(const SkRect& rect, const SkPaint& paint) {
|
||||
addDrawCommand(new DrawRectC(rect, paint));
|
||||
}
|
||||
|
||||
void SkDebugCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
|
||||
addDrawCommand(new DrawRRect(rrect, paint));
|
||||
}
|
||||
|
||||
void SkDebugCanvas::drawSprite(const SkBitmap& bitmap, int left, int top,
|
||||
const SkPaint* paint = NULL) {
|
||||
SkBitmap resizedBitmap = createBitmap(bitmap, NULL);
|
||||
@ -393,6 +406,6 @@ bool SkDebugCanvas::translate(SkScalar dx, SkScalar dy) {
|
||||
}
|
||||
|
||||
void SkDebugCanvas::toggleCommand(int index, bool toggle) {
|
||||
SkASSERT(index < commandVector.count());
|
||||
commandVector[index]->setVisible(toggle);
|
||||
SkASSERT(index < fCommandVector.count());
|
||||
fCommandVector[index]->setVisible(toggle);
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ public:
|
||||
Returns length of draw command vector.
|
||||
*/
|
||||
int getSize() {
|
||||
return commandVector.count();
|
||||
return fCommandVector.count();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -128,6 +128,10 @@ public:
|
||||
|
||||
virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE;
|
||||
|
||||
virtual bool clipRRect(const SkRRect& rrect,
|
||||
SkRegion::Op op = SkRegion::kIntersect_Op,
|
||||
bool doAntiAlias = false) SK_OVERRIDE;
|
||||
|
||||
virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) SK_OVERRIDE;
|
||||
|
||||
virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
|
||||
@ -146,6 +150,8 @@ public:
|
||||
|
||||
virtual void drawData(const void*, size_t) SK_OVERRIDE;
|
||||
|
||||
virtual void drawOval(const SkRect& oval, const SkPaint&) SK_OVERRIDE;
|
||||
|
||||
virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
|
||||
|
||||
virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE;
|
||||
@ -159,10 +165,13 @@ public:
|
||||
const SkPoint pos[], const SkPaint&) SK_OVERRIDE;
|
||||
|
||||
virtual void drawPosTextH(const void* text, size_t byteLength,
|
||||
const SkScalar xpos[], SkScalar constY, const SkPaint&) SK_OVERRIDE;
|
||||
const SkScalar xpos[], SkScalar constY,
|
||||
const SkPaint&) SK_OVERRIDE;
|
||||
|
||||
virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE;
|
||||
|
||||
virtual void drawRRect(const SkRRect& rrect, const SkPaint& paint) SK_OVERRIDE;
|
||||
|
||||
virtual void drawSprite(const SkBitmap&, int left, int top,
|
||||
const SkPaint*) SK_OVERRIDE;
|
||||
|
||||
@ -170,13 +179,13 @@ public:
|
||||
SkScalar y, const SkPaint&) SK_OVERRIDE;
|
||||
|
||||
virtual void drawTextOnPath(const void* text, size_t byteLength,
|
||||
const SkPath& path, const SkMatrix* matrix,
|
||||
const SkPath& path, const SkMatrix* matrix,
|
||||
const SkPaint&) SK_OVERRIDE;
|
||||
|
||||
virtual void drawVertices(VertexMode, int vertexCount,
|
||||
const SkPoint vertices[], const SkPoint texs[],
|
||||
const SkColor colors[], SkXfermode*,
|
||||
const uint16_t indices[], int indexCount,
|
||||
const SkPoint vertices[], const SkPoint texs[],
|
||||
const SkColor colors[], SkXfermode*,
|
||||
const uint16_t indices[], int indexCount,
|
||||
const SkPaint&) SK_OVERRIDE;
|
||||
|
||||
virtual void restore() SK_OVERRIDE;
|
||||
@ -197,7 +206,7 @@ public:
|
||||
|
||||
private:
|
||||
typedef SkCanvas INHERITED;
|
||||
SkTDArray<SkDrawCommand*> commandVector;
|
||||
SkTDArray<SkDrawCommand*> fCommandVector;
|
||||
int fHeight;
|
||||
int fWidth;
|
||||
SkBitmap fBm;
|
||||
|
@ -27,12 +27,14 @@ const char* SkDrawCommand::GetCommandString(DrawType type) {
|
||||
case CLIP_PATH: return "Clip Path";
|
||||
case CLIP_REGION: return "Clip Region";
|
||||
case CLIP_RECT: return "Clip Rect";
|
||||
case CLIP_RRECT: return "Clip RRect";
|
||||
case CONCAT: return "Concat";
|
||||
case DRAW_BITMAP: return "Draw Bitmap";
|
||||
case DRAW_BITMAP_MATRIX: return "Draw Bitmap Matrix";
|
||||
case DRAW_BITMAP_NINE: return "Draw Bitmap Nine";
|
||||
case DRAW_BITMAP_RECT_TO_RECT: return "Draw Bitmap Rect";
|
||||
case DRAW_DATA: return "Draw Data";
|
||||
case DRAW_OVAL: return "Draw Oval";
|
||||
case DRAW_PAINT: return "Draw Paint";
|
||||
case DRAW_PATH: return "Draw Path";
|
||||
case DRAW_PICTURE: return "Draw Picture";
|
||||
@ -40,6 +42,7 @@ const char* SkDrawCommand::GetCommandString(DrawType type) {
|
||||
case DRAW_POS_TEXT: return "Draw Pos Text";
|
||||
case DRAW_POS_TEXT_H: return "Draw Pos Text H";
|
||||
case DRAW_RECT: return "Draw Rect";
|
||||
case DRAW_RRECT: return "Draw RRect";
|
||||
case DRAW_SPRITE: return "Draw Sprite";
|
||||
case DRAW_TEXT: return "Draw Text";
|
||||
case DRAW_TEXT_ON_PATH: return "Draw Text On Path";
|
||||
@ -123,6 +126,21 @@ void ClipRect::execute(SkCanvas* canvas) {
|
||||
canvas->clipRect(*this->fRect, this->fOp, this->fDoAA);
|
||||
}
|
||||
|
||||
ClipRRect::ClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
|
||||
this->fRRect = &rrect;
|
||||
this->fOp = op;
|
||||
this->fDoAA = doAA;
|
||||
this->fDrawType = CLIP_RRECT;
|
||||
|
||||
this->fInfo.push(SkObjectParser::RRectToString(rrect));
|
||||
this->fInfo.push(SkObjectParser::RegionOpToString(op));
|
||||
this->fInfo.push(SkObjectParser::BoolToString(doAA));
|
||||
}
|
||||
|
||||
void ClipRRect::execute(SkCanvas* canvas) {
|
||||
canvas->clipRRect(*this->fRRect, this->fOp, this->fDoAA);
|
||||
}
|
||||
|
||||
Concat::Concat(const SkMatrix& matrix) {
|
||||
this->fMatrix = &matrix;
|
||||
this->fDrawType = CONCAT;
|
||||
@ -234,6 +252,19 @@ void DrawData::execute(SkCanvas* canvas) {
|
||||
canvas->drawData(this->fData, this->fLength);
|
||||
}
|
||||
|
||||
DrawOval::DrawOval(const SkRect& oval, const SkPaint& paint) {
|
||||
this->fOval = &oval;
|
||||
this->fPaint = &paint;
|
||||
this->fDrawType = DRAW_OVAL;
|
||||
|
||||
this->fInfo.push(SkObjectParser::RectToString(oval));
|
||||
this->fInfo.push(SkObjectParser::PaintToString(paint));
|
||||
}
|
||||
|
||||
void DrawOval::execute(SkCanvas* canvas) {
|
||||
canvas->drawOval(*this->fOval, *this->fPaint);
|
||||
}
|
||||
|
||||
DrawPaint::DrawPaint(const SkPaint& paint) {
|
||||
this->fPaint = &paint;
|
||||
this->fDrawType = DRAW_PAINT;
|
||||
@ -343,6 +374,19 @@ void DrawRectC::execute(SkCanvas* canvas) {
|
||||
canvas->drawRect(*this->fRect, *this->fPaint);
|
||||
}
|
||||
|
||||
DrawRRect::DrawRRect(const SkRRect& rrect, const SkPaint& paint) {
|
||||
this->fRRect = rrect;
|
||||
this->fPaint = &paint;
|
||||
this->fDrawType = DRAW_RRECT;
|
||||
|
||||
this->fInfo.push(SkObjectParser::RRectToString(rrect));
|
||||
this->fInfo.push(SkObjectParser::PaintToString(paint));
|
||||
}
|
||||
|
||||
void DrawRRect::execute(SkCanvas* canvas) {
|
||||
canvas->drawRRect(this->fRRect, *this->fPaint);
|
||||
}
|
||||
|
||||
DrawSprite::DrawSprite(const SkBitmap& bitmap, int left, int top,
|
||||
const SkPaint* paint, SkBitmap& resizedBitmap) {
|
||||
this->fBitmap = &bitmap;
|
||||
|
@ -98,6 +98,16 @@ private:
|
||||
bool fDoAA;
|
||||
};
|
||||
|
||||
class ClipRRect : public SkDrawCommand {
|
||||
public:
|
||||
ClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA);
|
||||
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
|
||||
private:
|
||||
const SkRRect* fRRect;
|
||||
SkRegion::Op fOp;
|
||||
bool fDoAA;
|
||||
};
|
||||
|
||||
class Concat : public SkDrawCommand {
|
||||
public:
|
||||
Concat(const SkMatrix& matrix);
|
||||
@ -170,6 +180,15 @@ private:
|
||||
size_t fLength;
|
||||
};
|
||||
|
||||
class DrawOval : public SkDrawCommand {
|
||||
public:
|
||||
DrawOval(const SkRect& oval, const SkPaint& paint);
|
||||
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
|
||||
private:
|
||||
const SkRect* fOval;
|
||||
const SkPaint* fPaint;
|
||||
};
|
||||
|
||||
class DrawPaint : public SkDrawCommand {
|
||||
public:
|
||||
DrawPaint(const SkPaint& paint);
|
||||
@ -273,6 +292,15 @@ private:
|
||||
const SkPaint* fPaint;
|
||||
};
|
||||
|
||||
class DrawRRect : public SkDrawCommand {
|
||||
public:
|
||||
DrawRRect(const SkRRect& rrect, const SkPaint& paint);
|
||||
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
|
||||
private:
|
||||
SkRRect fRRect;
|
||||
const SkPaint* fPaint;
|
||||
};
|
||||
|
||||
class DrawSprite : public SkDrawCommand {
|
||||
public:
|
||||
DrawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint,
|
||||
|
@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include "SkObjectParser.h"
|
||||
#include "SkRRect.h"
|
||||
|
||||
/* TODO(chudy): Replace all std::strings with char */
|
||||
|
||||
@ -214,6 +215,50 @@ SkString* SkObjectParser::RectToString(const SkRect& rect, const char* title) {
|
||||
return mRect;
|
||||
}
|
||||
|
||||
SkString* SkObjectParser::RRectToString(const SkRRect& rrect, const char* title) {
|
||||
|
||||
SkString* mRRect = new SkString;
|
||||
|
||||
if (NULL == title) {
|
||||
mRRect->append("SkRRect (");
|
||||
if (rrect.isEmpty()) {
|
||||
mRRect->append("empty");
|
||||
} else if (rrect.isRect()) {
|
||||
mRRect->append("rect");
|
||||
} else if (rrect.isOval()) {
|
||||
mRRect->append("oval");
|
||||
} else if (rrect.isSimple()) {
|
||||
mRRect->append("simple");
|
||||
} else {
|
||||
SkASSERT(rrect.isComplex());
|
||||
mRRect->append("complex");
|
||||
}
|
||||
mRRect->append("): ");
|
||||
} else {
|
||||
mRRect->append(title);
|
||||
}
|
||||
mRRect->append("(");
|
||||
mRRect->appendScalar(rrect.rect().left());
|
||||
mRRect->append(", ");
|
||||
mRRect->appendScalar(rrect.rect().top());
|
||||
mRRect->append(", ");
|
||||
mRRect->appendScalar(rrect.rect().right());
|
||||
mRRect->append(", ");
|
||||
mRRect->appendScalar(rrect.rect().bottom());
|
||||
mRRect->append(") radii: (");
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
const SkVector& radii = rrect.radii((SkRRect::Corner) i);
|
||||
mRRect->appendScalar(radii.fX);
|
||||
mRRect->append(", ");
|
||||
mRRect->appendScalar(radii.fY);
|
||||
if (i < 3) {
|
||||
mRRect->append(", ");
|
||||
}
|
||||
}
|
||||
mRRect->append(")");
|
||||
return mRRect;
|
||||
}
|
||||
|
||||
SkString* SkObjectParser::RegionOpToString(SkRegion::Op op) {
|
||||
SkString* mOp = new SkString("SkRegion::Op: ");
|
||||
if (op == SkRegion::kDifference_Op) {
|
||||
|
@ -85,6 +85,12 @@ public:
|
||||
*/
|
||||
static SkString* RectToString(const SkRect& rect, const char* title = NULL);
|
||||
|
||||
/**
|
||||
Returns a string representation of an SkRRect.
|
||||
@param rrect SkRRect
|
||||
*/
|
||||
static SkString* RRectToString(const SkRRect& rrect, const char* title = NULL);
|
||||
|
||||
/**
|
||||
Returns a string representation of the SkRegion enum.
|
||||
@param op SkRegion::op enum
|
||||
|
Loading…
Reference in New Issue
Block a user