OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkLatticeIter.h" | 8 #include "SkLatticeIter.h" |
9 #include "SkRect.h" | 9 #include "SkRect.h" |
10 | 10 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 set_points(fDstX.begin(), fSrcX.begin(), xDivs, xCount, xCountFixed, xCountS
calable, | 152 set_points(fDstX.begin(), fSrcX.begin(), xDivs, xCount, xCountFixed, xCountS
calable, |
153 dst.fLeft, dst.fRight, xIsScalable); | 153 dst.fLeft, dst.fRight, xIsScalable); |
154 | 154 |
155 fSrcY.reset(yCount + 2); | 155 fSrcY.reset(yCount + 2); |
156 fDstY.reset(yCount + 2); | 156 fDstY.reset(yCount + 2); |
157 set_points(fDstY.begin(), fSrcY.begin(), yDivs, yCount, yCountFixed, yCountS
calable, | 157 set_points(fDstY.begin(), fSrcY.begin(), yDivs, yCount, yCountFixed, yCountS
calable, |
158 dst.fTop, dst.fBottom, yIsScalable); | 158 dst.fTop, dst.fBottom, yIsScalable); |
159 | 159 |
160 fCurrX = fCurrY = 0; | 160 fCurrX = fCurrY = 0; |
161 fDone = false; | 161 fDone = false; |
162 fNumRects = (xCount + 1) * (yCount + 1); | |
163 } | 162 } |
164 | 163 |
165 bool SkLatticeIter::Valid(int width, int height, const SkIRect& center) { | 164 bool SkLatticeIter::Valid(int width, int height, const SkIRect& center) { |
166 return !center.isEmpty() && SkIRect::MakeWH(width, height).contains(center); | 165 return !center.isEmpty() && SkIRect::MakeWH(width, height).contains(center); |
167 } | 166 } |
168 | 167 |
169 SkLatticeIter::SkLatticeIter(int w, int h, const SkIRect& c, const SkRect& dst)
{ | 168 SkLatticeIter::SkLatticeIter(int w, int h, const SkIRect& c, const SkRect& dst)
{ |
170 SkASSERT(SkIRect::MakeWH(w, h).contains(c)); | 169 SkASSERT(SkIRect::MakeWH(w, h).contains(c)); |
171 | 170 |
172 fSrcX.reset(4); | 171 fSrcX.reset(4); |
(...skipping 26 matching lines...) Expand all Loading... |
199 fDstX[2] = fDstX[1]; | 198 fDstX[2] = fDstX[1]; |
200 } | 199 } |
201 | 200 |
202 if (fDstY[1] > fDstY[2]) { | 201 if (fDstY[1] > fDstY[2]) { |
203 fDstY[1] = fDstY[0] + (fDstY[3] - fDstY[0]) * c.fTop / (h - c.height()); | 202 fDstY[1] = fDstY[0] + (fDstY[3] - fDstY[0]) * c.fTop / (h - c.height()); |
204 fDstY[2] = fDstY[1]; | 203 fDstY[2] = fDstY[1]; |
205 } | 204 } |
206 | 205 |
207 fCurrX = fCurrY = 0; | 206 fCurrX = fCurrY = 0; |
208 fDone = false; | 207 fDone = false; |
209 fNumRects = 9; | |
210 } | 208 } |
211 | 209 |
212 bool SkLatticeIter::next(SkRect* src, SkRect* dst) { | 210 bool SkLatticeIter::next(SkRect* src, SkRect* dst) { |
213 if (fDone) { | 211 if (fDone) { |
214 return false; | 212 return false; |
215 } | 213 } |
216 | 214 |
217 const int x = fCurrX; | 215 const int x = fCurrX; |
218 const int y = fCurrY; | 216 const int y = fCurrY; |
219 SkASSERT(x >= 0 && x < fSrcX.count() - 1); | 217 SkASSERT(x >= 0 && x < fSrcX.count() - 1); |
220 SkASSERT(y >= 0 && y < fSrcY.count() - 1); | 218 SkASSERT(y >= 0 && y < fSrcY.count() - 1); |
221 | 219 |
222 src->set(fSrcX[x], fSrcY[y], fSrcX[x + 1], fSrcY[y + 1]); | 220 src->set(fSrcX[x], fSrcY[y], fSrcX[x + 1], fSrcY[y + 1]); |
223 dst->set(fDstX[x], fDstY[y], fDstX[x + 1], fDstY[y + 1]); | 221 dst->set(fDstX[x], fDstY[y], fDstX[x + 1], fDstY[y + 1]); |
224 if (fSrcX.count() - 1 == ++fCurrX) { | 222 if (fSrcX.count() - 1 == ++fCurrX) { |
225 fCurrX = 0; | 223 fCurrX = 0; |
226 fCurrY += 1; | 224 fCurrY += 1; |
227 if (fCurrY >= fSrcY.count() - 1) { | 225 if (fCurrY >= fSrcY.count() - 1) { |
228 fDone = true; | 226 fDone = true; |
229 } | 227 } |
230 } | 228 } |
231 return true; | 229 return true; |
232 } | 230 } |
233 | |
234 void SkLatticeIter::mapDstScaleTranslate(const SkMatrix& matrix) { | |
235 SkASSERT(matrix.isScaleTranslate()); | |
236 SkScalar tx = matrix.getTranslateX(); | |
237 SkScalar sx = matrix.getScaleX(); | |
238 for (int i = 0; i < fDstX.count(); i++) { | |
239 fDstX[i] = fDstX[i] * sx + tx; | |
240 } | |
241 | |
242 SkScalar ty = matrix.getTranslateY(); | |
243 SkScalar sy = matrix.getScaleY(); | |
244 for (int i = 0; i < fDstY.count(); i++) { | |
245 fDstY[i] = fDstY[i] * sy + ty; | |
246 } | |
247 } | |
OLD | NEW |