Visualize bitmaps in debugger

https://codereview.appspot.com/6847084/



git-svn-id: http://skia.googlecode.com/svn/trunk@6541 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
robertphillips@google.com 2012-11-26 13:09:17 +00:00
parent 1c9c0d3711
commit 53ec73d1e6
3 changed files with 98 additions and 15 deletions

View File

@ -199,6 +199,48 @@ static SkBitmap createBitmap(const SkPath& path) {
return bitmap;
}
static SkBitmap createBitmap(const SkBitmap& input, const SkRect* srcRect) {
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config,
SkImageWidget::kImageWidgetWidth,
SkImageWidget::kImageWidgetHeight);
bitmap.allocPixels();
bitmap.eraseColor(SK_ColorLTGRAY);
SkDevice* device = new SkDevice(bitmap);
SkCanvas canvas(device);
device->unref();
SkScalar xScale = (SkImageWidget::kImageWidgetWidth-2.0) / input.width();
SkScalar yScale = (SkImageWidget::kImageWidgetHeight-2.0) / 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));
@ -222,22 +264,26 @@ bool SkDebugCanvas::concat(const SkMatrix& matrix) {
void SkDebugCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar left,
SkScalar top, const SkPaint* paint = NULL) {
addDrawCommand(new DrawBitmap(bitmap, left, top, paint));
SkBitmap resizedBitmap = createBitmap(bitmap, NULL);
addDrawCommand(new DrawBitmap(bitmap, left, top, paint, resizedBitmap));
}
void SkDebugCanvas::drawBitmapRectToRect(const SkBitmap& bitmap,
const SkRect* src, const SkRect& dst, const SkPaint* paint) {
addDrawCommand(new DrawBitmapRect(bitmap, src, dst, paint));
SkBitmap resizedBitmap = createBitmap(bitmap, src);
addDrawCommand(new DrawBitmapRect(bitmap, src, dst, paint, resizedBitmap));
}
void SkDebugCanvas::drawBitmapMatrix(const SkBitmap& bitmap,
const SkMatrix& matrix, const SkPaint* paint) {
addDrawCommand(new DrawBitmapMatrix(bitmap, matrix, paint));
SkBitmap resizedBitmap = createBitmap(bitmap, NULL);
addDrawCommand(new DrawBitmapMatrix(bitmap, matrix, paint, resizedBitmap));
}
void SkDebugCanvas::drawBitmapNine(const SkBitmap& bitmap,
const SkIRect& center, const SkRect& dst, const SkPaint* paint) {
addDrawCommand(new DrawBitmapNine(bitmap, center, dst, paint));
SkBitmap resizedBitmap = createBitmap(bitmap, NULL);
addDrawCommand(new DrawBitmapNine(bitmap, center, dst, paint, resizedBitmap));
}
void SkDebugCanvas::drawData(const void* data, size_t length) {
@ -279,7 +325,8 @@ void SkDebugCanvas::drawRect(const SkRect& rect, const SkPaint& paint) {
void SkDebugCanvas::drawSprite(const SkBitmap& bitmap, int left, int top,
const SkPaint* paint = NULL) {
addDrawCommand(new DrawSprite(bitmap, left, top, paint));
SkBitmap resizedBitmap = createBitmap(bitmap, NULL);
addDrawCommand(new DrawSprite(bitmap, left, top, paint, resizedBitmap));
}
void SkDebugCanvas::drawText(const void* text, size_t byteLength, SkScalar x,

View File

@ -135,12 +135,13 @@ void Concat::execute(SkCanvas* canvas) {
}
DrawBitmap::DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
const SkPaint* paint) {
const SkPaint* paint, SkBitmap& resizedBitmap) {
this->fBitmap = &bitmap;
this->fLeft = left;
this->fTop = top;
this->fPaint = paint;
this->fDrawType = DRAW_BITMAP;
this->fResizedBitmap = resizedBitmap;
this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
this->fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
@ -151,12 +152,17 @@ void DrawBitmap::execute(SkCanvas* canvas) {
canvas->drawBitmap(*this->fBitmap, this->fLeft, this->fTop, this->fPaint);
}
const SkBitmap* DrawBitmap::getBitmap() const {
return &fResizedBitmap;
}
DrawBitmapMatrix::DrawBitmapMatrix(const SkBitmap& bitmap,
const SkMatrix& matrix, const SkPaint* paint) {
const SkMatrix& matrix, const SkPaint* paint, SkBitmap& resizedBitmap) {
this->fBitmap = &bitmap;
this->fMatrix = &matrix;
this->fPaint = paint;
this->fDrawType = DRAW_BITMAP_MATRIX;
this->fResizedBitmap = resizedBitmap;
this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
this->fInfo.push(SkObjectParser::MatrixToString(matrix));
@ -167,13 +173,18 @@ void DrawBitmapMatrix::execute(SkCanvas* canvas) {
canvas->drawBitmapMatrix(*this->fBitmap, *this->fMatrix, this->fPaint);
}
const SkBitmap* DrawBitmapMatrix::getBitmap() const {
return &fResizedBitmap;
}
DrawBitmapNine::DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
const SkRect& dst, const SkPaint* paint) {
const SkRect& dst, const SkPaint* paint, SkBitmap& resizedBitmap) {
this->fBitmap = &bitmap;
this->fCenter = &center;
this->fDst = &dst;
this->fPaint = paint;
this->fDrawType = DRAW_BITMAP_NINE;
this->fResizedBitmap = resizedBitmap;
this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
this->fInfo.push(SkObjectParser::IRectToString(center));
@ -185,13 +196,18 @@ void DrawBitmapNine::execute(SkCanvas* canvas) {
canvas->drawBitmapNine(*this->fBitmap, *this->fCenter, *this->fDst, this->fPaint);
}
const SkBitmap* DrawBitmapNine::getBitmap() const {
return &fResizedBitmap;
}
DrawBitmapRect::DrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
const SkRect& dst, const SkPaint* paint) {
const SkRect& dst, const SkPaint* paint, SkBitmap& resizedBitmap) {
this->fBitmap = &bitmap;
this->fSrc = src;
this->fDst = &dst;
this->fPaint = paint;
this->fDrawType = DRAW_BITMAP_RECT_TO_RECT;
this->fResizedBitmap = resizedBitmap;
this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
if (src) this->fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
@ -203,6 +219,10 @@ void DrawBitmapRect::execute(SkCanvas* canvas) {
canvas->drawBitmapRectToRect(*this->fBitmap, this->fSrc, *this->fDst, this->fPaint);
}
const SkBitmap* DrawBitmapRect::getBitmap() const {
return &fResizedBitmap;
}
DrawData::DrawData(const void* data, size_t length) {
this->fData = data;
this->fLength = length;
@ -324,12 +344,13 @@ void DrawRectC::execute(SkCanvas* canvas) {
}
DrawSprite::DrawSprite(const SkBitmap& bitmap, int left, int top,
const SkPaint* paint) {
const SkPaint* paint, SkBitmap& resizedBitmap) {
this->fBitmap = &bitmap;
this->fLeft = left;
this->fTop = top;
this->fPaint = paint;
this->fDrawType = DRAW_SPRITE;
this->fResizedBitmap = resizedBitmap;
this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
this->fInfo.push(SkObjectParser::IntToString(left, "Left: "));
@ -340,6 +361,10 @@ void DrawSprite::execute(SkCanvas* canvas) {
canvas->drawSprite(*this->fBitmap, this->fLeft, this->fTop, this->fPaint);
}
const SkBitmap* DrawSprite::getBitmap() const {
return &fResizedBitmap;
}
DrawTextC::DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y,
const SkPaint& paint) {
this->fText = text;

View File

@ -105,48 +105,56 @@ private:
class DrawBitmap : public SkDrawCommand {
public:
DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
const SkPaint* paint);
const SkPaint* paint, SkBitmap& resizedBitmap);
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
private:
const SkPaint* fPaint;
const SkBitmap* fBitmap;
SkScalar fLeft;
SkScalar fTop;
SkBitmap fResizedBitmap;
};
class DrawBitmapMatrix : public SkDrawCommand {
public:
DrawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix,
const SkPaint* paint);
const SkPaint* paint, SkBitmap& resizedBitmap);
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
private:
const SkPaint* fPaint;
const SkBitmap* fBitmap;
const SkMatrix* fMatrix;
SkBitmap fResizedBitmap;
};
class DrawBitmapNine : public SkDrawCommand {
public:
DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
const SkRect& dst, const SkPaint* paint);
const SkRect& dst, const SkPaint* paint, SkBitmap& resizedBitmap);
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
private:
const SkBitmap* fBitmap;
const SkIRect* fCenter;
const SkRect* fDst;
const SkPaint* fPaint;
SkBitmap fResizedBitmap;
};
class DrawBitmapRect : public SkDrawCommand {
public:
DrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
const SkRect& dst, const SkPaint* paint);
const SkRect& dst, const SkPaint* paint, SkBitmap& resizedBitmap);
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
private:
const SkRect* fSrc;
const SkPaint* fPaint;
const SkBitmap* fBitmap;
const SkRect* fDst;
SkBitmap fResizedBitmap;
};
class DrawData : public SkDrawCommand {
@ -263,13 +271,16 @@ private:
class DrawSprite : public SkDrawCommand {
public:
DrawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint);
DrawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint,
SkBitmap& resizedBitmap);
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 fResizedBitmap;
};
class DrawVertices : public SkDrawCommand {