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:
parent
1c9c0d3711
commit
53ec73d1e6
@ -199,6 +199,48 @@ static SkBitmap createBitmap(const SkPath& path) {
|
|||||||
return bitmap;
|
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) {
|
bool SkDebugCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
|
||||||
SkBitmap bitmap = createBitmap(path);
|
SkBitmap bitmap = createBitmap(path);
|
||||||
addDrawCommand(new ClipPath(path, op, doAA, bitmap));
|
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,
|
void SkDebugCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar left,
|
||||||
SkScalar top, const SkPaint* paint = NULL) {
|
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,
|
void SkDebugCanvas::drawBitmapRectToRect(const SkBitmap& bitmap,
|
||||||
const SkRect* src, const SkRect& dst, const SkPaint* paint) {
|
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,
|
void SkDebugCanvas::drawBitmapMatrix(const SkBitmap& bitmap,
|
||||||
const SkMatrix& matrix, const SkPaint* paint) {
|
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,
|
void SkDebugCanvas::drawBitmapNine(const SkBitmap& bitmap,
|
||||||
const SkIRect& center, const SkRect& dst, const SkPaint* paint) {
|
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) {
|
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,
|
void SkDebugCanvas::drawSprite(const SkBitmap& bitmap, int left, int top,
|
||||||
const SkPaint* paint = NULL) {
|
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,
|
void SkDebugCanvas::drawText(const void* text, size_t byteLength, SkScalar x,
|
||||||
|
@ -135,12 +135,13 @@ void Concat::execute(SkCanvas* canvas) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DrawBitmap::DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
|
DrawBitmap::DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
|
||||||
const SkPaint* paint) {
|
const SkPaint* paint, SkBitmap& resizedBitmap) {
|
||||||
this->fBitmap = &bitmap;
|
this->fBitmap = &bitmap;
|
||||||
this->fLeft = left;
|
this->fLeft = left;
|
||||||
this->fTop = top;
|
this->fTop = top;
|
||||||
this->fPaint = paint;
|
this->fPaint = paint;
|
||||||
this->fDrawType = DRAW_BITMAP;
|
this->fDrawType = DRAW_BITMAP;
|
||||||
|
this->fResizedBitmap = resizedBitmap;
|
||||||
|
|
||||||
this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
|
this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
|
||||||
this->fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
|
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);
|
canvas->drawBitmap(*this->fBitmap, this->fLeft, this->fTop, this->fPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SkBitmap* DrawBitmap::getBitmap() const {
|
||||||
|
return &fResizedBitmap;
|
||||||
|
}
|
||||||
|
|
||||||
DrawBitmapMatrix::DrawBitmapMatrix(const SkBitmap& bitmap,
|
DrawBitmapMatrix::DrawBitmapMatrix(const SkBitmap& bitmap,
|
||||||
const SkMatrix& matrix, const SkPaint* paint) {
|
const SkMatrix& matrix, const SkPaint* paint, SkBitmap& resizedBitmap) {
|
||||||
this->fBitmap = &bitmap;
|
this->fBitmap = &bitmap;
|
||||||
this->fMatrix = &matrix;
|
this->fMatrix = &matrix;
|
||||||
this->fPaint = paint;
|
this->fPaint = paint;
|
||||||
this->fDrawType = DRAW_BITMAP_MATRIX;
|
this->fDrawType = DRAW_BITMAP_MATRIX;
|
||||||
|
this->fResizedBitmap = resizedBitmap;
|
||||||
|
|
||||||
this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
|
this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
|
||||||
this->fInfo.push(SkObjectParser::MatrixToString(matrix));
|
this->fInfo.push(SkObjectParser::MatrixToString(matrix));
|
||||||
@ -167,13 +173,18 @@ void DrawBitmapMatrix::execute(SkCanvas* canvas) {
|
|||||||
canvas->drawBitmapMatrix(*this->fBitmap, *this->fMatrix, this->fPaint);
|
canvas->drawBitmapMatrix(*this->fBitmap, *this->fMatrix, this->fPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SkBitmap* DrawBitmapMatrix::getBitmap() const {
|
||||||
|
return &fResizedBitmap;
|
||||||
|
}
|
||||||
|
|
||||||
DrawBitmapNine::DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
|
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->fBitmap = &bitmap;
|
||||||
this->fCenter = ¢er;
|
this->fCenter = ¢er;
|
||||||
this->fDst = &dst;
|
this->fDst = &dst;
|
||||||
this->fPaint = paint;
|
this->fPaint = paint;
|
||||||
this->fDrawType = DRAW_BITMAP_NINE;
|
this->fDrawType = DRAW_BITMAP_NINE;
|
||||||
|
this->fResizedBitmap = resizedBitmap;
|
||||||
|
|
||||||
this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
|
this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
|
||||||
this->fInfo.push(SkObjectParser::IRectToString(center));
|
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);
|
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,
|
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->fBitmap = &bitmap;
|
||||||
this->fSrc = src;
|
this->fSrc = src;
|
||||||
this->fDst = &dst;
|
this->fDst = &dst;
|
||||||
this->fPaint = paint;
|
this->fPaint = paint;
|
||||||
this->fDrawType = DRAW_BITMAP_RECT_TO_RECT;
|
this->fDrawType = DRAW_BITMAP_RECT_TO_RECT;
|
||||||
|
this->fResizedBitmap = resizedBitmap;
|
||||||
|
|
||||||
this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
|
this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
|
||||||
if (src) this->fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
|
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);
|
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) {
|
DrawData::DrawData(const void* data, size_t length) {
|
||||||
this->fData = data;
|
this->fData = data;
|
||||||
this->fLength = length;
|
this->fLength = length;
|
||||||
@ -324,12 +344,13 @@ void DrawRectC::execute(SkCanvas* canvas) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DrawSprite::DrawSprite(const SkBitmap& bitmap, int left, int top,
|
DrawSprite::DrawSprite(const SkBitmap& bitmap, int left, int top,
|
||||||
const SkPaint* paint) {
|
const SkPaint* paint, SkBitmap& resizedBitmap) {
|
||||||
this->fBitmap = &bitmap;
|
this->fBitmap = &bitmap;
|
||||||
this->fLeft = left;
|
this->fLeft = left;
|
||||||
this->fTop = top;
|
this->fTop = top;
|
||||||
this->fPaint = paint;
|
this->fPaint = paint;
|
||||||
this->fDrawType = DRAW_SPRITE;
|
this->fDrawType = DRAW_SPRITE;
|
||||||
|
this->fResizedBitmap = resizedBitmap;
|
||||||
|
|
||||||
this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
|
this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
|
||||||
this->fInfo.push(SkObjectParser::IntToString(left, "Left: "));
|
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);
|
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,
|
DrawTextC::DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y,
|
||||||
const SkPaint& paint) {
|
const SkPaint& paint) {
|
||||||
this->fText = text;
|
this->fText = text;
|
||||||
|
@ -105,48 +105,56 @@ private:
|
|||||||
class DrawBitmap : public SkDrawCommand {
|
class DrawBitmap : public SkDrawCommand {
|
||||||
public:
|
public:
|
||||||
DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
|
DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
|
||||||
const SkPaint* paint);
|
const SkPaint* paint, SkBitmap& resizedBitmap);
|
||||||
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
|
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
|
||||||
|
virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
|
||||||
private:
|
private:
|
||||||
const SkPaint* fPaint;
|
const SkPaint* fPaint;
|
||||||
const SkBitmap* fBitmap;
|
const SkBitmap* fBitmap;
|
||||||
SkScalar fLeft;
|
SkScalar fLeft;
|
||||||
SkScalar fTop;
|
SkScalar fTop;
|
||||||
|
SkBitmap fResizedBitmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DrawBitmapMatrix : public SkDrawCommand {
|
class DrawBitmapMatrix : public SkDrawCommand {
|
||||||
public:
|
public:
|
||||||
DrawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix,
|
DrawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix,
|
||||||
const SkPaint* paint);
|
const SkPaint* paint, SkBitmap& resizedBitmap);
|
||||||
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
|
virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
|
||||||
|
virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
|
||||||
private:
|
private:
|
||||||
const SkPaint* fPaint;
|
const SkPaint* fPaint;
|
||||||
const SkBitmap* fBitmap;
|
const SkBitmap* fBitmap;
|
||||||
const SkMatrix* fMatrix;
|
const SkMatrix* fMatrix;
|
||||||
|
SkBitmap fResizedBitmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DrawBitmapNine : public SkDrawCommand {
|
class DrawBitmapNine : public SkDrawCommand {
|
||||||
public:
|
public:
|
||||||
DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
|
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 void execute(SkCanvas* canvas) SK_OVERRIDE;
|
||||||
|
virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
|
||||||
private:
|
private:
|
||||||
const SkBitmap* fBitmap;
|
const SkBitmap* fBitmap;
|
||||||
const SkIRect* fCenter;
|
const SkIRect* fCenter;
|
||||||
const SkRect* fDst;
|
const SkRect* fDst;
|
||||||
const SkPaint* fPaint;
|
const SkPaint* fPaint;
|
||||||
|
SkBitmap fResizedBitmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DrawBitmapRect : public SkDrawCommand {
|
class DrawBitmapRect : public SkDrawCommand {
|
||||||
public:
|
public:
|
||||||
DrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
|
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 void execute(SkCanvas* canvas) SK_OVERRIDE;
|
||||||
|
virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
|
||||||
private:
|
private:
|
||||||
const SkRect* fSrc;
|
const SkRect* fSrc;
|
||||||
const SkPaint* fPaint;
|
const SkPaint* fPaint;
|
||||||
const SkBitmap* fBitmap;
|
const SkBitmap* fBitmap;
|
||||||
const SkRect* fDst;
|
const SkRect* fDst;
|
||||||
|
SkBitmap fResizedBitmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DrawData : public SkDrawCommand {
|
class DrawData : public SkDrawCommand {
|
||||||
@ -263,13 +271,16 @@ private:
|
|||||||
|
|
||||||
class DrawSprite : public SkDrawCommand {
|
class DrawSprite : public SkDrawCommand {
|
||||||
public:
|
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 void execute(SkCanvas* canvas) SK_OVERRIDE;
|
||||||
|
virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
|
||||||
private:
|
private:
|
||||||
const SkPaint* fPaint;
|
const SkPaint* fPaint;
|
||||||
int fLeft;
|
int fLeft;
|
||||||
int fTop;
|
int fTop;
|
||||||
const SkBitmap* fBitmap;
|
const SkBitmap* fBitmap;
|
||||||
|
SkBitmap fResizedBitmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DrawVertices : public SkDrawCommand {
|
class DrawVertices : public SkDrawCommand {
|
||||||
|
Loading…
Reference in New Issue
Block a user