gfx/skia/trunk/src/core/SkQuadClipper.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 2009 The Android Open Source Project
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 "SkQuadClipper.h"
michael@0 9 #include "SkGeometry.h"
michael@0 10
michael@0 11 SkQuadClipper::SkQuadClipper() {
michael@0 12 fClip.setEmpty();
michael@0 13 }
michael@0 14
michael@0 15 void SkQuadClipper::setClip(const SkIRect& clip) {
michael@0 16 // conver to scalars, since that's where we'll see the points
michael@0 17 fClip.set(clip);
michael@0 18 }
michael@0 19
michael@0 20 ///////////////////////////////////////////////////////////////////////////////
michael@0 21
michael@0 22 static bool chopMonoQuadAt(SkScalar c0, SkScalar c1, SkScalar c2,
michael@0 23 SkScalar target, SkScalar* t) {
michael@0 24 /* Solve F(t) = y where F(t) := [0](1-t)^2 + 2[1]t(1-t) + [2]t^2
michael@0 25 * We solve for t, using quadratic equation, hence we have to rearrange
michael@0 26 * our cooefficents to look like At^2 + Bt + C
michael@0 27 */
michael@0 28 SkScalar A = c0 - c1 - c1 + c2;
michael@0 29 SkScalar B = 2*(c1 - c0);
michael@0 30 SkScalar C = c0 - target;
michael@0 31
michael@0 32 SkScalar roots[2]; // we only expect one, but make room for 2 for safety
michael@0 33 int count = SkFindUnitQuadRoots(A, B, C, roots);
michael@0 34 if (count) {
michael@0 35 *t = roots[0];
michael@0 36 return true;
michael@0 37 }
michael@0 38 return false;
michael@0 39 }
michael@0 40
michael@0 41 static bool chopMonoQuadAtY(SkPoint pts[3], SkScalar y, SkScalar* t) {
michael@0 42 return chopMonoQuadAt(pts[0].fY, pts[1].fY, pts[2].fY, y, t);
michael@0 43 }
michael@0 44
michael@0 45 ///////////////////////////////////////////////////////////////////////////////
michael@0 46
michael@0 47 /* If we somehow returned the fact that we had to flip the pts in Y, we could
michael@0 48 communicate that to setQuadratic, and then avoid having to flip it back
michael@0 49 here (only to have setQuadratic do the flip again)
michael@0 50 */
michael@0 51 bool SkQuadClipper::clipQuad(const SkPoint srcPts[3], SkPoint dst[3]) {
michael@0 52 bool reverse;
michael@0 53
michael@0 54 // we need the data to be monotonically increasing in Y
michael@0 55 if (srcPts[0].fY > srcPts[2].fY) {
michael@0 56 dst[0] = srcPts[2];
michael@0 57 dst[1] = srcPts[1];
michael@0 58 dst[2] = srcPts[0];
michael@0 59 reverse = true;
michael@0 60 } else {
michael@0 61 memcpy(dst, srcPts, 3 * sizeof(SkPoint));
michael@0 62 reverse = false;
michael@0 63 }
michael@0 64
michael@0 65 // are we completely above or below
michael@0 66 const SkScalar ctop = fClip.fTop;
michael@0 67 const SkScalar cbot = fClip.fBottom;
michael@0 68 if (dst[2].fY <= ctop || dst[0].fY >= cbot) {
michael@0 69 return false;
michael@0 70 }
michael@0 71
michael@0 72 SkScalar t;
michael@0 73 SkPoint tmp[5]; // for SkChopQuadAt
michael@0 74
michael@0 75 // are we partially above
michael@0 76 if (dst[0].fY < ctop) {
michael@0 77 if (chopMonoQuadAtY(dst, ctop, &t)) {
michael@0 78 // take the 2nd chopped quad
michael@0 79 SkChopQuadAt(dst, tmp, t);
michael@0 80 dst[0] = tmp[2];
michael@0 81 dst[1] = tmp[3];
michael@0 82 } else {
michael@0 83 // if chopMonoQuadAtY failed, then we may have hit inexact numerics
michael@0 84 // so we just clamp against the top
michael@0 85 for (int i = 0; i < 3; i++) {
michael@0 86 if (dst[i].fY < ctop) {
michael@0 87 dst[i].fY = ctop;
michael@0 88 }
michael@0 89 }
michael@0 90 }
michael@0 91 }
michael@0 92
michael@0 93 // are we partially below
michael@0 94 if (dst[2].fY > cbot) {
michael@0 95 if (chopMonoQuadAtY(dst, cbot, &t)) {
michael@0 96 SkChopQuadAt(dst, tmp, t);
michael@0 97 dst[1] = tmp[1];
michael@0 98 dst[2] = tmp[2];
michael@0 99 } else {
michael@0 100 // if chopMonoQuadAtY failed, then we may have hit inexact numerics
michael@0 101 // so we just clamp against the bottom
michael@0 102 for (int i = 0; i < 3; i++) {
michael@0 103 if (dst[i].fY > cbot) {
michael@0 104 dst[i].fY = cbot;
michael@0 105 }
michael@0 106 }
michael@0 107 }
michael@0 108 }
michael@0 109
michael@0 110 if (reverse) {
michael@0 111 SkTSwap<SkPoint>(dst[0], dst[2]);
michael@0 112 }
michael@0 113 return true;
michael@0 114 }

mercurial