add drawBitmapNine to canvas

will add to device soon I think



git-svn-id: http://skia.googlecode.com/svn/trunk@2233 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2011-09-07 11:57:34 +00:00
parent 46a2a1ee46
commit f0b5e1190a
5 changed files with 55 additions and 1 deletions

View File

@ -542,6 +542,23 @@ public:
virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
const SkPaint* paint = NULL);
/**
* Draw the bitmap stretched differentially to fit into dst.
* center is a rect within the bitmap, and logically divides the bitmap
* into 9 sections (3x3). For example, if the middle pixel of a [5x5]
* bitmap is the "center", then the center-rect should be [2, 2, 3, 3].
*
* If the dst is >= the bitmap size, then...
* - The 4 corners are not stretch at all.
* - The sides are stretch in only one axis.
* - The center is stretch in both axes.
* Else, for each axis where dst < bitmap,
* - The corners shrink proportionally
* - The sides (along the shrink axis) and center are not drawn
*/
virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
const SkRect& dst, const SkPaint* paint = NULL);
/** Draw the specified bitmap, with its top/left corner at (x,y),
NOT transformed by the current matrix. Note: if the paint
contains a maskfilter that generates a mask which extends beyond the
@ -810,8 +827,16 @@ private:
bool isOpaque);
SkDevice* init(SkDevice*);
// internal methods are not virtual, so they can safely be called by other
// canvas apis, without confusing subclasses (like SkPictureRecording)
void internalDrawBitmap(const SkBitmap&, const SkIRect*, const SkMatrix& m,
const SkPaint* paint);
void internalDrawBitmapRect(const SkBitmap& bitmap, const SkIRect* src,
const SkRect& dst, const SkPaint* paint);
void internalDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
const SkRect& dst, const SkPaint* paint);
void drawDevice(SkDevice*, int x, int y, const SkPaint*);
// shared by save() and saveLayer()
int internalSave(SaveFlags flags);

View File

@ -24,6 +24,7 @@ enum DrawType {
CONCAT,
DRAW_BITMAP,
DRAW_BITMAP_MATRIX,
DRAW_BITMAP_NINE,
DRAW_BITMAP_RECT,
DRAW_CLEAR,
DRAW_DATA,

View File

@ -489,6 +489,10 @@ struct SkipClipRec {
};
#endif
static const SkIRect* skipIRect(SkReader32& reader) {
return (const SkIRect*)reader.skip(sizeof(SkIRect));
}
void SkPicturePlayback::draw(SkCanvas& canvas) {
#ifdef ENABLE_TIME_DRAW
SkAutoTime at("SkPicture::draw", 50);
@ -562,6 +566,13 @@ void SkPicturePlayback::draw(SkCanvas& canvas) {
const SkMatrix* matrix = getMatrix();
canvas.drawBitmapMatrix(bitmap, *matrix, paint);
} break;
case DRAW_BITMAP_NINE: {
const SkPaint* paint = getPaint();
const SkBitmap& bitmap = getBitmap();
const SkIRect* src = skipIRect(fReader);
const SkRect* dst = fReader.skipRect();
canvas.drawBitmapNine(bitmap, *src, *dst, paint);
} break;
case DRAW_CLEAR:
canvas.clear(getInt());
break;

View File

@ -258,7 +258,7 @@ void SkPictureRecord::drawBitmapRect(const SkBitmap& bitmap, const SkIRect* src,
}
void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix,
const SkPaint* paint) {
const SkPaint* paint) {
addDraw(DRAW_BITMAP_MATRIX);
addPaintPtr(paint);
addBitmap(bitmap);
@ -266,6 +266,16 @@ void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m
validate();
}
void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
const SkRect& dst, const SkPaint* paint) {
addDraw(DRAW_BITMAP_NINE);
addPaintPtr(paint);
addBitmap(bitmap);
addIRect(center);
addRect(dst);
validate();
}
void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top,
const SkPaint* paint = NULL) {
addDraw(DRAW_SPRITE);
@ -538,6 +548,10 @@ void SkPictureRecord::addRectPtr(const SkRect* rect) {
}
}
void SkPictureRecord::addIRect(const SkIRect& rect) {
fWriter.write(&rect, sizeof(rect));
}
void SkPictureRecord::addIRectPtr(const SkIRect* rect) {
if (fWriter.writeBool(rect != NULL)) {
*(SkIRect*)fWriter.reserve(sizeof(SkIRect)) = *rect;

View File

@ -46,6 +46,8 @@ public:
const SkRect& dst, const SkPaint*);
virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&,
const SkPaint*);
virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
const SkRect& dst, const SkPaint*);
virtual void drawSprite(const SkBitmap&, int left, int top,
const SkPaint*);
virtual void drawText(const void* text, size_t byteLength, SkScalar x,
@ -116,6 +118,7 @@ private:
void addPoints(const SkPoint pts[], int count);
void addRect(const SkRect& rect);
void addRectPtr(const SkRect* rect);
void addIRect(const SkIRect& rect);
void addIRectPtr(const SkIRect* rect);
void addRegion(const SkRegion& region);
void addText(const void* text, size_t byteLength);