Make sure random unit test processors use an alpha type compatible with

texture data.

It'd probably be good to provide an opaque texture that has an alpha
channel and widen the range of color types that are present in the
future.

Change-Id: I5587a479f7e2f3991f8ae27a4cd44afc533324e8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/260696
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2019-12-18 10:41:58 -05:00 committed by Skia Commit-Bot
parent cd774debd7
commit 766098de94
22 changed files with 182 additions and 197 deletions

View File

@ -545,12 +545,8 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDisplacementMapEffect);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrDisplacementMapEffect::TestCreate(GrProcessorTestData* d) {
int texIdxDispl = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
GrProcessorUnitTest::kAlphaTextureIdx;
int texIdxColor = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
GrProcessorUnitTest::kAlphaTextureIdx;
sk_sp<GrTextureProxy> dispProxy = d->textureProxy(texIdxDispl);
sk_sp<GrTextureProxy> colorProxy = d->textureProxy(texIdxColor);
auto [dispProxy, ct1, at1] = d->randomProxy();
auto [colorProxy, ct2, at2] = d->randomProxy();
static const int kMaxComponent = static_cast<int>(SkColorChannel::kLastEnum);
SkColorChannel xChannelSelector =
static_cast<SkColorChannel>(d->fRandom->nextRangeU(1, kMaxComponent));

View File

@ -1705,9 +1705,7 @@ static SkImageFilterLight* create_random_light(SkRandom* random) {
}
std::unique_ptr<GrFragmentProcessor> GrDiffuseLightingEffect::TestCreate(GrProcessorTestData* d) {
int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: GrProcessorUnitTest::kAlphaTextureIdx;
sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx);
auto [proxy, ct, at] = d->randomProxy();
SkScalar surfaceScale = d->fRandom->nextSScalar1();
SkScalar kd = d->fRandom->nextUScalar1();
sk_sp<SkImageFilterLight> light(create_random_light(d->fRandom));
@ -1923,9 +1921,7 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrSpecularLightingEffect::TestCreate(GrProcessorTestData* d) {
int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: GrProcessorUnitTest::kAlphaTextureIdx;
sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx);
auto [proxy, ct, at] = d->randomProxy();
SkScalar surfaceScale = d->fRandom->nextSScalar1();
SkScalar ks = d->fRandom->nextUScalar1();
SkScalar shininess = d->fRandom->nextUScalar1();

View File

@ -455,17 +455,13 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMorphologyEffect);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrMorphologyEffect::TestCreate(GrProcessorTestData* d) {
int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: GrProcessorUnitTest::kAlphaTextureIdx;
sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx);
auto [proxy, ct, at] = d->randomProxy();
MorphDirection dir = d->fRandom->nextBool() ? MorphDirection::kX : MorphDirection::kY;
static const int kMaxRadius = 10;
int radius = d->fRandom->nextRangeU(1, kMaxRadius);
MorphType type = d->fRandom->nextBool() ? MorphType::kErode : MorphType::kDilate;
auto alphaType = static_cast<SkAlphaType>(
d->fRandom->nextRangeU(kUnknown_SkAlphaType + 1, kLastEnum_SkAlphaType));
return GrMorphologyEffect::Make(std::move(proxy), alphaType, dir, radius, type);
return GrMorphologyEffect::Make(std::move(proxy), at, dir, radius, type);
}
#endif

View File

