gfx/skia/trunk/src/pathops/SkPathWriter.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 "SkPathOpsPoint.h"
michael@0 8 #include "SkPathWriter.h"
michael@0 9
michael@0 10 // wrap path to keep track of whether the contour is initialized and non-empty
michael@0 11 SkPathWriter::SkPathWriter(SkPath& path)
michael@0 12 : fPathPtr(&path)
michael@0 13 , fCloses(0)
michael@0 14 , fMoves(0)
michael@0 15 {
michael@0 16 init();
michael@0 17 }
michael@0 18
michael@0 19 void SkPathWriter::close() {
michael@0 20 if (!fHasMove) {
michael@0 21 return;
michael@0 22 }
michael@0 23 bool callClose = isClosed();
michael@0 24 lineTo();
michael@0 25 if (fEmpty) {
michael@0 26 return;
michael@0 27 }
michael@0 28 if (callClose) {
michael@0 29 #if DEBUG_PATH_CONSTRUCTION
michael@0 30 SkDebugf("path.close();\n");
michael@0 31 #endif
michael@0 32 fPathPtr->close();
michael@0 33 fCloses++;
michael@0 34 }
michael@0 35 init();
michael@0 36 }
michael@0 37
michael@0 38 void SkPathWriter::cubicTo(const SkPoint& pt1, const SkPoint& pt2, const SkPoint& pt3) {
michael@0 39 lineTo();
michael@0 40 if (fEmpty && AlmostEqualUlps(fDefer[0], pt1) && AlmostEqualUlps(pt1, pt2)
michael@0 41 && AlmostEqualUlps(pt2, pt3)) {
michael@0 42 deferredLine(pt3);
michael@0 43 return;
michael@0 44 }
michael@0 45 moveTo();
michael@0 46 fDefer[1] = pt3;
michael@0 47 nudge();
michael@0 48 fDefer[0] = fDefer[1];
michael@0 49 #if DEBUG_PATH_CONSTRUCTION
michael@0 50 SkDebugf("path.cubicTo(%1.9g,%1.9g, %1.9g,%1.9g, %1.9g,%1.9g);\n",
michael@0 51 pt1.fX, pt1.fY, pt2.fX, pt2.fY, fDefer[1].fX, fDefer[1].fY);
michael@0 52 #endif
michael@0 53 fPathPtr->cubicTo(pt1.fX, pt1.fY, pt2.fX, pt2.fY, fDefer[1].fX, fDefer[1].fY);
michael@0 54 fEmpty = false;
michael@0 55 }
michael@0 56
michael@0 57 void SkPathWriter::deferredLine(const SkPoint& pt) {
michael@0 58 if (pt == fDefer[1]) {
michael@0 59 return;
michael@0 60 }
michael@0 61 if (changedSlopes(pt)) {
michael@0 62 lineTo();
michael@0 63 fDefer[0] = fDefer[1];
michael@0 64 }
michael@0 65 fDefer[1] = pt;
michael@0 66 }
michael@0 67
michael@0 68 void SkPathWriter::deferredMove(const SkPoint& pt) {
michael@0 69 fMoved = true;
michael@0 70 fHasMove = true;
michael@0 71 fEmpty = true;
michael@0 72 fDefer[0] = fDefer[1] = pt;
michael@0 73 }
michael@0 74
michael@0 75 void SkPathWriter::deferredMoveLine(const SkPoint& pt) {
michael@0 76 if (!fHasMove) {
michael@0 77 deferredMove(pt);
michael@0 78 }
michael@0 79 deferredLine(pt);
michael@0 80 }
michael@0 81
michael@0 82 bool SkPathWriter::hasMove() const {
michael@0 83 return fHasMove;
michael@0 84 }
michael@0 85
michael@0 86 void SkPathWriter::init() {
michael@0 87 fEmpty = true;
michael@0 88 fHasMove = false;
michael@0 89 fMoved = false;
michael@0 90 }
michael@0 91
michael@0 92 bool SkPathWriter::isClosed() const {
michael@0 93 return !fEmpty && SkDPoint::ApproximatelyEqual(fFirstPt, fDefer[1]);
michael@0 94 }
michael@0 95
michael@0 96 void SkPathWriter::lineTo() {
michael@0 97 if (fDefer[0] == fDefer[1]) {
michael@0 98 return;
michael@0 99 }
michael@0 100 moveTo();
michael@0 101 nudge();
michael@0 102 fEmpty = false;
michael@0 103 #if DEBUG_PATH_CONSTRUCTION
michael@0 104 SkDebugf("path.lineTo(%1.9g,%1.9g);\n", fDefer[1].fX, fDefer[1].fY);
michael@0 105 #endif
michael@0 106 fPathPtr->lineTo(fDefer[1].fX, fDefer[1].fY);
michael@0 107 fDefer[0] = fDefer[1];
michael@0 108 }
michael@0 109
michael@0 110 const SkPath* SkPathWriter::nativePath() const {
michael@0 111 return fPathPtr;
michael@0 112 }
michael@0 113
michael@0 114 void SkPathWriter::nudge() {
michael@0 115 if (fEmpty || !AlmostEqualUlps(fDefer[1].fX, fFirstPt.fX)
michael@0 116 || !AlmostEqualUlps(fDefer[1].fY, fFirstPt.fY)) {
michael@0 117 return;
michael@0 118 }
michael@0 119 fDefer[1] = fFirstPt;
michael@0 120 }
michael@0 121
michael@0 122 void SkPathWriter::quadTo(const SkPoint& pt1, const SkPoint& pt2) {
michael@0 123 lineTo();
michael@0 124 if (fEmpty && AlmostEqualUlps(fDefer[0], pt1) && AlmostEqualUlps(pt1, pt2)) {
michael@0 125 deferredLine(pt2);
michael@0 126 return;
michael@0 127 }
michael@0 128 moveTo();
michael@0 129 fDefer[1] = pt2;
michael@0 130 nudge();
michael@0 131 fDefer[0] = fDefer[1];
michael@0 132 #if DEBUG_PATH_CONSTRUCTION
michael@0 133 SkDebugf("path.quadTo(%1.9g,%1.9g, %1.9g,%1.9g);\n",
michael@0 134 pt1.fX, pt1.fY, fDefer[1].fX, fDefer[1].fY);
michael@0 135 #endif
michael@0 136 fPathPtr->quadTo(pt1.fX, pt1.fY, fDefer[1].fX, fDefer[1].fY);
michael@0 137 fEmpty = false;
michael@0 138 }
michael@0 139
michael@0 140 bool SkPathWriter::someAssemblyRequired() const {
michael@0 141 return fCloses < fMoves;
michael@0 142 }
michael@0 143
michael@0 144 bool SkPathWriter::changedSlopes(const SkPoint& pt) const {
michael@0 145 if (fDefer[0] == fDefer[1]) {
michael@0 146 return false;
michael@0 147 }
michael@0 148 SkScalar deferDx = fDefer[1].fX - fDefer[0].fX;
michael@0 149 SkScalar deferDy = fDefer[1].fY - fDefer[0].fY;
michael@0 150 SkScalar lineDx = pt.fX - fDefer[1].fX;
michael@0 151 SkScalar lineDy = pt.fY - fDefer[1].fY;
michael@0 152 return deferDx * lineDy != deferDy * lineDx;
michael@0 153 }
michael@0 154
michael@0 155 void SkPathWriter::moveTo() {
michael@0 156 if (!fMoved) {
michael@0 157 return;
michael@0 158 }
michael@0 159 fFirstPt = fDefer[0];
michael@0 160 #if DEBUG_PATH_CONSTRUCTION
michael@0 161 SkDebugf("path.moveTo(%1.9g,%1.9g);\n", fDefer[0].fX, fDefer[0].fY);
michael@0 162 #endif
michael@0 163 fPathPtr->moveTo(fDefer[0].fX, fDefer[0].fY);
michael@0 164 fMoved = false;
michael@0 165 fMoves++;
michael@0 166 }

mercurial