OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 #ifndef SkDeviceLooper_DEFINED | 8 #ifndef SkDeviceLooper_DEFINED |
9 #define SkDeviceLooper_DEFINED | 9 #define SkDeviceLooper_DEFINED |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 * add/subtract two fixed values and still be in range. If we're drawing AA, | 23 * add/subtract two fixed values and still be in range. If we're drawing AA, |
24 * then we reduce that size by the amount that the supersampler scan converter | 24 * then we reduce that size by the amount that the supersampler scan converter |
25 * needs (at the moment, that is 4X, so the "safe" range is +- 4K). | 25 * needs (at the moment, that is 4X, so the "safe" range is +- 4K). |
26 * | 26 * |
27 * For performance reasons, the class first checks to see if any help is needed | 27 * For performance reasons, the class first checks to see if any help is needed |
28 * at all, and if not (i.e. the specified bounds and base bitmap area already | 28 * at all, and if not (i.e. the specified bounds and base bitmap area already |
29 * in the safe-zone, then the class does nothing (effectively). | 29 * in the safe-zone, then the class does nothing (effectively). |
30 */ | 30 */ |
31 class SkDeviceLooper { | 31 class SkDeviceLooper { |
32 public: | 32 public: |
33 SkDeviceLooper(const SkBitmap& base, const SkRasterClip&, | 33 SkDeviceLooper(const SkPixmap& base, const SkRasterClip&, const SkIRect& bou
nds, bool aa); |
34 const SkIRect& bounds, bool aa); | |
35 ~SkDeviceLooper(); | 34 ~SkDeviceLooper(); |
36 | 35 |
37 const SkBitmap& getBitmap() const { | 36 const SkPixmap& getPixmap() const { |
38 SkASSERT(kDone_State != fState); | 37 SkASSERT(kDone_State != fState); |
39 SkASSERT(fCurrBitmap); | 38 SkASSERT(fCurrDst); |
40 return *fCurrBitmap; | 39 return *fCurrDst; |
41 } | 40 } |
42 | 41 |
43 const SkRasterClip& getRC() const { | 42 const SkRasterClip& getRC() const { |
44 SkASSERT(kDone_State != fState); | 43 SkASSERT(kDone_State != fState); |
45 SkASSERT(fCurrRC); | 44 SkASSERT(fCurrRC); |
46 return *fCurrRC; | 45 return *fCurrRC; |
47 } | 46 } |
48 | 47 |
49 void mapRect(SkRect* dst, const SkRect& src) const; | 48 void mapRect(SkRect* dst, const SkRect& src) const; |
50 void mapMatrix(SkMatrix* dst, const SkMatrix& src) const; | 49 void mapMatrix(SkMatrix* dst, const SkMatrix& src) const; |
51 | 50 |
52 /** | 51 /** |
53 * Call next to setup the looper to return a valid coordinate chunk. | 52 * Call next to setup the looper to return a valid coordinate chunk. |
54 * Each time this returns true, it is safe to call mapRect() and | 53 * Each time this returns true, it is safe to call mapRect() and |
55 * mapMatrix(), to convert from "global" coordinate values to ones that | 54 * mapMatrix(), to convert from "global" coordinate values to ones that |
56 * are local to this chunk. | 55 * are local to this chunk. |
57 * | 56 * |
58 * When next() returns false, the list of chunks is done, and mapRect() | 57 * When next() returns false, the list of chunks is done, and mapRect() |
59 * and mapMatrix() should no longer be called. | 58 * and mapMatrix() should no longer be called. |
60 */ | 59 */ |
61 bool next(); | 60 bool next(); |
62 | 61 |
63 private: | 62 private: |
64 const SkBitmap& fBaseBitmap; | 63 const SkPixmap& fBaseDst; |
65 const SkRasterClip& fBaseRC; | 64 const SkRasterClip& fBaseRC; |
66 | 65 |
67 enum State { | 66 enum State { |
68 kDone_State, // iteration is complete, getters will assert | 67 kDone_State, // iteration is complete, getters will assert |
69 kSimple_State, // no translate/clip mods needed | 68 kSimple_State, // no translate/clip mods needed |
70 kComplex_State | 69 kComplex_State |
71 }; | 70 }; |
72 | 71 |
73 // storage for our tiled versions. Perhaps could use SkTLazy | 72 // storage for our tiled versions. Perhaps could use SkTLazy |
74 SkBitmap fSubsetBitmap; | 73 SkPixmap fSubsetDst; |
75 SkRasterClip fSubsetRC; | 74 SkRasterClip fSubsetRC; |
76 | 75 |
77 const SkBitmap* fCurrBitmap; | 76 const SkPixmap* fCurrDst; |
78 const SkRasterClip* fCurrRC; | 77 const SkRasterClip* fCurrRC; |
79 SkIRect fClippedBounds; | 78 SkIRect fClippedBounds; |
80 SkIPoint fCurrOffset; | 79 SkIPoint fCurrOffset; |
81 int fDelta; | 80 int fDelta; |
82 State fState; | 81 State fState; |
83 | 82 |
84 enum Delta { | 83 enum Delta { |
85 kBW_Delta = 1 << 14, // 16K, gives room to spare for fixedpoint | 84 kBW_Delta = 1 << 14, // 16K, gives room to spare for fixedpoint |
86 kAA_Delta = kBW_Delta >> 2 // supersample 4x | 85 kAA_Delta = kBW_Delta >> 2 // supersample 4x |
87 }; | 86 }; |
88 | 87 |
89 bool fitsInDelta(const SkIRect& r) const { | 88 bool fitsInDelta(const SkIRect& r) const { |
90 return r.right() < fDelta && r.bottom() < fDelta; | 89 return r.right() < fDelta && r.bottom() < fDelta; |
91 } | 90 } |
92 | 91 |
93 bool computeCurrBitmapAndClip(); | 92 bool computeCurrBitmapAndClip(); |
94 }; | 93 }; |
95 | 94 |
96 #endif | 95 #endif |
OLD | NEW |