@ -15,86 +15,6 @@
#include "src/gpu/GrTextureProxy.h"
#include "src/gpu/GrXferProcessor.h"
#if GR_TEST_UTILS
GrResourceProvider* GrProcessorTestData::resourceProvider() {
return fContext->priv().resourceProvider();
}
GrProxyProvider* GrProcessorTestData::proxyProvider() {
return fContext->priv().proxyProvider();
}
const GrCaps* GrProcessorTestData::caps() { return fContext->priv().caps(); }
class GrFragmentProcessor;
class GrGeometryProcessor;
/*
* Originally these were both in the processor unit test header, but then it seemed to cause linker
* problems on android.
*/
template <>
SkTArray<GrFragmentProcessorTestFactory*, true>* GrFragmentProcessorTestFactory::GetFactories() {
static SkTArray<GrFragmentProcessorTestFactory*, true> gFactories;
return &gFactories;
}
template <>
SkTArray<GrGeometryProcessorTestFactory*, true>* GrGeometryProcessorTestFactory::GetFactories() {
static SkTArray<GrGeometryProcessorTestFactory*, true> gFactories;
return &gFactories;
}
SkTArray<GrXPFactoryTestFactory*, true>* GrXPFactoryTestFactory::GetFactories() {
static SkTArray<GrXPFactoryTestFactory*, true> gFactories;
return &gFactories;
}
/*
* To ensure we always have successful static initialization, before creating from the factories
* we verify the count is as expected. If a new factory is added, then these numbers must be
* manually adjusted.
*/
#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
static const int kFPFactoryCount = 37;
static const int kGPFactoryCount = 14;
static const int kXPFactoryCount = 4;
#else
static const int kFPFactoryCount = 0;
static const int kGPFactoryCount = 0;
static const int kXPFactoryCount = 0;
#endif
template <>
void GrFragmentProcessorTestFactory::VerifyFactoryCount() {
if (kFPFactoryCount != GetFactories()->count()) {
SkDebugf("\nExpected %d fragment processor factories, found %d.\n",
kFPFactoryCount, GetFactories()->count());
SK_ABORT("Wrong number of fragment processor factories!");
}
}
template <>
void GrGeometryProcessorTestFactory::VerifyFactoryCount() {
if (kGPFactoryCount != GetFactories()->count()) {
SkDebugf("\nExpected %d geometry processor factories, found %d.\n",
kGPFactoryCount, GetFactories()->count());
SK_ABORT("Wrong number of geometry processor factories!");
}
}
void GrXPFactoryTestFactory::VerifyFactoryCount() {
if (kXPFactoryCount != GetFactories()->count()) {
SkDebugf("\nExpected %d xp factory factories, found %d.\n",
kXPFactoryCount, GetFactories()->count());
SK_ABORT("Wrong number of xp factory factories!");
}
}
#endif
// We use a global pool protected by a mutex(spinlock). Chrome may use the same GrContext on
// different threads. The GrContext is not used concurrently on different threads and there is a
// memory barrier between accesses of a context on different threads. Also, there may be multiple

View File

@ -5,21 +5,116 @@
* found in the LICENSE file.
*/
#include "src/gpu/GrFragmentProcessor.h"
#include "src/gpu/GrProcessorUnitTest.h"
#include "include/gpu/GrContext.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrFragmentProcessor.h"
#if GR_TEST_UTILS
GrProcessorTestData::GrProcessorTestData(SkRandom* random,
GrContext* context,
int numProxies,
const ProxyInfo proxies[])
: fRandom(random), fContext(context) {
fProxies.reset(proxies, numProxies);
fArena = std::unique_ptr<SkArenaAlloc>(new SkArenaAlloc(1000));
}
GrResourceProvider* GrProcessorTestData::resourceProvider() {
return fContext->priv().resourceProvider();
}
GrProxyProvider* GrProcessorTestData::proxyProvider() { return fContext->priv().proxyProvider(); }
const GrCaps* GrProcessorTestData::caps() { return fContext->priv().caps(); }
GrProcessorTestData::ProxyInfo GrProcessorTestData::randomProxy() {
SkASSERT(!fProxies.empty());
return fProxies[fRandom->nextULessThan(fProxies.count())];
}
GrProcessorTestData::ProxyInfo GrProcessorTestData::randomAlphaOnlyProxy() {
int numAlphaOnly = 0;
for (const auto& [p, ct, at] : fProxies) {
if (GrColorTypeIsAlphaOnly(ct)) {
++numAlphaOnly;
}
}
SkASSERT(numAlphaOnly);
int idx = fRandom->nextULessThan(numAlphaOnly);
for (const auto& [p, ct, at] : fProxies) {
if (GrColorTypeIsAlphaOnly(ct) && !idx--) {
return {p, ct, at};
}
}
SkUNREACHABLE;
}
class GrFragmentProcessor;
class GrGeometryProcessor;
/*
* Originally these were both in the processor unit test header, but then it seemed to cause linker
* problems on android.
*/
template <>
SkTArray<GrFragmentProcessorTestFactory*, true>* GrFragmentProcessorTestFactory::GetFactories() {
static SkTArray<GrFragmentProcessorTestFactory*, true> gFactories;
return &gFactories;
}
template <>
SkTArray<GrGeometryProcessorTestFactory*, true>* GrGeometryProcessorTestFactory::GetFactories() {
static SkTArray<GrGeometryProcessorTestFactory*, true> gFactories;
return &gFactories;
}
SkTArray<GrXPFactoryTestFactory*, true>* GrXPFactoryTestFactory::GetFactories() {
static SkTArray<GrXPFactoryTestFactory*, true> gFactories;
return &gFactories;
}
/*
* To ensure we always have successful static initialization, before creating from the factories
* we verify the count is as expected. If a new factory is added, then these numbers must be
* manually adjusted.
*/
static const int kFPFactoryCount = 37;
static const int kGPFactoryCount = 14;
static const int kXPFactoryCount = 4;
template <> void GrFragmentProcessorTestFactory::VerifyFactoryCount() {
if (kFPFactoryCount != GetFactories()->count()) {
SkDebugf("\nExpected %d fragment processor factories, found %d.\n", kFPFactoryCount,
GetFactories()->count());
SK_ABORT("Wrong number of fragment processor factories!");
}
}
template <> void GrGeometryProcessorTestFactory::VerifyFactoryCount() {
if (kGPFactoryCount != GetFactories()->count()) {
SkDebugf("\nExpected %d geometry processor factories, found %d.\n", kGPFactoryCount,
GetFactories()->count());
SK_ABORT("Wrong number of geometry processor factories!");
}
}
void GrXPFactoryTestFactory::VerifyFactoryCount() {
if (kXPFactoryCount != GetFactories()->count()) {
SkDebugf("\nExpected %d xp factory factories, found %d.\n", kXPFactoryCount,
GetFactories()->count());
SK_ABORT("Wrong number of xp factory factories!");
}
}
std::unique_ptr<GrFragmentProcessor> GrProcessorUnitTest::MakeChildFP(GrProcessorTestData* data) {
#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
std::unique_ptr<GrFragmentProcessor> fp;
do {
fp = GrFragmentProcessorTestFactory::Make(data);
SkASSERT(fp);
} while (fp->numChildProcessors() != 0);
return fp;
#else
SK_ABORT("Should not be called if !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS");
#endif
}
#endif

