#ifndef GrProcessorUnitTest_DEFINED
#define GrProcessorUnitTest_DEFINED
#include "include/core/SkTypes.h"
#if defined(GPU_TEST_UTILS)
#include "include/core/SkString.h"
#include "include/private/base/SkNoncopyable.h"
#include "include/private/base/SkTArray.h"
#include "src/gpu/ganesh/GrFragmentProcessor.h"
#include "src/gpu/ganesh/GrSurfaceProxyView.h"
#include <memory>
#include <tuple>
class GrCaps;
class GrGeometryProcessor;
class GrProcessorTestData;
class GrProxyProvider;
class GrRecordingContext;
class GrXPFactory;
class SkArenaAlloc;
class SkRandom;
enum SkAlphaType : int;
enum class GrColorType;
namespace GrProcessorUnitTest {
std::unique_ptr<GrFragmentProcessor> MakeChildFP(GrProcessorTestData*);
std::unique_ptr<GrFragmentProcessor> MakeOptionalChildFP(GrProcessorTestData*);
}
class GrProcessorTestData {
public:
using ViewInfo = std::tuple<GrSurfaceProxyView, GrColorType, SkAlphaType>;
GrProcessorTestData(SkRandom* random, GrRecordingContext* context, int maxTreeDepth,
int numViews, const ViewInfo views[]);
GrProcessorTestData(SkRandom* random, GrRecordingContext* context, int maxTreeDepth,
int numViews, const ViewInfo views[],
std::unique_ptr<GrFragmentProcessor> inputFP);
GrProcessorTestData(const GrProcessorTestData&) = delete;
~GrProcessorTestData();
GrRecordingContext* context() { return fContext; }
GrProxyProvider* proxyProvider();
const GrCaps* caps();
SkArenaAlloc* allocator() { return fArena.get(); }
std::unique_ptr<GrFragmentProcessor> inputFP();
ViewInfo randomView();
ViewInfo randomAlphaOnlyView();
SkRandom* fRandom;
int fCurrentTreeDepth = 0;
int fMaxTreeDepth = 1;
private:
GrRecordingContext* fContext;
skia_private::TArray<ViewInfo> fViews;
std::unique_ptr<SkArenaAlloc> fArena;
std::unique_ptr<GrFragmentProcessor> fInputFP;
};
template <class ProcessorSmartPtr>
class GrProcessorTestFactory : private SkNoncopyable {
public:
using MakeProc = ProcessorSmartPtr (*)(GrProcessorTestData*);
GrProcessorTestFactory(MakeProc makeProc, const char* name);
static ProcessorSmartPtr Make(GrProcessorTestData* data);
static ProcessorSmartPtr MakeIdx(int idx, GrProcessorTestData* data);
static int Count();
private:
static void VerifyFactoryCount();
static skia_private::TArray<GrProcessorTestFactory<ProcessorSmartPtr>*, true>* GetFactories();
MakeProc fMakeProc;
SkString fName;
};
using GrFragmentProcessorTestFactory = GrProcessorTestFactory<std::unique_ptr<GrFragmentProcessor>>;
using GrGeometryProcessorTestFactory = GrProcessorTestFactory<GrGeometryProcessor*>;
class GrXPFactoryTestFactory : private SkNoncopyable {
public:
using GetFn = const GrXPFactory*(GrProcessorTestData*);
GrXPFactoryTestFactory(GetFn* getProc);
static const GrXPFactory* Get(GrProcessorTestData* data);
private:
static void VerifyFactoryCount();
static skia_private::TArray<GrXPFactoryTestFactory*, true>* GetFactories();
GetFn* fGetProc;
};
#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
#define GR_DECLARE_GEOMETRY_PROCESSOR_TEST …
#define GR_DECLARE_FRAGMENT_PROCESSOR_TEST …
#define GR_DECLARE_XP_FACTORY_TEST …
#define GR_DEFINE_FRAGMENT_PROCESSOR_TEST …
#define GR_DEFINE_GEOMETRY_PROCESSOR_TEST …
#define GR_DEFINE_XP_FACTORY_TEST …
#else
#define GR_DECLARE_FRAGMENT_PROCESSOR_TEST …
#define GR_DEFINE_FRAGMENT_PROCESSOR_TEST …
#define GR_DECLARE_GEOMETRY_PROCESSOR_TEST …
#define GR_DEFINE_GEOMETRY_PROCESSOR_TEST …
#define GR_DECLARE_XP_FACTORY_TEST …
#define GR_DEFINE_XP_FACTORY_TEST …
#endif
#else
#define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
#define GR_DECLARE_FRAGMENT_PROCESSOR_TEST
#define GR_DECLARE_XP_FACTORY_TEST
#define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(...) …
#define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(...) …
#define GR_DEFINE_XP_FACTORY_TEST(...) …
#define GR_DECLARE_FRAGMENT_PROCESSOR_TEST
#define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(...) …
#define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
#define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(...) …
#define GR_DECLARE_XP_FACTORY_TEST
#define GR_DEFINE_XP_FACTORY_TEST(...) …
#endif
#endif