| 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 #include "SkDeviceLooper.h" | 8 #include "SkDeviceLooper.h" |
| 9 | 9 |
| 10 SkDeviceLooper::SkDeviceLooper(const SkBitmap& base, | 10 SkDeviceLooper::SkDeviceLooper(const SkPixmap& base, const SkRasterClip& rc, con
st SkIRect& bounds, |
| 11 const SkRasterClip& rc, | 11 bool aa) |
| 12 const SkIRect& bounds, bool aa) | 12 : fBaseDst(base) |
| 13 : fBaseBitmap(base) | |
| 14 , fBaseRC(rc) | 13 , fBaseRC(rc) |
| 15 , fSubsetRC(rc.isForceConservativeRects()) | 14 , fSubsetRC(rc.isForceConservativeRects()) |
| 16 , fDelta(aa ? kAA_Delta : kBW_Delta) | 15 , fDelta(aa ? kAA_Delta : kBW_Delta) |
| 17 { | 16 { |
| 18 // sentinels that next() has not yet been called, and so our mapper function
s | 17 // sentinels that next() has not yet been called, and so our mapper function
s |
| 19 // should not be called either. | 18 // should not be called either. |
| 20 fCurrBitmap = NULL; | 19 fCurrDst = NULL; |
| 21 fCurrRC = NULL; | 20 fCurrRC = NULL; |
| 22 | 21 |
| 23 if (!rc.isEmpty()) { | 22 if (!rc.isEmpty()) { |
| 24 // clip must be contained by the bitmap | 23 // clip must be contained by the bitmap |
| 25 SkASSERT(SkIRect::MakeWH(base.width(), base.height()).contains(rc.getBou
nds())); | 24 SkASSERT(SkIRect::MakeWH(base.width(), base.height()).contains(rc.getBou
nds())); |
| 26 } | 25 } |
| 27 | 26 |
| 28 if (rc.isEmpty() || !fClippedBounds.intersect(bounds, rc.getBounds())) { | 27 if (rc.isEmpty() || !fClippedBounds.intersect(bounds, rc.getBounds())) { |
| 29 fState = kDone_State; | 28 fState = kDone_State; |
| 30 } else if (this->fitsInDelta(fClippedBounds)) { | 29 } else if (this->fitsInDelta(fClippedBounds)) { |
| 31 fState = kSimple_State; | 30 fState = kSimple_State; |
| 32 } else { | 31 } else { |
| 33 // back up by 1 DX, so that next() will put us in a correct starting | 32 // back up by 1 DX, so that next() will put us in a correct starting |
| 34 // position. | 33 // position. |
| 35 fCurrOffset.set(fClippedBounds.left() - fDelta, | 34 fCurrOffset.set(fClippedBounds.left() - fDelta, |
| 36 fClippedBounds.top()); | 35 fClippedBounds.top()); |
| 37 fState = kComplex_State; | 36 fState = kComplex_State; |
| 38 } | 37 } |
| 39 } | 38 } |
| 40 | 39 |
| 41 SkDeviceLooper::~SkDeviceLooper() { | 40 SkDeviceLooper::~SkDeviceLooper() {} |
| 42 } | |
| 43 | 41 |
| 44 void SkDeviceLooper::mapRect(SkRect* dst, const SkRect& src) const { | 42 void SkDeviceLooper::mapRect(SkRect* dst, const SkRect& src) const { |
| 45 SkASSERT(kDone_State != fState); | 43 SkASSERT(kDone_State != fState); |
| 46 SkASSERT(fCurrBitmap); | 44 SkASSERT(fCurrDst); |
| 47 SkASSERT(fCurrRC); | 45 SkASSERT(fCurrRC); |
| 48 | 46 |
| 49 *dst = src; | 47 *dst = src; |
| 50 dst->offset(SkIntToScalar(-fCurrOffset.fX), | 48 dst->offset(SkIntToScalar(-fCurrOffset.fX), |
| 51 SkIntToScalar(-fCurrOffset.fY)); | 49 SkIntToScalar(-fCurrOffset.fY)); |
| 52 } | 50 } |
| 53 | 51 |
| 54 void SkDeviceLooper::mapMatrix(SkMatrix* dst, const SkMatrix& src) const { | 52 void SkDeviceLooper::mapMatrix(SkMatrix* dst, const SkMatrix& src) const { |
| 55 SkASSERT(kDone_State != fState); | 53 SkASSERT(kDone_State != fState); |
| 56 SkASSERT(fCurrBitmap); | 54 SkASSERT(fCurrDst); |
| 57 SkASSERT(fCurrRC); | 55 SkASSERT(fCurrRC); |
| 58 | 56 |
| 59 *dst = src; | 57 *dst = src; |
| 60 dst->postTranslate(SkIntToScalar(-fCurrOffset.fX), | 58 dst->postTranslate(SkIntToScalar(-fCurrOffset.fX), SkIntToScalar(-fCurrOffse
t.fY)); |
| 61 SkIntToScalar(-fCurrOffset.fY)); | |
| 62 } | 59 } |
| 63 | 60 |
| 64 bool SkDeviceLooper::computeCurrBitmapAndClip() { | 61 bool SkDeviceLooper::computeCurrBitmapAndClip() { |
| 65 SkASSERT(kComplex_State == fState); | 62 SkASSERT(kComplex_State == fState); |
| 66 | 63 |
| 67 SkIRect r = SkIRect::MakeXYWH(fCurrOffset.x(), fCurrOffset.y(), | 64 SkIRect r = SkIRect::MakeXYWH(fCurrOffset.x(), fCurrOffset.y(), |
| 68 fDelta, fDelta); | 65 fDelta, fDelta); |
| 69 if (!fBaseBitmap.extractSubset(&fSubsetBitmap, r)) { | 66 if (!fBaseDst.extractSubset(&fSubsetDst, r)) { |
| 70 fSubsetRC.setEmpty(); | 67 fSubsetRC.setEmpty(); |
| 71 } else { | 68 } else { |
| 72 fSubsetBitmap.lockPixels(); | |
| 73 fBaseRC.translate(-r.left(), -r.top(), &fSubsetRC); | 69 fBaseRC.translate(-r.left(), -r.top(), &fSubsetRC); |
| 74 (void)fSubsetRC.op(SkIRect::MakeWH(fDelta, fDelta), | 70 (void)fSubsetRC.op(SkIRect::MakeWH(fDelta, fDelta), SkRegion::kIntersect
_Op); |
| 75 SkRegion::kIntersect_Op); | |
| 76 } | 71 } |
| 77 | 72 |
| 78 fCurrBitmap = &fSubsetBitmap; | 73 fCurrDst = &fSubsetDst; |
| 79 fCurrRC = &fSubsetRC; | 74 fCurrRC = &fSubsetRC; |
| 80 return !fCurrRC->isEmpty(); | 75 return !fCurrRC->isEmpty(); |
| 81 } | 76 } |
| 82 | 77 |
| 83 static bool next_tile(const SkIRect& boundary, int delta, SkIPoint* offset) { | 78 static bool next_tile(const SkIRect& boundary, int delta, SkIPoint* offset) { |
| 84 // can we move to the right? | 79 // can we move to the right? |
| 85 if (offset->x() + delta < boundary.right()) { | 80 if (offset->x() + delta < boundary.right()) { |
| 86 offset->fX += delta; | 81 offset->fX += delta; |
| 87 return true; | 82 return true; |
| 88 } | 83 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 100 | 95 |
| 101 bool SkDeviceLooper::next() { | 96 bool SkDeviceLooper::next() { |
| 102 switch (fState) { | 97 switch (fState) { |
| 103 case kDone_State: | 98 case kDone_State: |
| 104 // in theory, we should not get called here, since we must have | 99 // in theory, we should not get called here, since we must have |
| 105 // previously returned false, but we check anyway. | 100 // previously returned false, but we check anyway. |
| 106 break; | 101 break; |
| 107 | 102 |
| 108 case kSimple_State: | 103 case kSimple_State: |
| 109 // first time for simple | 104 // first time for simple |
| 110 if (NULL == fCurrBitmap) { | 105 if (NULL == fCurrDst) { |
| 111 fCurrBitmap = &fBaseBitmap; | 106 fCurrDst = &fBaseDst; |
| 112 fCurrRC = &fBaseRC; | 107 fCurrRC = &fBaseRC; |
| 113 fCurrOffset.set(0, 0); | 108 fCurrOffset.set(0, 0); |
| 114 return true; | 109 return true; |
| 115 } | 110 } |
| 116 // 2nd time for simple, we are done | 111 // 2nd time for simple, we are done |
| 117 break; | 112 break; |
| 118 | 113 |
| 119 case kComplex_State: | 114 case kComplex_State: |
| 120 // need to propogate fCurrOffset through clippedbounds | 115 // need to propogate fCurrOffset through clippedbounds |
| 121 // left to right, until we wrap around and move down | 116 // left to right, until we wrap around and move down |
| 122 | 117 |
| 123 while (next_tile(fClippedBounds, fDelta, &fCurrOffset)) { | 118 while (next_tile(fClippedBounds, fDelta, &fCurrOffset)) { |
| 124 if (this->computeCurrBitmapAndClip()) { | 119 if (this->computeCurrBitmapAndClip()) { |
| 125 return true; | 120 return true; |
| 126 } | 121 } |
| 127 } | 122 } |
| 128 break; | 123 break; |
| 129 } | 124 } |
| 130 fState = kDone_State; | 125 fState = kDone_State; |
| 131 return false; | 126 return false; |
| 132 } | 127 } |
| OLD | NEW |