2014-09-23 16:50:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrProcessorUnitTest_DEFINED
|
|
|
|
#define GrProcessorUnitTest_DEFINED
|
|
|
|
|
2015-04-28 20:31:18 +00:00
|
|
|
#include "GrTestUtils.h"
|
2014-09-23 16:50:21 +00:00
|
|
|
#include "SkTArray.h"
|
|
|
|
#include "SkTypes.h"
|
|
|
|
|
|
|
|
class SkMatrix;
|
2015-05-19 16:29:46 +00:00
|
|
|
class GrCaps;
|
2015-07-08 21:26:19 +00:00
|
|
|
class GrContext;
|
2015-11-12 20:11:04 +00:00
|
|
|
class GrRenderTarget;
|
2015-09-14 20:16:26 +00:00
|
|
|
struct GrProcessorTestData;
|
2014-09-23 16:50:21 +00:00
|
|
|
|
|
|
|
namespace GrProcessorUnitTest {
|
2015-09-14 20:16:26 +00:00
|
|
|
|
2014-09-23 16:50:21 +00:00
|
|
|
// Used to access the dummy textures in TestCreate procs.
|
|
|
|
enum {
|
|
|
|
kSkiaPMTextureIdx = 0,
|
|
|
|
kAlphaTextureIdx = 1,
|
|
|
|
};
|
|
|
|
|
2015-09-14 20:16:26 +00:00
|
|
|
/** 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*);
|
|
|
|
|
2014-12-09 21:31:14 +00:00
|
|
|
}
|
|
|
|
|
2015-07-08 21:26:19 +00:00
|
|
|
/*
|
|
|
|
* GrProcessorTestData is an argument struct to TestCreate functions
|
|
|
|
* fTextures are valid textures that can optionally be used to construct
|
|
|
|
* GrTextureAccesses. The first texture has config kSkia8888_GrPixelConfig and the second has
|
|
|
|
* kAlpha_8_GrPixelConfig. TestCreate functions are also free to create additional textures using
|
|
|
|
* the GrContext.
|
|
|
|
*/
|
|
|
|
struct GrProcessorTestData {
|
|
|
|
GrProcessorTestData(SkRandom* random,
|
|
|
|
GrContext* context,
|
|
|
|
const GrCaps* caps,
|
2015-11-12 20:11:04 +00:00
|
|
|
const GrRenderTarget* rt,
|
2015-07-08 21:26:19 +00:00
|
|
|
GrTexture* textures[2])
|
|
|
|
: fRandom(random)
|
|
|
|
, fContext(context)
|
2015-11-12 20:11:04 +00:00
|
|
|
, fCaps(caps)
|
|
|
|
, fRenderTarget(rt) {
|
2015-07-08 21:26:19 +00:00
|
|
|
fTextures[0] = textures[0];
|
|
|
|
fTextures[1] = textures[1];
|
|
|
|
}
|
|
|
|
SkRandom* fRandom;
|
|
|
|
GrContext* fContext;
|
|
|
|
const GrCaps* fCaps;
|
2015-11-12 20:11:04 +00:00
|
|
|
const GrRenderTarget* fRenderTarget;
|
2015-07-08 21:26:19 +00:00
|
|
|
GrTexture* fTextures[2];
|
|
|
|
};
|
|
|
|
|
2014-09-23 16:50:21 +00:00
|
|
|
#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
|
|
|
|
|
|
|
|
class GrProcessor;
|
|
|
|
class GrTexture;
|
|
|
|
|
2015-09-14 20:16:26 +00:00
|
|
|
template <class Processor> class GrProcessorTestFactory : SkNoncopyable {
|
2014-09-23 16:50:21 +00:00
|
|
|
public:
|
2015-08-29 01:46:56 +00:00
|
|
|
typedef const Processor* (*CreateProc)(GrProcessorTestData*);
|
2014-09-23 16:50:21 +00:00
|
|
|
|
|
|
|
GrProcessorTestFactory(CreateProc createProc) {
|
|
|
|
fCreateProc = createProc;
|
|
|
|
GetFactories()->push_back(this);
|
|
|
|
}
|
|
|
|
|
2015-09-14 19:26:33 +00:00
|
|
|
/** Pick a random factory function and create a processor. */
|
|
|
|
static const Processor* Create(GrProcessorTestData* data) {
|
2014-10-09 20:12:35 +00:00
|
|
|
VerifyFactoryCount();
|
|
|
|
SkASSERT(GetFactories()->count());
|
2015-07-08 21:26:19 +00:00
|
|
|
uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1);
|
2015-09-14 19:26:33 +00:00
|
|
|
return CreateIdx(idx, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Number of registered factory functions */
|
|
|
|
static int Count() { return GetFactories()->count(); }
|
|
|
|
|
|
|
|
/** Use factory function at Index idx to create a processor. */
|
|
|
|
static const Processor* CreateIdx(int idx, GrProcessorTestData* data) {
|
2014-09-23 16:50:21 +00:00
|
|
|
GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx];
|
2015-07-08 21:26:19 +00:00
|
|
|
return factory->fCreateProc(data);
|
2014-09-23 16:50:21 +00:00
|
|
|
}
|
|
|
|
|
2014-10-09 20:12:35 +00:00
|
|
|
/*
|
|
|
|
* A test function which verifies the count of factories.
|
|
|
|
*/
|
|
|
|
static void VerifyFactoryCount();
|
|
|
|
|
2014-09-23 16:50:21 +00:00
|
|
|
private:
|
|
|
|
CreateProc fCreateProc;
|
|
|
|
|
2014-10-09 20:12:35 +00:00
|
|
|
static SkTArray<GrProcessorTestFactory<Processor>*, true>* GetFactories();
|
2014-09-23 16:50:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** GrProcessor subclasses should insert this macro in their declaration to be included in the
|
|
|
|
* program generation unit test.
|
|
|
|
*/
|
|
|
|
#define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \
|
2014-10-09 20:12:35 +00:00
|
|
|
static GrProcessorTestFactory<GrGeometryProcessor> gTestFactory SK_UNUSED; \
|
2015-08-29 01:46:56 +00:00
|
|
|
static const GrGeometryProcessor* TestCreate(GrProcessorTestData*)
|
2014-09-23 16:50:21 +00:00
|
|
|
|
|
|
|
#define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \
|
2014-10-09 20:12:35 +00:00
|
|
|
static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory SK_UNUSED; \
|
2015-08-29 01:46:56 +00:00
|
|
|
static const GrFragmentProcessor* TestCreate(GrProcessorTestData*)
|
2014-09-23 16:50:21 +00:00
|
|
|
|
2014-12-11 21:15:13 +00:00
|
|
|
#define GR_DECLARE_XP_FACTORY_TEST \
|
|
|
|
static GrProcessorTestFactory<GrXPFactory> gTestFactory SK_UNUSED; \
|
2015-08-29 01:46:56 +00:00
|
|
|
static const GrXPFactory* TestCreate(GrProcessorTestData*)
|
2014-12-11 21:15:13 +00:00
|
|
|
|
2014-09-23 16:50:21 +00:00
|
|
|
/** GrProcessor subclasses should insert this macro in their implementation file. They must then
|
|
|
|
* also implement this static function:
|
2015-07-08 21:26:19 +00:00
|
|
|
* GrProcessor* TestCreate(GrProcessorTestData*);
|
2014-09-23 16:50:21 +00:00
|
|
|
*/
|
|
|
|
#define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Effect) \
|
|
|
|
GrProcessorTestFactory<GrFragmentProcessor> Effect :: gTestFactory(Effect :: TestCreate)
|
|
|
|
|
2014-12-11 21:15:13 +00:00
|
|
|
#define GR_DEFINE_XP_FACTORY_TEST(Factory) \
|
|
|
|
GrProcessorTestFactory<GrXPFactory> Factory :: gTestFactory(Factory :: TestCreate)
|
|
|
|
|
2014-09-23 16:50:21 +00:00
|
|
|
#define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(Effect) \
|
|
|
|
GrProcessorTestFactory<GrGeometryProcessor> Effect :: gTestFactory(Effect :: TestCreate)
|
|
|
|
|
|
|
|
#else // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
|
|
|
|
|
|
|
|
// The unit test relies on static initializers. Just declare the TestCreate function so that
|
|
|
|
// its definitions will compile.
|
|
|
|
#define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \
|
2015-08-29 01:46:56 +00:00
|
|
|
static const GrFragmentProcessor* TestCreate(GrProcessorTestData*)
|
2014-09-23 16:50:21 +00:00
|
|
|
#define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(X)
|
|
|
|
|
2014-12-11 21:15:13 +00:00
|
|
|
// The unit test relies on static initializers. Just declare the TestCreate function so that
|
|
|
|
// its definitions will compile.
|
|
|
|
#define GR_DECLARE_XP_FACTORY_TEST \
|
2015-08-29 01:46:56 +00:00
|
|
|
static const GrXPFactory* TestCreate(GrProcessorTestData*)
|
2014-12-11 21:15:13 +00:00
|
|
|
#define GR_DEFINE_XP_FACTORY_TEST(X)
|
|
|
|
|
2014-09-23 16:50:21 +00:00
|
|
|
// The unit test relies on static initializers. Just declare the TestCreate function so that
|
|
|
|
// its definitions will compile.
|
|
|
|
#define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \
|
2015-08-29 01:46:56 +00:00
|
|
|
static const GrGeometryProcessor* TestCreate(GrProcessorTestData*)
|
2014-09-23 16:50:21 +00:00
|
|
|
#define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X)
|
|
|
|
|
|
|
|
#endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
|
|
|
|
#endif
|