Remove SkPictureFlat.h include from SkDrawCommands.h

This cannot land until https://codereview.chromium.org/909353004/ (Prepare SkiaBenchmarkingExtensionTest for upcoming Skia changes) lands in Chromium

Committed: https://skia.googlesource.com/skia/+/5a4c233a3657d12d836de388b41e30405b4ab976

Committed: https://skia.googlesource.com/skia/+/fa3a83d0fe53907e618346d3f1c17a95da1a9d22

Review URL: https://codereview.chromium.org/912403004
This commit is contained in:
robertphillips 2015-02-13 11:13:00 -08:00 committed by Commit bot
parent 3555bd88a6
commit 9bafc30c79
6 changed files with 222 additions and 318 deletions

View File

@ -66,8 +66,8 @@ void SkDebugger::getOverviewText(const SkTDArray<double>* typeTimes,
const SkTDArray<SkDrawCommand*>& commands = this->getDrawCommands(); const SkTDArray<SkDrawCommand*>& commands = this->getDrawCommands();
SkTDArray<int> counts; SkTDArray<int> counts;
counts.setCount(LAST_DRAWTYPE_ENUM+1); counts.setCount(SkDrawCommand::kOpTypeCount);
for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) { for (int i = 0; i < SkDrawCommand::kOpTypeCount; ++i) {
counts[i] = 0; counts[i] = 0;
} }
@ -80,14 +80,14 @@ void SkDebugger::getOverviewText(const SkTDArray<double>* typeTimes,
#ifdef SK_DEBUG #ifdef SK_DEBUG
double totPercent = 0, tempSum = 0; double totPercent = 0, tempSum = 0;
#endif #endif
for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) { for (int i = 0; i < SkDrawCommand::kOpTypeCount; ++i) {
if (0 == counts[i]) { if (0 == counts[i]) {
// if there were no commands of this type then they should've consumed no time // if there were no commands of this type then they should've consumed no time
SkASSERT(NULL == typeTimes || 0.0 == (*typeTimes)[i]); SkASSERT(NULL == typeTimes || 0.0 == (*typeTimes)[i]);
continue; continue;
} }
overview->append(SkDrawCommand::GetCommandString((DrawType) i)); overview->append(SkDrawCommand::GetCommandString((SkDrawCommand::OpType) i));
overview->append(": "); overview->append(": ");
overview->appendS32(counts[i]); overview->appendS32(counts[i]);
if (typeTimes && totTime >= 0.0) { if (typeTimes && totTime >= 0.0) {

View File

@ -396,20 +396,7 @@ void SkDebugCanvas::onClipRegion(const SkRegion& region, SkRegion::Op op) {
} }
void SkDebugCanvas::didConcat(const SkMatrix& matrix) { void SkDebugCanvas::didConcat(const SkMatrix& matrix) {
switch (matrix.getType()) { this->addDrawCommand(new SkConcatCommand(matrix));
case SkMatrix::kTranslate_Mask:
this->addDrawCommand(new SkTranslateCommand(matrix.getTranslateX(),
matrix.getTranslateY()));
break;
case SkMatrix::kScale_Mask:
this->addDrawCommand(new SkScaleCommand(matrix.getScaleX(),
matrix.getScaleY()));
break;
default:
this->addDrawCommand(new SkConcatCommand(matrix));
break;
}
this->INHERITED::didConcat(matrix); this->INHERITED::didConcat(matrix);
} }
@ -518,6 +505,12 @@ void SkDebugCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar
this->addDrawCommand(new SkDrawTextBlobCommand(blob, x, y, paint)); this->addDrawCommand(new SkDrawTextBlobCommand(blob, x, y, paint));
} }
void SkDebugCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
const SkPoint texCoords[4], SkXfermode* xmode,
const SkPaint& paint) {
this->addDrawCommand(new SkDrawPatchCommand(cubics, colors, texCoords, xmode, paint));
}
void SkDebugCanvas::onDrawVertices(VertexMode vmode, int vertexCount, const SkPoint vertices[], void SkDebugCanvas::onDrawVertices(VertexMode vmode, int vertexCount, const SkPoint vertices[],
const SkPoint texs[], const SkColor colors[], const SkPoint texs[], const SkColor colors[],
SkXfermode*, const uint16_t indices[], int indexCount, SkXfermode*, const uint16_t indices[], int indexCount,

View File

@ -175,22 +175,30 @@ protected:
void didSetMatrix(const SkMatrix&) SK_OVERRIDE; void didSetMatrix(const SkMatrix&) SK_OVERRIDE;
void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE; void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
const SkPaint&) SK_OVERRIDE; const SkPaint&) SK_OVERRIDE;
virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
const SkPaint&) SK_OVERRIDE; const SkPaint&) SK_OVERRIDE;
virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
SkScalar constY, const SkPaint&) SK_OVERRIDE; SkScalar constY, const SkPaint&) SK_OVERRIDE;
virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
const SkMatrix* matrix, const SkPaint&) SK_OVERRIDE; const SkMatrix* matrix, const SkPaint&) SK_OVERRIDE;
virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
const SkPaint& paint) SK_OVERRIDE; const SkPaint& paint) SK_OVERRIDE;
void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint);
void onDrawPaint(const SkPaint&) SK_OVERRIDE; void onDrawPaint(const SkPaint&) SK_OVERRIDE;
void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) SK_OVERRIDE;
void onDrawRect(const SkRect&, const SkPaint&) SK_OVERRIDE; void onDrawRect(const SkRect&, const SkPaint&) SK_OVERRIDE;
void onDrawOval(const SkRect&, const SkPaint&) SK_OVERRIDE; void onDrawOval(const SkRect&, const SkPaint&) SK_OVERRIDE;
void onDrawRRect(const SkRRect&, const SkPaint&) SK_OVERRIDE; void onDrawRRect(const SkRRect&, const SkPaint&) SK_OVERRIDE;
void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) SK_OVERRIDE;
void onDrawVertices(VertexMode vmode, int vertexCount,
const SkPoint vertices[], const SkPoint texs[],
const SkColor colors[], SkXfermode* xmode,
const uint16_t indices[], int indexCount,
const SkPaint&) SK_OVERRIDE;
void onDrawPath(const SkPath&, const SkPaint&) SK_OVERRIDE; void onDrawPath(const SkPath&, const SkPaint&) SK_OVERRIDE;
void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) SK_OVERRIDE; void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) SK_OVERRIDE;
void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*, void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*,
@ -201,12 +209,6 @@ protected:
void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst, void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
const SkPaint*) SK_OVERRIDE; const SkPaint*) SK_OVERRIDE;
void onDrawSprite(const SkBitmap&, int left, int top, const SkPaint*) SK_OVERRIDE; void onDrawSprite(const SkBitmap&, int left, int top, const SkPaint*) SK_OVERRIDE;
void onDrawVertices(VertexMode vmode, int vertexCount,
const SkPoint vertices[], const SkPoint texs[],
const SkColor colors[], SkXfermode* xmode,
const uint16_t indices[], int indexCount,
const SkPaint&) SK_OVERRIDE;
void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;

