aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2009-10-16 14:48:38 +0000
committerGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2009-10-16 14:48:38 +0000
commit878999965b977c4ed771c3d655f9e23ef9b5adb1 (patch)
tree99f5eb66cf5a3b7cdc955c3ff687d16109968d59
parentfead49e3c43e67cf9648ec1999b34da959e1e36b (diff)
clean up fix to drawBitmapRect
git-svn-id: http://skia.googlecode.com/svn/trunk@388 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--samplecode/SampleBitmapRect.cpp7
-rw-r--r--src/core/SkCanvas.cpp41
2 files changed, 20 insertions, 28 deletions
diff --git a/samplecode/SampleBitmapRect.cpp b/samplecode/SampleBitmapRect.cpp
index 842dfc4904..0d981d6a4a 100644
--- a/samplecode/SampleBitmapRect.cpp
+++ b/samplecode/SampleBitmapRect.cpp
@@ -60,7 +60,7 @@ protected:
const SkIRect src[] = {
{ 0, 0, 32, 32 },
- { -8, -8, 80, 80 },
+ { 0, 0, 80, 80 },
{ 32, 32, 96, 96 },
{ -32, -32, 32, 32, }
};
@@ -73,11 +73,12 @@ protected:
canvas->translate(16, 40);
for (size_t i = 0; i < SK_ARRAY_COUNT(src); i++) {
+ SkRect srcR;
+ srcR.set(src[i]);
+
canvas->drawBitmap(fBitmap, 0, 0, &paint);
canvas->drawBitmapRect(fBitmap, &src[i], dstR, &paint);
- SkRect srcR;
- srcR.set(src[i]);
canvas->drawRect(srcR, paint);
canvas->drawRect(dstR, paint);
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index ce4a624ec7..0bf0614264 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -1113,33 +1113,24 @@ void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkIRect* src,
}
SkMatrix matrix;
-#if 0
- SkScalar width = SkIntToScalar(bitmapPtr->width());
- SkScalar height = SkIntToScalar(bitmapPtr->height());
- if (dst.width() == width && dst.height() == height) {
- matrix.setTranslate(dst.fLeft, dst.fTop);
- } else
-#endif
- {
- SkRect tmpSrc;
- if (src) {
- tmpSrc.set(*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()));
+ SkRect tmpSrc;
+ if (src) {
+ tmpSrc.set(*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;
}
- matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit);
+ 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);
this->internalDrawBitmap(*bitmapPtr, matrix, paint);
}