| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2013 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 #include "SkDeviceLooper.h" | |
| 9 | |
| 10 SkDeviceLooper::SkDeviceLooper(const SkBitmap& base, | |
| 11 const SkRasterClip& rc, | |
| 12 const SkIRect& bounds, bool aa) | |
| 13 : fBaseBitmap(base) | |
| 14 , fBaseRC(rc) | |
| 15 , fDelta(aa ? kAA_Delta : kBW_Delta) | |
| 16 { | |
| 17 SkIRect bitmapBounds = SkIRect::MakeWH(base.width(), base.height()); | |
| 18 if (!fClippedBounds.intersect(bounds, bitmapBounds)) { | |
| 19 fState = kDone_State; | |
| 20 } else if (this->fitsInDelta(bounds)) { | |
| 21 fCurrBitmap = &fBaseBitmap; | |
| 22 fCurrRC = &fBaseRC; | |
| 23 fState = kSimple_State; | |
| 24 } else { | |
| 25 fCurrBitmap = &fSubsetBitmap; | |
| 26 fCurrRC = &fSubsetRC; | |
| 27 // back up by 1 DX, so that next() will put us in a correct starting | |
| 28 // position. | |
| 29 fCurrOffset.set(fClippedBounds.left() - fDelta, | |
| 30 fClippedBounds.top()); | |
| 31 fState = kComplex_State; | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 SkDeviceLooper::~SkDeviceLooper() { | |
| 36 } | |
| 37 | |
| 38 void SkDeviceLooper::mapRect(SkRect* dst, const SkRect& src) const { | |
| 39 SkASSERT(kDone_State != fState); | |
| 40 *dst = src; | |
| 41 dst->offset(SkIntToScalar(-fCurrOffset.fX), | |
| 42 SkIntToScalar(-fCurrOffset.fY)); | |
| 43 } | |
| 44 | |
| 45 void SkDeviceLooper::mapMatrix(SkMatrix* dst, const SkMatrix& src) const { | |
| 46 SkASSERT(kDone_State != fState); | |
| 47 *dst = src; | |
| 48 dst->postTranslate(SkIntToScalar(-fCurrOffset.fX), | |
| 49 SkIntToScalar(-fCurrOffset.fY)); | |
| 50 } | |
| 51 | |
| 52 bool SkDeviceLooper::computeCurrBitmapAndClip() { | |
| 53 SkASSERT(kComplex_State == fState); | |
| 54 | |
| 55 SkIRect r = SkIRect::MakeXYWH(fCurrOffset.x(), fCurrOffset.y(), | |
| 56 fDelta, fDelta); | |
| 57 if (!fBaseBitmap.extractSubset(&fSubsetBitmap, r)) { | |
| 58 fState = kDone_State; | |
| 59 return false; | |
| 60 } | |
| 61 fSubsetBitmap.lockPixels(); | |
| 62 | |
| 63 fBaseRC.translate(-r.left(), -r.top(), &fSubsetRC); | |
| 64 (void)fSubsetRC.op(SkIRect::MakeWH(fDelta, fDelta), SkRegion::kIntersect_Op)
; | |
| 65 return true; | |
| 66 } | |
| 67 | |
| 68 bool SkDeviceLooper::next() { | |
| 69 if (kDone_State == fState) { | |
| 70 return false; | |
| 71 } | |
| 72 | |
| 73 if (kSimple_State == fState) { | |
| 74 fCurrBitmap = &fBaseBitmap; | |
| 75 fCurrRC = &fBaseRC; | |
| 76 fCurrOffset.set(0, 0); | |
| 77 fState = kDone_State; | |
| 78 return true; | |
| 79 } | |
| 80 | |
| 81 SkASSERT(kComplex_State == fState); | |
| 82 | |
| 83 // need to propogate fCurrOffset through clippedbounds | |
| 84 // left to right, until we wrap around and move down | |
| 85 | |
| 86 if (fCurrOffset.x() + fDelta < fClippedBounds.right()) { | |
| 87 fCurrOffset.fX += fDelta; | |
| 88 return this->computeCurrBitmapAndClip(); | |
| 89 } | |
| 90 fCurrOffset.fX = fClippedBounds.left(); | |
| 91 if (fCurrOffset.y() + fDelta < fClippedBounds.bottom()) { | |
| 92 fCurrOffset.fY += fDelta; | |
| 93 return this->computeCurrBitmapAndClip(); | |
| 94 } | |
| 95 fState = kDone_State; | |
| 96 return false; | |
| 97 } | |
| OLD | NEW |