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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 fDstX.reset(xCount + 2); | 151 fDstX.reset(xCount + 2); |
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 fNumRectsInLattice = (xCount + 1) * (yCount + 1); |
162 fNumRects = (xCount + 1) * (yCount + 1); | 162 fNumRectsToDraw = fNumRectsInLattice; |
| 163 |
| 164 if (lattice.fFlags && fNumRectsInLattice == lattice.fFlagCount) { |
| 165 fFlags.push_back_n(lattice.fFlagCount, lattice.fFlags); |
| 166 |
| 167 for (int i = 0; i < lattice.fFlagCount; i++) { |
| 168 if (SkCanvas::Lattice::kSkip_Flags == fFlags[i]) { |
| 169 fNumRectsToDraw--; |
| 170 } |
| 171 } |
| 172 } |
163 } | 173 } |
164 | 174 |
165 bool SkLatticeIter::Valid(int width, int height, const SkIRect& center) { | 175 bool SkLatticeIter::Valid(int width, int height, const SkIRect& center) { |
166 return !center.isEmpty() && SkIRect::MakeWH(width, height).contains(center); | 176 return !center.isEmpty() && SkIRect::MakeWH(width, height).contains(center); |
167 } | 177 } |
168 | 178 |
169 SkLatticeIter::SkLatticeIter(int w, int h, const SkIRect& c, const SkRect& dst)
{ | 179 SkLatticeIter::SkLatticeIter(int w, int h, const SkIRect& c, const SkRect& dst)
{ |
170 SkASSERT(SkIRect::MakeWH(w, h).contains(c)); | 180 SkASSERT(SkIRect::MakeWH(w, h).contains(c)); |
171 | 181 |
172 fSrcX.reset(4); | 182 fSrcX.reset(4); |
(...skipping 25 matching lines...) Expand all Loading... |
198 fDstX[1] = fDstX[0] + (fDstX[3] - fDstX[0]) * c.fLeft / (w - c.width()); | 208 fDstX[1] = fDstX[0] + (fDstX[3] - fDstX[0]) * c.fLeft / (w - c.width()); |
199 fDstX[2] = fDstX[1]; | 209 fDstX[2] = fDstX[1]; |
200 } | 210 } |
201 | 211 |
202 if (fDstY[1] > fDstY[2]) { | 212 if (fDstY[1] > fDstY[2]) { |
203 fDstY[1] = fDstY[0] + (fDstY[3] - fDstY[0]) * c.fTop / (h - c.height()); | 213 fDstY[1] = fDstY[0] + (fDstY[3] - fDstY[0]) * c.fTop / (h - c.height()); |
204 fDstY[2] = fDstY[1]; | 214 fDstY[2] = fDstY[1]; |
205 } | 215 } |
206 | 216 |
207 fCurrX = fCurrY = 0; | 217 fCurrX = fCurrY = 0; |
208 fDone = false; | 218 fNumRectsInLattice = 9; |
209 fNumRects = 9; | 219 fNumRectsToDraw = 9; |
210 } | 220 } |
211 | 221 |
212 bool SkLatticeIter::next(SkRect* src, SkRect* dst) { | 222 bool SkLatticeIter::next(SkRect* src, SkRect* dst) { |
213 if (fDone) { | 223 int currRect = fCurrX + fCurrY * (fSrcX.count() - 1); |
| 224 if (currRect == fNumRectsInLattice) { |
214 return false; | 225 return false; |
215 } | 226 } |
216 | 227 |
217 const int x = fCurrX; | 228 const int x = fCurrX; |
218 const int y = fCurrY; | 229 const int y = fCurrY; |
219 SkASSERT(x >= 0 && x < fSrcX.count() - 1); | 230 SkASSERT(x >= 0 && x < fSrcX.count() - 1); |
220 SkASSERT(y >= 0 && y < fSrcY.count() - 1); | 231 SkASSERT(y >= 0 && y < fSrcY.count() - 1); |
221 | 232 |
222 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]); | |
224 if (fSrcX.count() - 1 == ++fCurrX) { | 233 if (fSrcX.count() - 1 == ++fCurrX) { |
225 fCurrX = 0; | 234 fCurrX = 0; |
226 fCurrY += 1; | 235 fCurrY += 1; |
227 if (fCurrY >= fSrcY.count() - 1) { | |
228 fDone = true; | |
229 } | |
230 } | 236 } |
| 237 |
| 238 if (fFlags.count() > 0 && SkToBool(SkCanvas::Lattice::kSkip_Flags & fFlags[c
urrRect])) { |
| 239 return this->next(src, dst); |
| 240 } |
| 241 |
| 242 src->set(fSrcX[x], fSrcY[y], fSrcX[x + 1], fSrcY[y + 1]); |
| 243 dst->set(fDstX[x], fDstY[y], fDstX[x + 1], fDstY[y + 1]); |
231 return true; | 244 return true; |
232 } | 245 } |
233 | 246 |
234 void SkLatticeIter::mapDstScaleTranslate(const SkMatrix& matrix) { | 247 void SkLatticeIter::mapDstScaleTranslate(const SkMatrix& matrix) { |
235 SkASSERT(matrix.isScaleTranslate()); | 248 SkASSERT(matrix.isScaleTranslate()); |
236 SkScalar tx = matrix.getTranslateX(); | 249 SkScalar tx = matrix.getTranslateX(); |
237 SkScalar sx = matrix.getScaleX(); | 250 SkScalar sx = matrix.getScaleX(); |
238 for (int i = 0; i < fDstX.count(); i++) { | 251 for (int i = 0; i < fDstX.count(); i++) { |
239 fDstX[i] = fDstX[i] * sx + tx; | 252 fDstX[i] = fDstX[i] * sx + tx; |
240 } | 253 } |
241 | 254 |
242 SkScalar ty = matrix.getTranslateY(); | 255 SkScalar ty = matrix.getTranslateY(); |
243 SkScalar sy = matrix.getScaleY(); | 256 SkScalar sy = matrix.getScaleY(); |
244 for (int i = 0; i < fDstY.count(); i++) { | 257 for (int i = 0; i < fDstY.count(); i++) { |
245 fDstY[i] = fDstY[i] * sy + ty; | 258 fDstY[i] = fDstY[i] * sy + ty; |
246 } | 259 } |
247 } | 260 } |
OLD | NEW |