Port several Skia upstream fixes.

This commit is contained in:
wolfbeast 2019-02-14 16:59:52 +01:00 • committed by Roy Tam
commit 80610e5548
7 changed files with 60 additions and 39 deletions

View file

@ -373,7 +373,7 @@ public:
@param extraPtCount The number of extra points the path should @param extraPtCount The number of extra points the path should
preallocate for. preallocate for.
*/ */
void incReserve(unsigned extraPtCount); void incReserve(int extraPtCount);
/** Set the beginning of the next contour to the point (x,y). /** Set the beginning of the next contour to the point (x,y).

View file

@ -547,6 +547,8 @@ private:
friend class PathRefTest_Private; friend class PathRefTest_Private;
friend class ForceIsRRect_Private; // unit test isRRect friend class ForceIsRRect_Private; // unit test isRRect
friend class SkPath;
friend class SkPathPriv;
}; };
#endif #endif

View file

@ -716,9 +716,11 @@ void SkPath::setConvexity(Convexity c) {
fFirstDirection = SkPathPriv::kUnknown_FirstDirection; \ fFirstDirection = SkPathPriv::kUnknown_FirstDirection; \
} while (0) } while (0)
void SkPath::incReserve(U16CPU inc) { void SkPath::incReserve(int inc) {
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
SkPathRef::Editor(&fPathRef, inc, inc); if (inc > 0) {
SkPathRef::Editor(&fPathRef, inc, inc);
}
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
} }
@ -1691,6 +1693,13 @@ static void subdivide_cubic_to(SkPath* path, const SkPoint pts[4],
} }
void SkPath::transform(const SkMatrix& matrix, SkPath* dst) const { void SkPath::transform(const SkMatrix& matrix, SkPath* dst) const {
if (matrix.isIdentity()) {
if (dst != nullptr && dst != this) {
*dst = *this;
}
return;
}
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
if (dst == nullptr) { if (dst == nullptr) {
dst = (SkPath*)this; dst = (SkPath*)this;
@ -1738,14 +1747,21 @@ void SkPath::transform(const SkMatrix& matrix, SkPath* dst) const {
matrix.mapPoints(ed.points(), ed.pathRef()->countPoints()); matrix.mapPoints(ed.points(), ed.pathRef()->countPoints());
dst->fFirstDirection = SkPathPriv::kUnknown_FirstDirection; dst->fFirstDirection = SkPathPriv::kUnknown_FirstDirection;
} else { } else {
Convexity convexity = Convexity(fConvexity);
SkPathRef::CreateTransformedCopy(&dst->fPathRef, *fPathRef.get(), matrix); SkPathRef::CreateTransformedCopy(&dst->fPathRef, *fPathRef.get(), matrix);
if (this != dst) { if (this != dst) {
dst->fFillType = fFillType; dst->fFillType = fFillType;
dst->fConvexity = fConvexity;
dst->fIsVolatile = fIsVolatile; dst->fIsVolatile = fIsVolatile;
} }
if (matrix.isScaleTranslate() && SkPathPriv::IsAxisAligned(*this)) {
dst->fConvexity = convexity;
} else {
dst->fConvexity = kUnknown_Convexity;
}
if (SkPathPriv::kUnknown_FirstDirection == fFirstDirection) { if (SkPathPriv::kUnknown_FirstDirection == fFirstDirection) {
dst->fFirstDirection = SkPathPriv::kUnknown_FirstDirection; dst->fFirstDirection = SkPathPriv::kUnknown_FirstDirection;
} else { } else {
@ -1758,7 +1774,6 @@ void SkPath::transform(const SkMatrix& matrix, SkPath* dst) const {
} else if (det2x2 > 0) { } else if (det2x2 > 0) {
dst->fFirstDirection = fFirstDirection.load(); dst->fFirstDirection = fFirstDirection.load();
} else { } else {
dst->fConvexity = kUnknown_Convexity;
dst->fFirstDirection = SkPathPriv::kUnknown_FirstDirection; dst->fFirstDirection = SkPathPriv::kUnknown_FirstDirection;
} }
} }

View file

@ -121,6 +121,11 @@ public:
static const SkScalar* ConicWeightData(const SkPath& path) { static const SkScalar* ConicWeightData(const SkPath& path) {
return path.fPathRef->conicWeights(); return path.fPathRef->conicWeights();
} }
static bool IsAxisAligned(const SkPath& path) {
SkRect tmp;
return (path.fPathRef->fIsRRect | path.fPathRef->fIsOval) || path.isRect(&tmp);
}
}; };
#endif #endif

View file

@ -241,9 +241,17 @@ static bool update_edge(SkEdge* edge, int last_y) {
return false; return false;
} }
static void walk_convex_edges(SkEdge* prevHead, SkPath::FillType, // Unexpected conditions for which we need to return
SkBlitter* blitter, int start_y, int stop_y, #define ASSERT_RETURN(cond) \
PrePostProc proc) { do { \
if (!(cond)) { \
SkASSERT(false); \
return; \
} \
} while (0)
// Needs Y to only change once (looser than convex in X)
static void walk_simple_edges(SkEdge* prevHead, SkBlitter* blitter, int start_y, int stop_y) {
validate_sort(prevHead->fNext); validate_sort(prevHead->fNext);
SkEdge* leftE = prevHead->fNext; SkEdge* leftE = prevHead->fNext;
@ -258,30 +266,28 @@ static void walk_convex_edges(SkEdge* prevHead, SkPath::FillType,
// not lining up, so we take the max. // not lining up, so we take the max.
int local_top = SkMax32(leftE->fFirstY, riteE->fFirstY); int local_top = SkMax32(leftE->fFirstY, riteE->fFirstY);
#endif #endif
SkASSERT(local_top >= start_y); ASSERT_RETURN(local_top >= start_y);
for (;;) { while (local_top < stop_y) {
SkASSERT(leftE->fFirstY <= stop_y); SkASSERT(leftE->fFirstY <= stop_y);
SkASSERT(riteE->fFirstY <= stop_y); SkASSERT(riteE->fFirstY <= stop_y);
if (leftE->fX > riteE->fX || (leftE->fX == riteE->fX &&
leftE->fDX > riteE->fDX)) {
SkTSwap(leftE, riteE);
}
int local_bot = SkMin32(leftE->fLastY, riteE->fLastY); int local_bot = SkMin32(leftE->fLastY, riteE->fLastY);
local_bot = SkMin32(local_bot, stop_y - 1); local_bot = SkMin32(local_bot, stop_y - 1);
SkASSERT(local_top <= local_bot); ASSERT_RETURN(local_top <= local_bot);
SkFixed left = leftE->fX; SkFixed left = leftE->fX;
SkFixed dLeft = leftE->fDX; SkFixed dLeft = leftE->fDX;
SkFixed rite = riteE->fX; SkFixed rite = riteE->fX;
SkFixed dRite = riteE->fDX; SkFixed dRite = riteE->fDX;
int count = local_bot - local_top; int count = local_bot - local_top;
SkASSERT(count >= 0); ASSERT_RETURN(count >= 0);
if (0 == (dLeft | dRite)) { if (0 == (dLeft | dRite)) {
int L = SkFixedRoundToInt(left); int L = SkFixedRoundToInt(left);
int R = SkFixedRoundToInt(rite); int R = SkFixedRoundToInt(rite);
if (L > R) {
SkTSwap(L, R);
}
if (L < R) { if (L < R) {
count += 1; count += 1;
blitter->blitRect(L, local_top, R - L, count); blitter->blitRect(L, local_top, R - L, count);
@ -291,6 +297,9 @@ static void walk_convex_edges(SkEdge* prevHead, SkPath::FillType,
do { do {
int L = SkFixedRoundToInt(left); int L = SkFixedRoundToInt(left);
int R = SkFixedRoundToInt(rite); int R = SkFixedRoundToInt(rite);
if (L > R) {
SkTSwap(L, R);
}
if (L < R) { if (L < R) {
blitter->blitH(L, local_top, R - L); blitter->blitH(L, local_top, R - L);
} }
@ -303,28 +312,21 @@ static void walk_convex_edges(SkEdge* prevHead, SkPath::FillType,
leftE->fX = left; leftE->fX = left;
riteE->fX = rite; riteE->fX = rite;
if (update_edge(leftE, local_bot)) { if (!update_edge(leftE, local_bot)) {
if (currE->fFirstY >= stop_y) { if (currE->fFirstY >= stop_y) {
break; return; // we're done
} }
leftE = currE; leftE = currE;
currE = currE->fNext; currE = currE->fNext;
ASSERT_RETURN(leftE->fFirstY == local_top);
} }
if (update_edge(riteE, local_bot)) { if (!update_edge(riteE, local_bot)) {
if (currE->fFirstY >= stop_y) { if (currE->fFirstY >= stop_y) {
break; return; // we're done
} }
riteE = currE; riteE = currE;
currE = currE->fNext; currE = currE->fNext;
} ASSERT_RETURN(riteE->fFirstY == local_top);
SkASSERT(leftE);
SkASSERT(riteE);
// check our bottom clip
SkASSERT(local_top == local_bot + 1);
if (local_top >= stop_y) {
break;
} }
} }
} }
@ -500,9 +502,9 @@ void sk_fill_path(const SkPath& path, const SkIRect* clipRect, SkBlitter* blitte
proc = PrePostInverseBlitterProc; proc = PrePostInverseBlitterProc;
} }
if (path.isConvex() && (nullptr == proc)) { // count >= 2 is required as the convex walker does not handle missing right edges
SkASSERT(count >= 2); // convex walker does not handle missing right edges if (path.isConvex() && (nullptr == proc) && count >= 2) {
walk_convex_edges(&headEdge, path.getFillType(), blitter, start_y, stop_y, nullptr); walk_simple_edges(&headEdge, blitter, start_y, stop_y);
} else { } else {
int rightEdge; int rightEdge;
if (clipRect) { if (clipRect) {
@ -766,8 +768,7 @@ static void sk_fill_triangle(const SkPoint pts[], const SkIRect* clipRect,
if (clipRect && start_y < clipRect->fTop) { if (clipRect && start_y < clipRect->fTop) {
start_y = clipRect->fTop; start_y = clipRect->fTop;
} }
walk_convex_edges(&headEdge, SkPath::kEvenOdd_FillType, blitter, start_y, stop_y, nullptr); walk_simple_edges(&headEdge, blitter, start_y, stop_y);
// walk_edges(&headEdge, SkPath::kEvenOdd_FillType, blitter, start_y, stop_y, nullptr);
} }
void SkScan::FillTriangle(const SkPoint pts[], const SkRasterClip& clip, void SkScan::FillTriangle(const SkPoint pts[], const SkRasterClip& clip,

View file

@ -780,9 +780,9 @@ pref("dom.phonenumber.substringmatching.BR", 8);
pref("dom.phonenumber.substringmatching.CO", 10); pref("dom.phonenumber.substringmatching.CO", 10);
pref("dom.phonenumber.substringmatching.VE", 7); pref("dom.phonenumber.substringmatching.VE", 7);
// Enable hardware-accelerated Skia canvas // Support, but deprecate, hardware-accelerated Skia canvas
pref("gfx.canvas.azure.backends", "skia"); pref("gfx.canvas.azure.backends", "skia");
pref("gfx.canvas.azure.accelerated", true); pref("gfx.canvas.azure.accelerated", false);
// See ua-update.json.in for the packaged UA override list // See ua-update.json.in for the packaged UA override list
pref("general.useragent.updates.enabled", true); pref("general.useragent.updates.enabled", true);

View file

@ -795,8 +795,6 @@ pref("gfx.content.azure.backends", "direct2d1.1,cairo");
#ifdef XP_MACOSX #ifdef XP_MACOSX
pref("gfx.content.azure.backends", "cg"); pref("gfx.content.azure.backends", "cg");
pref("gfx.canvas.azure.backends", "skia,cg"); pref("gfx.canvas.azure.backends", "skia,cg");
// Accelerated cg canvas where available (10.7+)
pref("gfx.canvas.azure.accelerated", true);
#else #else
// Linux etc. // Linux etc.
pref("gfx.canvas.azure.backends", "skia,cairo"); pref("gfx.canvas.azure.backends", "skia,cairo");