#include "SkDrawCommand.h"
#include "SkObjectParser.h"
+#include "SkTextBlob.h"
+
// TODO(chudy): Refactor into non subclass model.
SkDrawCommand::SkDrawCommand(DrawType type)
case DRAW_RRECT: return "Draw RRect";
case DRAW_SPRITE: return "Draw Sprite";
case DRAW_TEXT: return "Draw Text";
+ case DRAW_TEXT_BLOB: return "Draw Text Blob";
case DRAW_TEXT_ON_PATH: return "Draw Text On Path";
case DRAW_VERTICES: return "Draw Vertices";
case RESTORE: return "Restore";
canvas->clear(0xFFFFFFFF);
canvas->drawBitmapRect(input, NULL, dst);
- if (NULL != srcRect) {
+ if (srcRect) {
SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
srcRect->fTop * yScale + SK_Scalar1,
srcRect->fRight * xScale + SK_Scalar1,
fBitmap = bitmap;
fLeft = left;
fTop = top;
- if (NULL != paint) {
+ if (paint) {
fPaint = *paint;
fPaintPtr = &fPaint;
} else {
fInfo.push(SkObjectParser::BitmapToString(bitmap));
fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
- if (NULL != paint) {
+ if (paint) {
fInfo.push(SkObjectParser::PaintToString(*paint));
}
}
: INHERITED(DRAW_BITMAP_MATRIX) {
fBitmap = bitmap;
fMatrix = matrix;
- if (NULL != paint) {
+ if (paint) {
fPaint = *paint;
fPaintPtr = &fPaint;
} else {
fInfo.push(SkObjectParser::BitmapToString(bitmap));
fInfo.push(SkObjectParser::MatrixToString(matrix));
- if (NULL != paint) {
+ if (paint) {
fInfo.push(SkObjectParser::PaintToString(*paint));
}
}
fBitmap = bitmap;
fCenter = center;
fDst = dst;
- if (NULL != paint) {
+ if (paint) {
fPaint = *paint;
fPaintPtr = &fPaint;
} else {
fInfo.push(SkObjectParser::BitmapToString(bitmap));
fInfo.push(SkObjectParser::IRectToString(center));
fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
- if (NULL != paint) {
+ if (paint) {
fInfo.push(SkObjectParser::PaintToString(*paint));
}
}
SkCanvas::DrawBitmapRectFlags flags)
: INHERITED(DRAW_BITMAP_RECT_TO_RECT) {
fBitmap = bitmap;
- if (NULL != src) {
+ if (src) {
fSrc = *src;
} else {
fSrc.setEmpty();
}
fDst = dst;
- if (NULL != paint) {
+ if (paint) {
fPaint = *paint;
fPaintPtr = &fPaint;
} else {
fFlags = flags;
fInfo.push(SkObjectParser::BitmapToString(bitmap));
- if (NULL != src) {
+ if (src) {
fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
}
fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
- if (NULL != paint) {
+ if (paint) {
fInfo.push(SkObjectParser::PaintToString(*paint));
}
fInfo.push(SkObjectParser::IntToString(fFlags, "Flags: "));
, fMatrixPtr(NULL)
, fPaintPtr(NULL) {
- if (NULL != matrix) {
+ if (matrix) {
fMatrix = *matrix;
fMatrixPtr = &fMatrix;
}
- if (NULL != paint) {
+ if (paint) {
fPaint = *paint;
fPaintPtr = &fPaint;
}
SkString* temp = new SkString;
- temp->appendf("SkPicture: W: %d H: %d", picture->width(), picture->height());
+ temp->appendf("SkPicture: L: %f T: %f R: %f B: %f",
+ picture->cullRect().fLeft, picture->cullRect().fTop,
+ picture->cullRect().fRight, picture->cullRect().fBottom);
fInfo.push(temp);
- if (NULL != matrix) {
+ if (matrix) {
fInfo.push(SkObjectParser::MatrixToString(*matrix));
}
- if (NULL != paint) {
+ if (paint) {
fInfo.push(SkObjectParser::PaintToString(*paint));
}
}
canvas->clear(0xFFFFFFFF);
canvas->save();
- SkRect bounds = SkRect::MakeWH(SkIntToScalar(fPicture->width()),
- SkIntToScalar(fPicture->height()));
- xlate_and_scale_to_bounds(canvas, bounds);
+ xlate_and_scale_to_bounds(canvas, fPicture->cullRect());
canvas->drawPicture(fPicture.get());
canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
}
+SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y,
+ const SkPaint& paint)
+ : INHERITED(DRAW_TEXT_BLOB)
+ , fBlob(blob)
+ , fXPos(x)
+ , fYPos(y)
+ , fPaint(paint) {
+
+ blob->ref();
+
+ // FIXME: push blob info
+ fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: "));
+ fInfo.push(SkObjectParser::ScalarToString(x, "YPOS: "));
+ fInfo.push(SkObjectParser::PaintToString(paint));
+}
+
+void SkDrawTextBlobCommand::execute(SkCanvas* canvas) {
+ canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint);
+}
+
+bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const {
+ canvas->clear(SK_ColorWHITE);
+ canvas->save();
+
+ SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos);
+ xlate_and_scale_to_bounds(canvas, bounds);
+
+ canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint);
+
+ canvas->restore();
+
+ return true;
+}
+
SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
: INHERITED(DRAW_RECT) {
fRect = rect;
fBitmap = bitmap;
fLeft = left;
fTop = top;
- if (NULL != paint) {
+ if (paint) {
fPaint = *paint;
fPaintPtr = &fPaint;
} else {
fInfo.push(SkObjectParser::BitmapToString(bitmap));
fInfo.push(SkObjectParser::IntToString(left, "Left: "));
fInfo.push(SkObjectParser::IntToString(top, "Top: "));
- if (NULL != paint) {
+ if (paint) {
fInfo.push(SkObjectParser::PaintToString(*paint));
}
}
memcpy(fText, text, byteLength);
fByteLength = byteLength;
fPath = path;
- if (NULL != matrix) {
+ if (matrix) {
fMatrix = *matrix;
} else {
fMatrix.setIdentity();
fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
fInfo.push(SkObjectParser::PathToString(path));
- if (NULL != matrix) {
+ if (matrix) {
fInfo.push(SkObjectParser::MatrixToString(*matrix));
}
fInfo.push(SkObjectParser::PaintToString(paint));
fVertices = new SkPoint[vertexCount];
memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
- if (NULL != texs) {
+ if (texs) {
fTexs = new SkPoint[vertexCount];
memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
} else {
fTexs = NULL;
}
- if (NULL != colors) {
+ if (colors) {
fColors = new SkColor[vertexCount];
memcpy(fColors, colors, vertexCount * sizeof(SkColor));
} else {
}
fXfermode = xfermode;
- if (NULL != fXfermode) {
+ if (fXfermode) {
fXfermode->ref();
}
SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
SkCanvas::SaveFlags flags)
: INHERITED(SAVE_LAYER) {
- if (NULL != bounds) {
+ if (bounds) {
fBounds = *bounds;
} else {
fBounds.setEmpty();
}
- if (NULL != paint) {
+ if (paint) {
fPaint = *paint;
fPaintPtr = &fPaint;
} else {
}
fFlags = flags;
- if (NULL != bounds) {
+ if (bounds) {
fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
}
- if (NULL != paint) {
+ if (paint) {
fInfo.push(SkObjectParser::PaintToString(*paint));
}
fInfo.push(SkObjectParser::SaveFlagsToString(flags));