Add helper to create random AsFPArgs for Ganesh unit tests

Reduces copy-paste and eases maintenance. I'll be adding another field to
AsFPArgs soon, and this is going to streamline that change.

BUG=skia:

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3639

Change-Id: I6372ed5dce50a5ba9d73039bd4714e34502a1f75
Reviewed-on: https://skia-review.googlesource.com/3639
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Osman 2016-10-19 11:12:09 -04:00 committed by Skia Commit-Bot
parent 5e3d9c2e31
commit 9f532a3598
9 changed files with 50 additions and 57 deletions

View File

@ -727,12 +727,8 @@ sk_sp<GrFragmentProcessor> GrPerlinNoise2Effect::TestCreate(GrProcessorTestData*
SkPerlinNoiseShader2::MakeTurbulence(baseFrequencyX, baseFrequencyY, numOctaves, seed,
stitchTiles ? &tileSize : nullptr));
GrPaint grPaint;
SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom);
auto colorSpace = GrTest::TestColorSpace(d->fRandom);
return shader->asFragmentProcessor(SkShader::AsFPArgs(d->fContext, &viewMatrix, nullptr,
kNone_SkFilterQuality, colorSpace.get(),
SkSourceGammaTreatment::kRespect));
GrTest::TestAsFPArgs asFPArgs(d);
return shader->asFragmentProcessor(asFPArgs.args());
}
void GrGLPerlinNoise2::emitCode(EmitArgs& args) {
@ -1136,12 +1132,8 @@ sk_sp<GrFragmentProcessor> GrImprovedPerlinNoiseEffect::TestCreate(GrProcessorTe
numOctaves,
z));
GrPaint grPaint;
SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom);
auto colorSpace = GrTest::TestColorSpace(d->fRandom);
return shader->asFragmentProcessor(SkShader::AsFPArgs(d->fContext, &viewMatrix, nullptr,
kNone_SkFilterQuality, colorSpace.get(),
SkSourceGammaTreatment::kRespect));
GrTest::TestAsFPArgs asFPArgs(d);
return shader->asFragmentProcessor(asFPArgs.args());
}
void GrGLImprovedPerlinNoise::emitCode(EmitArgs& args) {

View File

@ -327,6 +327,7 @@ public:
#if SK_SUPPORT_GPU
struct AsFPArgs {
AsFPArgs() {}
AsFPArgs(GrContext* context,
const SkMatrix* viewMatrix,
const SkMatrix* localMatrix,

View File

@ -16,9 +16,11 @@
#include "GrColorSpaceXform.h"
#include "SkPathEffect.h"
#include "SkRandom.h"
#include "SkShader.h"
#include "SkStrokeRec.h"
#include "../private/SkTemplates.h"
struct GrProcessorTestData;
class GrStyle;
class SkMatrix;
class SkPath;
@ -45,6 +47,17 @@ void TestStyle(SkRandom*, GrStyle*);
sk_sp<SkColorSpace> TestColorSpace(SkRandom*);
sk_sp<GrColorSpaceXform> TestColorXform(SkRandom*);
class TestAsFPArgs {
public:
TestAsFPArgs(GrProcessorTestData*);
const SkShader::AsFPArgs& args() const { return fArgs; }
private:
SkShader::AsFPArgs fArgs;
SkMatrix fViewMatrixStorage;
sk_sp<SkColorSpace> fColorSpaceStorage;
};
// We have a simplified dash path effect here to avoid relying on SkDashPathEffect which
// is in the optional build target effects.
class TestDashPathEffect : public SkPathEffect {

View File

@ -592,11 +592,8 @@ sk_sp<GrFragmentProcessor> GrPerlinNoiseEffect::TestCreate(GrProcessorTestData*
SkPerlinNoiseShader::MakeTurbulence(baseFrequencyX, baseFrequencyY, numOctaves, seed,
stitchTiles ? &tileSize : nullptr));
SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom);
auto colorSpace = GrTest::TestColorSpace(d->fRandom);
return shader->asFragmentProcessor(SkShader::AsFPArgs(d->fContext, &viewMatrix, nullptr,
kNone_SkFilterQuality, colorSpace.get(),
SkSourceGammaTreatment::kRespect));
GrTest::TestAsFPArgs asFPArgs(d);
return shader->asFragmentProcessor(asFPArgs.args());
}
void GrGLPerlinNoise::emitCode(EmitArgs& args) {

View File

@ -420,11 +420,8 @@ sk_sp<GrFragmentProcessor> GrLinearGradient::TestCreate(GrProcessorTestData* d)
params.fColorCount, params.fTileMode) :
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(
d->fContext, &viewMatrix, NULL, kNone_SkFilterQuality, dstColorSpace.get(),
SkSourceGammaTreatment::kRespect));
GrTest::TestAsFPArgs asFPArgs(d);
sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(asFPArgs.args());
GrAlwaysAssert(fp);
return fp;
}