View File

@ -17,12 +17,14 @@
#include "src/gpu/GrTestUtils.h"
#include "src/gpu/GrTextureProxy.h"
#include <tuple>
class SkMatrix;
class GrCaps;
class GrContext;
class GrProxyProvider;
class GrRenderTargetContext;
struct GrProcessorTestData;
class GrProcessorTestData;
class GrTexture;
class GrXPFactory;
class GrGeometryProcessor;
@ -48,33 +50,25 @@ std::unique_ptr<GrFragmentProcessor> MakeChildFP(GrProcessorTestData*);
* kAlpha_8_GrPixelConfig. TestCreate functions are also free to create additional textures using
* the GrContext.
*/
struct GrProcessorTestData {
GrProcessorTestData(SkRandom* random,
GrContext* context,
const GrRenderTargetContext* renderTargetContext,
sk_sp<GrTextureProxy> proxies[2])
: fRandom(random), fRenderTargetContext(renderTargetContext), fContext(context) {
SkASSERT(proxies[0] && proxies[1]);
fProxies[0] = proxies[0];
fProxies[1] = proxies[1];
fArena = std::unique_ptr<SkArenaAlloc>(new SkArenaAlloc(1000));
}
SkRandom* fRandom;
const GrRenderTargetContext* fRenderTargetContext;
class GrProcessorTestData {
public:
using ProxyInfo = std::tuple<sk_sp<GrTextureProxy>, GrColorType, SkAlphaType>;
GrProcessorTestData(SkRandom* random, GrContext* context, int numProxies, const ProxyInfo[]);
GrContext* context() { return fContext; }
GrResourceProvider* resourceProvider();
GrProxyProvider* proxyProvider();
const GrCaps* caps();
sk_sp<GrTextureProxy> textureProxy(int index) { return fProxies[index]; }
SkArenaAlloc* allocator() { return fArena.get(); }
ProxyInfo randomProxy();
ProxyInfo randomAlphaOnlyProxy();
SkRandom* fRandom;
private:
GrContext* fContext;
sk_sp<GrTextureProxy> fProxies[2];
SkTArray<ProxyInfo> fProxies;
std::unique_ptr<SkArenaAlloc> fArena;
};

View File

@ -24,7 +24,7 @@
class GrColorInfo;
class GrColorSpaceXform;
struct GrProcessorTestData;
class GrProcessorTestData;
class GrStyle;
class SkMatrix;
class SkPath;

View File

@ -61,7 +61,7 @@ void main() {
}
@test(testData) {
sk_sp<GrTextureProxy> maskProxy = testData->textureProxy(GrProcessorUnitTest::kAlphaTextureIdx);
auto [maskProxy, ct, at] = testData->randomAlphaOnlyProxy();
// Make the inner and outer thresholds be in (0, 1) exclusive and be sorted correctly.
float innerThresh = testData->fRandom->nextUScalar1() * .99f + 0.005f;
float outerThresh = testData->fRandom->nextUScalar1() * .99f + 0.005f;

View File

@ -208,11 +208,8 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrBicubicEffect);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrBicubicEffect::TestCreate(GrProcessorTestData* d) {
int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: GrProcessorUnitTest::kAlphaTextureIdx;
static const GrSamplerState::WrapMode kClampClamp[] = {GrSamplerState::WrapMode::kClamp,
GrSamplerState::WrapMode::kClamp};
SkAlphaType alphaType = d->fRandom->nextBool() ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
Direction direction = Direction::kX;
switch (d->fRandom->nextULessThan(3)) {
case 0:
@ -225,8 +222,8 @@ std::unique_ptr<GrFragmentProcessor> GrBicubicEffect::TestCreate(GrProcessorTest
direction = Direction::kXY;
break;
}
return GrBicubicEffect::Make(d->textureProxy(texIdx), SkMatrix::I(), kClampClamp, direction,
alphaType);
auto [proxy, ct, at] = d->randomProxy();
return GrBicubicEffect::Make(proxy, SkMatrix::I(), kClampClamp, direction, at);
}
#endif

View File

@ -199,9 +199,7 @@ GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrBitmapTextGeoProc);
#if GR_TEST_UTILS
GrGeometryProcessor* GrBitmapTextGeoProc::TestCreate(GrProcessorTestData* d) {
int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: GrProcessorUnitTest::kAlphaTextureIdx;
sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx);
auto [proxy, ct, at] = d->randomProxy();
GrSamplerState::WrapMode wrapModes[2];
GrTest::TestWrapModes(d->fRandom, wrapModes);
@ -209,15 +207,16 @@ GrGeometryProcessor* GrBitmapTextGeoProc::TestCreate(GrProcessorTestData* d) {
? GrSamplerState::Filter::kBilerp
: GrSamplerState::Filter::kNearest);
GrMaskFormat format = kARGB_GrMaskFormat; // init to avoid warning
switch (d->fRandom->nextULessThan(3)) {
case 0:
GrMaskFormat format;
switch (ct) {
case GrColorType::kAlpha_8:
format = kA8_GrMaskFormat;
break;
case 1:
case GrColorType::kBGR_565:
format = kA565_GrMaskFormat;
break;
case 2:
case GrColorType::kRGBA_8888:
default: // It doesn't really matter that color type and mask format agree.
format = kARGB_GrMaskFormat;
break;
}

View File

@ -287,9 +287,7 @@ GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldA8TextGeoProc);
#if GR_TEST_UTILS
GrGeometryProcessor* GrDistanceFieldA8TextGeoProc::TestCreate(GrProcessorTestData* d) {
int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: GrProcessorUnitTest::kAlphaTextureIdx;
sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx);
auto [proxy, ct, at] = d->randomAlphaOnlyProxy();
GrSamplerState::WrapMode wrapModes[2];
GrTest::TestWrapModes(d->fRandom, wrapModes);
@ -582,9 +580,7 @@ GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldPathGeoProc);
#if GR_TEST_UTILS
GrGeometryProcessor* GrDistanceFieldPathGeoProc::TestCreate(GrProcessorTestData* d) {
int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: GrProcessorUnitTest::kAlphaTextureIdx;
sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx);
auto [proxy, ct, at] = d->randomAlphaOnlyProxy();
GrSamplerState::WrapMode wrapModes[2];
GrTest::TestWrapModes(d->fRandom, wrapModes);
@ -906,9 +902,7 @@ GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldLCDTextGeoProc);
#if GR_TEST_UTILS
GrGeometryProcessor* GrDistanceFieldLCDTextGeoProc::TestCreate(GrProcessorTestData* d) {
int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
GrProcessorUnitTest::kAlphaTextureIdx;
sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx);
auto [proxy, ct, at] = d->randomProxy();
GrSamplerState::WrapMode wrapModes[2];
GrTest::TestWrapModes(d->fRandom, wrapModes);

