Make SkDrawCommands lighter weight
https://codereview.chromium.org/15907023/ git-svn-id: http://skia.googlecode.com/svn/trunk@9470 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
7bb28a1679
commit
6ede1fe62b
@ -15,6 +15,14 @@ SkImageWidget::SkImageWidget(SkDebugger *debugger)
|
||||
: QWidget()
|
||||
, fDebugger(debugger) {
|
||||
this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cccccc;}");
|
||||
|
||||
SkImage::Info info;
|
||||
info.fWidth = kImageWidgetWidth;
|
||||
info.fHeight = kImageWidgetHeight;
|
||||
info.fColorType = SkImage::kPMColor_ColorType;
|
||||
info.fAlphaType = SkImage::kPremul_AlphaType;
|
||||
|
||||
fSurface = SkSurface::NewRasterDirect(info, fPixels, 4 * kImageWidgetWidth);
|
||||
}
|
||||
|
||||
void SkImageWidget::paintEvent(QPaintEvent* event) {
|
||||
@ -32,18 +40,14 @@ void SkImageWidget::paintEvent(QPaintEvent* event) {
|
||||
if (0 != commands.count()) {
|
||||
SkDrawCommand* command = commands[fDebugger->index()];
|
||||
|
||||
const SkBitmap* bitmap = command->getBitmap();
|
||||
|
||||
if (NULL != bitmap) {
|
||||
bitmap->lockPixels();
|
||||
|
||||
if (command->render(fSurface->getCanvas())) {
|
||||
QPoint origin(0,0);
|
||||
QImage image((uchar *)bitmap->getPixels(), bitmap->width(),
|
||||
bitmap->height(), QImage::Format_ARGB32_Premultiplied);
|
||||
QImage image((uchar*) fPixels,
|
||||
kImageWidgetWidth,
|
||||
kImageWidgetHeight,
|
||||
QImage::Format_ARGB32_Premultiplied);
|
||||
|
||||
painter.drawImage(origin, image);
|
||||
|
||||
bitmap->unlockPixels();
|
||||
} else {
|
||||
painter.drawRect(0, 0, kImageWidgetWidth, kImageWidgetHeight);
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "SkSurface.h"
|
||||
class SkDebugger;
|
||||
|
||||
class SkImageWidget : public QWidget {
|
||||
@ -18,6 +19,10 @@ class SkImageWidget : public QWidget {
|
||||
|
||||
public:
|
||||
SkImageWidget(SkDebugger* debugger);
|
||||
|
||||
virtual ~SkImageWidget() {
|
||||
fSurface->unref();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
this->update();
|
||||
@ -33,7 +38,9 @@ protected:
|
||||
void paintEvent(QPaintEvent* event);
|
||||
|
||||
private:
|
||||
SkDebugger *fDebugger;
|
||||
SkDebugger* fDebugger;
|
||||
char fPixels[kImageWidgetHeight * 4 * kImageWidgetWidth];
|
||||
SkSurface* fSurface;
|
||||
};
|
||||
|
||||
#endif /* SKIMAGEWIDGET_H_ */
|
||||
|
@ -261,83 +261,8 @@ void SkDebugCanvas::clear(SkColor color) {
|
||||
addDrawCommand(new Clear(color));
|
||||
}
|
||||
|
||||
static SkBitmap createBitmap(const SkPath& path) {
|
||||
SkBitmap bitmap;
|
||||
bitmap.setConfig(SkBitmap::kARGB_8888_Config,
|
||||
SkDebugCanvas::kVizImageWidth,
|
||||
SkDebugCanvas::kVizImageHeight);
|
||||
bitmap.allocPixels();
|
||||
bitmap.eraseColor(SK_ColorWHITE);
|
||||
SkDevice* device = new SkDevice(bitmap);
|
||||
|
||||
SkCanvas canvas(device);
|
||||
device->unref();
|
||||
|
||||
const SkRect& bounds = path.getBounds();
|
||||
|
||||
if (bounds.width() > bounds.height()) {
|
||||
canvas.scale(SkDoubleToScalar((0.9*SkDebugCanvas::kVizImageWidth)/bounds.width()),
|
||||
SkDoubleToScalar((0.9*SkDebugCanvas::kVizImageHeight)/bounds.width()));
|
||||
} else {
|
||||
canvas.scale(SkDoubleToScalar((0.9*SkDebugCanvas::kVizImageWidth)/bounds.height()),
|
||||
SkDoubleToScalar((0.9*SkDebugCanvas::kVizImageHeight)/bounds.height()));
|
||||
}
|
||||
canvas.translate(-bounds.fLeft+2, -bounds.fTop+2);
|
||||
|
||||
SkPaint p;
|
||||
p.setColor(SK_ColorBLACK);
|
||||
p.setStyle(SkPaint::kStroke_Style);
|
||||
|
||||
canvas.drawPath(path, p);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
static SkBitmap createBitmap(const SkBitmap& input, const SkRect* srcRect) {
|
||||
SkBitmap bitmap;
|
||||
bitmap.setConfig(SkBitmap::kARGB_8888_Config,
|
||||
SkDebugCanvas::kVizImageWidth,
|
||||
SkDebugCanvas::kVizImageHeight);
|
||||
bitmap.allocPixels();
|
||||
bitmap.eraseColor(SK_ColorLTGRAY);
|
||||
SkDevice* device = new SkDevice(bitmap);
|
||||
|
||||
SkCanvas canvas(device);
|
||||
device->unref();
|
||||
|
||||
SkScalar xScale = SkIntToScalar(SkDebugCanvas::kVizImageWidth-2) / input.width();
|
||||
SkScalar yScale = SkIntToScalar(SkDebugCanvas::kVizImageHeight-2) / input.height();
|
||||
|
||||
if (input.width() > input.height()) {
|
||||
yScale *= input.height() / (float) input.width();
|
||||
} else {
|
||||
xScale *= input.width() / (float) input.height();
|
||||
}
|
||||
|
||||
SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
|
||||
xScale * input.width(),
|
||||
yScale * input.height());
|
||||
|
||||
canvas.drawBitmapRect(input, NULL, dst);
|
||||
|
||||
if (NULL != srcRect) {
|
||||
SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
|
||||
srcRect->fTop * yScale + SK_Scalar1,
|
||||
srcRect->fRight * xScale + SK_Scalar1,
|
||||
srcRect->fBottom * yScale + SK_Scalar1);
|
||||
SkPaint p;
|
||||
p.setColor(SK_ColorRED);
|
||||
p.setStyle(SkPaint::kStroke_Style);
|
||||
|
||||
canvas.drawRect(r, p);
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
bool SkDebugCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
|
||||
SkBitmap bitmap = createBitmap(path);
|
||||
addDrawCommand(new ClipPath(path, op, doAA, bitmap));
|
||||
addDrawCommand(new ClipPath(path, op, doAA));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -363,26 +288,22 @@ bool SkDebugCanvas::concat(const SkMatrix& matrix) {
|
||||
|
||||
void SkDebugCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar left,
|
||||
SkScalar top, const SkPaint* paint = NULL) {
|
||||
SkBitmap resizedBitmap = createBitmap(bitmap, NULL);
|
||||
addDrawCommand(new DrawBitmap(bitmap, left, top, paint, resizedBitmap));
|
||||
addDrawCommand(new DrawBitmap(bitmap, left, top, paint));
|
||||
}
|
||||
|
||||
void SkDebugCanvas::drawBitmapRectToRect(const SkBitmap& bitmap,
|
||||
const SkRect* src, const SkRect& dst, const SkPaint* paint) {
|
||||
SkBitmap resizedBitmap = createBitmap(bitmap, src);
|
||||
addDrawCommand(new DrawBitmapRect(bitmap, src, dst, paint, resizedBitmap));
|
||||
addDrawCommand(new DrawBitmapRect(bitmap, src, dst, paint));
|
||||
}
|
||||
|
||||
void SkDebugCanvas::drawBitmapMatrix(const SkBitmap& bitmap,
|
||||
const SkMatrix& matrix, const SkPaint* paint) {
|
||||
SkBitmap resizedBitmap = createBitmap(bitmap, NULL);
|
||||
addDrawCommand(new DrawBitmapMatrix(bitmap, matrix, paint, resizedBitmap));
|
||||
addDrawCommand(new DrawBitmapMatrix(bitmap, matrix, paint));
|
||||
}
|
||||
|
||||
void SkDebugCanvas::drawBitmapNine(const SkBitmap& bitmap,
|
||||
const SkIRect& center, const SkRect& dst, const SkPaint* paint) {
|
||||
SkBitmap resizedBitmap = createBitmap(bitmap, NULL);
|
||||
addDrawCommand(new DrawBitmapNine(bitmap, center, dst, paint, resizedBitmap));
|
||||
addDrawCommand(new DrawBitmapNine(bitmap, center, dst, paint));
|
||||
}
|
||||
|
||||
void SkDebugCanvas::drawData(const void* data, size_t length) {
|
||||
@ -410,8 +331,7 @@ void SkDebugCanvas::drawPaint(const SkPaint& paint) {
|
||||
}
|
||||
|
||||
void SkDebugCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
|
||||
SkBitmap bitmap = createBitmap(path);
|
||||
addDrawCommand(new DrawPath(path, paint, bitmap));
|
||||
addDrawCommand(new DrawPath(path, paint));
|
||||
}
|
||||
|
||||
void SkDebugCanvas::drawPicture(SkPicture& picture) {
|
||||
@ -443,9 +363,8 @@ void SkDebugCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
|
||||
}
|
||||
|
||||
void SkDebugCanvas::drawSprite(const SkBitmap& bitmap, int left, int top,
|
||||
const SkPaint* paint = NULL) {
|
||||
SkBitmap resizedBitmap = createBitmap(bitmap, NULL);
|
||||
addDrawCommand(new DrawSprite(bitmap, left, top, paint, resizedBitmap));
|
||||
const SkPaint* paint = NULL) {
|
||||
addDrawCommand(new DrawSprite(bitmap, left, top, paint));
|
||||
}
|
||||
|
||||
void SkDebugCanvas::drawText(const void* text, size_t byteLength, SkScalar x,
|
||||
|
@ -87,12 +87,97 @@ void Clear::execute(SkCanvas* canvas) {
|
||||
canvas->clear(fColor);
|
||||
}
|
||||
|
||||
ClipPath::ClipPath(const SkPath& path, SkRegion::Op op, bool doAA, SkBitmap& bitmap) {
|
||||
namespace {
|
||||
|
||||
void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) {
|
||||
const SkISize& size = canvas->getDeviceSize();
|
||||
|
||||
static const SkScalar kInsetFrac = 0.9f; // Leave a border around object
|
||||
|
||||
canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f);
|
||||
if (bounds.width() > bounds.height()) {
|
||||
canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()),
|
||||
SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.width()));
|
||||
} else {
|
||||
canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.height()),
|
||||
SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.height()));
|
||||
}
|
||||
canvas->translate(-bounds.centerX(), -bounds.centerY());
|
||||
}
|
||||
|
||||
|
||||
void render_path(SkCanvas* canvas, const SkPath& path) {
|
||||
canvas->clear(0xFFFFFFFF);
|
||||
canvas->save();
|
||||
|
||||
const SkRect& bounds = path.getBounds();
|
||||
|
||||
xlate_and_scale_to_bounds(canvas, bounds);
|
||||
|
||||
SkPaint p;
|
||||
p.setColor(SK_ColorBLACK);
|
||||
p.setStyle(SkPaint::kStroke_Style);
|
||||
|
||||
canvas->drawPath(path, p);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = NULL) {
|
||||
const SkISize& size = canvas->getDeviceSize();
|
||||
|
||||
SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width();
|
||||
SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height();
|
||||
|
||||
if (input.width() > input.height()) {
|
||||
yScale *= input.height() / (float) input.width();
|
||||
} else {
|
||||
xScale *= input.width() / (float) input.height();
|
||||
}
|
||||
|
||||
SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
|
||||
xScale * input.width(),
|
||||
yScale * input.height());
|
||||
|
||||
canvas->clear(0xFFFFFFFF);
|
||||
canvas->drawBitmapRect(input, NULL, dst);
|
||||
|
||||
if (NULL != srcRect) {
|
||||
SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
|
||||
srcRect->fTop * yScale + SK_Scalar1,
|
||||
srcRect->fRight * xScale + SK_Scalar1,
|
||||
srcRect->fBottom * yScale + SK_Scalar1);
|
||||
SkPaint p;
|
||||
p.setColor(SK_ColorRED);
|
||||
p.setStyle(SkPaint::kStroke_Style);
|
||||
|
||||
canvas->drawRect(r, p);
|
||||
}
|
||||
}
|
||||
|
||||
void render_rrect(SkCanvas* canvas, const SkRRect& rrect) {
|
||||
canvas->clear(0xFFFFFFFF);
|
||||
canvas->save();
|
||||
|
||||
const SkRect& bounds = rrect.getBounds();
|
||||
|
||||
xlate_and_scale_to_bounds(canvas, bounds);
|
||||
|
||||
SkPaint p;
|
||||
p.setColor(SK_ColorBLACK);
|
||||
p.setStyle(SkPaint::kStroke_Style);
|
||||
|
||||
canvas->drawRRect(rrect, p);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
ClipPath::ClipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
|
||||
fPath = path;
|
||||
fOp = op;
|
||||
fDoAA = doAA;
|
||||
fDrawType = CLIP_PATH;
|
||||
fBitmap = bitmap;
|
||||
|
||||
fInfo.push(SkObjectParser::PathToString(path));
|
||||
fInfo.push(SkObjectParser::RegionOpToString(op));
|
||||
@ -103,8 +188,9 @@ void ClipPath::execute(SkCanvas* canvas) {
|
||||
canvas->clipPath(fPath, fOp, fDoAA);
|
||||
}
|
||||
|
||||
const SkBitmap* ClipPath::getBitmap() const {
|
||||
return &fBitmap;
|
||||
bool ClipPath::render(SkCanvas* canvas) const {
|
||||
render_path(canvas, fPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
ClipRegion::ClipRegion(const SkRegion& region, SkRegion::Op op) {
|
||||
@ -150,6 +236,11 @@ void ClipRRect::execute(SkCanvas* canvas) {
|
||||
canvas->clipRRect(fRRect, fOp, fDoAA);
|
||||
}
|
||||
|
||||
bool ClipRRect::render(SkCanvas* canvas) const {
|
||||
render_rrect(canvas, fRRect);
|
||||
return true;
|
||||
}
|
||||
|
||||
Concat::Concat(const SkMatrix& matrix) {
|
||||
fMatrix = matrix;
|
||||
fDrawType = CONCAT;
|
||||
@ -162,7 +253,7 @@ void Concat::execute(SkCanvas* canvas) {
|
||||
}
|
||||
|
||||
DrawBitmap::DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
|
||||
const SkPaint* paint, SkBitmap& resizedBitmap) {
|
||||
const SkPaint* paint) {
|
||||
fBitmap = bitmap;
|
||||
fLeft = left;
|
||||
fTop = top;
|
||||
@ -173,7 +264,6 @@ DrawBitmap::DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
|
||||
fPaintPtr = NULL;
|
||||
}
|
||||
fDrawType = DRAW_BITMAP;
|
||||
fResizedBitmap = resizedBitmap;
|
||||
|
||||
fInfo.push(SkObjectParser::BitmapToString(bitmap));
|
||||
fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
|
||||
@ -187,14 +277,14 @@ void DrawBitmap::execute(SkCanvas* canvas) {
|
||||
canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
|
||||
}
|
||||
|
||||
const SkBitmap* DrawBitmap::getBitmap() const {
|
||||
return &fResizedBitmap;
|
||||
bool DrawBitmap::render(SkCanvas* canvas) const {
|
||||
render_bitmap(canvas, fBitmap);
|
||||
return true;
|
||||
}
|
||||
|
||||
DrawBitmapMatrix::DrawBitmapMatrix(const SkBitmap& bitmap,
|
||||
const SkMatrix& matrix,
|
||||
const SkPaint* paint,
|
||||
SkBitmap& resizedBitmap) {
|
||||
const SkPaint* paint) {
|
||||
fBitmap = bitmap;
|
||||
fMatrix = matrix;
|
||||
if (NULL != paint) {
|
||||
@ -204,7 +294,6 @@ DrawBitmapMatrix::DrawBitmapMatrix(const SkBitmap& bitmap,
|
||||
fPaintPtr = NULL;
|
||||
}
|
||||
fDrawType = DRAW_BITMAP_MATRIX;
|
||||
fResizedBitmap = resizedBitmap;
|
||||
|
||||
fInfo.push(SkObjectParser::BitmapToString(bitmap));
|
||||
fInfo.push(SkObjectParser::MatrixToString(matrix));
|
||||
@ -217,13 +306,13 @@ void DrawBitmapMatrix::execute(SkCanvas* canvas) {
|
||||
canvas->drawBitmapMatrix(fBitmap, fMatrix, fPaintPtr);
|
||||
}
|
||||
|
||||
const SkBitmap* DrawBitmapMatrix::getBitmap() const {
|
||||
return &fResizedBitmap;
|
||||
bool DrawBitmapMatrix::render(SkCanvas* canvas) const {
|
||||
render_bitmap(canvas, fBitmap);
|
||||
return true;
|
||||
}
|
||||
|
||||
DrawBitmapNine::DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
|
||||
const SkRect& dst, const SkPaint* paint,
|
||||
SkBitmap& resizedBitmap) {
|
||||
const SkRect& dst, const SkPaint* paint) {
|
||||
fBitmap = bitmap;
|
||||
fCenter = center;
|
||||
fDst = dst;
|
||||
@ -234,7 +323,6 @@ DrawBitmapNine::DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
|
||||
fPaintPtr = NULL;
|
||||
}
|
||||
fDrawType = DRAW_BITMAP_NINE;
|
||||
fResizedBitmap = resizedBitmap;
|
||||
|
||||
fInfo.push(SkObjectParser::BitmapToString(bitmap));
|
||||
fInfo.push(SkObjectParser::IRectToString(center));
|
||||
@ -248,13 +336,13 @@ void DrawBitmapNine::execute(SkCanvas* canvas) {
|
||||
canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
|
||||
}
|
||||
|
||||
const SkBitmap* DrawBitmapNine::getBitmap() const {
|
||||
return &fResizedBitmap;
|
||||
bool DrawBitmapNine::render(SkCanvas* canvas) const {
|
||||
render_bitmap(canvas, fBitmap);
|
||||
return true;
|
||||
}
|
||||
|
||||
DrawBitmapRect::DrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
|
||||
const SkRect& dst, const SkPaint* paint,
|
||||
SkBitmap& resizedBitmap) {
|
||||
const SkRect& dst, const SkPaint* paint) {
|
||||
fBitmap = bitmap;
|
||||
if (NULL != src) {
|
||||
fSrc = *src;
|
||||
@ -270,7 +358,6 @@ DrawBitmapRect::DrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
|
||||
fPaintPtr = NULL;
|
||||
}
|
||||
fDrawType = DRAW_BITMAP_RECT_TO_RECT;
|
||||
fResizedBitmap = resizedBitmap;
|
||||
|
||||
fInfo.push(SkObjectParser::BitmapToString(bitmap));
|
||||
if (NULL != src) {
|
||||
@ -286,8 +373,9 @@ void DrawBitmapRect::execute(SkCanvas* canvas) {
|
||||
canvas->drawBitmapRectToRect(fBitmap, this->srcRect(), fDst, fPaintPtr);
|
||||
}
|
||||
|
||||
const SkBitmap* DrawBitmapRect::getBitmap() const {
|
||||
return &fResizedBitmap;
|
||||
bool DrawBitmapRect::render(SkCanvas* canvas) const {
|
||||
render_bitmap(canvas, fBitmap, this->srcRect());
|
||||
return true;
|
||||
}
|
||||
|
||||
DrawData::DrawData(const void* data, size_t length) {
|
||||
@ -339,6 +427,22 @@ void DrawOval::execute(SkCanvas* canvas) {
|
||||
canvas->drawOval(fOval, fPaint);
|
||||
}
|
||||
|
||||
bool DrawOval::render(SkCanvas* canvas) const {
|
||||
canvas->clear(0xFFFFFFFF);
|
||||
canvas->save();
|
||||
|
||||
xlate_and_scale_to_bounds(canvas, fOval);
|
||||
|
||||
SkPaint p;
|
||||
p.setColor(SK_ColorBLACK);
|
||||
p.setStyle(SkPaint::kStroke_Style);
|
||||
|
||||
canvas->drawOval(fOval, p);
|
||||
canvas->restore();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DrawPaint::DrawPaint(const SkPaint& paint) {
|
||||
fPaint = paint;
|
||||
fDrawType = DRAW_PAINT;
|
||||
@ -350,10 +454,15 @@ void DrawPaint::execute(SkCanvas* canvas) {
|
||||
canvas->drawPaint(fPaint);
|
||||
}
|
||||
|
||||
DrawPath::DrawPath(const SkPath& path, const SkPaint& paint, SkBitmap& bitmap) {
|
||||
bool DrawPaint::render(SkCanvas* canvas) const {
|
||||
canvas->clear(0xFFFFFFFF);
|
||||
canvas->drawPaint(fPaint);
|
||||
return true;
|
||||
}
|
||||
|
||||
DrawPath::DrawPath(const SkPath& path, const SkPaint& paint) {
|
||||
fPath = path;
|
||||
fPaint = paint;
|
||||
fBitmap = bitmap;
|
||||
fDrawType = DRAW_PATH;
|
||||
|
||||
fInfo.push(SkObjectParser::PathToString(path));
|
||||
@ -364,8 +473,9 @@ void DrawPath::execute(SkCanvas* canvas) {
|
||||
canvas->drawPath(fPath, fPaint);
|
||||
}
|
||||
|
||||
const SkBitmap* DrawPath::getBitmap() const {
|
||||
return &fBitmap;
|
||||
bool DrawPath::render(SkCanvas* canvas) const {
|
||||
render_path(canvas, fPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
DrawPicture::DrawPicture(SkPicture& picture) :
|
||||
@ -398,6 +508,29 @@ void DrawPoints::execute(SkCanvas* canvas) {
|
||||
canvas->drawPoints(fMode, fCount, fPts, fPaint);
|
||||
}
|
||||
|
||||
bool DrawPoints::render(SkCanvas* canvas) const {
|
||||
canvas->clear(0xFFFFFFFF);
|
||||
canvas->save();
|
||||
|
||||
SkRect bounds;
|
||||
|
||||
bounds.setEmpty();
|
||||
for (unsigned int i = 0; i < fCount; ++i) {
|
||||
bounds.growToInclude(fPts[i].fX, fPts[i].fY);
|
||||
}
|
||||
|
||||
xlate_and_scale_to_bounds(canvas, bounds);
|
||||
|
||||
SkPaint p;
|
||||
p.setColor(SK_ColorBLACK);
|
||||
p.setStyle(SkPaint::kStroke_Style);
|
||||
|
||||
canvas->drawPoints(fMode, fCount, fPts, p);
|
||||
canvas->restore();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DrawPosText::DrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
|
||||
const SkPaint& paint) {
|
||||
size_t numPts = paint.countText(text, byteLength);
|
||||
@ -475,8 +608,13 @@ void DrawRRect::execute(SkCanvas* canvas) {
|
||||
canvas->drawRRect(fRRect, fPaint);
|
||||
}
|
||||
|
||||
bool DrawRRect::render(SkCanvas* canvas) const {
|
||||
render_rrect(canvas, fRRect);
|
||||
return true;
|
||||
}
|
||||
|
||||
DrawSprite::DrawSprite(const SkBitmap& bitmap, int left, int top,
|
||||
const SkPaint* paint, SkBitmap& resizedBitmap) {
|
||||
const SkPaint* paint) {
|
||||
fBitmap = bitmap;
|
||||
fLeft = left;
|
||||
fTop = top;
|
||||
@ -487,7 +625,6 @@ DrawSprite::DrawSprite(const SkBitmap& bitmap, int left, int top,
|
||||
fPaintPtr = NULL;
|
||||
}
|
||||
fDrawType = DRAW_SPRITE;
|
||||
fResizedBitmap = resizedBitmap;
|
||||
|
||||
fInfo.push(SkObjectParser::BitmapToString(bitmap));
|
||||
fInfo.push(SkObjectParser::IntToString(left, "Left: "));
|
||||
@ -501,8 +638,9 @@ void DrawSprite::execute(SkCanvas* canvas) {
|
||||
canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
|
||||
}
|
||||
|
||||
const SkBitmap* DrawSprite::getBitmap() const {
|
||||
return &fResizedBitmap;
|
||||
bool DrawSprite::render(SkCanvas* canvas) const {
|
||||
render_bitmap(canvas, fBitmap);
|
||||
return true;
|
||||
}
|
||||
|
||||
DrawTextC::DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y,
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
virtual void trackSaveState(int* state) { };
|
||||
DrawType getType() { return fDrawType; };
|
||||
|
||||
virtual const SkBitmap* getBitmap() const { return NULL; }
|
||||
virtual bool render(SkCanvas* canvas) const { return false; }
|
||||
|
||||
static const char* GetCommandString(DrawType type);
|
||||
|
||||
@ -76,14 +76,13 @@ private:
|
||||
|
||||
class ClipPath : public SkDrawCommand {
|
||||
public:
|
||||
ClipPath(const SkPath& path, SkRegion::Op op, bool doAA, SkBitmap& bitmap);
|
||||
ClipPath(const SkPath& path, SkRegion::Op op, bool doAA);
|
||||
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
|
||||
virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
|
||||
virtual bool render(SkCanvas* canvas) const SK_OVERRIDE;
|
||||
private:
|
||||
SkPath fPath;
|
||||
SkRegion::Op fOp;
|
||||
bool fDoAA;
|
||||
SkBitmap fBitmap;
|
||||
|
||||
typedef SkDrawCommand INHERITED;
|
||||
};
|
||||
@ -120,6 +119,7 @@ class ClipRRect : public SkDrawCommand {
|
||||
public:
|
||||
ClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA);
|
||||
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
|
||||
virtual bool render(SkCanvas* canvas) const SK_OVERRIDE;
|
||||
|
||||
const SkRRect& rrect() const { return fRRect; }
|
||||
SkRegion::Op op() const { return fOp; }
|
||||
@ -146,16 +146,15 @@ private:
|
||||
class DrawBitmap : public SkDrawCommand {
|
||||
public:
|
||||
DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
|
||||
const SkPaint* paint, SkBitmap& resizedBitmap);
|
||||
const SkPaint* paint);
|
||||
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
|
||||
virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
|
||||
virtual bool render(SkCanvas* canvas) const SK_OVERRIDE;
|
||||
private:
|
||||
SkBitmap fBitmap;
|
||||
SkScalar fLeft;
|
||||
SkScalar fTop;
|
||||
SkPaint fPaint;
|
||||
SkPaint* fPaintPtr;
|
||||
SkBitmap fResizedBitmap;
|
||||
|
||||
typedef SkDrawCommand INHERITED;
|
||||
};
|
||||
@ -163,15 +162,14 @@ private:
|
||||
class DrawBitmapMatrix : public SkDrawCommand {
|
||||
public:
|
||||
DrawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix,
|
||||
const SkPaint* paint, SkBitmap& resizedBitmap);
|
||||
const SkPaint* paint);
|
||||
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
|
||||
virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
|
||||
virtual bool render(SkCanvas* canvas) const SK_OVERRIDE;
|
||||
private:
|
||||
SkBitmap fBitmap;
|
||||
SkMatrix fMatrix;
|
||||
SkPaint fPaint;
|
||||
SkPaint* fPaintPtr;
|
||||
SkBitmap fResizedBitmap;
|
||||
|
||||
typedef SkDrawCommand INHERITED;
|
||||
};
|
||||
@ -179,17 +177,15 @@ private:
|
||||
class DrawBitmapNine : public SkDrawCommand {
|
||||
public:
|
||||
DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
|
||||
const SkRect& dst, const SkPaint* paint,
|
||||
SkBitmap& resizedBitmap);
|
||||
const SkRect& dst, const SkPaint* paint);
|
||||
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
|
||||
virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
|
||||
virtual bool render(SkCanvas* canvas) const SK_OVERRIDE;
|
||||
private:
|
||||
SkBitmap fBitmap;
|
||||
SkIRect fCenter;
|
||||
SkRect fDst;
|
||||
SkPaint fPaint;
|
||||
SkPaint* fPaintPtr;
|
||||
SkBitmap fResizedBitmap;
|
||||
|
||||
typedef SkDrawCommand INHERITED;
|
||||
};
|
||||
@ -197,10 +193,9 @@ private:
|
||||
class DrawBitmapRect : public SkDrawCommand {
|
||||
public:
|
||||
DrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
|
||||
const SkRect& dst, const SkPaint* paint,
|
||||
SkBitmap& resizedBitmap);
|
||||
const SkRect& dst, const SkPaint* paint);
|
||||
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
|
||||
virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
|
||||
virtual bool render(SkCanvas* canvas) const SK_OVERRIDE;
|
||||
|
||||
const SkBitmap& bitmap() const { return fBitmap; }
|
||||
|
||||
@ -225,7 +220,6 @@ private:
|
||||
SkRect fDst;
|
||||
SkPaint fPaint;
|
||||
SkPaint* fPaintPtr;
|
||||
SkBitmap fResizedBitmap;
|
||||
|
||||
typedef SkDrawCommand INHERITED;
|
||||
};
|
||||
@ -281,6 +275,7 @@ class DrawOval : public SkDrawCommand {
|
||||
public:
|
||||
DrawOval(const SkRect& oval, const SkPaint& paint);
|
||||
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
|
||||
virtual bool render(SkCanvas* canvas) const SK_OVERRIDE;
|
||||
private:
|
||||
SkRect fOval;
|
||||
SkPaint fPaint;
|
||||
@ -292,6 +287,7 @@ class DrawPaint : public SkDrawCommand {
|
||||
public:
|
||||
DrawPaint(const SkPaint& paint);
|
||||
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
|
||||
virtual bool render(SkCanvas* canvas) const SK_OVERRIDE;
|
||||
private:
|
||||
SkPaint fPaint;
|
||||
|
||||
@ -300,14 +296,13 @@ private:
|
||||
|
||||
class DrawPath : public SkDrawCommand {
|
||||
public:
|
||||
DrawPath(const SkPath& path, const SkPaint& paint, SkBitmap& bitmap);
|
||||
DrawPath(const SkPath& path, const SkPaint& paint);
|
||||
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
|
||||
virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
|
||||
virtual bool render(SkCanvas* canvas) const SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
SkPath fPath;
|
||||
SkPaint fPaint;
|
||||
SkBitmap fBitmap;
|
||||
|
||||
typedef SkDrawCommand INHERITED;
|
||||
};
|
||||
@ -328,7 +323,7 @@ public:
|
||||
const SkPaint& paint);
|
||||
virtual ~DrawPoints() { delete [] fPts; }
|
||||
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
|
||||
|
||||
virtual bool render(SkCanvas* canvas) const SK_OVERRIDE;
|
||||
private:
|
||||
SkCanvas::PointMode fMode;
|
||||
size_t fCount;
|
||||
@ -422,6 +417,7 @@ class DrawRRect : public SkDrawCommand {
|
||||
public:
|
||||
DrawRRect(const SkRRect& rrect, const SkPaint& paint);
|
||||
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
|
||||
virtual bool render(SkCanvas* canvas) const SK_OVERRIDE;
|
||||
private:
|
||||
SkRRect fRRect;
|
||||
SkPaint fPaint;
|
||||
@ -431,17 +427,15 @@ private:
|
||||
|
||||
class DrawSprite : public SkDrawCommand {
|
||||
public:
|
||||
DrawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint,
|
||||
SkBitmap& resizedBitmap);
|
||||
DrawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint);
|
||||
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
|
||||
virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
|
||||
virtual bool render(SkCanvas* canvas) const SK_OVERRIDE;
|
||||
private:
|
||||
SkBitmap fBitmap;
|
||||
int fLeft;
|
||||
int fTop;
|
||||
SkPaint fPaint;
|
||||
SkPaint* fPaintPtr;
|
||||
SkBitmap fResizedBitmap;
|
||||
|
||||
typedef SkDrawCommand INHERITED;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user