gfx/skia/trunk/src/core/SkDeviceLooper.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright 2013 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #ifndef SkDeviceLooper_DEFINED
michael@0 9 #define SkDeviceLooper_DEFINED
michael@0 10
michael@0 11 #include "SkBitmap.h"
michael@0 12 #include "SkMatrix.h"
michael@0 13 #include "SkRasterClip.h"
michael@0 14
michael@0 15 /**
michael@0 16 * Helper class to manage "tiling" a large coordinate space into managable
michael@0 17 * chunks, where managable means areas that are <= some max critical coordinate
michael@0 18 * size.
michael@0 19 *
michael@0 20 * The constructor takes an antialiasing bool, which affects what this maximum
michael@0 21 * allowable size is: If we're drawing BW, then we need coordinates to stay
michael@0 22 * safely within fixed-point range (we use +- 16K, to give ourselves room to
michael@0 23 * add/subtract two fixed values and still be in range. If we're drawing AA,
michael@0 24 * then we reduce that size by the amount that the supersampler scan converter
michael@0 25 * needs (at the moment, that is 4X, so the "safe" range is +- 4K).
michael@0 26 *
michael@0 27 * For performance reasons, the class first checks to see if any help is needed
michael@0 28 * at all, and if not (i.e. the specified bounds and base bitmap area already
michael@0 29 * in the safe-zone, then the class does nothing (effectively).
michael@0 30 */
michael@0 31 class SkDeviceLooper {
michael@0 32 public:
michael@0 33 SkDeviceLooper(const SkBitmap& base, const SkRasterClip&,
michael@0 34 const SkIRect& bounds, bool aa);
michael@0 35 ~SkDeviceLooper();
michael@0 36
michael@0 37 const SkBitmap& getBitmap() const {
michael@0 38 SkASSERT(kDone_State != fState);
michael@0 39 SkASSERT(fCurrBitmap);
michael@0 40 return *fCurrBitmap;
michael@0 41 }
michael@0 42
michael@0 43 const SkRasterClip& getRC() const {
michael@0 44 SkASSERT(kDone_State != fState);
michael@0 45 SkASSERT(fCurrRC);
michael@0 46 return *fCurrRC;
michael@0 47 }
michael@0 48
michael@0 49 void mapRect(SkRect* dst, const SkRect& src) const;
michael@0 50 void mapMatrix(SkMatrix* dst, const SkMatrix& src) const;
michael@0 51
michael@0 52 /**
michael@0 53 * Call next to setup the looper to return a valid coordinate chunk.
michael@0 54 * Each time this returns true, it is safe to call mapRect() and
michael@0 55 * mapMatrix(), to convert from "global" coordinate values to ones that
michael@0 56 * are local to this chunk.
michael@0 57 *
michael@0 58 * When next() returns false, the list of chunks is done, and mapRect()
michael@0 59 * and mapMatrix() should no longer be called.
michael@0 60 */
michael@0 61 bool next();
michael@0 62
michael@0 63 private:
michael@0 64 const SkBitmap& fBaseBitmap;
michael@0 65 const SkRasterClip& fBaseRC;
michael@0 66
michael@0 67 enum State {
michael@0 68 kDone_State, // iteration is complete, getters will assert
michael@0 69 kSimple_State, // no translate/clip mods needed
michael@0 70 kComplex_State
michael@0 71 };
michael@0 72
michael@0 73 // storage for our tiled versions. Perhaps could use SkTLazy
michael@0 74 SkBitmap fSubsetBitmap;
michael@0 75 SkRasterClip fSubsetRC;
michael@0 76
michael@0 77 const SkBitmap* fCurrBitmap;
michael@0 78 const SkRasterClip* fCurrRC;
michael@0 79 SkIRect fClippedBounds;
michael@0 80 SkIPoint fCurrOffset;
michael@0 81 int fDelta;
michael@0 82 State fState;
michael@0 83
michael@0 84 enum Delta {
michael@0 85 kBW_Delta = 1 << 14, // 16K, gives room to spare for fixedpoint
michael@0 86 kAA_Delta = kBW_Delta >> 2 // supersample 4x
michael@0 87 };
michael@0 88
michael@0 89 bool fitsInDelta(const SkIRect& r) const {
michael@0 90 return r.right() < fDelta && r.bottom() < fDelta;
michael@0 91 }
michael@0 92
michael@0 93 bool computeCurrBitmapAndClip();
michael@0 94 };
michael@0 95
michael@0 96 #endif

mercurial