View File

@ -280,9 +280,7 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrGaussianConvolutionFragmentProcessor);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrGaussianConvolutionFragmentProcessor::TestCreate(
GrProcessorTestData* d) {
int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: GrProcessorUnitTest::kAlphaTextureIdx;
sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx);
auto [proxy, ct, at] = d->randomProxy();
int bounds[2];
int modeIdx = d->fRandom->nextRangeU(0, GrTextureDomain::kModeCount-1);
@ -301,10 +299,8 @@ std::unique_ptr<GrFragmentProcessor> GrGaussianConvolutionFragmentProcessor::Tes
int radius = d->fRandom->nextRangeU(1, kMaxKernelRadius);
float sigma = radius / 3.f;
auto alphaType = static_cast<SkAlphaType>(
d->fRandom->nextRangeU(kUnknown_SkAlphaType + 1, kLastEnum_SkAlphaType));
return GrGaussianConvolutionFragmentProcessor::Make(
std::move(proxy), alphaType, dir, radius, sigma,
static_cast<GrTextureDomain::Mode>(modeIdx), bounds);
return GrGaussianConvolutionFragmentProcessor::Make(std::move(proxy), at, dir, radius, sigma,
static_cast<GrTextureDomain::Mode>(modeIdx),
bounds);
}
#endif

