1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/core/SkDeviceLooper.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,96 @@ 1.4 +/* 1.5 + * Copyright 2013 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#ifndef SkDeviceLooper_DEFINED 1.12 +#define SkDeviceLooper_DEFINED 1.13 + 1.14 +#include "SkBitmap.h" 1.15 +#include "SkMatrix.h" 1.16 +#include "SkRasterClip.h" 1.17 + 1.18 +/** 1.19 + * Helper class to manage "tiling" a large coordinate space into managable 1.20 + * chunks, where managable means areas that are <= some max critical coordinate 1.21 + * size. 1.22 + * 1.23 + * The constructor takes an antialiasing bool, which affects what this maximum 1.24 + * allowable size is: If we're drawing BW, then we need coordinates to stay 1.25 + * safely within fixed-point range (we use +- 16K, to give ourselves room to 1.26 + * add/subtract two fixed values and still be in range. If we're drawing AA, 1.27 + * then we reduce that size by the amount that the supersampler scan converter 1.28 + * needs (at the moment, that is 4X, so the "safe" range is +- 4K). 1.29 + * 1.30 + * For performance reasons, the class first checks to see if any help is needed 1.31 + * at all, and if not (i.e. the specified bounds and base bitmap area already 1.32 + * in the safe-zone, then the class does nothing (effectively). 1.33 + */ 1.34 +class SkDeviceLooper { 1.35 +public: 1.36 + SkDeviceLooper(const SkBitmap& base, const SkRasterClip&, 1.37 + const SkIRect& bounds, bool aa); 1.38 + ~SkDeviceLooper(); 1.39 + 1.40 + const SkBitmap& getBitmap() const { 1.41 + SkASSERT(kDone_State != fState); 1.42 + SkASSERT(fCurrBitmap); 1.43 + return *fCurrBitmap; 1.44 + } 1.45 + 1.46 + const SkRasterClip& getRC() const { 1.47 + SkASSERT(kDone_State != fState); 1.48 + SkASSERT(fCurrRC); 1.49 + return *fCurrRC; 1.50 + } 1.51 + 1.52 + void mapRect(SkRect* dst, const SkRect& src) const; 1.53 + void mapMatrix(SkMatrix* dst, const SkMatrix& src) const; 1.54 + 1.55 + /** 1.56 + * Call next to setup the looper to return a valid coordinate chunk. 1.57 + * Each time this returns true, it is safe to call mapRect() and 1.58 + * mapMatrix(), to convert from "global" coordinate values to ones that 1.59 + * are local to this chunk. 1.60 + * 1.61 + * When next() returns false, the list of chunks is done, and mapRect() 1.62 + * and mapMatrix() should no longer be called. 1.63 + */ 1.64 + bool next(); 1.65 + 1.66 +private: 1.67 + const SkBitmap& fBaseBitmap; 1.68 + const SkRasterClip& fBaseRC; 1.69 + 1.70 + enum State { 1.71 + kDone_State, // iteration is complete, getters will assert 1.72 + kSimple_State, // no translate/clip mods needed 1.73 + kComplex_State 1.74 + }; 1.75 + 1.76 + // storage for our tiled versions. Perhaps could use SkTLazy 1.77 + SkBitmap fSubsetBitmap; 1.78 + SkRasterClip fSubsetRC; 1.79 + 1.80 + const SkBitmap* fCurrBitmap; 1.81 + const SkRasterClip* fCurrRC; 1.82 + SkIRect fClippedBounds; 1.83 + SkIPoint fCurrOffset; 1.84 + int fDelta; 1.85 + State fState; 1.86 + 1.87 + enum Delta { 1.88 + kBW_Delta = 1 << 14, // 16K, gives room to spare for fixedpoint 1.89 + kAA_Delta = kBW_Delta >> 2 // supersample 4x 1.90 + }; 1.91 + 1.92 + bool fitsInDelta(const SkIRect& r) const { 1.93 + return r.right() < fDelta && r.bottom() < fDelta; 1.94 + } 1.95 + 1.96 + bool computeCurrBitmapAndClip(); 1.97 +}; 1.98 + 1.99 +#endif