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

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

mercurial