View File

@ -71,7 +71,7 @@ void main() {
}
@test(d) {
sk_sp<GrTextureProxy> proxy = d->textureProxy(0);
auto [proxy, ct, at] = d->randomProxy();
const int kMaxWidth = 200;
const int kMaxHeight = 200;
const SkScalar kMaxInset = 20.0f;

View File

@ -317,9 +317,7 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMatrixConvolutionEffect);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrMatrixConvolutionEffect::TestCreate(GrProcessorTestData* d) {
int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: GrProcessorUnitTest::kAlphaTextureIdx;
sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx);
auto [proxy, ct, at] = d->randomProxy();
int width = d->fRandom->nextRangeU(1, MAX_KERNEL_SIZE);
int height = d->fRandom->nextRangeU(1, MAX_KERNEL_SIZE / width);

View File

@ -85,7 +85,7 @@ GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrRRectShadowGeoProc);
#if GR_TEST_UTILS
GrGeometryProcessor* GrRRectShadowGeoProc::TestCreate(GrProcessorTestData* d) {
sk_sp<GrSurfaceProxy> proxy = d->textureProxy(GrProcessorUnitTest::kAlphaTextureIdx);
auto [proxy, ct, at] = d->randomAlphaOnlyProxy();
GrSurfaceOrigin origin = proxy->origin();
const GrSwizzle& swizzle = proxy->textureSwizzle();
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);

View File

@ -60,8 +60,7 @@ void main() {
}
@test(testData) {
int texIdx = testData->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: GrProcessorUnitTest::kAlphaTextureIdx;
auto [proxy, ct, at] = testData->randomProxy();
GrSamplerState::WrapMode wrapModes[2];
GrTest::TestWrapModes(testData->fRandom, wrapModes);
if (!testData->caps()->npotTextureTileSupport()) {
@ -76,7 +75,5 @@ void main() {
: GrSamplerState::Filter::kNearest);
const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom);
auto alphaType = static_cast<SkAlphaType>(
testData->fRandom->nextRangeU(kUnknown_SkAlphaType + 1, kLastEnum_SkAlphaType));
return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx),
alphaType, matrix, params);}
return GrSimpleTextureEffect::Make(std::move(proxy), at, matrix, params);
}

View File

@ -607,9 +607,7 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDeviceSpaceTextureDecalFragmentProcessor);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrDeviceSpaceTextureDecalFragmentProcessor::TestCreate(
GrProcessorTestData* d) {
int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: GrProcessorUnitTest::kAlphaTextureIdx;
sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx);
auto [proxy, at, ct] = d->randomProxy();
SkIRect subset;
subset.fLeft = d->fRandom->nextULessThan(proxy->width() - 1);
subset.fRight = d->fRandom->nextRangeU(subset.fLeft, proxy->width());

View File

