gfx/skia/trunk/src/core/SkEdge.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 /*
michael@0 3 * Copyright 2006 The Android Open Source Project
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #ifndef SkEdge_DEFINED
michael@0 11 #define SkEdge_DEFINED
michael@0 12
michael@0 13 #include "SkRect.h"
michael@0 14 #include "SkFDot6.h"
michael@0 15 #include "SkMath.h"
michael@0 16
michael@0 17 // This correctly favors the lower-pixel when y0 is on a 1/2 pixel boundary
michael@0 18 #define SkEdge_Compute_DY(top, y0) ((top << 6) + 32 - (y0))
michael@0 19
michael@0 20 struct SkEdge {
michael@0 21 enum Type {
michael@0 22 kLine_Type,
michael@0 23 kQuad_Type,
michael@0 24 kCubic_Type
michael@0 25 };
michael@0 26
michael@0 27 SkEdge* fNext;
michael@0 28 SkEdge* fPrev;
michael@0 29
michael@0 30 SkFixed fX;
michael@0 31 SkFixed fDX;
michael@0 32 int32_t fFirstY;
michael@0 33 int32_t fLastY;
michael@0 34 int8_t fCurveCount; // only used by kQuad(+) and kCubic(-)
michael@0 35 uint8_t fCurveShift; // appled to all Dx/DDx/DDDx except for fCubicDShift exception
michael@0 36 uint8_t fCubicDShift; // applied to fCDx and fCDy only in cubic
michael@0 37 int8_t fWinding; // 1 or -1
michael@0 38
michael@0 39 int setLine(const SkPoint& p0, const SkPoint& p1, const SkIRect* clip,
michael@0 40 int shiftUp);
michael@0 41 // call this version if you know you don't have a clip
michael@0 42 inline int setLine(const SkPoint& p0, const SkPoint& p1, int shiftUp);
michael@0 43 inline int updateLine(SkFixed ax, SkFixed ay, SkFixed bx, SkFixed by);
michael@0 44 void chopLineWithClip(const SkIRect& clip);
michael@0 45
michael@0 46 inline bool intersectsClip(const SkIRect& clip) const {
michael@0 47 SkASSERT(fFirstY < clip.fBottom);
michael@0 48 return fLastY >= clip.fTop;
michael@0 49 }
michael@0 50
michael@0 51 #ifdef SK_DEBUG
michael@0 52 void dump() const {
michael@0 53 SkDebugf("edge: firstY:%d lastY:%d x:%g dx:%g w:%d\n", fFirstY, fLastY, SkFixedToFloat(fX), SkFixedToFloat(fDX), fWinding);
michael@0 54 }
michael@0 55
michael@0 56 void validate() const {
michael@0 57 SkASSERT(fPrev && fNext);
michael@0 58 SkASSERT(fPrev->fNext == this);
michael@0 59 SkASSERT(fNext->fPrev == this);
michael@0 60
michael@0 61 SkASSERT(fFirstY <= fLastY);
michael@0 62 SkASSERT(SkAbs32(fWinding) == 1);
michael@0 63 }
michael@0 64 #endif
michael@0 65 };
michael@0 66
michael@0 67 struct SkQuadraticEdge : public SkEdge {
michael@0 68 SkFixed fQx, fQy;
michael@0 69 SkFixed fQDx, fQDy;
michael@0 70 SkFixed fQDDx, fQDDy;
michael@0 71 SkFixed fQLastX, fQLastY;
michael@0 72
michael@0 73 int setQuadratic(const SkPoint pts[3], int shiftUp);
michael@0 74 int updateQuadratic();
michael@0 75 };
michael@0 76
michael@0 77 struct SkCubicEdge : public SkEdge {
michael@0 78 SkFixed fCx, fCy;
michael@0 79 SkFixed fCDx, fCDy;
michael@0 80 SkFixed fCDDx, fCDDy;
michael@0 81 SkFixed fCDDDx, fCDDDy;
michael@0 82 SkFixed fCLastX, fCLastY;
michael@0 83
michael@0 84 int setCubic(const SkPoint pts[4], const SkIRect* clip, int shiftUp);
michael@0 85 int updateCubic();
michael@0 86 };
michael@0 87
michael@0 88 int SkEdge::setLine(const SkPoint& p0, const SkPoint& p1, int shift) {
michael@0 89 SkFDot6 x0, y0, x1, y1;
michael@0 90
michael@0 91 {
michael@0 92 float scale = float(1 << (shift + 6));
michael@0 93 x0 = int(p0.fX * scale);
michael@0 94 y0 = int(p0.fY * scale);
michael@0 95 x1 = int(p1.fX * scale);
michael@0 96 y1 = int(p1.fY * scale);
michael@0 97 }
michael@0 98
michael@0 99 int winding = 1;
michael@0 100
michael@0 101 if (y0 > y1) {
michael@0 102 SkTSwap(x0, x1);
michael@0 103 SkTSwap(y0, y1);
michael@0 104 winding = -1;
michael@0 105 }
michael@0 106
michael@0 107 int top = SkFDot6Round(y0);
michael@0 108 int bot = SkFDot6Round(y1);
michael@0 109
michael@0 110 // are we a zero-height line?
michael@0 111 if (top == bot) {
michael@0 112 return 0;
michael@0 113 }
michael@0 114
michael@0 115 SkFixed slope = SkFDot6Div(x1 - x0, y1 - y0);
michael@0 116 const int dy = SkEdge_Compute_DY(top, y0);
michael@0 117
michael@0 118 fX = SkFDot6ToFixed(x0 + SkFixedMul(slope, dy)); // + SK_Fixed1/2
michael@0 119 fDX = slope;
michael@0 120 fFirstY = top;
michael@0 121 fLastY = bot - 1;
michael@0 122 fCurveCount = 0;
michael@0 123 fWinding = SkToS8(winding);
michael@0 124 fCurveShift = 0;
michael@0 125 return 1;
michael@0 126 }
michael@0 127
michael@0 128
michael@0 129 #endif

mercurial