2011-08-16 19:45:58 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2012-08-03 18:34:46 +04:00
|
|
|
// This is a GPU-backend specific test. It relies on static intializers to work
|
2012-08-02 18:03:32 +04:00
|
|
|
|
2012-08-03 18:54:45 +04:00
|
|
|
#include "SkTypes.h"
|
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
|
|
|
|
|
2012-05-31 19:07:19 +04:00
|
|
|
#include "gl/GrGpuGL.h"
|
2012-10-25 23:00:29 +04:00
|
|
|
#include "GrBackendEffectFactory.h"
|
2012-08-27 16:53:13 +04:00
|
|
|
#include "effects/GrConfigConversionEffect.h"
|
2012-08-07 21:36:29 +04:00
|
|
|
|
2012-11-22 02:38:36 +04:00
|
|
|
#include "SkRandom.h"
|
2012-08-02 22:11:43 +04:00
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2012-11-22 02:38:36 +04:00
|
|
|
// SkRandoms nextU() values have patterns in the low bits
|
2012-08-02 22:11:43 +04:00
|
|
|
// So using nextU() % array_count might never take some values.
|
2012-11-22 02:38:36 +04:00
|
|
|
int random_int(SkRandom* r, int count) {
|
2012-08-02 22:11:43 +04:00
|
|
|
return (int)(r->nextF() * count);
|
|
|
|
}
|
|
|
|
|
2012-11-22 02:38:36 +04:00
|
|
|
bool random_bool(SkRandom* r) {
|
2012-08-02 22:11:43 +04:00
|
|
|
return r->nextF() > .5f;
|
|
|
|
}
|
|
|
|
|
2013-01-16 19:16:18 +04:00
|
|
|
const GrEffectRef* create_random_effect(SkRandom* random,
|
|
|
|
GrContext* context,
|
|
|
|
GrTexture* dummyTextures[]) {
|
2012-08-02 22:11:43 +04:00
|
|
|
|
2012-08-03 18:34:46 +04:00
|
|
|
SkRandom sk_random;
|
|
|
|
sk_random.setSeed(random->nextU());
|
2013-01-16 19:16:18 +04:00
|
|
|
GrEffectRef* effect = GrEffectTestFactory::CreateStage(&sk_random, context, dummyTextures);
|
2012-10-25 16:47:42 +04:00
|
|
|
GrAssert(effect);
|
|
|
|
return effect;
|
2012-08-02 22:11:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GrGpuGL::programUnitTest() {
|
|
|
|
|
2012-08-03 18:34:46 +04:00
|
|
|
GrTextureDesc dummyDesc;
|
|
|
|
dummyDesc.fConfig = kSkia8888_PM_GrPixelConfig;
|
|
|
|
dummyDesc.fWidth = 34;
|
|
|
|
dummyDesc.fHeight = 18;
|
|
|
|
SkAutoTUnref<GrTexture> dummyTexture1(this->createTexture(dummyDesc, NULL, 0));
|
|
|
|
dummyDesc.fConfig = kAlpha_8_GrPixelConfig;
|
|
|
|
dummyDesc.fWidth = 16;
|
|
|
|
dummyDesc.fHeight = 22;
|
|
|
|
SkAutoTUnref<GrTexture> dummyTexture2(this->createTexture(dummyDesc, NULL, 0));
|
|
|
|
|
2012-08-02 22:11:43 +04:00
|
|
|
static const int NUM_TESTS = 512;
|
|
|
|
|
2012-11-22 02:38:36 +04:00
|
|
|
SkRandom random;
|
2012-08-02 22:11:43 +04:00
|
|
|
for (int t = 0; t < NUM_TESTS; ++t) {
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
GrPrintf("\nTest Program %d\n-------------\n", t);
|
|
|
|
static const int stop = -1;
|
|
|
|
if (t == stop) {
|
|
|
|
int breakpointhere = 9;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ProgramDesc pdesc;
|
|
|
|
pdesc.fVertexLayout = 0;
|
|
|
|
pdesc.fEmitsPointSize = random.nextF() > .5f;
|
|
|
|
pdesc.fColorInput = random_int(&random, ProgramDesc::kColorInputCnt);
|
|
|
|
pdesc.fCoverageInput = random_int(&random, ProgramDesc::kColorInputCnt);
|
|
|
|
|
|
|
|
pdesc.fColorFilterXfermode = random_int(&random, SkXfermode::kCoeffModesCnt);
|
|
|
|
|
|
|
|
pdesc.fFirstCoverageStage = random_int(&random, GrDrawState::kNumStages);
|
|
|
|
|
|
|
|
pdesc.fVertexLayout |= random_bool(&random) ?
|
|
|
|
GrDrawTarget::kCoverage_VertexLayoutBit :
|
|
|
|
0;
|
|
|
|
|
|
|
|
#if GR_GL_EXPERIMENTAL_GS
|
2012-08-29 01:11:35 +04:00
|
|
|
pdesc.fExperimentalGS = this->getCaps().geometryShaderSupport() &&
|
2012-08-02 22:11:43 +04:00
|
|
|
random_bool(&random);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool edgeAA = random_bool(&random);
|
|
|
|
if (edgeAA) {
|
|
|
|
pdesc.fVertexLayout |= GrDrawTarget::kEdge_VertexLayoutBit;
|
2012-08-29 01:11:35 +04:00
|
|
|
if (this->getCaps().shaderDerivativeSupport()) {
|
2012-08-02 22:11:43 +04:00
|
|
|
pdesc.fVertexEdgeType = (GrDrawState::VertexEdgeType) random_int(&random, GrDrawState::kVertexEdgeTypeCnt);
|
2012-12-10 23:10:17 +04:00
|
|
|
pdesc.fDiscardIfOutsideEdge = random.nextBool();
|
2012-08-02 22:11:43 +04:00
|
|
|
} else {
|
|
|
|
pdesc.fVertexEdgeType = GrDrawState::kHairLine_EdgeType;
|
2012-12-10 23:10:17 +04:00
|
|
|
pdesc.fDiscardIfOutsideEdge = false;
|
2012-08-02 22:11:43 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
2012-08-29 01:11:35 +04:00
|
|
|
if (this->getCaps().dualSourceBlendingSupport()) {
|
2012-08-02 22:11:43 +04:00
|
|
|
pdesc.fDualSrcOutput = random_int(&random, ProgramDesc::kDualSrcOutputCnt);
|
|
|
|
} else {
|
|
|
|
pdesc.fDualSrcOutput = ProgramDesc::kNone_DualSrcOutput;
|
|
|
|
}
|
|
|
|
|
2012-10-29 23:51:22 +04:00
|
|
|
GrEffectStage stages[GrDrawState::kNumStages];
|
2012-08-02 22:11:43 +04:00
|
|
|
|
|
|
|
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
|
|
|
|
// enable the stage?
|
|
|
|
if (random_bool(&random)) {
|
|
|
|
// use separate tex coords?
|
|
|
|
if (random_bool(&random)) {
|
|
|
|
int t = random_int(&random, GrDrawState::kMaxTexCoords);
|
|
|
|
pdesc.fVertexLayout |= StageTexCoordVertexLayoutBit(s, t);
|
|
|
|
}
|
2012-11-05 20:36:02 +04:00
|
|
|
// use text-formatted verts?
|
|
|
|
if (random_bool(&random)) {
|
|
|
|
pdesc.fVertexLayout |= kTextFormat_VertexLayoutBit;
|
|
|
|
}
|
2012-08-02 22:11:43 +04:00
|
|
|
|
2012-08-03 18:34:46 +04:00
|
|
|
GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
|
2013-01-16 19:16:18 +04:00
|
|
|
SkAutoTUnref<const GrEffectRef> effect(create_random_effect(&random,
|
2012-11-05 20:36:02 +04:00
|
|
|
getContext(),
|
|
|
|
dummyTextures));
|
2012-10-29 23:51:22 +04:00
|
|
|
stages[s].setEffect(effect.get());
|
|
|
|
if (NULL != stages[s].getEffect()) {
|
2012-11-05 20:36:02 +04:00
|
|
|
pdesc.fEffectKeys[s] =
|
2013-01-22 23:55:59 +04:00
|
|
|
(*stages[s].getEffect())->getFactory().glEffectKey(stages[s],
|
|
|
|
this->glCaps());
|
2012-08-02 22:11:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-29 23:51:22 +04:00
|
|
|
const GrEffectStage* stagePtrs[GrDrawState::kNumStages];
|
|
|
|
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
|
|
|
|
stagePtrs[s] = &stages[s];
|
|
|
|
}
|
2012-08-02 22:11:43 +04:00
|
|
|
SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this->glContextInfo(),
|
|
|
|
pdesc,
|
2012-10-29 23:51:22 +04:00
|
|
|
stagePtrs));
|
2012-08-02 22:11:43 +04:00
|
|
|
if (NULL == program.get()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-08-16 19:45:58 +04:00
|
|
|
|
|
|
|
static void GLProgramsTest(skiatest::Reporter* reporter, GrContext* context) {
|
2012-05-31 19:07:19 +04:00
|
|
|
GrGpuGL* shadersGpu = static_cast<GrGpuGL*>(context->getGpu());
|
2011-08-16 19:45:58 +04:00
|
|
|
REPORTER_ASSERT(reporter, shadersGpu->programUnitTest());
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "TestClassDef.h"
|
|
|
|
DEFINE_GPUTESTCLASS("GLPrograms", GLProgramsTestClass, GLProgramsTest)
|
|
|
|
|
2012-08-23 22:14:13 +04:00
|
|
|
// This is evil evil evil. The linker may throw away whole translation units as dead code if it
|
2012-10-17 17:36:14 +04:00
|
|
|
// thinks none of the functions are called. It will do this even if there are static initializers
|
2012-08-07 21:36:29 +04:00
|
|
|
// in the unit that could pass pointers to functions from the unit out to other translation units!
|
|
|
|
// We force some of the effects that would otherwise be discarded to link here.
|
|
|
|
|
|
|
|
#include "SkLightingImageFilter.h"
|
2012-08-13 18:22:17 +04:00
|
|
|
#include "SkMagnifierImageFilter.h"
|
2012-10-17 17:36:14 +04:00
|
|
|
#include "SkColorMatrixFilter.h"
|
2012-08-07 21:36:29 +04:00
|
|
|
|
|
|
|
void forceLinking();
|
|
|
|
|
|
|
|
void forceLinking() {
|
|
|
|
SkLightingImageFilter::CreateDistantLitDiffuse(SkPoint3(0,0,0), 0, 0, 0);
|
2012-08-13 18:22:17 +04:00
|
|
|
SkMagnifierImageFilter mag(SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1);
|
2012-11-01 21:02:46 +04:00
|
|
|
GrEffectStage dummyStage;
|
|
|
|
GrConfigConversionEffect::InstallEffect(NULL,
|
|
|
|
false,
|
|
|
|
GrConfigConversionEffect::kNone_PMConversion,
|
2012-11-01 22:02:54 +04:00
|
|
|
SkMatrix::I(),
|
2012-11-01 21:02:46 +04:00
|
|
|
&dummyStage);
|
2012-10-17 17:36:14 +04:00
|
|
|
SkScalar matrix[20];
|
|
|
|
SkColorMatrixFilter cmf(matrix);
|
2012-08-07 21:36:29 +04:00
|
|
|
}
|
|
|
|
|
2012-08-02 18:03:32 +04:00
|
|
|
#endif
|