@ -111,7 +111,7 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrAlphaThresholdFragmentProcessor);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrAlphaThresholdFragmentProcessor::TestCreate(
GrProcessorTestData* testData) {
sk_sp<GrTextureProxy> maskProxy = testData->textureProxy(GrProcessorUnitTest::kAlphaTextureIdx);
auto [maskProxy, ct, at] = testData->randomAlphaOnlyProxy();
// Make the inner and outer thresholds be in (0, 1) exclusive and be sorted correctly.
float innerThresh = testData->fRandom->nextUScalar1() * .99f + 0.005f;
float outerThresh = testData->fRandom->nextUScalar1() * .99f + 0.005f;

View File

@ -178,7 +178,7 @@ const GrFragmentProcessor::TextureSampler& GrMagnifierEffect::onTextureSampler(i
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMagnifierEffect);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrMagnifierEffect::TestCreate(GrProcessorTestData* d) {
sk_sp<GrTextureProxy> proxy = d->textureProxy(0);
auto [proxy, ct, at] = d->randomProxy();
const int kMaxWidth = 200;
const int kMaxHeight = 200;
const SkScalar kMaxInset = 20.0f;

View File

@ -72,8 +72,7 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrSimpleTextureEffect::TestCreate(
GrProcessorTestData* testData) {
int texIdx = testData->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: GrProcessorUnitTest::kAlphaTextureIdx;
auto [proxy, ct, at] = testData->randomProxy();
GrSamplerState::WrapMode wrapModes[2];
GrTest::TestWrapModes(testData->fRandom, wrapModes);
if (!testData->caps()->npotTextureTileSupport()) {
@ -88,8 +87,6 @@ std::unique_ptr<GrFragmentProcessor> GrSimpleTextureEffect::TestCreate(
: GrSamplerState::Filter::kNearest);
const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom);
auto alphaType = static_cast<SkAlphaType>(
testData->fRandom->nextRangeU(kUnknown_SkAlphaType + 1, kLastEnum_SkAlphaType));
return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx), alphaType, matrix, params);
return GrSimpleTextureEffect::Make(std::move(proxy), at, matrix, params);
}
#endif

View File

