aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2017-06-29 15:47:16 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-06-30 18:09:46 +0000
commit981deec8b2928f07e3899849bed31bfbb8c19b9b (patch)
tree9729e21494b71b432ba7f6754a2f450b3a140fac /src
parent9f183505acc94a587e71b485761f47781d6f5030 (diff)
Delete non-raster-pipeline SkTwoPointConicalGradient impl
Change-Id: If39a2b01d6099fef14695a4ce05b57a3d5c3d99c Reviewed-on: https://skia-review.googlesource.com/21320 Reviewed-by: Mike Reed <reed@google.com> Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'src')
-rw-r--r--src/shaders/gradients/SkTwoPointConicalGradient.cpp262
-rw-r--r--src/shaders/gradients/SkTwoPointConicalGradient.h42
2 files changed, 1 insertions, 303 deletions
diff --git a/src/shaders/gradients/SkTwoPointConicalGradient.cpp b/src/shaders/gradients/SkTwoPointConicalGradient.cpp
index c901127981..0f48affc85 100644
--- a/src/shaders/gradients/SkTwoPointConicalGradient.cpp
+++ b/src/shaders/gradients/SkTwoPointConicalGradient.cpp
@@ -10,186 +10,6 @@
#include "SkRasterPipeline.h"
#include "../../jumper/SkJumper.h"
-struct TwoPtRadialContext {
- const TwoPtRadial& fRec;
- float fRelX, fRelY;
- const float fIncX, fIncY;
- float fB;
- const float fDB;
-
- TwoPtRadialContext(const TwoPtRadial& rec, SkScalar fx, SkScalar fy,
- SkScalar dfx, SkScalar dfy);
- SkFixed nextT();
-};
-
-static int valid_divide(float numer, float denom, float* ratio) {
- SkASSERT(ratio);
- if (0 == denom) {
- return 0;
- }
- *ratio = numer / denom;
- return 1;
-}
-
-// 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], bool descendingOrder = false) {
- SkASSERT(roots);
-
- if (A == 0) {
- return valid_divide(-C, B, roots);
- }
-
- float R = B*B - 4*A*C;
- if (R < 0) {
- return 0;
- }
- R = sk_float_sqrt(R);
-
-#if 1
- float Q = B;
- if (Q < 0) {
- Q -= R;
- } else {
- Q += R;
- }
-#else
- // on 10.6 this was much slower than the above branch :(
- float Q = B + copysignf(R, B);
-#endif
- Q *= -0.5f;
- if (0 == Q) {
- roots[0] = 0;
- return 1;
- }
-
- float r0 = Q / A;
- 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;
-}
-
-static float lerp(float x, float dx, float t) {
- return x + t * dx;
-}
-
-static float sqr(float x) { return x * x; }
-
-void TwoPtRadial::init(const SkPoint& center0, SkScalar rad0,
- const SkPoint& center1, SkScalar rad1,
- bool flipped) {
- fCenterX = SkScalarToFloat(center0.fX);
- fCenterY = SkScalarToFloat(center0.fY);
- fDCenterX = SkScalarToFloat(center1.fX) - fCenterX;
- fDCenterY = SkScalarToFloat(center1.fY) - fCenterY;
- fRadius = SkScalarToFloat(rad0);
- fDRadius = SkScalarToFloat(rad1) - fRadius;
-
- fA = sqr(fDCenterX) + sqr(fDCenterY) - sqr(fDRadius);
- fRadius2 = sqr(fRadius);
- fRDR = fRadius * fDRadius;
-
- fFlipped = flipped;
-}
-
-TwoPtRadialContext::TwoPtRadialContext(const TwoPtRadial& rec, SkScalar fx, SkScalar fy,
- SkScalar dfx, SkScalar dfy)
- : fRec(rec)
- , fRelX(SkScalarToFloat(fx) - rec.fCenterX)
- , fRelY(SkScalarToFloat(fy) - rec.fCenterY)
- , fIncX(SkScalarToFloat(dfx))
- , fIncY(SkScalarToFloat(dfy))
- , fB(-2 * (rec.fDCenterX * fRelX + rec.fDCenterY * fRelY + rec.fRDR))
- , fDB(-2 * (rec.fDCenterX * fIncX + rec.fDCenterY * fIncY)) {}
-
-SkFixed TwoPtRadialContext::nextT() {
- float roots[2];
-
- float C = sqr(fRelX) + sqr(fRelY) - fRec.fRadius2;
- int countRoots = find_quad_roots(fRec.fA, fB, C, roots, fRec.fFlipped);
-
- fRelX += fIncX;
- fRelY += fIncY;
- fB += fDB;
-
- if (0 == countRoots) {
- return TwoPtRadial::kDontDrawT;
- }
-
- // Prefer the bigger t value if both give a radius(t) > 0
- // find_quad_roots returns the values sorted, so we start with the last
- float t = roots[countRoots - 1];
- float r = lerp(fRec.fRadius, fRec.fDRadius, t);
- if (r < 0) {
- t = roots[0]; // might be the same as roots[countRoots-1]
- r = lerp(fRec.fRadius, fRec.fDRadius, t);
- if (r < 0) {
- return TwoPtRadial::kDontDrawT;
- }
- }
- return SkFloatToFixed(t);
-}
-
-typedef void (*TwoPointConicalProc)(TwoPtRadialContext* rec, SkPMColor* dstC,
- const SkPMColor* cache, int toggle, int count);
-
-static void twopoint_clamp(TwoPtRadialContext* rec, SkPMColor* SK_RESTRICT dstC,
- const SkPMColor* SK_RESTRICT cache, int toggle,
- int count) {
- for (; count > 0; --count) {
- SkFixed t = rec->nextT();
- if (TwoPtRadial::DontDrawT(t)) {
- *dstC++ = 0;
- } else {
- SkFixed index = SkClampMax(t, 0xFFFF);
- SkASSERT(index <= 0xFFFF);
- *dstC++ = cache[toggle +
- (index >> SkGradientShaderBase::kCache32Shift)];
- }
- toggle = next_dither_toggle(toggle);
- }
-}
-
-static void twopoint_repeat(TwoPtRadialContext* rec, SkPMColor* SK_RESTRICT dstC,
- const SkPMColor* SK_RESTRICT cache, int toggle,
- int count) {
- for (; count > 0; --count) {
- SkFixed t = rec->nextT();
- if (TwoPtRadial::DontDrawT(t)) {
- *dstC++ = 0;
- } else {
- SkFixed index = repeat_tileproc(t);
- SkASSERT(index <= 0xFFFF);
- *dstC++ = cache[toggle +
- (index >> SkGradientShaderBase::kCache32Shift)];
- }
- toggle = next_dither_toggle(toggle);
- }
-}
-
-static void twopoint_mirror(TwoPtRadialContext* rec, SkPMColor* SK_RESTRICT dstC,
- const SkPMColor* SK_RESTRICT cache, int toggle,
- int count) {
- for (; count > 0; --count) {
- SkFixed t = rec->nextT();
- if (TwoPtRadial::DontDrawT(t)) {
- *dstC++ = 0;
- } else {
- SkFixed index = mirror_tileproc(t);
- SkASSERT(index <= 0xFFFF);
- *dstC++ = cache[toggle +
- (index >> SkGradientShaderBase::kCache32Shift)];
- }
- toggle = next_dither_toggle(toggle);
- }
-}
-
-/////////////////////////////////////////////////////////////////////
-
SkTwoPointConicalGradient::SkTwoPointConicalGradient(
const SkPoint& start, SkScalar startRadius,
const SkPoint& end, SkScalar endRadius,
@@ -203,7 +23,6 @@ SkTwoPointConicalGradient::SkTwoPointConicalGradient(
{
// this is degenerate, and should be caught by our caller
SkASSERT(fCenter1 != fCenter2 || fRadius1 != fRadius2);
- fRec.init(fCenter1, fRadius1, fCenter2, fRadius2, fFlippedGrad);
}
bool SkTwoPointConicalGradient::isOpaque() const {
@@ -213,79 +32,6 @@ bool SkTwoPointConicalGradient::isOpaque() const {
return false;
}
-SkShaderBase::Context* SkTwoPointConicalGradient::onMakeContext(
- const ContextRec& rec, SkArenaAlloc* alloc) const {
- return CheckedMakeContext<TwoPointConicalGradientContext>(alloc, *this, rec);
-}
-
-SkTwoPointConicalGradient::TwoPointConicalGradientContext::TwoPointConicalGradientContext(
- const SkTwoPointConicalGradient& shader, const ContextRec& rec)
- : INHERITED(shader, rec)
-{
- // in general, we might discard based on computed-radius, so clear
- // this flag (todo: sometimes we can detect that we never discard...)
- fFlags &= ~kOpaqueAlpha_Flag;
-}
-
-void SkTwoPointConicalGradient::TwoPointConicalGradientContext::shadeSpan(
- int x, int y, SkPMColor* dstCParam, int count) {
- const SkTwoPointConicalGradient& twoPointConicalGradient =
- static_cast<const SkTwoPointConicalGradient&>(fShader);
-
- int toggle = init_dither_toggle(x, y);
-
- SkASSERT(count > 0);
-
- SkPMColor* SK_RESTRICT dstC = dstCParam;
-
- SkMatrix::MapXYProc dstProc = fDstToIndexProc;
-
- const SkPMColor* SK_RESTRICT cache = fCache->getCache32();
-
- TwoPointConicalProc shadeProc = twopoint_repeat;
- if (SkShader::kClamp_TileMode == twoPointConicalGradient.fTileMode) {
- shadeProc = twopoint_clamp;
- } else if (SkShader::kMirror_TileMode == twoPointConicalGradient.fTileMode) {
- shadeProc = twopoint_mirror;
- } else {
- SkASSERT(SkShader::kRepeat_TileMode == twoPointConicalGradient.fTileMode);
- }
-
- if (fDstToIndexClass != kPerspective_MatrixClass) {
- SkPoint srcPt;
- dstProc(fDstToIndex, SkIntToScalar(x) + SK_ScalarHalf,
- SkIntToScalar(y) + SK_ScalarHalf, &srcPt);
- SkScalar dx, fx = srcPt.fX;
- SkScalar dy, fy = srcPt.fY;
-
- if (fDstToIndexClass == kFixedStepInX_MatrixClass) {
- const auto step = fDstToIndex.fixedStepInX(SkIntToScalar(y));
- dx = step.fX;
- dy = step.fY;
- } else {
- SkASSERT(fDstToIndexClass == kLinear_MatrixClass);
- dx = fDstToIndex.getScaleX();
- dy = fDstToIndex.getSkewY();
- }
-
- TwoPtRadialContext rec(twoPointConicalGradient.fRec, fx, fy, dx, dy);
- (*shadeProc)(&rec, dstC, cache, toggle, count);
- } else { // perspective case
- SkScalar dstX = SkIntToScalar(x) + SK_ScalarHalf;
- SkScalar dstY = SkIntToScalar(y) + SK_ScalarHalf;
- for (; count > 0; --count) {
- SkPoint srcPt;
- dstProc(fDstToIndex, dstX, dstY, &srcPt);
- TwoPtRadialContext rec(twoPointConicalGradient.fRec, srcPt.fX, srcPt.fY, 0, 0);
- (*shadeProc)(&rec, dstC, cache, toggle, 1);
-
- dstX += SK_Scalar1;
- toggle = next_dither_toggle(toggle);
- dstC += 1;
- }
- }
-}
-
// Returns the original non-sorted version of the gradient
SkShader::GradientType SkTwoPointConicalGradient::asAGradient(
GradientInfo* info) const {
@@ -505,11 +251,3 @@ bool SkTwoPointConicalGradient::adjustMatrixAndAppendStages(SkArenaAlloc* alloc,
return true;
}
-
-bool SkTwoPointConicalGradient::isRasterPipelineOnly() const {
-#ifdef SK_SUPPORT_LEGACY_2PTCONICAL_GRADIENT
- return false;
-#else
- return true;
-#endif
-}
diff --git a/src/shaders/gradients/SkTwoPointConicalGradient.h b/src/shaders/gradients/SkTwoPointConicalGradient.h
index 8e65c2f663..3e48a4b4df 100644
--- a/src/shaders/gradients/SkTwoPointConicalGradient.h
+++ b/src/shaders/gradients/SkTwoPointConicalGradient.h
@@ -11,51 +11,12 @@
#include "SkColorSpaceXformer.h"
#include "SkGradientShaderPriv.h"
-// TODO(dominikg): Worth making it truly immutable (i.e. set values in constructor)?
-// Should only be initialized once via init(). Immutable afterwards.
-struct TwoPtRadial {
- enum {
- // This value is outside the range SK_FixedMin to SK_FixedMax.
- kDontDrawT = 0x80000000
- };
-
- float fCenterX, fCenterY;
- float fDCenterX, fDCenterY;
- float fRadius;
- float fDRadius;
- float fA;
- float fRadius2;
- float fRDR;
- bool fFlipped;
-
- void init(const SkPoint& center0, SkScalar rad0,
- const SkPoint& center1, SkScalar rad1,
- bool flipped);
-
- static bool DontDrawT(SkFixed t) {
- return kDontDrawT == (uint32_t)t;
- }
-};
-
-
class SkTwoPointConicalGradient final : public SkGradientShaderBase {
- TwoPtRadial fRec;
public:
SkTwoPointConicalGradient(const SkPoint& start, SkScalar startRadius,
const SkPoint& end, SkScalar endRadius,
bool flippedGrad, const Descriptor&);
- class TwoPointConicalGradientContext : public SkGradientShaderBase::GradientShaderBaseContext {
- public:
- TwoPointConicalGradientContext(const SkTwoPointConicalGradient&, const ContextRec&);
- ~TwoPointConicalGradientContext() override {}
-
- void shadeSpan(int x, int y, SkPMColor dstC[], int count) override;
-
- private:
- typedef SkGradientShaderBase::GradientShaderBaseContext INHERITED;
- };
-
SkShader::GradientType asAGradient(GradientInfo* info) const override;
#if SK_SUPPORT_GPU
sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const override;
@@ -76,7 +37,6 @@ public:
protected:
SkTwoPointConicalGradient(SkReadBuffer& buffer);
void flatten(SkWriteBuffer& buffer) const override;
- Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override;
sk_sp<SkShader> onMakeColorSpace(SkColorSpaceXformer* xformer) const override;
bool adjustMatrixAndAppendStages(SkArenaAlloc* alloc,
@@ -84,7 +44,7 @@ protected:
SkRasterPipeline* tPipeline,
SkRasterPipeline* postPipeline) const override;
- bool isRasterPipelineOnly() const override;
+ bool isRasterPipelineOnly() const override { return true; }
private:
SkPoint fCenter1;