Move test code out of header into CPP file.
This test code is templated, but not really generic (it's only meant to
work with two specific classes) so it doesn't need to live in a header.
Change-Id: I38d4f2cc9637207eca678fc81ff35ebbd7e69fce
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/303656
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
diff --git a/src/gpu/GrProcessorUnitTest.cpp b/src/gpu/GrProcessorUnitTest.cpp
index 852954b..5336b5b 100644
--- a/src/gpu/GrProcessorUnitTest.cpp
+++ b/src/gpu/GrProcessorUnitTest.cpp
@@ -13,6 +13,8 @@
#if GR_TEST_UTILS
+class GrGeometryProcessor;
+
GrProcessorTestData::GrProcessorTestData(SkRandom* random, GrRecordingContext* context,
int numViews, const ViewInfo views[])
: GrProcessorTestData(random, context, numViews, views, /*inputFP=*/nullptr) {}
@@ -55,8 +57,51 @@
SkUNREACHABLE;
}
-class GrFragmentProcessor;
-class GrGeometryProcessor;
+template <class ProcessorSmartPtr>
+GrProcessorTestFactory<ProcessorSmartPtr>::GrProcessorTestFactory(MakeProc makeProc) {
+ fMakeProc = makeProc;
+ GetFactories()->push_back(this);
+}
+
+template <class ProcessorSmartPtr>
+ProcessorSmartPtr GrProcessorTestFactory<ProcessorSmartPtr>::Make(GrProcessorTestData* data) {
+ VerifyFactoryCount();
+ if (GetFactories()->count() == 0) {
+ return nullptr;
+ }
+ uint32_t idx = data->fRandom->nextULessThan(GetFactories()->count());
+ return MakeIdx(idx, data);
+}
+
+template <class ProcessorSmartPtr>
+ProcessorSmartPtr GrProcessorTestFactory<ProcessorSmartPtr>::MakeIdx(int idx,
+ GrProcessorTestData* data) {
+ SkASSERT(idx < GetFactories()->count());
+ GrProcessorTestFactory<ProcessorSmartPtr>* factory = (*GetFactories())[idx];
+ ProcessorSmartPtr processor = factory->fMakeProc(data);
+ SkASSERT(processor);
+ return processor;
+}
+
+template <class ProcessorSmartPtr>
+int GrProcessorTestFactory<ProcessorSmartPtr>::Count() {
+ return GetFactories()->count();
+}
+
+GrXPFactoryTestFactory::GrXPFactoryTestFactory(GetFn* getProc) : fGetProc(getProc) {
+ GetFactories()->push_back(this);
+}
+
+const GrXPFactory* GrXPFactoryTestFactory::Get(GrProcessorTestData* data) {
+ VerifyFactoryCount();
+ if (GetFactories()->count() == 0) {
+ return nullptr;
+ }
+ uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1);
+ const GrXPFactory* xpf = (*GetFactories())[idx]->fGetProc(data);
+ SkASSERT(xpf);
+ return xpf;
+}
/*
* Originally these were both in the processor unit test header, but then it seemed to cause linker
@@ -84,9 +129,9 @@
* 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;
+static constexpr int kFPFactoryCount = 37;
+static constexpr int kGPFactoryCount = 14;
+static constexpr int kXPFactoryCount = 4;
template <> void GrFragmentProcessorTestFactory::VerifyFactoryCount() {
if (kFPFactoryCount != GetFactories()->count()) {
@@ -120,4 +165,8 @@
} while (fp->numNonNullChildProcessors() != 0);
return fp;
}
+
+template class GrProcessorTestFactory<GrGeometryProcessor*>;
+template class GrProcessorTestFactory<std::unique_ptr<GrFragmentProcessor>>;
+
#endif