aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2009-06-24 12:41:42 +0000
committerGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2009-06-24 12:41:42 +0000
commit0baf19375466cfc24c96532df406e7c5b1d1aae8 (patch)
treed18cd9b7858d84963007dab7df0f5243de7d03b7 /src
parentd66eef71012bdbc14834c12c8af1c946fe0d8499 (diff)
detect nearly translate-only matrices when drawing bitmaps (for speed)
rename setXfermode(Mode) to setXfermodeMode(Mode) for sanity fix memory leak in setXfermode(Mode) git-svn-id: http://skia.googlecode.com/svn/trunk@239 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/core/SkCanvas.cpp4
-rw-r--r--src/core/SkDraw.cpp27
-rw-r--r--src/core/SkPaint.cpp2
3 files changed, 26 insertions, 7 deletions
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 28772b0d8d..24131681a2 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -1234,7 +1234,7 @@ void SkCanvas::drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b,
paint.setARGB(a, r, g, b);
if (SkXfermode::kSrcOver_Mode != mode) {
- paint.setXfermode(mode);
+ paint.setXfermodeMode(mode);
}
this->drawPaint(paint);
}
@@ -1244,7 +1244,7 @@ void SkCanvas::drawColor(SkColor c, SkXfermode::Mode mode) {
paint.setColor(c);
if (SkXfermode::kSrcOver_Mode != mode) {
- paint.setXfermode(mode);
+ paint.setXfermodeMode(mode);
}
this->drawPaint(paint);
}
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index 8146ff8c14..fa3eb55a36 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -873,15 +873,33 @@ void SkDraw::drawPath(const SkPath& origSrcPath, const SkPaint& paint,
}
}
-static inline bool just_translate(const SkMatrix& m) {
- return (m.getType() & ~SkMatrix::kTranslate_Mask) == 0;
+/** For the purposes of drawing bitmaps, if a matrix is "almost" translate
+ go ahead and treat it as if it were, so that subsequent code can go fast.
+ */
+static bool just_translate(const SkMatrix& matrix, const SkBitmap& bitmap) {
+ SkMatrix::TypeMask mask = matrix.getType();
+
+ if (mask & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
+ return false;
+ }
+ if (mask & SkMatrix::kScale_Mask) {
+ SkScalar sx = matrix[SkMatrix::kMScaleX];
+ SkScalar sy = matrix[SkMatrix::kMScaleY];
+ int w = bitmap.width();
+ int h = bitmap.height();
+ int sw = SkScalarRound(SkScalarMul(sx, SkIntToScalar(w)));
+ int sh = SkScalarRound(SkScalarMul(sy, SkIntToScalar(h)));
+ return sw == w && sh == h;
+ }
+ // if we got here, we're either kTranslate_Mask or identity
+ return true;
}
void SkDraw::drawBitmapAsMask(const SkBitmap& bitmap,
const SkPaint& paint) const {
SkASSERT(bitmap.getConfig() == SkBitmap::kA8_Config);
- if (just_translate(*fMatrix)) {
+ if (just_translate(*fMatrix, bitmap)) {
int ix = SkScalarRound(fMatrix->getTranslateX());
int iy = SkScalarRound(fMatrix->getTranslateY());
@@ -1005,7 +1023,8 @@ void SkDraw::drawBitmap(const SkBitmap& bitmap, const SkMatrix& prematrix,
return;
}
- if (bitmap.getConfig() != SkBitmap::kA8_Config && just_translate(matrix)) {
+ if (bitmap.getConfig() != SkBitmap::kA8_Config &&
+ just_translate(matrix, bitmap)) {
int ix = SkScalarRound(matrix.getTranslateX());
int iy = SkScalarRound(matrix.getTranslateY());
uint32_t storage[kBlitterStorageLongCount];
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index 049590361e..8b2a21b5bd 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -1437,7 +1437,7 @@ SkXfermode* SkPaint::setXfermode(SkXfermode* mode)
return mode;
}
-SkXfermode* SkPaint::setXfermode(SkXfermode::Mode mode) {
+SkXfermode* SkPaint::setXfermodeMode(SkXfermode::Mode mode) {
SkSafeUnref(fXfermode);
fXfermode = SkXfermode::Create(mode);
return fXfermode;