Index: src/effects/gradients/SkTwoPointConicalGradient.cpp |
diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp |
index b0955a2583144e3f2a509360b0504f9802c0210d..1852e930e8041c7fa5275ce78ad1000448d02a2f 100644 |
--- a/src/effects/gradients/SkTwoPointConicalGradient.cpp |
+++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp |
@@ -32,7 +32,7 @@ static int valid_divide(float numer, float denom, float* ratio) { |
// Return the number of distinct real roots, and write them into roots[] in |
// ascending order |
-static int find_quad_roots(float A, float B, float C, float roots[2]) { |
+static int find_quad_roots(float A, float B, float C, float roots[2], bool descendingOrder = false) { |
SkASSERT(roots); |
if (A == 0) { |
@@ -66,6 +66,9 @@ static int find_quad_roots(float A, float B, float C, float roots[2]) { |
float r1 = C / Q; |
roots[0] = r0 < r1 ? r0 : r1; |
roots[1] = r0 > r1 ? r0 : r1; |
+ if (descendingOrder) { |
+ SkTSwap(roots[0], roots[1]); |
+ } |
return 2; |
} |
@@ -76,7 +79,8 @@ static float lerp(float x, float dx, float t) { |
static float sqr(float x) { return x * x; } |
void TwoPtRadial::init(const SkPoint& center0, SkScalar rad0, |
- const SkPoint& center1, SkScalar rad1) { |
+ const SkPoint& center1, SkScalar rad1, |
+ bool flipped) { |
fCenterX = SkScalarToFloat(center0.fX); |
fCenterY = SkScalarToFloat(center0.fY); |
fDCenterX = SkScalarToFloat(center1.fX) - fCenterX; |
@@ -87,6 +91,8 @@ void TwoPtRadial::init(const SkPoint& center0, SkScalar rad0, |
fA = sqr(fDCenterX) + sqr(fDCenterY) - sqr(fDRadius); |
fRadius2 = sqr(fRadius); |
fRDR = fRadius * fDRadius; |
+ |
+ fFlipped = flipped; |
} |
TwoPtRadialContext::TwoPtRadialContext(const TwoPtRadial& rec, SkScalar fx, SkScalar fy, |
@@ -182,7 +188,7 @@ static void twopoint_mirror(TwoPtRadialContext* rec, SkPMColor* SK_RESTRICT dstC |
} |
void SkTwoPointConicalGradient::init() { |
- fRec.init(fCenter1, fRadius1, fCenter2, fRadius2); |
+ fRec.init(fCenter1, fRadius1, fCenter2, fRadius2, fFlippedGrad); |
fPtsToUnit.reset(); |
} |
@@ -191,12 +197,13 @@ void SkTwoPointConicalGradient::init() { |
SkTwoPointConicalGradient::SkTwoPointConicalGradient( |
const SkPoint& start, SkScalar startRadius, |
const SkPoint& end, SkScalar endRadius, |
- const Descriptor& desc) |
+ bool flippedGrad, const Descriptor& desc) |
: SkGradientShaderBase(desc), |
fCenter1(start), |
fCenter2(end), |
fRadius1(startRadius), |
- fRadius2(endRadius) { |
+ fRadius2(endRadius), |
+ fFlippedGrad(flippedGrad) { |
// this is degenerate, and should be caught by our caller |
SkASSERT(fCenter1 != fCenter2 || fRadius1 != fRadius2); |
this->init(); |
@@ -338,6 +345,8 @@ SkShader::GradientType SkTwoPointConicalGradient::asAGradient( |
return kConical_GradientType; |
} |
+static const int kNewTwoPointConicalVersion = 24; |
+ |
SkTwoPointConicalGradient::SkTwoPointConicalGradient( |
SkReadBuffer& buffer) |
: INHERITED(buffer), |
@@ -345,6 +354,19 @@ SkTwoPointConicalGradient::SkTwoPointConicalGradient( |
fCenter2(buffer.readPoint()), |
fRadius1(buffer.readScalar()), |
fRadius2(buffer.readScalar()) { |
+ if (buffer.pictureVersion() > kNewTwoPointConicalVersion || 0 == buffer.pictureVersion()) { |
mtklein
2014/04/16 17:23:35
I'd personally just write the literal 24 until you
|
+ fFlippedGrad = buffer.readBool(); |
+ } else { |
+ // Sort gradient by radius size for old pictures |
mtklein
2014/04/16 17:23:35
Mark this with // V23_COMPATIBILITY_CODE so we can
|
+ if (fRadius2 < fRadius1) { |
+ SkTSwap(fCenter1, fCenter2); |
+ SkTSwap(fRadius1, fRadius2); |
+ this->flipGradientColors(); |
+ fFlippedGrad = true; |
+ } else { |
+ fFlippedGrad = false; |
+ } |
+ } |
this->init(); |
}; |
@@ -355,6 +377,7 @@ void SkTwoPointConicalGradient::flatten( |
buffer.writePoint(fCenter2); |
buffer.writeScalar(fRadius1); |
buffer.writeScalar(fRadius2); |
+ buffer.writeBool(fFlippedGrad); |
} |
#if SK_SUPPORT_GPU |