Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: src/core/SkBitmapProcState.cpp

Issue 14018020: use forward matrix to determine if we can ignore scale part of a matrix (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkBitmapProcState.h" 8 #include "SkBitmapProcState.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkFilterProc.h" 10 #include "SkFilterProc.h"
(...skipping 18 matching lines...) Expand all
29 #include "SkBitmapProcState_procs.h" 29 #include "SkBitmapProcState_procs.h"
30 30
31 /////////////////////////////////////////////////////////////////////////////// 31 ///////////////////////////////////////////////////////////////////////////////
32 32
33 /** 33 /**
34 * For the purposes of drawing bitmaps, if a matrix is "almost" translate 34 * For the purposes of drawing bitmaps, if a matrix is "almost" translate
35 * go ahead and treat it as if it were, so that subsequent code can go fast. 35 * go ahead and treat it as if it were, so that subsequent code can go fast.
36 */ 36 */
37 static bool just_trans_clamp(const SkMatrix& matrix, const SkBitmap& bitmap) { 37 static bool just_trans_clamp(const SkMatrix& matrix, const SkBitmap& bitmap) {
38 SkMatrix::TypeMask mask = matrix.getType(); 38 SkMatrix::TypeMask mask = matrix.getType();
39 39
robertphillips 2013/04/15 19:43:02 assert this now?
reed1 2013/04/15 20:00:26 Done.
40 if (mask & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) { 40 if (mask & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
41 return false; 41 return false;
42 } 42 }
43 if (mask & SkMatrix::kScale_Mask) { 43 if (mask & SkMatrix::kScale_Mask) {
44 #if 0
44 SkScalar sx = matrix[SkMatrix::kMScaleX]; 45 SkScalar sx = matrix[SkMatrix::kMScaleX];
45 SkScalar sy = matrix[SkMatrix::kMScaleY]; 46 SkScalar sy = matrix[SkMatrix::kMScaleY];
46 int w = bitmap.width(); 47 int w = bitmap.width();
47 int h = bitmap.height(); 48 int h = bitmap.height();
48 int sw = SkScalarRound(SkScalarMul(sx, SkIntToScalar(w))); 49 int sw = SkScalarRound(SkScalarMul(sx, SkIntToScalar(w)));
49 int sh = SkScalarRound(SkScalarMul(sy, SkIntToScalar(h))); 50 int sh = SkScalarRound(SkScalarMul(sy, SkIntToScalar(h)));
50 return sw == w && sh == h; 51 return sw == w && sh == h;
52 #else
53 SkRect src, dst;
54 bitmap.getBounds(&src);
55 matrix.mapRect(&dst, src);
56 SkIRect idst;
57 dst.round(&idst);
58 return idst.width() == bitmap.width() && idst.height() == bitmap.height( );
59 #endif
51 } 60 }
52 // if we got here, we're either kTranslate_Mask or identity 61 // if we got here, we're either kTranslate_Mask or identity
53 return true; 62 return true;
54 } 63 }
55 64
56 static bool just_trans_general(const SkMatrix& matrix) { 65 static bool just_trans_general(const SkMatrix& matrix) {
57 SkMatrix::TypeMask mask = matrix.getType(); 66 SkMatrix::TypeMask mask = matrix.getType();
58 67
robertphillips 2013/04/15 19:43:02 Assert this now?
59 if (mask & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) { 68 if (mask & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
60 return false; 69 return false;
61 } 70 }
62 if (mask & SkMatrix::kScale_Mask) { 71 if (mask & SkMatrix::kScale_Mask) {
63 const SkScalar tol = SK_Scalar1 / 32768; 72 const SkScalar tol = SK_Scalar1 / 32768;
64 73
65 if (!SkScalarNearlyZero(matrix[SkMatrix::kMScaleX] - SK_Scalar1, tol)) { 74 if (!SkScalarNearlyZero(matrix[SkMatrix::kMScaleX] - SK_Scalar1, tol)) {
66 return false; 75 return false;
67 } 76 }
68 if (!SkScalarNearlyZero(matrix[SkMatrix::kMScaleY] - SK_Scalar1, tol)) { 77 if (!SkScalarNearlyZero(matrix[SkMatrix::kMScaleY] - SK_Scalar1, tol)) {
69 return false; 78 return false;
70 } 79 }
71 } 80 }
72 // if we got here, treat us as either kTranslate_Mask or identity 81 // if we got here, treat us as either kTranslate_Mask or identity
73 return true; 82 return true;
74 } 83 }
75 84
76 /////////////////////////////////////////////////////////////////////////////// 85 ///////////////////////////////////////////////////////////////////////////////
77 86
78 static bool valid_for_filtering(unsigned dimension) { 87 static bool valid_for_filtering(unsigned dimension) {
79 // for filtering, width and height must fit in 14bits, since we use steal 88 // for filtering, width and height must fit in 14bits, since we use steal
80 // 2 bits from each to store our 4bit subpixel data 89 // 2 bits from each to store our 4bit subpixel data
81 return (dimension & ~0x3FFF) == 0; 90 return (dimension & ~0x3FFF) == 0;
82 } 91 }
83 92
93 static bool matrix_only_scale_translate(const SkMatrix& m) {
robertphillips 2013/04/15 19:43:02 This is done as "if (mask <= (SkMatrix::kTranslate
reed1 2013/04/15 20:00:26 Done.
94 unsigned mask = SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask;
95 return 0 == (m.getType() & ~mask);
96 }
97
84 bool SkBitmapProcState::chooseProcs(const SkMatrix& inv, const SkPaint& paint) { 98 bool SkBitmapProcState::chooseProcs(const SkMatrix& inv, const SkPaint& paint) {
85 if (fOrigBitmap.width() == 0 || fOrigBitmap.height() == 0) { 99 if (fOrigBitmap.width() == 0 || fOrigBitmap.height() == 0) {
86 return false; 100 return false;
87 } 101 }
88 102
89 const SkMatrix* m; 103 const SkMatrix* m;
90 bool trivial_matrix = (inv.getType() & ~SkMatrix::kTranslate_Mask) == 0; 104 bool trivial_matrix = (inv.getType() & ~SkMatrix::kTranslate_Mask) == 0;
91 bool clamp_clamp = SkShader::kClamp_TileMode == fTileModeX && 105 bool clamp_clamp = SkShader::kClamp_TileMode == fTileModeX &&
92 SkShader::kClamp_TileMode == fTileModeY; 106 SkShader::kClamp_TileMode == fTileModeY;
93 107
(...skipping 19 matching lines...) Expand all
113 127
114 SkScalar scale = SkFixedToScalar(SK_Fixed1 >> shift); 128 SkScalar scale = SkFixedToScalar(SK_Fixed1 >> shift);
115 fUnitInvMatrix.postScale(scale, scale); 129 fUnitInvMatrix.postScale(scale, scale);
116 130
117 // now point here instead of fOrigBitmap 131 // now point here instead of fOrigBitmap
118 fBitmap = &fMipBitmap; 132 fBitmap = &fMipBitmap;
119 } 133 }
120 } 134 }
121 135
122 // wack our matrix to exactly no-scale, if we're really close to begin with 136 // wack our matrix to exactly no-scale, if we're really close to begin with
123 { 137 if (false) {
124 bool fixupMatrix = clamp_clamp ? 138 bool fixupMatrix = clamp_clamp ?
125 just_trans_clamp(*m, *fBitmap) : just_trans_general(*m); 139 just_trans_clamp(*m, *fBitmap) : just_trans_general(*m);
126 if (fixupMatrix) { 140 if (fixupMatrix) {
127 // If we can be treated just like translate, construct that inverse 141 // If we can be treated just like translate, construct that inverse
128 // such that we landed in the proper place. Given that m may have 142 // such that we landed in the proper place. Given that m may have
129 // some slight scale, we have to invert it to compute this new 143 // some slight scale, we have to invert it to compute this new
130 // matrix. 144 // matrix.
131 SkMatrix forward; 145 SkMatrix forward;
132 if (m->invert(&forward)) { 146 if (m->invert(&forward)) {
133 SkScalar tx = -SkScalarRoundToScalar(forward.getTranslateX()); 147 SkScalar tx = -SkScalarRoundToScalar(forward.getTranslateX());
134 SkScalar ty = -SkScalarRoundToScalar(forward.getTranslateY()); 148 SkScalar ty = -SkScalarRoundToScalar(forward.getTranslateY());
135 fUnitInvMatrix.setTranslate(tx, ty); 149 fUnitInvMatrix.setTranslate(tx, ty);
136 m = &fUnitInvMatrix; 150 m = &fUnitInvMatrix;
137 // now the following code will sniff m, and decide to take the 151 // now the following code will sniff m, and decide to take the
138 // fast case (since m is purely translate). 152 // fast case (since m is purely translate).
139 } 153 }
140 } 154 }
141 } 155 }
156 if (matrix_only_scale_translate(*m)) {
157 SkMatrix forward;
158 if (m->invert(&forward)) {
159 if (clamp_clamp ? just_trans_clamp(forward, *fBitmap)
160 : just_trans_general(forward)) {
161 SkScalar tx = -SkScalarRoundToScalar(forward.getTranslateX());
162 SkScalar ty = -SkScalarRoundToScalar(forward.getTranslateY());
163 fUnitInvMatrix.setTranslate(tx, ty);
164 m = &fUnitInvMatrix;
165 // now the following code will sniff m, and decide to take the
166 // fast case (since m is purely translate).
167 }
168 }
169 }
142 170
143 // Below this point, we should never refer to the inv parameter, since we 171 // Below this point, we should never refer to the inv parameter, since we
144 // may be using a munged version for "our" inverse. 172 // may be using a munged version for "our" inverse.
145 173
146 fInvMatrix = m; 174 fInvMatrix = m;
147 fInvProc = m->getMapXYProc(); 175 fInvProc = m->getMapXYProc();
148 fInvType = m->getType(); 176 fInvType = m->getType();
149 fInvSx = SkScalarToFixed(m->getScaleX()); 177 fInvSx = SkScalarToFixed(m->getScaleX());
150 fInvSxFractionalInt = SkScalarToFractionalInt(m->getScaleX()); 178 fInvSxFractionalInt = SkScalarToFractionalInt(m->getScaleX());
151 fInvKy = SkScalarToFixed(m->getSkewY()); 179 fInvKy = SkScalarToFixed(m->getSkewY());
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 } else { 739 } else {
712 size >>= 2; 740 size >>= 2;
713 } 741 }
714 742
715 if (fDoFilter) { 743 if (fDoFilter) {
716 size >>= 1; 744 size >>= 1;
717 } 745 }
718 746
719 return size; 747 return size;
720 } 748 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698