remove legacy build-flags for drawBitmapRect

add SkRect::isetWH()
Review URL: https://codereview.appspot.com/7127045

git-svn-id: http://skia.googlecode.com/svn/trunk@7221 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2013-01-16 15:15:24 +00:00
parent ddbd83a1e9
commit 6f54724c11
2 changed files with 15 additions and 53 deletions

View File

@ -371,7 +371,7 @@ struct SK_API SkRect {
r.set(0, 0, size.width(), size.height());
return r;
}
static SkRect SK_WARN_UNUSED_RESULT MakeLTRB(SkScalar l, SkScalar t, SkScalar r, SkScalar b) {
SkRect rect;
rect.set(l, t, r, b);
@ -481,6 +481,16 @@ struct SK_API SkRect {
fBottom = SkIntToScalar(bottom);
}
/**
* Set this rectangle to be left/top at 0,0, and have the specified width
* and height (automatically converted to SkScalar).
*/
void isetWH(int width, int height) {
fLeft = fTop = 0;
fRight = SkIntToScalar(width);
fBottom = SkIntToScalar(height);
}
/** Set this rectangle to be the bounds of the array of points.
If the array is empty (count == 0), then set this rectangle
to the empty rectangle (0,0,0,0)

View File

@ -352,51 +352,11 @@ void SkDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap,
void SkDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
const SkRect* src, const SkRect& dst,
const SkPaint& paint) {
#ifdef SK_SUPPORT_INT_SRCRECT_DRAWBITMAPRECT
SkMatrix matrix;
// Compute matrix from the two rectangles
{
SkRect tmpSrc;
if (src) {
tmpSrc = *src;
// if the extract process clipped off the top or left of the
// original, we adjust for that here to get the position right.
if (tmpSrc.fLeft > 0) {
tmpSrc.fRight -= tmpSrc.fLeft;
tmpSrc.fLeft = 0;
}
if (tmpSrc.fTop > 0) {
tmpSrc.fBottom -= tmpSrc.fTop;
tmpSrc.fTop = 0;
}
} else {
tmpSrc.set(0, 0, SkIntToScalar(bitmap.width()),
SkIntToScalar(bitmap.height()));
}
matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit);
}
// ensure that src is "valid" before we pass it to our internal routines
// and to SkDevice. i.e. sure it is contained inside the original bitmap.
SkIRect isrcStorage;
SkIRect* isrcPtr = NULL;
if (src) {
src->roundOut(&isrcStorage);
if (!isrcStorage.intersect(0, 0, bitmap.width(), bitmap.height())) {
return;
}
isrcPtr = &isrcStorage;
}
this->drawBitmap(draw, bitmap, isrcPtr, matrix, paint);
#else
SkMatrix matrix;
SkRect bitmapBounds, tmpSrc, tmpDst;
SkBitmap tmpBitmap;
bitmapBounds.set(0, 0,
SkIntToScalar(bitmap.width()),
SkIntToScalar(bitmap.height()));
bitmapBounds.isetWH(bitmap.width(), bitmap.height());
// Compute matrix from the two rectangles
if (src) {
@ -442,27 +402,20 @@ void SkDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
matrix.preTranslate(dx, dy);
}
#ifndef SK_IGNORE_DRAWBITMAPRECT_AS_DRAWBITMAP
SkRect extractedBitmapBounds;
extractedBitmapBounds.set(0, 0,
SkIntToScalar(bitmapPtr->width()),
SkIntToScalar(bitmapPtr->height()));
extractedBitmapBounds.isetWH(bitmapPtr->width(), bitmapPtr->height());
if (extractedBitmapBounds == tmpSrc) {
// no fractional part in src, we can just call drawBitmap
goto USE_DRAWBITMAP;
}
#endif
}
#ifndef SK_IGNORE_DRAWBITMAPRECT_AS_DRAWBITMAP
else {
USE_DRAWBITMAP:
} else {
USE_DRAWBITMAP:
// We can go faster by just calling drawBitmap, which will concat the
// matrix with the CTM, and try to call drawSprite if it can. If not,
// it will make a shader and call drawRect, as we do below.
this->drawBitmap(draw, *bitmapPtr, NULL, matrix, paint);
return;
}
#endif
// construct a shader, so we can call drawRect with the dst
SkShader* s = SkShader::CreateBitmapShader(*bitmapPtr,
@ -480,7 +433,6 @@ void SkDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
// Call ourself, in case the subclass wanted to share this setup code
// but handle the drawRect code themselves.
this->drawRect(draw, *dstPtr, paintWithShader);
#endif
}
void SkDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,