diff options
author | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-03-25 11:50:42 +0000 |
---|---|---|
committer | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-03-25 11:50:42 +0000 |
commit | 0df2a9a8296173241671d47bd66f8474b4f46358 (patch) | |
tree | 48f28f8d0e24994b5be19d1667322d7281f73ae9 | |
parent | 4d3751df26e958dd479e9428c481cf2090212d2b (diff) |
SkDrawCommand cleanup
https://codereview.chromium.org/12989030/
git-svn-id: http://skia.googlecode.com/svn/trunk@8355 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | debugger/SkDrawCommand.cpp | 247 | ||||
-rw-r--r-- | debugger/SkDrawCommand.h | 100 |
2 files changed, 220 insertions, 127 deletions
diff --git a/debugger/SkDrawCommand.cpp b/debugger/SkDrawCommand.cpp index e85aab18eb..e7936a2a21 100644 --- a/debugger/SkDrawCommand.cpp +++ b/debugger/SkDrawCommand.cpp @@ -283,14 +283,19 @@ const SkBitmap* DrawBitmapRect::getBitmap() const { } DrawData::DrawData(const void* data, size_t length) { - this->fData = data; - this->fLength = length; - this->fDrawType = DRAW_DATA; - // TODO(chudy): See if we can't display data and length. + fData = new char[length]; + memcpy(fData, data, length); + fLength = length; + fDrawType = DRAW_DATA; + + // TODO: add display of actual data? + SkString* str = new SkString; + str->appendf("length: %d", length); + fInfo.push(str); } void DrawData::execute(SkCanvas* canvas) { - canvas->drawData(this->fData, this->fLength); + canvas->drawData(fData, fLength); } DrawOval::DrawOval(const SkRect& oval, const SkPaint& paint) { @@ -335,14 +340,14 @@ const SkBitmap* DrawPath::getBitmap() const { return &fBitmap; } -DrawPicture::DrawPicture(SkPicture& picture) { - this->fPicture = &picture; - this->fDrawType = DRAW_PICTURE; - this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented.")); +DrawPicture::DrawPicture(SkPicture& picture) : + fPicture(picture) { + fDrawType = DRAW_PICTURE; + fInfo.push(SkObjectParser::CustomTextToString("To be implemented.")); } void DrawPicture::execute(SkCanvas* canvas) { - canvas->drawPicture(*this->fPicture); + canvas->drawPicture(fPicture); } DrawPoints::DrawPoints(SkCanvas::PointMode mode, size_t count, @@ -430,12 +435,12 @@ void DrawRectC::execute(SkCanvas* canvas) { } DrawRRect::DrawRRect(const SkRRect& rrect, const SkPaint& paint) { - this->fRRect = rrect; - this->fPaint = paint; - this->fDrawType = DRAW_RRECT; + fRRect = rrect; + fPaint = paint; + fDrawType = DRAW_RRECT; - this->fInfo.push(SkObjectParser::RRectToString(rrect)); - this->fInfo.push(SkObjectParser::PaintToString(paint)); + fInfo.push(SkObjectParser::RRectToString(rrect)); + fInfo.push(SkObjectParser::PaintToString(paint)); } void DrawRRect::execute(SkCanvas* canvas) { @@ -443,21 +448,29 @@ void DrawRRect::execute(SkCanvas* canvas) { } DrawSprite::DrawSprite(const SkBitmap& bitmap, int left, int top, - const SkPaint* paint, SkBitmap& resizedBitmap) { - this->fBitmap = &bitmap; - this->fLeft = left; - this->fTop = top; - this->fPaint = paint; - this->fDrawType = DRAW_SPRITE; - this->fResizedBitmap = resizedBitmap; + const SkPaint* paint, SkBitmap& resizedBitmap) { + fBitmap = bitmap; + fLeft = left; + fTop = top; + if (NULL != paint) { + fPaint = *paint; + fPaintPtr = &fPaint; + } else { + fPaintPtr = NULL; + } + fDrawType = DRAW_SPRITE; + fResizedBitmap = resizedBitmap; - this->fInfo.push(SkObjectParser::BitmapToString(bitmap)); - this->fInfo.push(SkObjectParser::IntToString(left, "Left: ")); - this->fInfo.push(SkObjectParser::IntToString(top, "Top: ")); + fInfo.push(SkObjectParser::BitmapToString(bitmap)); + fInfo.push(SkObjectParser::IntToString(left, "Left: ")); + fInfo.push(SkObjectParser::IntToString(top, "Top: ")); + if (NULL != paint) { + fInfo.push(SkObjectParser::PaintToString(*paint)); + } } void DrawSprite::execute(SkCanvas* canvas) { - canvas->drawSprite(*this->fBitmap, this->fLeft, this->fTop, this->fPaint); + canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr); } const SkBitmap* DrawSprite::getBitmap() const { @@ -465,65 +478,113 @@ const SkBitmap* DrawSprite::getBitmap() const { } DrawTextC::DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y, - const SkPaint& paint) { - this->fText = text; - this->fByteLength = byteLength; - this->fX = x; - this->fY = y; - this->fPaint = &paint; - this->fDrawType = DRAW_TEXT; + const SkPaint& paint) { + fText = new char[byteLength]; + memcpy(fText, text, byteLength); + fByteLength = byteLength; + fX = x; + fY = y; + fPaint = paint; + fDrawType = DRAW_TEXT; - this->fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); - this->fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: ")); - this->fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: ")); - this->fInfo.push(SkObjectParser::PaintToString(paint)); + fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); + fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: ")); + fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: ")); + fInfo.push(SkObjectParser::PaintToString(paint)); } void DrawTextC::execute(SkCanvas* canvas) { - canvas->drawText(this->fText, this->fByteLength, this->fX, this->fY, *this->fPaint); + canvas->drawText(fText, fByteLength, fX, fY, fPaint); } DrawTextOnPath::DrawTextOnPath(const void* text, size_t byteLength, - const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) { - this->fText = text; - this->fByteLength = byteLength; - this->fPath = &path; - this->fMatrix = matrix; - this->fPaint = &paint; - this->fDrawType = DRAW_TEXT_ON_PATH; + const SkPath& path, const SkMatrix* matrix, + const SkPaint& paint) { + fText = new char[byteLength]; + memcpy(fText, text, byteLength); + fByteLength = byteLength; + fPath = path; + if (NULL != matrix) { + fMatrix = *matrix; + } else { + fMatrix.setIdentity(); + } + fPaint = paint; + fDrawType = DRAW_TEXT_ON_PATH; - this->fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); - this->fInfo.push(SkObjectParser::PathToString(path)); - if (matrix) this->fInfo.push(SkObjectParser::MatrixToString(*matrix)); - this->fInfo.push(SkObjectParser::PaintToString(paint)); + fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); + fInfo.push(SkObjectParser::PathToString(path)); + if (NULL != matrix) { + fInfo.push(SkObjectParser::MatrixToString(*matrix)); + } + fInfo.push(SkObjectParser::PaintToString(paint)); } void DrawTextOnPath::execute(SkCanvas* canvas) { - canvas->drawTextOnPath(this->fText, this->fByteLength, *this->fPath, - this->fMatrix, *this->fPaint); + canvas->drawTextOnPath(fText, fByteLength, fPath, + fMatrix.isIdentity() ? NULL : &fMatrix, + fPaint); } DrawVertices::DrawVertices(SkCanvas::VertexMode vmode, int vertexCount, - const SkPoint vertices[], const SkPoint texs[], const SkColor colors[], - SkXfermode* xfermode, const uint16_t indices[], int indexCount, - const SkPaint& paint) { - this->fVmode = vmode; - this->fVertexCount = vertexCount; - this->fTexs = texs; - this->fColors = colors; - this->fXfermode = xfermode; - this->fIndices = indices; - this->fIndexCount = indexCount; - this->fPaint = &paint; - this->fDrawType = DRAW_VERTICES; + const SkPoint vertices[], const SkPoint texs[], + const SkColor colors[], SkXfermode* xfermode, + const uint16_t indices[], int indexCount, + const SkPaint& paint) { + fVmode = vmode; + + fVertexCount = vertexCount; + + fVertices = new SkPoint[vertexCount]; + memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint)); + + if (NULL != texs) { + fTexs = new SkPoint[vertexCount]; + memcpy(fTexs, texs, vertexCount * sizeof(SkPoint)); + } else { + fTexs = NULL; + } + + if (NULL != colors) { + fColors = new SkColor[vertexCount]; + memcpy(fColors, colors, vertexCount * sizeof(SkColor)); + } else { + fColors = NULL; + } + + fXfermode = xfermode; + if (NULL != fXfermode) { + fXfermode->ref(); + } + + if (indexCount > 0) { + fIndices = new uint16_t[indexCount]; + memcpy(fIndices, indices, indexCount * sizeof(uint16_t)); + } else { + fIndices = NULL; + } + + fIndexCount = indexCount; + fPaint = paint; + fDrawType = DRAW_VERTICES; + // TODO(chudy) - this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented.")); + fInfo.push(SkObjectParser::CustomTextToString("To be implemented.")); + fInfo.push(SkObjectParser::PaintToString(paint)); +} + +DrawVertices::~DrawVertices() { + delete [] fVertices; + delete [] fTexs; + delete [] fColors; + SkSafeUnref(fXfermode); + delete [] fIndices; } void DrawVertices::execute(SkCanvas* canvas) { - canvas->drawVertices(this->fVmode, this->fVertexCount, this->fVertices, - this->fTexs, this->fColors, this->fXfermode, this->fIndices, - this->fIndexCount, *this->fPaint); + canvas->drawVertices(fVmode, fVertexCount, fVertices, + fTexs, fColors, fXfermode, fIndices, + fIndexCount, fPaint); } Restore::Restore() { @@ -540,14 +601,14 @@ void Restore::trackSaveState(int* state) { } Rotate::Rotate(SkScalar degrees) { - this->fDegrees = degrees; - this->fDrawType = ROTATE; + fDegrees = degrees; + fDrawType = ROTATE; - this->fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: ")); + fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: ")); } void Rotate::execute(SkCanvas* canvas) { - canvas->rotate(this->fDegrees); + canvas->rotate(fDegrees); } Save::Save(SkCanvas::SaveFlags flags) { @@ -601,51 +662,51 @@ void SaveLayer::trackSaveState(int* state) { } Scale::Scale(SkScalar sx, SkScalar sy) { - this->fSx = sx; - this->fSy = sy; - this->fDrawType = SCALE; + fSx = sx; + fSy = sy; + fDrawType = SCALE; - this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: ")); - this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: ")); + fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: ")); + fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: ")); } void Scale::execute(SkCanvas* canvas) { - canvas->scale(this->fSx, this->fSy); + canvas->scale(fSx, fSy); } SetMatrix::SetMatrix(const SkMatrix& matrix) { - this->fMatrix = matrix; - this->fDrawType = SET_MATRIX; + fMatrix = matrix; + fDrawType = SET_MATRIX; - this->fInfo.push(SkObjectParser::MatrixToString(matrix)); + fInfo.push(SkObjectParser::MatrixToString(matrix)); } void SetMatrix::execute(SkCanvas* canvas) { - canvas->setMatrix(this->fMatrix); + canvas->setMatrix(fMatrix); } Skew::Skew(SkScalar sx, SkScalar sy) { - this->fSx = sx; - this->fSy = sy; - this->fDrawType = SKEW; + fSx = sx; + fSy = sy; + fDrawType = SKEW; - this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: ")); - this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: ")); + fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: ")); + fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: ")); } void Skew::execute(SkCanvas* canvas) { - canvas->skew(this->fSx, this->fSy); + canvas->skew(fSx, fSy); } Translate::Translate(SkScalar dx, SkScalar dy) { - this->fDx = dx; - this->fDy = dy; - this->fDrawType = TRANSLATE; + fDx = dx; + fDy = dy; + fDrawType = TRANSLATE; - this->fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: ")); - this->fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: ")); + fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: ")); + fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: ")); } void Translate::execute(SkCanvas* canvas) { - canvas->translate(this->fDx, this->fDy); + canvas->translate(fDx, fDy); } diff --git a/debugger/SkDrawCommand.h b/debugger/SkDrawCommand.h index 6acc24f2ba..fc812b52c4 100644 --- a/debugger/SkDrawCommand.h +++ b/debugger/SkDrawCommand.h @@ -226,10 +226,13 @@ private: class DrawData : public SkDrawCommand { public: DrawData(const void* data, size_t length); + virtual ~DrawData() { delete [] fData; } virtual void execute(SkCanvas* canvas) SK_OVERRIDE; private: - const void* fData; + void* fData; size_t fLength; + + typedef SkDrawCommand INHERITED; }; class DrawOval : public SkDrawCommand { @@ -260,8 +263,8 @@ public: virtual const SkBitmap* getBitmap() const SK_OVERRIDE; private: - SkPath fPath; - SkPaint fPaint; + SkPath fPath; + SkPaint fPaint; SkBitmap fBitmap; typedef SkDrawCommand INHERITED; @@ -272,7 +275,9 @@ public: DrawPicture(SkPicture& picture); virtual void execute(SkCanvas* canvas) SK_OVERRIDE; private: - SkPicture* fPicture; + SkPicture fPicture; + + typedef SkDrawCommand INHERITED; }; class DrawPoints : public SkDrawCommand { @@ -297,14 +302,17 @@ private: class DrawTextC : public SkDrawCommand { public: DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y, - const SkPaint& paint); + const SkPaint& paint); + virtual ~DrawTextC() { delete [] fText; } virtual void execute(SkCanvas* canvas) SK_OVERRIDE; private: - const void* fText; - size_t fByteLength; + void* fText; + size_t fByteLength; SkScalar fX; SkScalar fY; - const SkPaint* fPaint; + SkPaint fPaint; + + typedef SkDrawCommand INHERITED; }; class DrawPosText : public SkDrawCommand { @@ -314,23 +322,28 @@ public: virtual ~DrawPosText() { delete [] fPos; delete [] fText; } virtual void execute(SkCanvas* canvas) SK_OVERRIDE; private: + char* fText; + size_t fByteLength; SkPoint* fPos; - char* fText; - size_t fByteLength; - SkPaint fPaint; + SkPaint fPaint; + + typedef SkDrawCommand INHERITED; }; class DrawTextOnPath : public SkDrawCommand { public: DrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, const SkMatrix* matrix, const SkPaint& paint); + virtual ~DrawTextOnPath() { delete [] fText; } virtual void execute(SkCanvas* canvas) SK_OVERRIDE; private: - const SkMatrix* fMatrix; - const void* fText; - size_t fByteLength; - const SkPath* fPath; - const SkPaint* fPaint; + void* fText; + size_t fByteLength; + SkPath fPath; + SkMatrix fMatrix; + SkPaint fPaint; + + typedef SkDrawCommand INHERITED; }; class DrawPosTextH : public SkDrawCommand { @@ -341,10 +354,10 @@ public: virtual void execute(SkCanvas* canvas) SK_OVERRIDE; private: SkScalar* fXpos; - char* fText; - size_t fByteLength; - SkScalar fConstY; - SkPaint fPaint; + char* fText; + size_t fByteLength; + SkScalar fConstY; + SkPaint fPaint; typedef SkDrawCommand INHERITED; }; @@ -370,6 +383,8 @@ public: private: SkRRect fRRect; SkPaint fPaint; + + typedef SkDrawCommand INHERITED; }; class DrawSprite : public SkDrawCommand { @@ -379,30 +394,37 @@ public: virtual void execute(SkCanvas* canvas) SK_OVERRIDE; virtual const SkBitmap* getBitmap() const SK_OVERRIDE; private: - const SkPaint* fPaint; - int fLeft; - int fTop; - const SkBitmap* fBitmap; + SkBitmap fBitmap; + int fLeft; + int fTop; + SkPaint fPaint; + SkPaint* fPaintPtr; SkBitmap fResizedBitmap; + + typedef SkDrawCommand INHERITED; }; class DrawVertices : public SkDrawCommand { public: DrawVertices(SkCanvas::VertexMode vmode, int vertexCount, - const SkPoint vertices[], const SkPoint texs[], const SkColor colors[], - SkXfermode* xfermode, const uint16_t indices[], int indexCount, - const SkPaint& paint); + const SkPoint vertices[], const SkPoint texs[], + const SkColor colors[], SkXfermode* xfermode, + const uint16_t indices[], int indexCount, + const SkPaint& paint); + virtual ~DrawVertices(); virtual void execute(SkCanvas* canvas) SK_OVERRIDE; private: SkCanvas::VertexMode fVmode; - int fVertexCount; - int fIndexCount; - const SkPoint* fVertices; - const SkPoint* fTexs; - const SkColor* fColors; - const uint16_t* fIndices; + int fVertexCount; + SkPoint* fVertices; + SkPoint* fTexs; + SkColor* fColors; SkXfermode* fXfermode; - const SkPaint* fPaint; + uint16_t* fIndices; + int fIndexCount; + SkPaint fPaint; + + typedef SkDrawCommand INHERITED; }; class Rotate : public SkDrawCommand { @@ -411,6 +433,8 @@ public: virtual void execute(SkCanvas* canvas) SK_OVERRIDE; private: SkScalar fDegrees; + + typedef SkDrawCommand INHERITED; }; class Save : public SkDrawCommand { @@ -453,6 +477,8 @@ public: private: SkScalar fSx; SkScalar fSy; + + typedef SkDrawCommand INHERITED; }; class SetMatrix : public SkDrawCommand { @@ -461,6 +487,8 @@ public: virtual void execute(SkCanvas* canvas) SK_OVERRIDE; private: SkMatrix fMatrix; + + typedef SkDrawCommand INHERITED; }; class Skew : public SkDrawCommand { @@ -470,6 +498,8 @@ public: private: SkScalar fSx; SkScalar fSy; + + typedef SkDrawCommand INHERITED; }; class Translate : public SkDrawCommand { @@ -483,6 +513,8 @@ public: private: SkScalar fDx; SkScalar fDy; + + typedef SkDrawCommand INHERITED; }; #endif |