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
15struct SkIRect;
16struct SkRect;
17
18/**
19 *  Disect a lattice request into an sequence of src-rect / dst-rect pairs
20 */
21class SK_API SkLatticeIter {
22public:
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. Optional parameters
34     *  isFixedColor and fixedColor specify if the rectangle is filled with a fixed color.
35     *  If (*isFixedColor) is true, then (*fixedColor) contains the rectangle color.
36     */
37    bool next(SkRect* src, SkRect* dst, bool* isFixedColor = nullptr,
38              SkColor* fixedColor = nullptr);
39
40    /**
41     *  Apply a matrix to the dst points.
42     */
43    void mapDstScaleTranslate(const SkMatrix& matrix);
44
45    /**
46     *  Returns the number of rects that will actually be drawn.
47     */
48    int numRectsToDraw() const {
49        return fNumRectsToDraw;
50    }
51
52private:
53    SkTArray<SkScalar> fSrcX;
54    SkTArray<SkScalar> fSrcY;
55    SkTArray<SkScalar> fDstX;
56    SkTArray<SkScalar> fDstY;
57    SkTArray<SkCanvas::Lattice::RectType> fRectTypes;
58    SkTArray<SkColor> fColors;
59
60    int  fCurrX;
61    int  fCurrY;
62    int  fNumRectsInLattice;
63    int  fNumRectsToDraw;
64};
65
66#endif
67