aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/effects
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2016-10-03 18:29:03 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-10-10 13:17:35 +0000
commit3f748606d8dcac21c7fcdd07c2083f611c633ad5 (patch)
treea557a490a1f3f1c1f3914abd4bc0bea9ea78349a /src/effects
parent644638c03705c0f81ec368cfb8e326efbbed31bb (diff)
Convert gradient params test helper to a struct
Much less copy-pasted code, fewer implementation details leaking out, and going to be easier to extend for 4f and color space testing. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2900 Change-Id: Icc468c606aa35fbe82c64bcc398e7e348e0faa20 Reviewed-on: https://skia-review.googlesource.com/2900 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src/effects')
-rw-r--r--src/effects/gradients/SkGradientShader.cpp27
-rw-r--r--src/effects/gradients/SkGradientShaderPriv.h13
-rw-r--r--src/effects/gradients/SkLinearGradient.cpp9
-rw-r--r--src/effects/gradients/SkRadialGradient.cpp9
-rw-r--r--src/effects/gradients/SkSweepGradient.cpp10
-rw-r--r--src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp56
6 files changed, 51 insertions, 73 deletions
diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp
index 17302d9d4f..bedc6e8868 100644
--- a/src/effects/gradients/SkGradientShader.cpp
+++ b/src/effects/gradients/SkGradientShader.cpp
@@ -1723,28 +1723,25 @@ void GrGradientEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const
}
}
-int GrGradientEffect::RandomGradientParams(SkRandom* random,
- SkColor colors[],
- SkScalar** stops,
- SkShader::TileMode* tm) {
- int outColors = random->nextRangeU(1, kMaxRandomGradientColors);
+GrGradientEffect::RandomGradientParams::RandomGradientParams(SkRandom* random) {
+ fColorCount = random->nextRangeU(1, kMaxRandomGradientColors);
// if one color, omit stops, otherwise randomly decide whether or not to
- if (outColors == 1 || (outColors >= 2 && random->nextBool())) {
- *stops = nullptr;
+ if (fColorCount == 1 || (fColorCount >= 2 && random->nextBool())) {
+ fStops = nullptr;
+ } else {
+ fStops = fStopStorage;
}
SkScalar stop = 0.f;
- for (int i = 0; i < outColors; ++i) {
- colors[i] = random->nextU();
- if (*stops) {
- (*stops)[i] = stop;
- stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - stop) : 1.f;
+ for (int i = 0; i < fColorCount; ++i) {
+ fColors[i] = random->nextU();
+ if (fStops) {
+ fStops[i] = stop;
+ stop = i < fColorCount - 1 ? stop + random->nextUScalar1() * (1.f - stop) : 1.f;
}
}
- *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileModeCount));
-
- return outColors;
+ fTileMode = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileModeCount));
}
#endif
diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h
index 61a44184ff..bbc94907d8 100644
--- a/src/effects/gradients/SkGradientShaderPriv.h
+++ b/src/effects/gradients/SkGradientShaderPriv.h
@@ -408,10 +408,15 @@ protected:
be passed to the gradient factory rather than the array.
*/
static const int kMaxRandomGradientColors = 4;
- static int RandomGradientParams(SkRandom* r,
- SkColor colors[kMaxRandomGradientColors],
- SkScalar** stops,
- SkShader::TileMode* tm);
+ struct RandomGradientParams {
+ RandomGradientParams(SkRandom* r);
+
+ SkColor fColors[kMaxRandomGradientColors];
+ SkScalar fStopStorage[kMaxRandomGradientColors];
+ SkShader::TileMode fTileMode;
+ int fColorCount;
+ SkScalar* fStops;
+ };
bool onIsEqual(const GrFragmentProcessor&) const override;
diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp
index a249ae4ac8..2fcaae1ca9 100644
--- a/src/effects/gradients/SkLinearGradient.cpp
+++ b/src/effects/gradients/SkLinearGradient.cpp
@@ -414,12 +414,9 @@ sk_sp<GrFragmentProcessor> GrLinearGradient::TestCreate(GrProcessorTestData* d)
SkPoint points[] = {{d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()},
{d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}};
- SkColor colors[kMaxRandomGradientColors];
- SkScalar stopsArray[kMaxRandomGradientColors];
- SkScalar* stops = stopsArray;
- SkShader::TileMode tm;
- int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm);
- auto shader = SkGradientShader::MakeLinear(points, colors, stops, colorCount, tm);
+ RandomGradientParams params(d->fRandom);
+ auto shader = SkGradientShader::MakeLinear(points, params.fColors, params.fStops,
+ params.fColorCount, params.fTileMode);
SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom);
auto dstColorSpace = GrTest::TestColorSpace(d->fRandom);
sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(SkShader::AsFPArgs(
diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp
index 18ef376862..f13deb1cdb 100644
--- a/src/effects/gradients/SkRadialGradient.cpp
+++ b/src/effects/gradients/SkRadialGradient.cpp
@@ -308,12 +308,9 @@ sk_sp<GrFragmentProcessor> GrRadialGradient::TestCreate(GrProcessorTestData* d)
SkPoint center = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()};
SkScalar radius = d->fRandom->nextUScalar1();
- SkColor colors[kMaxRandomGradientColors];
- SkScalar stopsArray[kMaxRandomGradientColors];
- SkScalar* stops = stopsArray;
- SkShader::TileMode tm;
- int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm);
- auto shader = SkGradientShader::MakeRadial(center, radius, colors, stops, colorCount, tm);
+ RandomGradientParams params(d->fRandom);
+ auto shader = SkGradientShader::MakeRadial(center, radius, params.fColors, params.fStops,
+ params.fColorCount, params.fTileMode);
SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom);
auto dstColorSpace = GrTest::TestColorSpace(d->fRandom);
sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(SkShader::AsFPArgs(
diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp
index d1fe269b9c..f4ef8ab41f 100644
--- a/src/effects/gradients/SkSweepGradient.cpp
+++ b/src/effects/gradients/SkSweepGradient.cpp
@@ -190,13 +190,9 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSweepGradient);
sk_sp<GrFragmentProcessor> GrSweepGradient::TestCreate(GrProcessorTestData* d) {
SkPoint center = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()};
- SkColor colors[kMaxRandomGradientColors];
- SkScalar stopsArray[kMaxRandomGradientColors];
- SkScalar* stops = stopsArray;
- SkShader::TileMode tmIgnored;
- int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tmIgnored);
- sk_sp<SkShader> shader(SkGradientShader::MakeSweep(center.fX, center.fY, colors, stops,
- colorCount));
+ RandomGradientParams params(d->fRandom);
+ sk_sp<SkShader> shader(SkGradientShader::MakeSweep(center.fX, center.fY, params.fColors,
+ params.fStops, params.fColorCount));
SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom);
auto dstColorSpace = GrTest::TestColorSpace(d->fRandom);
sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(SkShader::AsFPArgs(
diff --git a/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp b/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp
index a8df3b50c3..00d8fac73f 100644
--- a/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp
+++ b/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp
@@ -199,13 +199,10 @@ sk_sp<GrFragmentProcessor> Edge2PtConicalEffect::TestCreate(GrProcessorTestData*
SkScalar diffLen = diff.length();
radius2 = radius1 + diffLen;
- SkColor colors[kMaxRandomGradientColors];
- SkScalar stopsArray[kMaxRandomGradientColors];
- SkScalar* stops = stopsArray;
- SkShader::TileMode tm;
- int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm);
+ RandomGradientParams params(d->fRandom);
auto shader = SkGradientShader::MakeTwoPointConical(center1, radius1, center2, radius2,
- colors, stops, colorCount, tm);
+ params.fColors, params.fStops,
+ params.fColorCount, params.fTileMode);
SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom);
auto dstColorSpace = GrTest::TestColorSpace(d->fRandom);
sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(SkShader::AsFPArgs(
@@ -470,18 +467,16 @@ sk_sp<GrFragmentProcessor> FocalOutside2PtConicalEffect::TestCreate(GrProcessorT
center2.set(d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1());
// Need to make sure the centers are not the same or else focal point will be inside
} while (center1 == center2);
- SkPoint diff = center2 - center1;
- SkScalar diffLen = diff.length();
- // Below makes sure that the focal point is not contained within circle two
- radius2 = d->fRandom->nextRangeF(0.f, diffLen);
-
- SkColor colors[kMaxRandomGradientColors];
- SkScalar stopsArray[kMaxRandomGradientColors];
- SkScalar* stops = stopsArray;
- SkShader::TileMode tm;
- int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm);
+
+ SkPoint diff = center2 - center1;
+ SkScalar diffLen = diff.length();
+ // Below makes sure that the focal point is not contained within circle two
+ radius2 = d->fRandom->nextRangeF(0.f, diffLen);
+
+ RandomGradientParams params(d->fRandom);
auto shader = SkGradientShader::MakeTwoPointConical(center1, radius1, center2, radius2,
- colors, stops, colorCount, tm);
+ params.fColors, params.fStops,
+ params.fColorCount, params.fTileMode);
SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom);
auto dstColorSpace = GrTest::TestColorSpace(d->fRandom);
sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(SkShader::AsFPArgs(
@@ -680,13 +675,10 @@ sk_sp<GrFragmentProcessor> FocalInside2PtConicalEffect::TestCreate(GrProcessorTe
// If the circles are identical the factory will give us an empty shader.
} while (radius1 == radius2 && center1 == center2);
- SkColor colors[kMaxRandomGradientColors];
- SkScalar stopsArray[kMaxRandomGradientColors];
- SkScalar* stops = stopsArray;
- SkShader::TileMode tm;
- int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm);
+ RandomGradientParams params(d->fRandom);
auto shader = SkGradientShader::MakeTwoPointConical(center1, radius1, center2, radius2,
- colors, stops, colorCount, tm);
+ params.fColors, params.fStops,
+ params.fColorCount, params.fTileMode);
SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom);
auto dstColorSpace = GrTest::TestColorSpace(d->fRandom);
sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(SkShader::AsFPArgs(
@@ -927,13 +919,10 @@ sk_sp<GrFragmentProcessor> CircleInside2PtConicalEffect::TestCreate(GrProcessorT
// If the circles are identical the factory will give us an empty shader.
} while (radius1 == radius2 && center1 == center2);
- SkColor colors[kMaxRandomGradientColors];
- SkScalar stopsArray[kMaxRandomGradientColors];
- SkScalar* stops = stopsArray;
- SkShader::TileMode tm;
- int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm);
+ RandomGradientParams params(d->fRandom);
auto shader = SkGradientShader::MakeTwoPointConical(center1, radius1, center2, radius2,
- colors, stops, colorCount, tm);
+ params.fColors, params.fStops,
+ params.fColorCount, params.fTileMode);
SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom);
auto dstColorSpace = GrTest::TestColorSpace(d->fRandom);
sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(SkShader::AsFPArgs(
@@ -1161,13 +1150,10 @@ sk_sp<GrFragmentProcessor> CircleOutside2PtConicalEffect::TestCreate(GrProcessor
// and have radius2 >= radius to match sorting on cpu side
radius2 = radius1 + d->fRandom->nextRangeF(0.f, diffLen);
- SkColor colors[kMaxRandomGradientColors];
- SkScalar stopsArray[kMaxRandomGradientColors];
- SkScalar* stops = stopsArray;
- SkShader::TileMode tm;
- int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm);
+ RandomGradientParams params(d->fRandom);
auto shader = SkGradientShader::MakeTwoPointConical(center1, radius1, center2, radius2,
- colors, stops, colorCount, tm);
+ params.fColors, params.fStops,
+ params.fColorCount, params.fTileMode);
SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom);
auto dstColorSpace = GrTest::TestColorSpace(d->fRandom);
sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(SkShader::AsFPArgs(