2012-08-03 14:34:46 +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.
|
|
|
|
*/
|
|
|
|
|
2012-10-24 19:07:10 +00:00
|
|
|
#ifndef GrEffectUnitTest_DEFINED
|
|
|
|
#define GrEffectUnitTest_DEFINED
|
2012-08-03 14:34:46 +00:00
|
|
|
|
2013-03-25 18:19:00 +00:00
|
|
|
#include "SkRandom.h"
|
2012-08-03 14:54:45 +00:00
|
|
|
#include "SkTArray.h"
|
2013-09-18 13:00:55 +00:00
|
|
|
#include "SkTypes.h"
|
2012-08-03 14:34:46 +00:00
|
|
|
|
2012-11-01 17:02:46 +00:00
|
|
|
class SkMatrix;
|
2013-03-25 18:19:00 +00:00
|
|
|
class GrDrawTargetCaps;
|
2012-11-01 17:02:46 +00:00
|
|
|
|
2012-10-24 19:07:10 +00:00
|
|
|
namespace GrEffectUnitTest {
|
2012-08-03 18:49:51 +00:00
|
|
|
// Used to access the dummy textures in TestCreate procs.
|
|
|
|
enum {
|
|
|
|
kSkiaPMTextureIdx = 0,
|
|
|
|
kAlphaTextureIdx = 1,
|
|
|
|
};
|
2012-11-01 17:02:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A helper for use in GrEffect::TestCreate functions.
|
|
|
|
*/
|
2013-09-09 20:09:12 +00:00
|
|
|
const SkMatrix& TestMatrix(SkRandom*);
|
2012-11-01 17:02:46 +00:00
|
|
|
|
2012-08-03 18:49:51 +00:00
|
|
|
}
|
|
|
|
|
2012-08-03 14:34:46 +00:00
|
|
|
#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
|
|
|
|
|
|
|
|
class GrContext;
|
2013-01-16 15:16:18 +00:00
|
|
|
class GrEffectRef;
|
2012-08-03 14:34:46 +00:00
|
|
|
class GrTexture;
|
|
|
|
|
2013-09-18 13:00:55 +00:00
|
|
|
class GrEffectTestFactory : public SkNoncopyable {
|
2012-08-03 14:34:46 +00:00
|
|
|
public:
|
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
typedef GrEffectRef* (*CreateProc)(SkRandom*,
|
2013-03-25 18:19:00 +00:00
|
|
|
GrContext*,
|
|
|
|
const GrDrawTargetCaps& caps,
|
|
|
|
GrTexture* dummyTextures[]);
|
2012-08-03 14:34:46 +00:00
|
|
|
|
2012-10-24 18:28:34 +00:00
|
|
|
GrEffectTestFactory(CreateProc createProc) {
|
2012-08-03 14:34:46 +00:00
|
|
|
fCreateProc = createProc;
|
|
|
|
GetFactories()->push_back(this);
|
|
|
|
}
|
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
static GrEffectRef* CreateStage(SkRandom* random,
|
2013-01-16 15:16:18 +00:00
|
|
|
GrContext* context,
|
2013-03-25 18:19:00 +00:00
|
|
|
const GrDrawTargetCaps& caps,
|
2013-01-16 15:16:18 +00:00
|
|
|
GrTexture* dummyTextures[]) {
|
2012-08-03 14:34:46 +00:00
|
|
|
uint32_t idx = random->nextRangeU(0, GetFactories()->count() - 1);
|
2012-10-24 18:28:34 +00:00
|
|
|
GrEffectTestFactory* factory = (*GetFactories())[idx];
|
2013-03-25 18:19:00 +00:00
|
|
|
return factory->fCreateProc(random, context, caps, dummyTextures);
|
2012-08-03 14:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CreateProc fCreateProc;
|
2012-10-24 18:28:34 +00:00
|
|
|
static SkTArray<GrEffectTestFactory*, true>* GetFactories();
|
2012-08-03 14:34:46 +00:00
|
|
|
};
|
|
|
|
|
2012-10-24 18:28:34 +00:00
|
|
|
/** GrEffect subclasses should insert this macro in their declaration to be included in the
|
2012-08-03 14:34:46 +00:00
|
|
|
* program generation unit test.
|
|
|
|
*/
|
2012-10-24 19:35:13 +00:00
|
|
|
#define GR_DECLARE_EFFECT_TEST \
|
|
|
|
static GrEffectTestFactory gTestFactory; \
|
2014-02-08 19:31:05 +00:00
|
|
|
static GrEffectRef* TestCreate(SkRandom*, \
|
2013-03-25 18:19:00 +00:00
|
|
|
GrContext*, \
|
|
|
|
const GrDrawTargetCaps&, \
|
|
|
|
GrTexture* dummyTextures[2])
|
2012-08-03 14:34:46 +00:00
|
|
|
|
2012-11-01 17:02:46 +00:00
|
|
|
/** GrEffect subclasses should insert this macro in their implementation file. They must then
|
2012-08-03 14:34:46 +00:00
|
|
|
* also implement this static function:
|
2013-09-09 20:09:12 +00:00
|
|
|
* GrEffect* TestCreate(SkRandom*,
|
2013-03-25 18:19:00 +00:00
|
|
|
* GrContext*,
|
|
|
|
* const GrDrawTargetCaps&,
|
|
|
|
* GrTexture* dummyTextures[2]);
|
2012-11-01 17:02:46 +00:00
|
|
|
* dummyTextures[] are valid textures that can optionally be used to construct GrTextureAccesses.
|
2013-02-07 14:43:04 +00:00
|
|
|
* The first texture has config kSkia8888_GrPixelConfig and the second has
|
2012-11-01 17:02:46 +00:00
|
|
|
* kAlpha_8_GrPixelConfig. TestCreate functions are also free to create additional textures using
|
|
|
|
* the GrContext.
|
2012-08-03 14:34:46 +00:00
|
|
|
*/
|
2012-10-24 19:35:13 +00:00
|
|
|
#define GR_DEFINE_EFFECT_TEST(Effect) \
|
|
|
|
GrEffectTestFactory Effect :: gTestFactory(Effect :: TestCreate)
|
2012-08-03 14:34:46 +00:00
|
|
|
|
|
|
|
#else // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
|
|
|
|
|
|
|
|
// The unit test relies on static initializers. Just declare the TestCreate function so that
|
|
|
|
// its definitions will compile.
|
2013-03-25 18:19:00 +00:00
|
|
|
#define GR_DECLARE_EFFECT_TEST \
|
2014-02-08 19:31:05 +00:00
|
|
|
static GrEffectRef* TestCreate(SkRandom*, \
|
2013-03-25 18:19:00 +00:00
|
|
|
GrContext*, \
|
|
|
|
const GrDrawTargetCaps&, \
|
|
|
|
GrTexture* dummyTextures[2])
|
2012-10-24 19:35:13 +00:00
|
|
|
#define GR_DEFINE_EFFECT_TEST(X)
|
2012-08-03 14:34:46 +00:00
|
|
|
|
|
|
|
#endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
|
2012-08-06 14:37:22 +00:00
|
|
|
#endif
|