Make GrProcessorTestFactory be templated on smart ptr class rather than processor class.
This is part of setting the stage for moving GrFragmentProcessor to unique_ptr ownership. Change-Id: I2dfb4977319605d56c4debe05ff0b3dc970bb4c5 Reviewed-on: https://skia-review.googlesource.com/26141 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
parent
8e5be413c1
commit
1c053644a8
@ -33,17 +33,15 @@ class GrGeometryProcessor;
|
||||
* Originally these were both in the processor unit test header, but then it seemed to cause linker
|
||||
* problems on android.
|
||||
*/
|
||||
template<>
|
||||
SkTArray<GrProcessorTestFactory<GrFragmentProcessor>*, true>*
|
||||
GrProcessorTestFactory<GrFragmentProcessor>::GetFactories() {
|
||||
static SkTArray<GrProcessorTestFactory<GrFragmentProcessor>*, true> gFactories;
|
||||
template <>
|
||||
SkTArray<GrFragmentProcessorTestFactory*, true>* GrFragmentProcessorTestFactory::GetFactories() {
|
||||
static SkTArray<GrFragmentProcessorTestFactory*, true> gFactories;
|
||||
return &gFactories;
|
||||
}
|
||||
|
||||
template<>
|
||||
SkTArray<GrProcessorTestFactory<GrGeometryProcessor>*, true>*
|
||||
GrProcessorTestFactory<GrGeometryProcessor>::GetFactories() {
|
||||
static SkTArray<GrProcessorTestFactory<GrGeometryProcessor>*, true> gFactories;
|
||||
template <>
|
||||
SkTArray<GrGeometryProcessorTestFactory*, true>* GrGeometryProcessorTestFactory::GetFactories() {
|
||||
static SkTArray<GrGeometryProcessorTestFactory*, true> gFactories;
|
||||
return &gFactories;
|
||||
}
|
||||
|
||||
@ -61,8 +59,8 @@ static const int kFPFactoryCount = 42;
|
||||
static const int kGPFactoryCount = 14;
|
||||
static const int kXPFactoryCount = 4;
|
||||
|
||||
template<>
|
||||
void GrProcessorTestFactory<GrFragmentProcessor>::VerifyFactoryCount() {
|
||||
template <>
|
||||
void GrFragmentProcessorTestFactory::VerifyFactoryCount() {
|
||||
if (kFPFactoryCount != GetFactories()->count()) {
|
||||
SkDebugf("\nExpected %d fragment processor factories, found %d.\n",
|
||||
kFPFactoryCount, GetFactories()->count());
|
||||
@ -70,8 +68,8 @@ void GrProcessorTestFactory<GrFragmentProcessor>::VerifyFactoryCount() {
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
void GrProcessorTestFactory<GrGeometryProcessor>::VerifyFactoryCount() {
|
||||
template <>
|
||||
void GrGeometryProcessorTestFactory::VerifyFactoryCount() {
|
||||
if (kGPFactoryCount != GetFactories()->count()) {
|
||||
SkDebugf("\nExpected %d geometry processor factories, found %d.\n",
|
||||
kGPFactoryCount, GetFactories()->count());
|
||||
|
@ -14,7 +14,7 @@ sk_sp<GrFragmentProcessor> GrProcessorUnitTest::MakeChildFP(GrProcessorTestData*
|
||||
#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
|
||||
sk_sp<GrFragmentProcessor> fp;
|
||||
do {
|
||||
fp = GrProcessorTestFactory<GrFragmentProcessor>::Make(data);
|
||||
fp = GrFragmentProcessorTestFactory::Make(data);
|
||||
SkASSERT(fp);
|
||||
} while (fp->numChildProcessors() != 0);
|
||||
return fp;
|
||||
|
@ -23,6 +23,7 @@ class GrRenderTargetContext;
|
||||
struct GrProcessorTestData;
|
||||
class GrTexture;
|
||||
class GrXPFactory;
|
||||
class GrGeometryProcessor;
|
||||
|
||||
namespace GrProcessorUnitTest {
|
||||
|
||||
@ -75,9 +76,11 @@ private:
|
||||
class GrProcessor;
|
||||
class GrTexture;
|
||||
|
||||
template <class Processor> class GrProcessorTestFactory : private SkNoncopyable {
|
||||
template <class ProcessorSmartPtr>
|
||||
class GrProcessorTestFactory : private SkNoncopyable {
|
||||
public:
|
||||
typedef sk_sp<Processor> (*MakeProc)(GrProcessorTestData*);
|
||||
using Processor = typename ProcessorSmartPtr::element_type;
|
||||
using MakeProc = ProcessorSmartPtr (*)(GrProcessorTestData*);
|
||||
|
||||
GrProcessorTestFactory(MakeProc makeProc) {
|
||||
fMakeProc = makeProc;
|
||||
@ -85,7 +88,7 @@ public:
|
||||
}
|
||||
|
||||
/** Pick a random factory function and create a processor. */
|
||||
static sk_sp<Processor> Make(GrProcessorTestData* data) {
|
||||
static ProcessorSmartPtr Make(GrProcessorTestData* data) {
|
||||
VerifyFactoryCount();
|
||||
SkASSERT(GetFactories()->count());
|
||||
uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1);
|
||||
@ -97,8 +100,8 @@ public:
|
||||
|
||||
/** Use factory function at Index idx to create a processor. */
|
||||
static sk_sp<Processor> MakeIdx(int idx, GrProcessorTestData* data) {
|
||||
GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx];
|
||||
sk_sp<Processor> processor = factory->fMakeProc(data);
|
||||
GrProcessorTestFactory<ProcessorSmartPtr>* factory = (*GetFactories())[idx];
|
||||
ProcessorSmartPtr processor = factory->fMakeProc(data);
|
||||
SkASSERT(processor);
|
||||
return processor;
|
||||
}
|
||||
@ -111,9 +114,12 @@ private:
|
||||
|
||||
MakeProc fMakeProc;
|
||||
|
||||
static SkTArray<GrProcessorTestFactory<Processor>*, true>* GetFactories();
|
||||
static SkTArray<GrProcessorTestFactory<ProcessorSmartPtr>*, true>* GetFactories();
|
||||
};
|
||||
|
||||
using GrFragmentProcessorTestFactory = GrProcessorTestFactory<sk_sp<GrFragmentProcessor>>;
|
||||
using GrGeometryProcessorTestFactory = GrProcessorTestFactory<sk_sp<GrGeometryProcessor>>;
|
||||
|
||||
class GrXPFactoryTestFactory : private SkNoncopyable {
|
||||
public:
|
||||
using GetFn = const GrXPFactory*(GrProcessorTestData*);
|
||||
@ -139,12 +145,12 @@ private:
|
||||
/** GrProcessor subclasses should insert this macro in their declaration to be included in the
|
||||
* program generation unit test.
|
||||
*/
|
||||
#define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \
|
||||
static GrProcessorTestFactory<GrGeometryProcessor> gTestFactory SK_UNUSED; \
|
||||
#define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \
|
||||
static GrGeometryProcessorTestFactory gTestFactory SK_UNUSED; \
|
||||
static sk_sp<GrGeometryProcessor> TestCreate(GrProcessorTestData*);
|
||||
|
||||
#define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \
|
||||
static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory SK_UNUSED; \
|
||||
#define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \
|
||||
static GrFragmentProcessorTestFactory gTestFactory SK_UNUSED; \
|
||||
static sk_sp<GrFragmentProcessor> TestCreate(GrProcessorTestData*);
|
||||
|
||||
#define GR_DECLARE_XP_FACTORY_TEST \
|
||||
@ -155,11 +161,11 @@ private:
|
||||
* also implement this static function:
|
||||
* GrProcessor* TestCreate(GrProcessorTestData*);
|
||||
*/
|
||||
#define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Effect) \
|
||||
GrProcessorTestFactory<GrFragmentProcessor> Effect::gTestFactory(Effect::TestCreate)
|
||||
#define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Effect) \
|
||||
GrFragmentProcessorTestFactory Effect::gTestFactory(Effect::TestCreate)
|
||||
|
||||
#define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(Effect) \
|
||||
GrProcessorTestFactory<GrGeometryProcessor> Effect::gTestFactory(Effect::TestCreate)
|
||||
#define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(Effect) \
|
||||
GrGeometryProcessorTestFactory Effect::gTestFactory(Effect::TestCreate)
|
||||
|
||||
#define GR_DEFINE_XP_FACTORY_TEST(Factory) \
|
||||
GrXPFactoryTestFactory Factory::gTestFactory(Factory::TestGet)
|
||||
|
@ -177,7 +177,7 @@ static sk_sp<GrFragmentProcessor> create_random_proc_tree(GrProcessorTestData* d
|
||||
if (terminate) {
|
||||
sk_sp<GrFragmentProcessor> fp;
|
||||
while (true) {
|
||||
fp = GrProcessorTestFactory<GrFragmentProcessor>::Make(d);
|
||||
fp = GrFragmentProcessorTestFactory::Make(d);
|
||||
SkASSERT(fp);
|
||||
if (0 == fp->numChildProcessors()) {
|
||||
break;
|
||||
@ -225,7 +225,7 @@ static void set_random_color_coverage_stages(GrPaint* paint,
|
||||
int numColorProcs = d->fRandom->nextULessThan(numProcs + 1);
|
||||
|
||||
for (int s = 0; s < numProcs;) {
|
||||
sk_sp<GrFragmentProcessor> fp(GrProcessorTestFactory<GrFragmentProcessor>::Make(d));
|
||||
sk_sp<GrFragmentProcessor> fp(GrFragmentProcessorTestFactory::Make(d));
|
||||
SkASSERT(fp);
|
||||
|
||||
// finally add the stage to the correct pipeline in the drawstate
|
||||
@ -316,7 +316,7 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages, int ma
|
||||
return false;
|
||||
}
|
||||
|
||||
int fpFactoryCnt = GrProcessorTestFactory<GrFragmentProcessor>::Count();
|
||||
int fpFactoryCnt = GrFragmentProcessorTestFactory::Count();
|
||||
for (int i = 0; i < fpFactoryCnt; ++i) {
|
||||
// Since FP factories internally randomize, call each 10 times.
|
||||
for (int j = 0; j < 10; ++j) {
|
||||
@ -324,8 +324,7 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages, int ma
|
||||
|
||||
GrPaint paint;
|
||||
paint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
|
||||
sk_sp<GrFragmentProcessor> fp(
|
||||
GrProcessorTestFactory<GrFragmentProcessor>::MakeIdx(i, &ptd));
|
||||
sk_sp<GrFragmentProcessor> fp(GrFragmentProcessorTestFactory::MakeIdx(i, &ptd));
|
||||
sk_sp<GrFragmentProcessor> blockFP(
|
||||
BlockInputFragmentProcessor::Make(std::move(fp)));
|
||||
paint.addColorFragmentProcessor(std::move(blockFP));
|
||||
|
@ -288,7 +288,7 @@ DEFINE_bool(randomProcessorTest, false, "Use non-deterministic seed for random p
|
||||
#if GR_TEST_UTILS
|
||||
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, reporter, ctxInfo) {
|
||||
GrContext* context = ctxInfo.grContext();
|
||||
using FPFactory = GrProcessorTestFactory<GrFragmentProcessor>;
|
||||
using FPFactory = GrFragmentProcessorTestFactory;
|
||||
|
||||
uint32_t seed = 0;
|
||||
if (FLAGS_randomProcessorTest) {
|
||||
|
Loading…
Reference in New Issue
Block a user