/* * Copyright 2006 The Android Open Source Project * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file.
*/
/* In setLine, setQuadratic, setCubic, the first thing we do is to convert the points into FDot6. This is modulated by the shift parameter, which will either be 0, or something like 2 for antialiasing.
In the float case, we want to turn the float into .6 by saying pt * 64, or pt * 256 for antialiasing. This is implemented as 1 << (shift + 6).
In the fixed case, we want to turn the fixed into .6 by saying pt >> 10, or pt >> 8 for antialiasing. This is implemented as pt >> (10 - shift).
*/
staticinline SkFixed SkFDot6ToFixedDiv2(SkFDot6 value) { // we want to return SkFDot6ToFixed(value >> 1), but we don't want to throw // away data in value, so just perform a modify up-shift return SkLeftShift(value, 16 - 6 - 1);
}
if (y0 > y1) { using std::swap;
swap(x0, x1);
swap(y0, y1);
winding = -1;
}
int top = SkFDot6Round(y0); int bot = SkFDot6Round(y1);
// are we a zero-height line? if (top == bot) { return 0;
} // are we completely above or below the clip? if (clip && (top >= clip->fBottom || bot <= clip->fTop)) { return 0;
}
/* We store 1<<shift in a (signed) byte, so its maximum value is 1<<6 == 64. Note that this limits the number of lines we use to approximate a curve. If we need to increase this, we need to store fCurveCount in something larger than int8_t.
*/ #define MAX_COEFF_SHIFT 6
staticinline SkFDot6 cheap_distance(SkFDot6 dx, SkFDot6 dy)
{
dx = SkAbs32(dx);
dy = SkAbs32(dy); // return max + min/2 if (dx > dy)
dx += dy >> 1; else
dx = dy + (dx >> 1); return dx;
}
staticinlineint diff_to_shift(SkFDot6 dx, SkFDot6 dy, int shiftAA = 2)
{ // cheap calc of distance from center of p0-p2 to the center of the curve
SkFDot6 dist = cheap_distance(dx, dy);
// shift down dist (it is currently in dot6) // down by 3 should give us 1/8 pixel accuracy (assuming our dist is accurate...) // this is chosen by heuristic: make it as big as possible (to minimize segments) // ... but small enough so that our curves still look smooth // When shift > 0, we're using AA and everything is scaled up so we can // lower the accuracy.
dist = (dist + (1 << (2 + shiftAA))) >> (3 + shiftAA);
// each subdivision (shift value) cuts this dist (error) by 1/4 return (32 - SkCLZ(dist)) >> 1;
}
int winding = 1; if (y0 > y2)
{ using std::swap;
swap(x0, x2);
swap(y0, y2);
winding = -1;
}
SkASSERT(y0 <= y1 && y1 <= y2);
int top = SkFDot6Round(y0); int bot = SkFDot6Round(y2);
// are we a zero-height quad (line)? if (top == bot) return 0;
// compute number of steps needed (1 << shift)
{
SkFDot6 dx = (SkLeftShift(x1, 1) - x0 - x2) >> 2;
SkFDot6 dy = (SkLeftShift(y1, 1) - y0 - y2) >> 2; // This is a little confusing: // before this line, shift is the scale up factor for AA; // after this line, shift is the fCurveShift.
shift = diff_to_shift(dx, dy, shift);
SkASSERT(shift >= 0);
} // need at least 1 subdivision for our bias trick if (shift == 0) {
shift = 1;
} elseif (shift > MAX_COEFF_SHIFT) {
shift = MAX_COEFF_SHIFT;
}
fWinding = SkToS8(winding); //fCubicDShift only set for cubics
fEdgeType = kQuad_Type;
fCurveCount = SkToS8(1 << shift);
/* * We want to reformulate into polynomial form, to make it clear how we * should forward-difference. * * p0 (1 - t)^2 + p1 t(1 - t) + p2 t^2 ==> At^2 + Bt + C * * A = p0 - 2p1 + p2 * B = 2(p1 - p0) * C = p0 * * Our caller must have constrained our inputs (p0..p2) to all fit into * 16.16. However, as seen above, we sometimes compute values that can be * larger (e.g. B = 2*(p1 - p0)). To guard against overflow, we will store * A and B at 1/2 of their actual value, and just apply a 2x scale during * application in updateQuadratic(). Hence we store (shift - 1) in * fCurveShift.
*/
fCurveShift = SkToU8(shift - 1);
SkFixed A = SkFDot6ToFixedDiv2(x0 - x1 - x1 + x2); // 1/2 the real value
SkFixed B = SkFDot6ToFixed(x1 - x0); // 1/2 the real value
fQx = SkFDot6ToFixed(x0);
fQDx = B + (A >> shift); // biased by shift
fQDDx = A >> (shift - 1); // biased by shift
A = SkFDot6ToFixedDiv2(y0 - y1 - y1 + y2); // 1/2 the real value
B = SkFDot6ToFixed(y1 - y0); // 1/2 the real value
fQy = SkFDot6ToFixed(y0);
fQDy = B + (A >> shift); // biased by shift
fQDDy = A >> (shift - 1); // biased by shift
int winding = 1; if (sortY && y0 > y3)
{ using std::swap;
swap(x0, x3);
swap(x1, x2);
swap(y0, y3);
swap(y1, y2);
winding = -1;
}
int top = SkFDot6Round(y0); int bot = SkFDot6Round(y3);
// are we a zero-height cubic (line)? if (sortY && top == bot) return 0;
// compute number of steps needed (1 << shift)
{ // Can't use (center of curve - center of baseline), since center-of-curve // need not be the max delta from the baseline (it could even be coincident) // so we try just looking at the two off-curve points
SkFDot6 dx = cubic_delta_from_line(x0, x1, x2, x3);
SkFDot6 dy = cubic_delta_from_line(y0, y1, y2, y3); // add 1 (by observation)
shift = diff_to_shift(dx, dy) + 1;
} // need at least 1 subdivision for our bias trick
SkASSERT(shift > 0); if (shift > MAX_COEFF_SHIFT) {
shift = MAX_COEFF_SHIFT;
}
/* Since our in coming data is initially shifted down by 10 (or 8 in antialias). That means the most we can shift up is 8. However, we compute coefficients with a 3*, so the safest upshift is really 6
*/ int upShift = 6; // largest safe value int downShift = shift + upShift - 10; if (downShift < 0) {
downShift = 0;
upShift = 10 - shift;
}
// we want to say SkASSERT(oldy <= newy), but our finite fixedpoint // doesn't always achieve that, so we have to explicitly pin it here. if (newy < oldy) {
newy = oldy;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.