Remove SK_ALLOW_STATIC_GLOBAL_INITIALIZERS from tests.
The tests themselves should run fine if no factories were actually
registered. This isolates the last uses of this flag to the gpu code
which is actually depending on it.
Change-Id: Ief9c01abfc37c4e071d946d70ef85f13f94ae0f6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/213301
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
diff --git a/src/gpu/GrProcessor.cpp b/src/gpu/GrProcessor.cpp
index 34370de..2a58b54 100644
--- a/src/gpu/GrProcessor.cpp
+++ b/src/gpu/GrProcessor.cpp
@@ -27,7 +27,6 @@
const GrCaps* GrProcessorTestData::caps() { return fContext->priv().caps(); }
-#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
class GrFragmentProcessor;
class GrGeometryProcessor;
@@ -57,9 +56,15 @@
* 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 = 36;
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() {
@@ -88,7 +93,6 @@
}
#endif
-#endif
// We use a global pool protected by a mutex(spinlock). Chrome may use the same GrContext on
diff --git a/src/gpu/GrProcessorUnitTest.h b/src/gpu/GrProcessorUnitTest.h
index 2a763b7..8ed5297 100644
--- a/src/gpu/GrProcessorUnitTest.h
+++ b/src/gpu/GrProcessorUnitTest.h
@@ -73,8 +73,6 @@
sk_sp<GrTextureProxy> fProxies[2];
};
-#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
-
class GrProcessor;
class GrTexture;
@@ -92,7 +90,9 @@
/** Pick a random factory function and create a processor. */
static ProcessorSmartPtr Make(GrProcessorTestData* data) {
VerifyFactoryCount();
- SkASSERT(GetFactories()->count());
+ if (GetFactories()->count() == 0) {
+ return nullptr;
+ }
uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1);
return MakeIdx(idx, data);
}
@@ -102,6 +102,7 @@
/** Use factory function at Index idx to create a processor. */
static ProcessorSmartPtr MakeIdx(int idx, GrProcessorTestData* data) {
+ SkASSERT(idx < GetFactories()->count());
GrProcessorTestFactory<ProcessorSmartPtr>* factory = (*GetFactories())[idx];
ProcessorSmartPtr processor = factory->fMakeProc(data);
SkASSERT(processor);
@@ -130,7 +131,9 @@
static const GrXPFactory* Get(GrProcessorTestData* data) {
VerifyFactoryCount();
- SkASSERT(GetFactories()->count());
+ 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);
@@ -144,6 +147,8 @@
static SkTArray<GrXPFactoryTestFactory*, true>* GetFactories();
};
+#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
+
/** GrProcessor subclasses should insert this macro in their declaration to be included in the
* program generation unit test.
*/