'<(skia_src_path)/gpu/GrProgramDesc.h',
'<(skia_src_path)/gpu/GrProgramElement.cpp',
'<(skia_src_path)/gpu/GrProcessor.cpp',
+ '<(skia_src_path)/gpu/GrProcessorUnitTest.cpp',
'<(skia_src_path)/gpu/GrProcessorDataManager.cpp',
'<(skia_src_path)/gpu/GrProcOptInfo.cpp',
'<(skia_src_path)/gpu/GrProcOptInfo.h',
class SkMatrix;
class GrCaps;
class GrContext;
+struct GrProcessorTestData;
namespace GrProcessorUnitTest {
+
// Used to access the dummy textures in TestCreate procs.
enum {
kSkiaPMTextureIdx = 0,
kAlphaTextureIdx = 1,
};
+/** This allows parent FPs to implement a test create with known leaf children in order to avoid
+creating an unbounded FP tree which may overflow various shader limits. */
+const GrFragmentProcessor* CreateChildFP(GrProcessorTestData*);
+
}
/*
class GrProcessor;
class GrTexture;
-template <class Processor>
-class GrProcessorTestFactory : SkNoncopyable {
+template <class Processor> class GrProcessorTestFactory : SkNoncopyable {
public:
-
typedef const Processor* (*CreateProc)(GrProcessorTestData*);
GrProcessorTestFactory(CreateProc createProc) {
static GrProcessorTestFactory<GrXPFactory> gTestFactory SK_UNUSED; \
static const GrXPFactory* TestCreate(GrProcessorTestData*)
-
/** GrProcessor subclasses should insert this macro in their implementation file. They must then
* also implement this static function:
* GrProcessor* TestCreate(GrProcessorTestData*);
void onComputeInvariantOutput(GrInvariantOutput* inout) const override;
+ GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
+
typedef GrFragmentProcessor INHERITED;
};
* we verify the count is as expected. If a new factory is added, then these numbers must be
* manually adjusted.
*/
-static const int kFPFactoryCount = 38;
+static const int kFPFactoryCount = 39;
static const int kGPFactoryCount = 14;
static const int kXPFactoryCount = 5;
--- /dev/null
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrProcessorUnitTest.h"
+#include "GrFragmentProcessor.h"
+
+const GrFragmentProcessor* GrProcessorUnitTest::CreateChildFP(GrProcessorTestData* data) {
+#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
+ SkAutoTUnref<const GrFragmentProcessor> fp;
+ do {
+ fp.reset(GrProcessorTestFactory<GrFragmentProcessor>::Create(data));
+ SkASSERT(fp);
+ } while (fp->numChildProcessors() != 0);
+ return SkRef(fp.get());
+#else
+ SkFAIL("Should not be called if !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS");
+ return nullptr;
+#endif
+}
}
this->childProcessor(0).computeInvariantOutput(inout);
}
+
+GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrExtractAlphaFragmentProcessor);
+
+const GrFragmentProcessor* GrExtractAlphaFragmentProcessor::TestCreate(GrProcessorTestData* d) {
+ SkAutoTUnref<const GrFragmentProcessor> child(GrProcessorUnitTest::CreateChildFP(d));
+ return SkNEW_ARGS(GrExtractAlphaFragmentProcessor, (child));
+}
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrComposeTwoFragmentProcessor);
const GrFragmentProcessor* GrComposeTwoFragmentProcessor::TestCreate(GrProcessorTestData* d) {
-#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
// Create two random frag procs.
- // For now, we'll prevent either children from being a shader with children to prevent the
- // possibility of an arbitrarily large tree of procs.
- SkAutoTUnref<const GrFragmentProcessor> fpA;
- do {
- fpA.reset(GrProcessorTestFactory<GrFragmentProcessor>::Create(d));
- SkASSERT(fpA);
- } while (fpA->numChildProcessors() != 0);
- SkAutoTUnref<const GrFragmentProcessor> fpB;
- do {
- fpB.reset(GrProcessorTestFactory<GrFragmentProcessor>::Create(d));
- SkASSERT(fpB);
- } while (fpB->numChildProcessors() != 0);
+ SkAutoTUnref<const GrFragmentProcessor> fpA(GrProcessorUnitTest::CreateChildFP(d));
+ SkAutoTUnref<const GrFragmentProcessor> fpB(GrProcessorUnitTest::CreateChildFP(d));
SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(
d->fRandom->nextRangeU(0, SkXfermode::kLastCoeffMode));
return SkNEW_ARGS(GrComposeTwoFragmentProcessor, (fpA, fpB, mode));
-#else
- SkFAIL("Should not be called if !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS");
- return nullptr;
-#endif
}
GrGLFragmentProcessor* GrComposeTwoFragmentProcessor::onCreateGLInstance() const{