gfx/skia/trunk/src/pathops/SkOpEdgeBuilder.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 2012 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 #include "SkGeometry.h"
michael@0 8 #include "SkOpEdgeBuilder.h"
michael@0 9 #include "SkReduceOrder.h"
michael@0 10
michael@0 11 void SkOpEdgeBuilder::init() {
michael@0 12 fCurrentContour = NULL;
michael@0 13 fOperand = false;
michael@0 14 fXorMask[0] = fXorMask[1] = (fPath->getFillType() & 1) ? kEvenOdd_PathOpsMask
michael@0 15 : kWinding_PathOpsMask;
michael@0 16 #ifdef SK_DEBUG
michael@0 17 SkPathOpsDebug::gContourID = 0;
michael@0 18 SkPathOpsDebug::gSegmentID = 0;
michael@0 19 #endif
michael@0 20 fUnparseable = false;
michael@0 21 fSecondHalf = preFetch();
michael@0 22 }
michael@0 23
michael@0 24 void SkOpEdgeBuilder::addOperand(const SkPath& path) {
michael@0 25 SkASSERT(fPathVerbs.count() > 0 && fPathVerbs.end()[-1] == SkPath::kDone_Verb);
michael@0 26 fPathVerbs.pop_back();
michael@0 27 fPath = &path;
michael@0 28 fXorMask[1] = (fPath->getFillType() & 1) ? kEvenOdd_PathOpsMask
michael@0 29 : kWinding_PathOpsMask;
michael@0 30 preFetch();
michael@0 31 }
michael@0 32
michael@0 33 bool SkOpEdgeBuilder::finish() {
michael@0 34 if (fUnparseable || !walk()) {
michael@0 35 return false;
michael@0 36 }
michael@0 37 complete();
michael@0 38 if (fCurrentContour && !fCurrentContour->segments().count()) {
michael@0 39 fContours.pop_back();
michael@0 40 }
michael@0 41 return true;
michael@0 42 }
michael@0 43
michael@0 44 void SkOpEdgeBuilder::closeContour(const SkPoint& curveEnd, const SkPoint& curveStart) {
michael@0 45 if (!SkDPoint::ApproximatelyEqual(curveEnd, curveStart)) {
michael@0 46 fPathVerbs.push_back(SkPath::kLine_Verb);
michael@0 47 fPathPts.push_back_n(1, &curveStart);
michael@0 48 } else {
michael@0 49 fPathPts[fPathPts.count() - 1] = curveStart;
michael@0 50 }
michael@0 51 fPathVerbs.push_back(SkPath::kClose_Verb);
michael@0 52 }
michael@0 53
michael@0 54 int SkOpEdgeBuilder::preFetch() {
michael@0 55 if (!fPath->isFinite()) {
michael@0 56 fUnparseable = true;
michael@0 57 return 0;
michael@0 58 }
michael@0 59 SkAutoConicToQuads quadder;
michael@0 60 const SkScalar quadderTol = SK_Scalar1 / 16;
michael@0 61 SkPath::RawIter iter(*fPath);
michael@0 62 SkPoint curveStart;
michael@0 63 SkPoint curve[4];
michael@0 64 SkPoint pts[4];
michael@0 65 SkPath::Verb verb;
michael@0 66 bool lastCurve = false;
michael@0 67 do {
michael@0 68 verb = iter.next(pts);
michael@0 69 switch (verb) {
michael@0 70 case SkPath::kMove_Verb:
michael@0 71 if (!fAllowOpenContours && lastCurve) {
michael@0 72 closeContour(curve[0], curveStart);
michael@0 73 }
michael@0 74 fPathVerbs.push_back(verb);
michael@0 75 fPathPts.push_back(pts[0]);
michael@0 76 curveStart = curve[0] = pts[0];
michael@0 77 lastCurve = false;
michael@0 78 continue;
michael@0 79 case SkPath::kLine_Verb:
michael@0 80 if (SkDPoint::ApproximatelyEqual(curve[0], pts[1])) {
michael@0 81 uint8_t lastVerb = fPathVerbs.back();
michael@0 82 if (lastVerb != SkPath::kLine_Verb && lastVerb != SkPath::kMove_Verb) {
michael@0 83 fPathPts.back() = pts[1];
michael@0 84 }
michael@0 85 continue; // skip degenerate points
michael@0 86 }
michael@0 87 break;
michael@0 88 case SkPath::kQuad_Verb:
michael@0 89 curve[1] = pts[1];
michael@0 90 curve[2] = pts[2];
michael@0 91 verb = SkReduceOrder::Quad(curve, pts);
michael@0 92 if (verb == SkPath::kMove_Verb) {
michael@0 93 continue; // skip degenerate points
michael@0 94 }
michael@0 95 break;
michael@0 96 case SkPath::kConic_Verb: {
michael@0 97 const SkPoint* quadPts = quadder.computeQuads(pts, iter.conicWeight(),
michael@0 98 quadderTol);
michael@0 99 const int nQuads = quadder.countQuads();
michael@0 100 for (int i = 0; i < nQuads; ++i) {
michael@0 101 fPathVerbs.push_back(SkPath::kQuad_Verb);
michael@0 102 }
michael@0 103 fPathPts.push_back_n(nQuads * 2, quadPts);
michael@0 104 curve[0] = quadPts[nQuads * 2 - 1];
michael@0 105 lastCurve = true;
michael@0 106 }
michael@0 107 continue;
michael@0 108 case SkPath::kCubic_Verb:
michael@0 109 curve[1] = pts[1];
michael@0 110 curve[2] = pts[2];
michael@0 111 curve[3] = pts[3];
michael@0 112 verb = SkReduceOrder::Cubic(curve, pts);
michael@0 113 if (verb == SkPath::kMove_Verb) {
michael@0 114 continue; // skip degenerate points
michael@0 115 }
michael@0 116 break;
michael@0 117 case SkPath::kClose_Verb:
michael@0 118 closeContour(curve[0], curveStart);
michael@0 119 lastCurve = false;
michael@0 120 continue;
michael@0 121 case SkPath::kDone_Verb:
michael@0 122 continue;
michael@0 123 }
michael@0 124 fPathVerbs.push_back(verb);
michael@0 125 int ptCount = SkPathOpsVerbToPoints(verb);
michael@0 126 fPathPts.push_back_n(ptCount, &pts[1]);
michael@0 127 curve[0] = pts[ptCount];
michael@0 128 lastCurve = true;
michael@0 129 } while (verb != SkPath::kDone_Verb);
michael@0 130 if (!fAllowOpenContours && lastCurve) {
michael@0 131 closeContour(curve[0], curveStart);
michael@0 132 }
michael@0 133 fPathVerbs.push_back(SkPath::kDone_Verb);
michael@0 134 return fPathVerbs.count() - 1;
michael@0 135 }
michael@0 136
michael@0 137 bool SkOpEdgeBuilder::close() {
michael@0 138 complete();
michael@0 139 return true;
michael@0 140 }
michael@0 141
michael@0 142 bool SkOpEdgeBuilder::walk() {
michael@0 143 uint8_t* verbPtr = fPathVerbs.begin();
michael@0 144 uint8_t* endOfFirstHalf = &verbPtr[fSecondHalf];
michael@0 145 const SkPoint* pointsPtr = fPathPts.begin() - 1;
michael@0 146 SkPath::Verb verb;
michael@0 147 while ((verb = (SkPath::Verb) *verbPtr) != SkPath::kDone_Verb) {
michael@0 148 if (verbPtr == endOfFirstHalf) {
michael@0 149 fOperand = true;
michael@0 150 }
michael@0 151 verbPtr++;
michael@0 152 switch (verb) {
michael@0 153 case SkPath::kMove_Verb:
michael@0 154 if (fCurrentContour) {
michael@0 155 if (fAllowOpenContours) {
michael@0 156 complete();
michael@0 157 } else if (!close()) {
michael@0 158 return false;
michael@0 159 }
michael@0 160 }
michael@0 161 if (!fCurrentContour) {
michael@0 162 fCurrentContour = fContours.push_back_n(1);
michael@0 163 fCurrentContour->setOperand(fOperand);
michael@0 164 fCurrentContour->setXor(fXorMask[fOperand] == kEvenOdd_PathOpsMask);
michael@0 165 }
michael@0 166 pointsPtr += 1;
michael@0 167 continue;
michael@0 168 case SkPath::kLine_Verb:
michael@0 169 fCurrentContour->addLine(pointsPtr);
michael@0 170 break;
michael@0 171 case SkPath::kQuad_Verb:
michael@0 172 fCurrentContour->addQuad(pointsPtr);
michael@0 173 break;
michael@0 174 case SkPath::kCubic_Verb:
michael@0 175 fCurrentContour->addCubic(pointsPtr);
michael@0 176 break;
michael@0 177 case SkPath::kClose_Verb:
michael@0 178 SkASSERT(fCurrentContour);
michael@0 179 if (!close()) {
michael@0 180 return false;
michael@0 181 }
michael@0 182 continue;
michael@0 183 default:
michael@0 184 SkDEBUGFAIL("bad verb");
michael@0 185 return false;
michael@0 186 }
michael@0 187 pointsPtr += SkPathOpsVerbToPoints(verb);
michael@0 188 SkASSERT(fCurrentContour);
michael@0 189 }
michael@0 190 if (fCurrentContour && !fAllowOpenContours && !close()) {
michael@0 191 return false;
michael@0 192 }
michael@0 193 return true;
michael@0 194 }

mercurial