@ -257,7 +257,7 @@ void render_fp(GrContext* context, GrRenderTargetContext* rtc, GrFragmentProcess
bool init_test_textures(GrResourceProvider* resourceProvider,
GrProxyProvider* proxyProvider,
SkRandom* random,
sk_sp<GrTextureProxy> proxies[2]) {
GrProcessorTestData::ProxyInfo proxies[2]) {
static const int kTestTextureSize = 256;
{
@ -274,9 +274,12 @@ bool init_test_textures(GrResourceProvider* resourceProvider,
kRGBA_8888_SkColorType, kPremul_SkAlphaType);
SkPixmap pixmap(ii, rgbaData.get(), ii.minRowBytes());
sk_sp<SkImage> img = SkImage::MakeRasterCopy(pixmap);
proxies[0] =
auto proxy =
proxyProvider->createTextureProxy(img, 1, SkBudgeted::kYes, SkBackingFit::kExact);
proxies[0]->instantiate(resourceProvider);
if (!proxy || !proxy->instantiate(resourceProvider)) {
return false;
}
proxies[0] = {std::move(proxy), GrColorType::kRGBA_8888, kPremul_SkAlphaType};
}
{
@ -292,12 +295,15 @@ bool init_test_textures(GrResourceProvider* resourceProvider,
kAlpha_8_SkColorType, kPremul_SkAlphaType);
SkPixmap pixmap(ii, alphaData.get(), ii.minRowBytes());
sk_sp<SkImage> img = SkImage::MakeRasterCopy(pixmap);
proxies[1] =
auto proxy =
proxyProvider->createTextureProxy(img, 1, SkBudgeted::kYes, SkBackingFit::kExact);
proxies[1]->instantiate(resourceProvider);
if (!proxy || !proxy->instantiate(resourceProvider)) {
return false;
}
proxies[1] = {std::move(proxy), GrColorType::kAlpha_8, kPremul_SkAlphaType};
}
return proxies[0] && proxies[1];
return true;
}
// Creates a texture of premul colors used as the output of the fragment processor that precedes
@ -427,12 +433,12 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, repor
auto rtc = context->priv().makeDeferredRenderTargetContext(
SkBackingFit::kExact, kRenderSize, kRenderSize, GrColorType::kRGBA_8888, nullptr);
sk_sp<GrTextureProxy> proxies[2];
GrProcessorTestData::ProxyInfo proxies[2];
if (!init_test_textures(resourceProvider, proxyProvider, &random, proxies)) {
ERRORF(reporter, "Could not create test textures");
return;
}
GrProcessorTestData testData(&random, context, rtc.get(), proxies);
GrProcessorTestData testData(&random, context, 2, proxies);
// Coverage optimization uses three frames with a linearly transformed input texture. The first
// frame has no offset, second frames add .2 and .4, which should then be present as a fixed
@ -664,12 +670,12 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorCloneTest, reporter, ctxInfo) {
auto rtc = context->priv().makeDeferredRenderTargetContext(
SkBackingFit::kExact, kRenderSize, kRenderSize, GrColorType::kRGBA_8888, nullptr);
sk_sp<GrTextureProxy> proxies[2];
GrProcessorTestData::ProxyInfo proxies[2];
if (!init_test_textures(resourceProvider, proxyProvider, &random, proxies)) {
ERRORF(reporter, "Could not create test textures");
return;
}
GrProcessorTestData testData(&random, context, rtc.get(), proxies);
GrProcessorTestData testData(&random, context, 2, proxies);
auto inputTexture = make_input_texture(proxyProvider, kRenderSize, kRenderSize, 0.0f);
std::unique_ptr<GrColor[]> readData1(new GrColor[kRenderSize * kRenderSize]);

View File

@ -260,7 +260,7 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages, int ma
GrDrawingManager* drawingManager = context->priv().drawingManager();
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
sk_sp<GrTextureProxy> proxies[2];
GrProcessorTestData::ProxyInfo proxies[2];
// setup dummy textures
GrMipMapped mipMapped = GrMipMapped(context->priv().caps()->mipMapSupport());
@ -272,10 +272,13 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages, int ma
const GrBackendFormat format =
context->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888,
GrRenderable::kYes);
proxies[0] = proxyProvider->createProxy(format, dummyDesc, GrRenderable::kYes, 1,
kBottomLeft_GrSurfaceOrigin, mipMapped,
SkBackingFit::kExact, SkBudgeted::kNo,
GrProtected::kNo, GrInternalSurfaceFlags::kNone);
proxies[0] = {proxyProvider->createProxy(format, dummyDesc, GrRenderable::kYes, 1,
kBottomLeft_GrSurfaceOrigin, mipMapped,
SkBackingFit::kExact, SkBudgeted::kNo,
GrProtected::kNo, GrInternalSurfaceFlags::kNone),
GrColorType::kRGBA_8888,
kPremul_SkAlphaType
};
}
{
GrSurfaceDesc dummyDesc;
@ -285,13 +288,16 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages, int ma
const GrBackendFormat format =
context->priv().caps()->getDefaultBackendFormat(GrColorType::kAlpha_8,
GrRenderable::kNo);
proxies[1] = proxyProvider->createProxy(format, dummyDesc, GrRenderable::kNo, 1,
kTopLeft_GrSurfaceOrigin, mipMapped,
SkBackingFit::kExact, SkBudgeted::kNo,
GrProtected::kNo, GrInternalSurfaceFlags::kNone);
proxies[1] = {proxyProvider->createProxy(format, dummyDesc, GrRenderable::kNo, 1,
kTopLeft_GrSurfaceOrigin, mipMapped,
SkBackingFit::kExact, SkBudgeted::kNo,
GrProtected::kNo, GrInternalSurfaceFlags::kNone),
GrColorType::kAlpha_8,
kPremul_SkAlphaType
};
}
if (!proxies[0] || !proxies[1]) {
if (!std::get<0>(proxies[0]) || !std::get<0>(proxies[1])) {
SkDebugf("Could not allocate dummy textures");
return false;
}
@ -308,7 +314,7 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages, int ma
}
GrPaint paint;
GrProcessorTestData ptd(&random, context, renderTargetContext.get(), proxies);
GrProcessorTestData ptd(&random, context, 2, proxies);
set_random_color_coverage_stages(&paint, &ptd, maxStages, maxLevels);
set_random_xpf(&paint, &ptd);
GrDrawRandomOp(&random, renderTargetContext.get(), std::move(paint));
@ -333,7 +339,7 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages, int ma
for (int i = 0; i < fpFactoryCnt; ++i) {
// Since FP factories internally randomize, call each 10 times.
for (int j = 0; j < 10; ++j) {
GrProcessorTestData ptd(&random, context, renderTargetContext.get(), proxies);
GrProcessorTestData ptd(&random, context, 2, proxies);
GrPaint paint;
paint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));