• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkLatticeIter_DEFINED
9 #define SkLatticeIter_DEFINED
10 
11 #include "SkCanvas.h"
12 #include "SkScalar.h"
13 #include "SkTArray.h"
14 
15 struct SkIRect;
16 struct SkRect;
17 
18 /**
19  *  Disect a lattice request into an sequence of src-rect / dst-rect pairs
20  */
21 class SkLatticeIter {
22 public:
23 
24     static bool Valid(int imageWidth, int imageHeight, const SkCanvas::Lattice& lattice);
25 
26     SkLatticeIter(const SkCanvas::Lattice& lattice, const SkRect& dst);
27 
28     static bool Valid(int imageWidth, int imageHeight, const SkIRect& center);
29 
30     SkLatticeIter(int imageWidth, int imageHeight, const SkIRect& center, const SkRect& dst);
31 
32     /**
33      *  While it returns true, use src/dst to draw the image/bitmap
34      */
35     bool next(SkRect* src, SkRect* dst);
36 
37     /**
38      *  Apply a matrix to the dst points.
39      */
40     void mapDstScaleTranslate(const SkMatrix& matrix);
41 
42     /**
43      *  Returns the number of rects that will actually be drawn.
44      */
numRectsToDraw()45     int numRectsToDraw() const {
46         return fNumRectsToDraw;
47     }
48 
49 private:
50     SkTArray<SkScalar> fSrcX;
51     SkTArray<SkScalar> fSrcY;
52     SkTArray<SkScalar> fDstX;
53     SkTArray<SkScalar> fDstY;
54     SkTArray<SkCanvas::Lattice::Flags> fFlags;
55 
56     int  fCurrX;
57     int  fCurrY;
58     int  fNumRectsInLattice;
59     int  fNumRectsToDraw;
60 };
61 
62 #endif
63