Chromium Code Reviews| 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 #ifndef SkDeviceLooper_DEFINED | |
| 9 #define SkDeviceLooper_DEFINED | |
| 10 | |
| 11 #include "SkBitmap.h" | |
| 12 #include "SkMatrix.h" | |
| 13 #include "SkRasterClip.h" | |
| 14 | |
| 15 /** | |
| 16 * Helper class to manage "tiling" a large coordinate space into managable | |
| 17 * chunks, where managable means areas that are <= some max critical coordinate | |
| 18 * size. | |
| 19 * | |
| 20 * The constructor takes an antialiasing bool, which affects what this maximum | |
| 21 * allowable size is: If we're drawing BW, then we need coordinates to stay | |
| 22 * safely within fixed-point range (we use +- 16K, to give ourselves room to | |
| 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 | |
| 25 * needs (at the moment, that is 4X, so the "safe" range is +- 4K). | |
| 26 * | |
| 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 | |
| 29 * in the safe-zone, then the class does nothing (effectively). | |
| 30 */ | |
| 31 class SkDeviceLooper { | |
| 32 public: | |
| 33 SkDeviceLooper(const SkBitmap& base, const SkRasterClip&, | |
| 34 const SkIRect& bounds, bool aa); | |
| 35 ~SkDeviceLooper(); | |
| 36 | |
| 37 const SkBitmap& getBitmap() const { | |
| 38 SkASSERT(kDone_State != fState); | |
|
tomhudson
2013/08/28 15:01:21
SkASSERT(NULL != fCurrBitmap)?
reed1
2013/08/28 15:11:30
Done.
| |
| 39 return *fCurrBitmap; | |
| 40 } | |
| 41 | |
| 42 const SkRasterClip& getRC() const { | |
| 43 SkASSERT(kDone_State != fState); | |
|
tomhudson
2013/08/28 15:01:21
SkASSERT(NULL != fCurrRC)?
reed1
2013/08/28 15:11:30
Done.
| |
| 44 return *fCurrRC; | |
| 45 } | |
| 46 | |
| 47 void mapRect(SkRect* dst, const SkRect& src) const; | |
| 48 void mapMatrix(SkMatrix* dst, const SkMatrix& src) const; | |
| 49 | |
| 50 /** | |
| 51 * Call next to setup the looper to return a valid coordinate chunk. | |
| 52 * Each time this returns true, it is safe to call mapRect() and | |
| 53 * mapMatrix(), to convert from "global" coordinate values to ones that | |
| 54 * are local to this chunk. | |
| 55 * | |
| 56 * When next() returns false, the list of chunks is done, and mapRect() | |
| 57 * and mapMatrix() should no longer be called. | |
| 58 */ | |
| 59 bool next(); | |
| 60 | |
| 61 private: | |
| 62 const SkBitmap& fBaseBitmap; | |
| 63 const SkRasterClip& fBaseRC; | |
| 64 | |
| 65 enum State { | |
| 66 kDone_State, // iteration is complete, getters will assert | |
| 67 kSimple_State, // no translate/clip mods needed | |
| 68 kComplex_State | |
| 69 }; | |
| 70 | |
| 71 // storage for our tiled versions. Perhaps could use SkTLazy | |
| 72 SkBitmap fSubsetBitmap; | |
| 73 SkRasterClip fSubsetRC; | |
| 74 | |
| 75 const SkBitmap* fCurrBitmap; | |
| 76 const SkRasterClip* fCurrRC; | |
| 77 SkIRect fClippedBounds; | |
| 78 SkIPoint fCurrOffset; | |
| 79 int fDelta; | |
| 80 State fState; | |
| 81 | |
| 82 enum Delta { | |
| 83 kBW_Delta = 1 << 14, // 16K, gives room to spare for fixedpoint | |
| 84 kAA_Delta = kBW_Delta >> 2 // supersample 4x | |
| 85 }; | |
| 86 | |
| 87 bool fitsInDelta(const SkIRect& r) const { | |
| 88 return r.right() < fDelta && r.bottom() < fDelta; | |
| 89 } | |
| 90 | |
| 91 bool computeCurrBitmapAndClip(); | |
| 92 }; | |
| 93 | |
| 94 #endif | |
| OLD | NEW |