View File

@ -314,11 +314,8 @@ sk_sp<GrFragmentProcessor> GrRadialGradient::TestCreate(GrProcessorTestData* d)
params.fStops, params.fColorCount, params.fTileMode) :
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(
d->fContext, &viewMatrix, NULL, kNone_SkFilterQuality, dstColorSpace.get(),
SkSourceGammaTreatment::kRespect));
GrTest::TestAsFPArgs asFPArgs(d);
sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(asFPArgs.args());
GrAlwaysAssert(fp);
return fp;
}

View File

@ -196,11 +196,8 @@ sk_sp<GrFragmentProcessor> GrSweepGradient::TestCreate(GrProcessorTestData* d) {
params.fStops, params.fColorCount) :
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(
d->fContext, &viewMatrix, NULL, kNone_SkFilterQuality, dstColorSpace.get(),
SkSourceGammaTreatment::kRespect));
GrTest::TestAsFPArgs asFPArgs(d);
sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(asFPArgs.args());
GrAlwaysAssert(fp);
return fp;
}

View File

@ -207,11 +207,8 @@ sk_sp<GrFragmentProcessor> Edge2PtConicalEffect::TestCreate(GrProcessorTestData*
SkGradientShader::MakeTwoPointConical(center1, radius1, center2, radius2,
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(
d->fContext, &viewMatrix, NULL, kNone_SkFilterQuality, dstColorSpace.get(),
SkSourceGammaTreatment::kRespect));
GrTest::TestAsFPArgs asFPArgs(d);
sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(asFPArgs.args());
GrAlwaysAssert(fp);
return fp;
}
@ -485,11 +482,8 @@ sk_sp<GrFragmentProcessor> FocalOutside2PtConicalEffect::TestCreate(GrProcessorT
SkGradientShader::MakeTwoPointConical(center1, radius1, center2, radius2,
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(
d->fContext, &viewMatrix, NULL, kNone_SkFilterQuality, dstColorSpace.get(),
SkSourceGammaTreatment::kRespect));
GrTest::TestAsFPArgs asFPArgs(d);
sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(asFPArgs.args());
GrAlwaysAssert(fp);
return fp;
}
@ -691,11 +685,8 @@ sk_sp<GrFragmentProcessor> FocalInside2PtConicalEffect::TestCreate(GrProcessorTe
SkGradientShader::MakeTwoPointConical(center1, radius1, center2, radius2,
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(
d->fContext, &viewMatrix, NULL, kNone_SkFilterQuality, dstColorSpace.get(),
SkSourceGammaTreatment::kRespect));
GrTest::TestAsFPArgs asFPArgs(d);
sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(asFPArgs.args());
GrAlwaysAssert(fp);
return fp;
}
@ -939,11 +930,8 @@ sk_sp<GrFragmentProcessor> CircleInside2PtConicalEffect::TestCreate(GrProcessorT
SkGradientShader::MakeTwoPointConical(center1, radius1, center2, radius2,
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(
d->fContext, &viewMatrix, NULL, kNone_SkFilterQuality, dstColorSpace.get(),
SkSourceGammaTreatment::kRespect));
GrTest::TestAsFPArgs asFPArgs(d);
sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(asFPArgs.args());
GrAlwaysAssert(fp);
return fp;
}
@ -1174,11 +1162,8 @@ sk_sp<GrFragmentProcessor> CircleOutside2PtConicalEffect::TestCreate(GrProcessor
SkGradientShader::MakeTwoPointConical(center1, radius1, center2, radius2,
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(
d->fContext, &viewMatrix, NULL, kNone_SkFilterQuality, dstColorSpace.get(),
SkSourceGammaTreatment::kRespect));
GrTest::TestAsFPArgs asFPArgs(d);
sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(asFPArgs.args());
GrAlwaysAssert(fp);
return fp;
}

View File

@ -6,6 +6,7 @@
*/
#include "GrTestUtils.h"
#include "GrProcessorUnitTest.h"
#include "GrStyle.h"
#include "SkColorSpace.h"
#include "SkDashPathPriv.h"
@ -321,6 +322,19 @@ sk_sp<GrColorSpaceXform> TestColorXform(SkRandom* random) {
return gXforms[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gXforms)))];
}
TestAsFPArgs::TestAsFPArgs(GrProcessorTestData* d) {
fViewMatrixStorage = TestMatrix(d->fRandom);
fColorSpaceStorage = TestColorSpace(d->fRandom);
fArgs.fContext = d->fContext;
fArgs.fViewMatrix = &fViewMatrixStorage;
fArgs.fLocalMatrix = nullptr;
fArgs.fFilterQuality = kNone_SkFilterQuality;
fArgs.fDstColorSpace = fColorSpaceStorage.get();
fArgs.fGammaTreatment = SkToBool(fArgs.fDstColorSpace)
? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore;
}
} // namespace GrTest
#endif