View File

@ -9,22 +9,16 @@
#include "SkDrawCommand.h" #include "SkDrawCommand.h"
#include "SkObjectParser.h" #include "SkObjectParser.h"
#include "SkPicture.h"
#include "SkTextBlob.h" #include "SkTextBlob.h"
// TODO(chudy): Refactor into non subclass model. // TODO(chudy): Refactor into non subclass model.
const char* SkDrawCommand::kDrawRectString = "Draw Rect"; const char* SkDrawCommand::kDrawRectString = "DrawRect";
const char* SkDrawCommand::kClipRectString = "Clip Rect"; const char* SkDrawCommand::kClipRectString = "ClipRect";
const SkDrawCommand::OpType SkDrawCommand::kSave_OpType = SAVE; SkDrawCommand::SkDrawCommand(OpType type)
const SkDrawCommand::OpType SkDrawCommand::kClipRect_OpType = CLIP_RECT; : fOpType(type)
const SkDrawCommand::OpType SkDrawCommand::kDrawRect_OpType = DRAW_RECT;
const SkDrawCommand::OpType SkDrawCommand::kRestore_OpType = RESTORE;
const SkDrawCommand::OpType SkDrawCommand::kSetMatrix_OpType = SET_MATRIX;
SkDrawCommand::SkDrawCommand(DrawType type)
: fDrawType(type)
, fOffset(0) , fOffset(0)
, fVisible(true) { , fVisible(true) {
} }
@ -33,49 +27,42 @@ SkDrawCommand::~SkDrawCommand() {
fInfo.deleteAll(); fInfo.deleteAll();
} }
const char* SkDrawCommand::GetCommandString(DrawType type) { const char* SkDrawCommand::GetCommandString(OpType type) {
switch (type) { switch (type) {
case UNUSED: SkDEBUGFAIL("DrawType UNUSED\n"); break; case kBeginCommentGroup_OpType: return "BeginCommentGroup";
case DRAW_CLEAR: return "Clear"; case kClipPath_OpType: return "ClipPath";
case CLIP_PATH: return "Clip Path"; case kClipRegion_OpType: return "ClipRegion";
case CLIP_REGION: return "Clip Region"; case kClipRect_OpType: return "ClipRect";
case CLIP_RECT: return "Clip Rect"; case kClipRRect_OpType: return "ClipRRect";
case CLIP_RRECT: return "Clip RRect"; case kComment_OpType: return "Comment";
case CONCAT: return "Concat"; case kConcat_OpType: return "Concat";
case DRAW_BITMAP: return "Draw Bitmap"; case kDrawBitmap_OpType: return "DrawBitmap";
case DRAW_BITMAP_MATRIX: return "Draw Bitmap Matrix"; case kDrawBitmapNine_OpType: return "DrawBitmapNine";
case DRAW_BITMAP_NINE: return "Draw Bitmap Nine"; case kDrawBitmapRect_OpType: return "DrawBitmapRect";
case DRAW_BITMAP_RECT_TO_RECT: return "Draw Bitmap Rect"; case kDrawClear_OpType: return "DrawClear";
case DRAW_DATA: return "Draw Data"; case kDrawDRRect_OpType: return "DrawDRRect";
case DRAW_OVAL: return "Draw Oval"; case kDrawOval_OpType: return "DrawOval";
case DRAW_PAINT: return "Draw Paint"; case kDrawPaint_OpType: return "DrawPaint";
case DRAW_PATH: return "Draw Path"; case kDrawPatch_OpType: return "DrawPatch";
case DRAW_PICTURE: return "Draw Picture"; case kDrawPath_OpType: return "DrawPath";
case DRAW_POINTS: return "Draw Points"; case kDrawPicture_OpType: return "DrawPicture";
case DRAW_POS_TEXT: return "Draw Pos Text"; case kDrawPoints_OpType: return "DrawPoints";
case DRAW_POS_TEXT_H: return "Draw Pos Text H"; case kDrawPosText_OpType: return "DrawPosText";
case DRAW_RECT: return "Draw Rect"; case kDrawPosTextH_OpType: return "DrawPosTextH";
case DRAW_RRECT: return "Draw RRect"; case kDrawRect_OpType: return "DrawRect";
case DRAW_SPRITE: return "Draw Sprite"; case kDrawRRect_OpType: return "DrawRRect";
case DRAW_TEXT: return "Draw Text"; case kDrawSprite_OpType: return "DrawSprite";
case DRAW_TEXT_BLOB: return "Draw Text Blob"; case kDrawText_OpType: return "DrawText";
case DRAW_TEXT_ON_PATH: return "Draw Text On Path"; case kDrawTextBlob_OpType: return "DrawTextBlob";
case DRAW_VERTICES: return "Draw Vertices"; case kDrawTextOnPath_OpType: return "DrawTextOnPath";
case RESTORE: return "Restore"; case kDrawVertices_OpType: return "DrawVertices";
case ROTATE: return "Rotate"; case kEndCommentGroup_OpType: return "EndCommentGroup";
case SAVE: return "Save"; case kRestore_OpType: return "Restore";
case SAVE_LAYER: return "Save Layer"; case kSave_OpType: return "Save";
case SCALE: return "Scale"; case kSaveLayer_OpType: return "SaveLayer";
case SET_MATRIX: return "SetMatrix"; case kSetMatrix_OpType: return "SetMatrix";
case SKEW: return "Skew";
case TRANSLATE: return "Translate";
case NOOP: return "NoOp";
case BEGIN_COMMENT_GROUP: return "BeginCommentGroup";
case COMMENT: return "Comment";
case END_COMMENT_GROUP: return "EndCommentGroup";
case DRAW_DRRECT: return "Draw DRRect";
default: default:
SkDebugf("DrawType error 0x%08x\n", type); SkDebugf("OpType error 0x%08x\n", type);
SkASSERT(0); SkASSERT(0);
break; break;
} }
@ -84,10 +71,10 @@ const char* SkDrawCommand::GetCommandString(DrawType type) {
} }
SkString SkDrawCommand::toString() const { SkString SkDrawCommand::toString() const {
return SkString(GetCommandString(fDrawType)); return SkString(GetCommandString(fOpType));
} }
SkClearCommand::SkClearCommand(SkColor color) : INHERITED(DRAW_CLEAR) { SkClearCommand::SkClearCommand(SkColor color) : INHERITED(kDrawClear_OpType) {
fColor = color; fColor = color;
fInfo.push(SkObjectParser::CustomTextToString("No Parameters")); fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
} }
@ -199,7 +186,7 @@ void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner)
SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA) SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA)
: INHERITED(CLIP_PATH) { : INHERITED(kClipPath_OpType) {
fPath = path; fPath = path;
fOp = op; fOp = op;
fDoAA = doAA; fDoAA = doAA;
@ -219,7 +206,7 @@ bool SkClipPathCommand::render(SkCanvas* canvas) const {
} }
SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op) SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op)
: INHERITED(CLIP_REGION) { : INHERITED(kClipRegion_OpType) {
fRegion = region; fRegion = region;
fOp = op; fOp = op;
@ -232,7 +219,7 @@ void SkClipRegionCommand::execute(SkCanvas* canvas) const {
} }
SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA) SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA)
: INHERITED(CLIP_RECT) { : INHERITED(kClipRect_OpType) {
fRect = rect; fRect = rect;
fOp = op; fOp = op;
fDoAA = doAA; fDoAA = doAA;
@ -247,7 +234,7 @@ void SkClipRectCommand::execute(SkCanvas* canvas) const {
} }
SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA) SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA)
: INHERITED(CLIP_RRECT) { : INHERITED(kClipRRect_OpType) {
fRRect = rrect; fRRect = rrect;
fOp = op; fOp = op;
fDoAA = doAA; fDoAA = doAA;
@ -267,7 +254,7 @@ bool SkClipRRectCommand::render(SkCanvas* canvas) const {
} }
SkConcatCommand::SkConcatCommand(const SkMatrix& matrix) SkConcatCommand::SkConcatCommand(const SkMatrix& matrix)
: INHERITED(CONCAT) { : INHERITED(kConcat_OpType) {
fMatrix = matrix; fMatrix = matrix;
fInfo.push(SkObjectParser::MatrixToString(matrix)); fInfo.push(SkObjectParser::MatrixToString(matrix));
@ -279,7 +266,7 @@ void SkConcatCommand::execute(SkCanvas* canvas) const {
SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top, SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
const SkPaint* paint) const SkPaint* paint)
: INHERITED(DRAW_BITMAP) { : INHERITED(kDrawBitmap_OpType) {
fBitmap = bitmap; fBitmap = bitmap;
fLeft = left; fLeft = left;
fTop = top; fTop = top;
@ -309,7 +296,7 @@ bool SkDrawBitmapCommand::render(SkCanvas* canvas) const {
SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center, SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
const SkRect& dst, const SkPaint* paint) const SkRect& dst, const SkPaint* paint)
: INHERITED(DRAW_BITMAP_NINE) { : INHERITED(kDrawBitmapNine_OpType) {
fBitmap = bitmap; fBitmap = bitmap;
fCenter = center; fCenter = center;
fDst = dst; fDst = dst;
@ -340,7 +327,7 @@ bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const {
SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src, SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
const SkRect& dst, const SkPaint* paint, const SkRect& dst, const SkPaint* paint,
SkCanvas::DrawBitmapRectFlags flags) SkCanvas::DrawBitmapRectFlags flags)
: INHERITED(DRAW_BITMAP_RECT_TO_RECT) { : INHERITED(kDrawBitmapRect_OpType) {
fBitmap = bitmap; fBitmap = bitmap;
if (src) { if (src) {
fSrc = *src; fSrc = *src;
@ -378,7 +365,7 @@ bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
} }
SkBeginCommentGroupCommand::SkBeginCommentGroupCommand(const char* description) SkBeginCommentGroupCommand::SkBeginCommentGroupCommand(const char* description)
: INHERITED(BEGIN_COMMENT_GROUP) : INHERITED(kBeginCommentGroup_OpType)
, fDescription(description) { , fDescription(description) {
SkString* temp = new SkString; SkString* temp = new SkString;
temp->appendf("Description: %s", description); temp->appendf("Description: %s", description);
@ -386,7 +373,7 @@ SkBeginCommentGroupCommand::SkBeginCommentGroupCommand(const char* description)
} }
SkCommentCommand::SkCommentCommand(const char* kywd, const char* value) SkCommentCommand::SkCommentCommand(const char* kywd, const char* value)
: INHERITED(COMMENT) : INHERITED(kComment_OpType)
, fKywd(kywd) , fKywd(kywd)
, fValue(value) { , fValue(value) {
SkString* temp = new SkString; SkString* temp = new SkString;
@ -395,11 +382,11 @@ SkCommentCommand::SkCommentCommand(const char* kywd, const char* value)
} }
SkEndCommentGroupCommand::SkEndCommentGroupCommand() SkEndCommentGroupCommand::SkEndCommentGroupCommand()
: INHERITED(END_COMMENT_GROUP) { : INHERITED(kEndCommentGroup_OpType) {
} }
SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint) SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint)
: INHERITED(DRAW_OVAL) { : INHERITED(kDrawOval_OpType) {
fOval = oval; fOval = oval;
fPaint = paint; fPaint = paint;
@ -428,7 +415,7 @@ bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
} }
SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint) SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint)
: INHERITED(DRAW_PAINT) { : INHERITED(kDrawPaint_OpType) {
fPaint = paint; fPaint = paint;
fInfo.push(SkObjectParser::PaintToString(paint)); fInfo.push(SkObjectParser::PaintToString(paint));
@ -445,7 +432,7 @@ bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
} }
SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint) SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint)
: INHERITED(DRAW_PATH) { : INHERITED(kDrawPath_OpType) {
fPath = path; fPath = path;
fPaint = paint; fPaint = paint;
@ -465,7 +452,7 @@ bool SkDrawPathCommand::render(SkCanvas* canvas) const {
SkDrawPictureCommand::SkDrawPictureCommand(const SkPicture* picture, SkDrawPictureCommand::SkDrawPictureCommand(const SkPicture* picture,
const SkMatrix* matrix, const SkMatrix* matrix,
const SkPaint* paint) const SkPaint* paint)
: INHERITED(DRAW_PICTURE) : INHERITED(kDrawPicture_OpType)
, fPicture(SkRef(picture)) , fPicture(SkRef(picture))
, fMatrixPtr(NULL) , fMatrixPtr(NULL)
, fPaintPtr(NULL) { , fPaintPtr(NULL) {
@ -511,7 +498,7 @@ bool SkDrawPictureCommand::render(SkCanvas* canvas) const {
SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count, SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
const SkPoint pts[], const SkPaint& paint) const SkPoint pts[], const SkPaint& paint)
: INHERITED(DRAW_POINTS) { : INHERITED(kDrawPoints_OpType) {
fMode = mode; fMode = mode;
fCount = count; fCount = count;
fPts = new SkPoint[count]; fPts = new SkPoint[count];
@ -554,7 +541,7 @@ bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength, SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
const SkPoint pos[], const SkPaint& paint) const SkPoint pos[], const SkPaint& paint)
: INHERITED(DRAW_POS_TEXT) { : INHERITED(kDrawPosText_OpType) {
size_t numPts = paint.countText(text, byteLength); size_t numPts = paint.countText(text, byteLength);
fText = new char[byteLength]; fText = new char[byteLength];
@ -580,7 +567,7 @@ void SkDrawPosTextCommand::execute(SkCanvas* canvas) const {
SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength, SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
const SkScalar xpos[], SkScalar constY, const SkScalar xpos[], SkScalar constY,
const SkPaint& paint) const SkPaint& paint)
: INHERITED(DRAW_POS_TEXT_H) { : INHERITED(kDrawPosTextH_OpType) {
size_t numPts = paint.countText(text, byteLength); size_t numPts = paint.countText(text, byteLength);
fText = new char[byteLength]; fText = new char[byteLength];
@ -605,7 +592,7 @@ void SkDrawPosTextHCommand::execute(SkCanvas* canvas) const {
SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y, SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y,
const SkPaint& paint) const SkPaint& paint)
: INHERITED(DRAW_TEXT_BLOB) : INHERITED(kDrawTextBlob_OpType)
, fBlob(blob) , fBlob(blob)
, fXPos(x) , fXPos(x)
, fYPos(y) , fYPos(y)
@ -638,8 +625,25 @@ bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const {
return true; return true;
} }
SkDrawPatchCommand::SkDrawPatchCommand(const SkPoint cubics[12], const SkColor colors[4],
const SkPoint texCoords[4], SkXfermode* xfermode,
const SkPaint& paint)
: INHERITED(kDrawPatch_OpType) {
memcpy(fCubics, cubics, sizeof(fCubics));
memcpy(fColors, colors, sizeof(fColors));
memcpy(fTexCoords, texCoords, sizeof(fTexCoords));
fXfermode.reset(xfermode);
fPaint = paint;
fInfo.push(SkObjectParser::PaintToString(paint));
}
void SkDrawPatchCommand::execute(SkCanvas* canvas) const {
canvas->drawPatch(fCubics, fColors, fTexCoords, fXfermode, fPaint);
}
SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint) SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
: INHERITED(DRAW_RECT) { : INHERITED(kDrawRect_OpType) {
fRect = rect; fRect = rect;
fPaint = paint; fPaint = paint;
@ -652,7 +656,7 @@ void SkDrawRectCommand::execute(SkCanvas* canvas) const {
} }
SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint) SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint)
: INHERITED(DRAW_RRECT) { : INHERITED(kDrawRRect_OpType) {
fRRect = rrect; fRRect = rrect;
fPaint = paint; fPaint = paint;
@ -672,7 +676,7 @@ bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer, SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
const SkRRect& inner, const SkRRect& inner,
const SkPaint& paint) const SkPaint& paint)
: INHERITED(DRAW_DRRECT) { : INHERITED(kDrawDRRect_OpType) {
fOuter = outer; fOuter = outer;
fInner = inner; fInner = inner;
fPaint = paint; fPaint = paint;
@ -693,7 +697,7 @@ bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top, SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
const SkPaint* paint) const SkPaint* paint)
: INHERITED(DRAW_SPRITE) { : INHERITED(kDrawSprite_OpType) {
fBitmap = bitmap; fBitmap = bitmap;
fLeft = left; fLeft = left;
fTop = top; fTop = top;
@ -723,7 +727,7 @@ bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y, SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
const SkPaint& paint) const SkPaint& paint)
: INHERITED(DRAW_TEXT) { : INHERITED(kDrawText_OpType) {
fText = new char[byteLength]; fText = new char[byteLength];
memcpy(fText, text, byteLength); memcpy(fText, text, byteLength);
fByteLength = byteLength; fByteLength = byteLength;
@ -744,7 +748,7 @@ void SkDrawTextCommand::execute(SkCanvas* canvas) const {
SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength, SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
const SkPath& path, const SkMatrix* matrix, const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint) const SkPaint& paint)
: INHERITED(DRAW_TEXT_ON_PATH) { : INHERITED(kDrawTextOnPath_OpType) {
fText = new char[byteLength]; fText = new char[byteLength];
memcpy(fText, text, byteLength); memcpy(fText, text, byteLength);
fByteLength = byteLength; fByteLength = byteLength;
@ -775,7 +779,7 @@ SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int ver
const SkColor colors[], SkXfermode* xfermode, const SkColor colors[], SkXfermode* xfermode,
const uint16_t indices[], int indexCount, const uint16_t indices[], int indexCount,
const SkPaint& paint) const SkPaint& paint)
: INHERITED(DRAW_VERTICES) { : INHERITED(kDrawVertices_OpType) {
fVmode = vmode; fVmode = vmode;
fVertexCount = vertexCount; fVertexCount = vertexCount;
@ -832,7 +836,7 @@ void SkDrawVerticesCommand::execute(SkCanvas* canvas) const {
} }
SkRestoreCommand::SkRestoreCommand() SkRestoreCommand::SkRestoreCommand()
: INHERITED(RESTORE) { : INHERITED(kRestore_OpType) {
fInfo.push(SkObjectParser::CustomTextToString("No Parameters")); fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
} }
@ -840,19 +844,8 @@ void SkRestoreCommand::execute(SkCanvas* canvas) const {
canvas->restore(); canvas->restore();
} }
SkRotateCommand::SkRotateCommand(SkScalar degrees)
: INHERITED(ROTATE) {
fDegrees = degrees;
fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
}
void SkRotateCommand::execute(SkCanvas* canvas) const {
canvas->rotate(fDegrees);
}
SkSaveCommand::SkSaveCommand() SkSaveCommand::SkSaveCommand()
: INHERITED(SAVE) { : INHERITED(kSave_OpType) {
} }
void SkSaveCommand::execute(SkCanvas* canvas) const { void SkSaveCommand::execute(SkCanvas* canvas) const {
@ -861,7 +854,7 @@ void SkSaveCommand::execute(SkCanvas* canvas) const {
SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint, SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
SkCanvas::SaveFlags flags) SkCanvas::SaveFlags flags)
: INHERITED(SAVE_LAYER) { : INHERITED(kSaveLayer_OpType) {
if (bounds) { if (bounds) {
fBounds = *bounds; fBounds = *bounds;
} else { } else {
@ -895,21 +888,8 @@ void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const {
canvas->save(); canvas->save();
} }
SkScaleCommand::SkScaleCommand(SkScalar sx, SkScalar sy)
: INHERITED(SCALE) {
fSx = sx;
fSy = sy;
fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
}
void SkScaleCommand::execute(SkCanvas* canvas) const {
canvas->scale(fSx, fSy);
}
SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix) SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
: INHERITED(SET_MATRIX) { : INHERITED(kSetMatrix_OpType) {
fUserMatrix.reset(); fUserMatrix.reset();
fMatrix = matrix; fMatrix = matrix;
@ -925,29 +905,3 @@ void SkSetMatrixCommand::execute(SkCanvas* canvas) const {
canvas->setMatrix(temp); canvas->setMatrix(temp);
} }
SkSkewCommand::SkSkewCommand(SkScalar sx, SkScalar sy)
: INHERITED(SKEW) {
fSx = sx;
fSy = sy;
fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
}
void SkSkewCommand::execute(SkCanvas* canvas) const {
canvas->skew(fSx, fSy);
}
SkTranslateCommand::SkTranslateCommand(SkScalar dx, SkScalar dy)
: INHERITED(TRANSLATE) {
fDx = dx;
fDy = dy;
fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
}
void SkTranslateCommand::execute(SkCanvas* canvas) const {
canvas->translate(fDx, fDy);
}

View File

@ -9,29 +9,56 @@
#ifndef SKDRAWCOMMAND_H_ #ifndef SKDRAWCOMMAND_H_
#define SKDRAWCOMMAND_H_ #define SKDRAWCOMMAND_H_
#include "SkPictureFlat.h"
#include "SkCanvas.h" #include "SkCanvas.h"
#include "SkString.h" #include "SkString.h"
class SK_API SkDrawCommand { class SK_API SkDrawCommand {
public: public:
// Staging for Chromium // Staging for Chromium
typedef DrawType OpType;
static const int kOpTypeCount = LAST_DRAWTYPE_ENUM+1;
static const char* kDrawRectString; static const char* kDrawRectString;
static const char* kClipRectString; static const char* kClipRectString;
static const OpType kSave_OpType;
static const OpType kClipRect_OpType;
static const OpType kDrawRect_OpType;
static const OpType kRestore_OpType;
static const OpType kSetMatrix_OpType;
// End Staging // End Staging
enum OpType {
kBeginCommentGroup_OpType,
kClipPath_OpType,
kClipRegion_OpType,
kClipRect_OpType,
kClipRRect_OpType,
kComment_OpType,
kConcat_OpType,
kDrawBitmap_OpType,
kDrawBitmapNine_OpType,
kDrawBitmapRect_OpType,
kDrawClear_OpType,
kDrawDRRect_OpType,
kDrawOval_OpType,
kDrawPaint_OpType,
kDrawPatch_OpType,
kDrawPath_OpType,
kDrawPicture_OpType,
kDrawPoints_OpType,
kDrawPosText_OpType,
kDrawPosTextH_OpType,
kDrawRect_OpType,
kDrawRRect_OpType,
kDrawSprite_OpType,
kDrawText_OpType,
kDrawTextBlob_OpType,
kDrawTextOnPath_OpType,
kDrawVertices_OpType,
kEndCommentGroup_OpType,
kRestore_OpType,
kSave_OpType,
kSaveLayer_OpType,
kSetMatrix_OpType,
SkDrawCommand(DrawType drawType); kLast_OpType = kSetMatrix_OpType
};
static const int kOpTypeCount = kLast_OpType + 1;
SkDrawCommand(OpType opType);
virtual ~SkDrawCommand(); virtual ~SkDrawCommand();
@ -41,7 +68,7 @@ public:
size_t offset() const { return fOffset; } size_t offset() const { return fOffset; }
virtual const char* toCString() const { virtual const char* toCString() const {
return GetCommandString(fDrawType); return GetCommandString(fOpType);
} }
bool isVisible() const { bool isVisible() const {
@ -73,17 +100,17 @@ public:
virtual void setActive(bool active) {} virtual void setActive(bool active) {}
virtual bool active() const { return false; } virtual bool active() const { return false; }
DrawType getType() const { return fDrawType; } OpType getType() const { return fOpType; }
virtual bool render(SkCanvas* canvas) const { return false; } virtual bool render(SkCanvas* canvas) const { return false; }
static const char* GetCommandString(DrawType type); static const char* GetCommandString(OpType type);
protected: protected:
SkTDArray<SkString*> fInfo; SkTDArray<SkString*> fInfo;
private: private:
DrawType fDrawType; OpType fOpType;
size_t fOffset; size_t fOffset;
bool fVisible; bool fVisible;
}; };
@ -430,6 +457,24 @@ private:
typedef SkDrawCommand INHERITED; typedef SkDrawCommand INHERITED;
}; };
class SkDrawPatchCommand : public SkDrawCommand {
public:
SkDrawPatchCommand(const SkPoint cubics[12], const SkColor colors[4],
const SkPoint texCoords[4], SkXfermode* xmode,
const SkPaint& paint);
void execute(SkCanvas* canvas) const SK_OVERRIDE;
private:
SkPoint fCubics[12];
SkColor fColors[4];
SkPoint fTexCoords[4];
SkAutoTUnref<SkXfermode> fXfermode;
SkPaint fPaint;
typedef SkDrawCommand INHERITED;
};
class SkDrawRectCommand : public SkDrawCommand { class SkDrawRectCommand : public SkDrawCommand {
public: public:
SkDrawRectCommand(const SkRect& rect, const SkPaint& paint); SkDrawRectCommand(const SkRect& rect, const SkPaint& paint);
@ -508,16 +553,6 @@ private:
typedef SkDrawCommand INHERITED; typedef SkDrawCommand INHERITED;
}; };
class SkRotateCommand : public SkDrawCommand {
public:
SkRotateCommand(SkScalar degrees);
void execute(SkCanvas* canvas) const SK_OVERRIDE;
private:
SkScalar fDegrees;
typedef SkDrawCommand INHERITED;
};
class SkSaveCommand : public SkDrawCommand { class SkSaveCommand : public SkDrawCommand {
public: public:
SkSaveCommand(); SkSaveCommand();
@ -550,21 +585,6 @@ private:
typedef SkDrawCommand INHERITED; typedef SkDrawCommand INHERITED;
}; };
class SkScaleCommand : public SkDrawCommand {
public:
SkScaleCommand(SkScalar sx, SkScalar sy);
void execute(SkCanvas* canvas) const SK_OVERRIDE;
SkScalar x() const { return fSx; }
SkScalar y() const { return fSy; }
private:
SkScalar fSx;
SkScalar fSy;
typedef SkDrawCommand INHERITED;
};
class SkSetMatrixCommand : public SkDrawCommand { class SkSetMatrixCommand : public SkDrawCommand {
public: public:
SkSetMatrixCommand(const SkMatrix& matrix); SkSetMatrixCommand(const SkMatrix& matrix);
@ -577,30 +597,4 @@ private:
typedef SkDrawCommand INHERITED; typedef SkDrawCommand INHERITED;
}; };
class SkSkewCommand : public SkDrawCommand {
public:
SkSkewCommand(SkScalar sx, SkScalar sy);
void execute(SkCanvas* canvas) const SK_OVERRIDE;
private:
SkScalar fSx;
SkScalar fSy;
typedef SkDrawCommand INHERITED;
};
class SkTranslateCommand : public SkDrawCommand {
public:
SkTranslateCommand(SkScalar dx, SkScalar dy);
void execute(SkCanvas* canvas) const SK_OVERRIDE;
SkScalar x() const { return fDx; }
SkScalar y() const { return fDy; }
private:
SkScalar fDx;
SkScalar fDy;
typedef SkDrawCommand INHERITED;
};
#endif #endif

View File

@ -49,10 +49,10 @@ static bool is_simple(const SkPaint& p) {
// RESTORE // RESTORE
// where the saveLayer's color can be moved into the drawBitmapRect // where the saveLayer's color can be moved into the drawBitmapRect
static bool check_0(SkDebugCanvas* canvas, int curCommand) { static bool check_0(SkDebugCanvas* canvas, int curCommand) {
if (SAVE_LAYER != canvas->getDrawCommandAt(curCommand)->getType() || if (SkDrawCommand::kSaveLayer_OpType != canvas->getDrawCommandAt(curCommand)->getType() ||
canvas->getSize() <= curCommand+2 || canvas->getSize() <= curCommand+2 ||
DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() || SkDrawCommand::kDrawBitmapRect_OpType != canvas->getDrawCommandAt(curCommand+1)->getType() ||
RESTORE != canvas->getDrawCommandAt(curCommand+2)->getType()) { SkDrawCommand::kRestore_OpType != canvas->getDrawCommandAt(curCommand+2)->getType()) {
return false; return false;
} }
@ -121,13 +121,13 @@ static void apply_0(SkDebugCanvas* canvas, int curCommand) {
// RESTORE // RESTORE
// where the saveLayer's color can be moved into the drawBitmapRect // where the saveLayer's color can be moved into the drawBitmapRect
static bool check_1(SkDebugCanvas* canvas, int curCommand) { static bool check_1(SkDebugCanvas* canvas, int curCommand) {
if (SAVE_LAYER != canvas->getDrawCommandAt(curCommand)->getType() || if (SkDrawCommand::kSaveLayer_OpType != canvas->getDrawCommandAt(curCommand)->getType() ||
canvas->getSize() <= curCommand+5 || canvas->getSize() <= curCommand+5 ||
SAVE != canvas->getDrawCommandAt(curCommand+1)->getType() || SkDrawCommand::kSave_OpType != canvas->getDrawCommandAt(curCommand+1)->getType() ||
CLIP_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() || SkDrawCommand::kClipRect_OpType != canvas->getDrawCommandAt(curCommand+2)->getType() ||
DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+3)->getType() || SkDrawCommand::kDrawBitmapRect_OpType != canvas->getDrawCommandAt(curCommand+3)->getType() ||
RESTORE != canvas->getDrawCommandAt(curCommand+4)->getType() || SkDrawCommand::kRestore_OpType != canvas->getDrawCommandAt(curCommand+4)->getType() ||
RESTORE != canvas->getDrawCommandAt(curCommand+5)->getType()) { SkDrawCommand::kRestore_OpType != canvas->getDrawCommandAt(curCommand+5)->getType()) {
return false; return false;
} }
@ -187,11 +187,11 @@ static void apply_1(SkDebugCanvas* canvas, int curCommand) {
// RESTORE // RESTORE
// where the rect is entirely within the clip and the clip is an intersect // where the rect is entirely within the clip and the clip is an intersect
static bool check_2(SkDebugCanvas* canvas, int curCommand) { static bool check_2(SkDebugCanvas* canvas, int curCommand) {
if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() || if (SkDrawCommand::kSave_OpType != canvas->getDrawCommandAt(curCommand)->getType() ||
canvas->getSize() <= curCommand+4 || canvas->getSize() <= curCommand+4 ||
CLIP_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() || SkDrawCommand::kClipRect_OpType != canvas->getDrawCommandAt(curCommand+1)->getType() ||
DRAW_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() || SkDrawCommand::kDrawRect_OpType != canvas->getDrawCommandAt(curCommand+2)->getType() ||
RESTORE != canvas->getDrawCommandAt(curCommand+3)->getType()) { SkDrawCommand::kRestore_OpType != canvas->getDrawCommandAt(curCommand+3)->getType()) {
return false; return false;
} }
@ -222,11 +222,11 @@ static void apply_2(SkDebugCanvas* canvas, int curCommand) {
// RESTORE // RESTORE
// where the rect entirely encloses the clip // where the rect entirely encloses the clip
static bool check_3(SkDebugCanvas* canvas, int curCommand) { static bool check_3(SkDebugCanvas* canvas, int curCommand) {
if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() || if (SkDrawCommand::kSave_OpType != canvas->getDrawCommandAt(curCommand)->getType() ||
canvas->getSize() <= curCommand+4 || canvas->getSize() <= curCommand+4 ||
CLIP_RRECT != canvas->getDrawCommandAt(curCommand+1)->getType() || SkDrawCommand::kClipRRect_OpType != canvas->getDrawCommandAt(curCommand+1)->getType() ||
DRAW_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() || SkDrawCommand::kDrawRect_OpType != canvas->getDrawCommandAt(curCommand+2)->getType() ||
RESTORE != canvas->getDrawCommandAt(curCommand+3)->getType()) { SkDrawCommand::kRestore_OpType != canvas->getDrawCommandAt(curCommand+3)->getType()) {
return false; return false;
} }
@ -270,11 +270,11 @@ static void apply_3(SkDebugCanvas* canvas, int curCommand) {
// RESTORE // RESTORE
// where the rect and drawBitmapRect dst exactly match // where the rect and drawBitmapRect dst exactly match
static bool check_4(SkDebugCanvas* canvas, int curCommand) { static bool check_4(SkDebugCanvas* canvas, int curCommand) {
if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() || if (SkDrawCommand::kSave_OpType != canvas->getDrawCommandAt(curCommand)->getType() ||
canvas->getSize() <= curCommand+4 || canvas->getSize() <= curCommand+4 ||
CLIP_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() || SkDrawCommand::kClipRect_OpType != canvas->getDrawCommandAt(curCommand+1)->getType() ||
DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() || SkDrawCommand::kDrawBitmapRect_OpType != canvas->getDrawCommandAt(curCommand+2)->getType() ||
RESTORE != canvas->getDrawCommandAt(curCommand+3)->getType()) { SkDrawCommand::kRestore_OpType != canvas->getDrawCommandAt(curCommand+3)->getType()) {
return false; return false;
} }
@ -298,43 +298,6 @@ static void apply_4(SkDebugCanvas* canvas, int curCommand) {
canvas->deleteDrawCommandAt(curCommand); // save canvas->deleteDrawCommandAt(curCommand); // save
} }
// Check for:
// TRANSLATE
// where the translate is zero
static bool check_5(SkDebugCanvas* canvas, int curCommand) {
if (TRANSLATE != canvas->getDrawCommandAt(curCommand)->getType()) {
return false;
}
SkTranslateCommand* t =
(SkTranslateCommand*) canvas->getDrawCommandAt(curCommand);
return 0 == t->x() && 0 == t->y();
}
// Just remove the translate
static void apply_5(SkDebugCanvas* canvas, int curCommand) {
canvas->deleteDrawCommandAt(curCommand); // translate
}
// Check for:
// SCALE
// where the scale is 1,1
static bool check_6(SkDebugCanvas* canvas, int curCommand) {
if (SCALE != canvas->getDrawCommandAt(curCommand)->getType()) {
return false;
}
SkScaleCommand* s = (SkScaleCommand*) canvas->getDrawCommandAt(curCommand);
return SK_Scalar1 == s->x() && SK_Scalar1 == s->y();
}
// Just remove the scale
static void apply_6(SkDebugCanvas* canvas, int curCommand) {
canvas->deleteDrawCommandAt(curCommand); // scale
}
// Check for: // Check for:
// SAVE // SAVE
// CLIP_RECT // CLIP_RECT
@ -357,21 +320,21 @@ static void apply_6(SkDebugCanvas* canvas, int curCommand) {
// all the saveLayer's paints can be rolled into the drawBitmapRectToRect's paint // all the saveLayer's paints can be rolled into the drawBitmapRectToRect's paint
// This pattern is used by Google spreadsheet when drawing the toolbar buttons // This pattern is used by Google spreadsheet when drawing the toolbar buttons
static bool check_7(SkDebugCanvas* canvas, int curCommand) { static bool check_7(SkDebugCanvas* canvas, int curCommand) {
if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() || if (SkDrawCommand::kSave_OpType != canvas->getDrawCommandAt(curCommand)->getType() ||
canvas->getSize() <= curCommand+13 || canvas->getSize() <= curCommand+13 ||
CLIP_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() || SkDrawCommand::kClipRect_OpType != canvas->getDrawCommandAt(curCommand+1)->getType() ||
SAVE_LAYER != canvas->getDrawCommandAt(curCommand+2)->getType() || SkDrawCommand::kSaveLayer_OpType != canvas->getDrawCommandAt(curCommand+2)->getType() ||
SAVE != canvas->getDrawCommandAt(curCommand+3)->getType() || SkDrawCommand::kSave_OpType != canvas->getDrawCommandAt(curCommand+3)->getType() ||
CLIP_RECT != canvas->getDrawCommandAt(curCommand+4)->getType() || SkDrawCommand::kClipRect_OpType != canvas->getDrawCommandAt(curCommand+4)->getType() ||
SAVE_LAYER != canvas->getDrawCommandAt(curCommand+5)->getType() || SkDrawCommand::kSaveLayer_OpType != canvas->getDrawCommandAt(curCommand+5)->getType() ||
SAVE != canvas->getDrawCommandAt(curCommand+6)->getType() || SkDrawCommand::kSave_OpType != canvas->getDrawCommandAt(curCommand+6)->getType() ||
CLIP_RECT != canvas->getDrawCommandAt(curCommand+7)->getType() || SkDrawCommand::kClipRect_OpType != canvas->getDrawCommandAt(curCommand+7)->getType() ||
DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+8)->getType() || SkDrawCommand::kDrawBitmapRect_OpType != canvas->getDrawCommandAt(curCommand+8)->getType() ||
RESTORE != canvas->getDrawCommandAt(curCommand+9)->getType() || SkDrawCommand::kRestore_OpType != canvas->getDrawCommandAt(curCommand+9)->getType() ||
RESTORE != canvas->getDrawCommandAt(curCommand+10)->getType() || SkDrawCommand::kRestore_OpType != canvas->getDrawCommandAt(curCommand+10)->getType() ||
RESTORE != canvas->getDrawCommandAt(curCommand+11)->getType() || SkDrawCommand::kRestore_OpType != canvas->getDrawCommandAt(curCommand+11)->getType() ||
RESTORE != canvas->getDrawCommandAt(curCommand+12)->getType() || SkDrawCommand::kRestore_OpType != canvas->getDrawCommandAt(curCommand+12)->getType() ||
RESTORE != canvas->getDrawCommandAt(curCommand+13)->getType()) { SkDrawCommand::kRestore_OpType != canvas->getDrawCommandAt(curCommand+13)->getType()) {
return false; return false;
} }
@ -533,11 +496,11 @@ static void apply_7(SkDebugCanvas* canvas, int curCommand) {
// the drawBitmapRectToRect is a 1-1 copy from src to dest // the drawBitmapRectToRect is a 1-1 copy from src to dest
// the clip rect is BW and a subset of the drawBitmapRectToRect's dest rect // the clip rect is BW and a subset of the drawBitmapRectToRect's dest rect
static bool check_8(SkDebugCanvas* canvas, int curCommand) { static bool check_8(SkDebugCanvas* canvas, int curCommand) {
if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() || if (SkDrawCommand::kSave_OpType != canvas->getDrawCommandAt(curCommand)->getType() ||
canvas->getSize() <= curCommand+4 || canvas->getSize() <= curCommand+4 ||
CLIP_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() || SkDrawCommand::kClipRect_OpType != canvas->getDrawCommandAt(curCommand+1)->getType() ||
DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() || SkDrawCommand::kDrawBitmapRect_OpType != canvas->getDrawCommandAt(curCommand+2)->getType() ||
RESTORE != canvas->getDrawCommandAt(curCommand+3)->getType()) { SkDrawCommand::kRestore_OpType != canvas->getDrawCommandAt(curCommand+3)->getType()) {
return false; return false;
} }
@ -607,11 +570,11 @@ static void apply_8(SkDebugCanvas* canvas, int curCommand) {
// where: // where:
// clipRect is BW and encloses the DBMR2R's dest rect // clipRect is BW and encloses the DBMR2R's dest rect
static bool check_9(SkDebugCanvas* canvas, int curCommand) { static bool check_9(SkDebugCanvas* canvas, int curCommand) {
if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() || if (SkDrawCommand::kSave_OpType != canvas->getDrawCommandAt(curCommand)->getType() ||
canvas->getSize() <= curCommand+4 || canvas->getSize() <= curCommand+4 ||
CLIP_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() || SkDrawCommand::kClipRect_OpType != canvas->getDrawCommandAt(curCommand+1)->getType() ||
DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() || SkDrawCommand::kDrawBitmapRect_OpType != canvas->getDrawCommandAt(curCommand+2)->getType() ||
RESTORE != canvas->getDrawCommandAt(curCommand+3)->getType()) { SkDrawCommand::kRestore_OpType != canvas->getDrawCommandAt(curCommand+3)->getType()) {
return false; return false;
} }
@ -652,8 +615,6 @@ struct OptTableEntry {
{ check_2, apply_2, 0 }, { check_2, apply_2, 0 },
{ check_3, apply_3, 0 }, { check_3, apply_3, 0 },
{ check_4, apply_4, 0 }, { check_4, apply_4, 0 },
{ check_5, apply_5, 0 },
{ check_6, apply_6, 0 },
{ check_7, apply_7, 0 }, { check_7, apply_7, 0 },
{ check_8, apply_8, 0 }, { check_8, apply_8, 0 },
{ check_9, apply_9, 0 }, { check_9, apply_9, 0 },