aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-17 21:32:03 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-17 21:32:03 +0000
commit717d0cbf6688efe1c398468ba5047f61f5c2fdbe (patch)
tree2bae9de18b4da40c1a182021cfc288c9b2841c56 /src/core
parent4c6adf9a089dbdd541f25d01d257ec05aedcb57d (diff)
Revert r8701 and r8700 due to layout test discrepancies
git-svn-id: http://skia.googlecode.com/svn/trunk@8731 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkBitmapProcState.cpp52
1 files changed, 27 insertions, 25 deletions
diff --git a/src/core/SkBitmapProcState.cpp b/src/core/SkBitmapProcState.cpp
index 5a4cf177fc..e44237880f 100644
--- a/src/core/SkBitmapProcState.cpp
+++ b/src/core/SkBitmapProcState.cpp
@@ -30,39 +30,36 @@ extern void Clamp_SI8_opaque_D32_filter_DX_shaderproc_neon(const SkBitmapProcSt
///////////////////////////////////////////////////////////////////////////////
-// true iff the matrix contains, at most, scale and translate elements
-static bool matrix_only_scale_translate(const SkMatrix& m) {
- return m.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask);
-}
-
/**
* 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_trans_clamp(const SkMatrix& matrix, const SkBitmap& bitmap) {
- SkASSERT(matrix_only_scale_translate(matrix));
+ SkMatrix::TypeMask mask = matrix.getType();
- if (matrix.getType() & SkMatrix::kScale_Mask) {
- SkRect src, dst;
- bitmap.getBounds(&src);
- matrix.mapRect(&dst, src);
-
- // Now round all 4 edges to device space, and then compare the device
- // width/height to the original. Note: we must map all 4 and subtract
- // rather than map the "width" and compare, since we care about the
- // phase (in pixel space) that any translate in the matrix might impart.
- SkIRect idst;
- dst.round(&idst);
- return idst.width() == bitmap.width() && idst.height() == bitmap.height();
+ 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;
}
static bool just_trans_general(const SkMatrix& matrix) {
- SkASSERT(matrix_only_scale_translate(matrix));
+ SkMatrix::TypeMask mask = matrix.getType();
- if (matrix.getType() & SkMatrix::kScale_Mask) {
+ if (mask & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
+ return false;
+ }
+ if (mask & SkMatrix::kScale_Mask) {
const SkScalar tol = SK_Scalar1 / 32768;
if (!SkScalarNearlyZero(matrix[SkMatrix::kMScaleX] - SK_Scalar1, tol)) {
@@ -123,11 +120,16 @@ bool SkBitmapProcState::chooseProcs(const SkMatrix& inv, const SkPaint& paint) {
}
// wack our matrix to exactly no-scale, if we're really close to begin with
- if (matrix_only_scale_translate(*m)) {
- SkMatrix forward;
- if (m->invert(&forward)) {
- if (clamp_clamp ? just_trans_clamp(forward, *fBitmap)
- : just_trans_general(forward)) {
+ {
+ bool fixupMatrix = clamp_clamp ?
+ just_trans_clamp(*m, *fBitmap) : just_trans_general(*m);
+ if (fixupMatrix) {
+ // If we can be treated just like translate, construct that inverse
+ // such that we landed in the proper place. Given that m may have
+ // some slight scale, we have to invert it to compute this new
+ // matrix.
+ SkMatrix forward;
+ if (m->invert(&forward)) {
SkScalar tx = -SkScalarRoundToScalar(forward.getTranslateX());
SkScalar ty = -SkScalarRoundToScalar(forward.getTranslateY());
fUnitInvMatrix.setTranslate(tx, ty);