| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 // This is a GPU-backend specific test. It relies on static intializers to work | 9 // This is a GPU-backend specific test. It relies on static intializers to work |
| 10 | 10 |
| 11 #include "SkTypes.h" | 11 #include "SkTypes.h" |
| 12 | 12 |
| 13 #if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 13 #if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 14 | 14 |
| 15 #include "gl/GrGpuGL.h" | 15 #include "gl/GrGpuGL.h" |
| 16 #include "GrBackendEffectFactory.h" | 16 #include "GrBackendEffectFactory.h" |
| 17 #include "GrContextFactory.h" | 17 #include "GrContextFactory.h" |
| 18 #include "GrDrawEffect.h" | 18 #include "GrDrawEffect.h" |
| 19 #include "effects/GrConfigConversionEffect.h" | 19 #include "effects/GrConfigConversionEffect.h" |
| 20 | 20 |
| 21 #include "SkRandom.h" | 21 #include "SkRandom.h" |
| 22 #include "Test.h" | 22 #include "Test.h" |
| 23 | 23 |
| 24 void GrGLProgramDesc::setRandom(SkMWCRandom* random, | 24 void GrGLProgramDesc::setRandom(SkMWCRandom* random, |
| 25 const GrGpuGL* gpu, | 25 const GrGpuGL* gpu, |
| 26 const GrTexture* dstTexture, | 26 const GrTexture* dstTexture, |
| 27 const GrEffectStage stages[GrDrawState::kNumStag
es]) { | 27 const GrEffectStage stages[GrDrawState::kNumStag
es], |
| 28 fAttribBindings = 0; | 28 int currAttribIndex) { |
| 29 fEmitsPointSize = random->nextBool(); | 29 fEmitsPointSize = random->nextBool(); |
| 30 fColorInput = random->nextULessThan(kColorInputCnt); | 30 |
| 31 fCoverageInput = random->nextULessThan(kColorInputCnt); | 31 fPositionAttributeIndex = 0; |
| 32 |
| 33 // if the effects have used up all off the available attributes, |
| 34 // don't try to use color or coverage attributes as input |
| 35 do { |
| 36 fColorInput = random->nextULessThan(kColorInputCnt); |
| 37 } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex && |
| 38 kAttribute_ColorInput == fColorInput); |
| 39 fColorAttributeIndex = (fColorInput == kAttribute_ColorInput) ? currAttribIn
dex++ : -1; |
| 40 |
| 41 do { |
| 42 fCoverageInput = random->nextULessThan(kColorInputCnt); |
| 43 } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex && |
| 44 kAttribute_ColorInput == fCoverageInput); |
| 45 fCoverageAttributeIndex = (fCoverageInput == kAttribute_ColorInput) ? currAt
tribIndex++ : -1; |
| 32 | 46 |
| 33 fColorFilterXfermode = random->nextULessThan(SkXfermode::kCoeffModesCnt); | 47 fColorFilterXfermode = random->nextULessThan(SkXfermode::kCoeffModesCnt); |
| 34 | 48 |
| 35 fFirstCoverageStage = random->nextULessThan(GrDrawState::kNumStages); | 49 fFirstCoverageStage = random->nextULessThan(GrDrawState::kNumStages); |
| 36 | 50 |
| 37 fAttribBindings |= random->nextBool() ? GrDrawState::kCoverage_AttribBinding
sBit : 0; | |
| 38 | |
| 39 #if GR_GL_EXPERIMENTAL_GS | 51 #if GR_GL_EXPERIMENTAL_GS |
| 40 fExperimentalGS = gpu->caps()->geometryShaderSupport() && random->nextBool()
; | 52 fExperimentalGS = gpu->caps()->geometryShaderSupport() && random->nextBool()
; |
| 41 #endif | 53 #endif |
| 42 | 54 |
| 43 fDiscardIfZeroCoverage = random->nextBool(); | 55 fDiscardIfZeroCoverage = random->nextBool(); |
| 44 | 56 |
| 45 if (gpu->caps()->dualSourceBlendingSupport()) { | 57 if (gpu->caps()->dualSourceBlendingSupport()) { |
| 46 fDualSrcOutput = random->nextULessThan(kDualSrcOutputCnt); | 58 fDualSrcOutput = random->nextULessThan(kDualSrcOutputCnt); |
| 47 } else { | 59 } else { |
| 48 fDualSrcOutput = kNone_DualSrcOutput; | 60 fDualSrcOutput = kNone_DualSrcOutput; |
| 49 } | 61 } |
| 50 | 62 |
| 51 // use separate tex coords? | 63 bool useLocalCoords = random->nextBool() && currAttribIndex < GrDrawState::k
MaxVertexAttribCnt; |
| 52 if (random->nextBool()) { | 64 fLocalCoordAttributeIndex = useLocalCoords ? currAttribIndex++ : -1; |
| 53 fAttribBindings |= GrDrawState::kLocalCoords_AttribBindingsBit; | |
| 54 } | |
| 55 | 65 |
| 56 bool dstRead = false; | 66 bool dstRead = false; |
| 57 for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 67 for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| 58 if (NULL != stages[s].getEffect()) { | 68 if (NULL != stages[s].getEffect()) { |
| 59 const GrBackendEffectFactory& factory = (*stages[s].getEffect())->ge
tFactory(); | 69 const GrBackendEffectFactory& factory = (*stages[s].getEffect())->ge
tFactory(); |
| 60 bool explicitLocalCoords = (fAttribBindings & | 70 GrDrawEffect drawEffect(stages[s], useLocalCoords); |
| 61 GrDrawState::kLocalCoords_AttribBindings
Bit); | |
| 62 GrDrawEffect drawEffect(stages[s], explicitLocalCoords); | |
| 63 fEffectKeys[s] = factory.glEffectKey(drawEffect, gpu->glCaps()); | 71 fEffectKeys[s] = factory.glEffectKey(drawEffect, gpu->glCaps()); |
| 64 if ((*stages[s].getEffect())->willReadDst()) { | 72 if ((*stages[s].getEffect())->willReadDst()) { |
| 65 dstRead = true; | 73 dstRead = true; |
| 66 } | 74 } |
| 67 } | 75 } |
| 68 } | 76 } |
| 69 | 77 |
| 70 if (dstRead) { | 78 if (dstRead) { |
| 71 this->fDstRead = GrGLShaderBuilder::KeyForDstRead(dstTexture, gpu->glCap
s()); | 79 this->fDstRead = GrGLShaderBuilder::KeyForDstRead(dstTexture, gpu->glCap
s()); |
| 72 } | 80 } |
| 73 | |
| 74 int attributeIndex = 0; | |
| 75 fPositionAttributeIndex = attributeIndex; | |
| 76 ++attributeIndex; | |
| 77 if (fColorInput || (fAttribBindings & GrDrawState::kColor_AttribBindingsBit)
) { | |
| 78 fColorAttributeIndex = attributeIndex; | |
| 79 ++attributeIndex; | |
| 80 } | |
| 81 if (fCoverageInput || (fAttribBindings & GrDrawState::kCoverage_AttribBindin
gsBit)) { | |
| 82 fCoverageAttributeIndex = attributeIndex; | |
| 83 ++attributeIndex; | |
| 84 } | |
| 85 if (fAttribBindings & GrDrawState::kLocalCoords_AttribBindingsBit) { | |
| 86 fLocalCoordsAttributeIndex = attributeIndex; | |
| 87 ++attributeIndex; | |
| 88 } | |
| 89 } | 81 } |
| 90 | 82 |
| 91 bool GrGpuGL::programUnitTest(int maxStages) { | 83 bool GrGpuGL::programUnitTest(int maxStages) { |
| 92 | 84 |
| 93 maxStages = GrMin(maxStages, (int)GrDrawState::kNumStages); | 85 maxStages = GrMin(maxStages, (int)GrDrawState::kNumStages); |
| 94 | 86 |
| 95 GrTextureDesc dummyDesc; | 87 GrTextureDesc dummyDesc; |
| 96 dummyDesc.fConfig = kSkia8888_GrPixelConfig; | 88 dummyDesc.fConfig = kSkia8888_GrPixelConfig; |
| 97 dummyDesc.fWidth = 34; | 89 dummyDesc.fWidth = 34; |
| 98 dummyDesc.fHeight = 18; | 90 dummyDesc.fHeight = 18; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 111 GrPrintf("\nTest Program %d\n-------------\n", t); | 103 GrPrintf("\nTest Program %d\n-------------\n", t); |
| 112 static const int stop = -1; | 104 static const int stop = -1; |
| 113 if (t == stop) { | 105 if (t == stop) { |
| 114 int breakpointhere = 9; | 106 int breakpointhere = 9; |
| 115 } | 107 } |
| 116 #endif | 108 #endif |
| 117 | 109 |
| 118 GrGLProgramDesc pdesc; | 110 GrGLProgramDesc pdesc; |
| 119 GrEffectStage stages[GrDrawState::kNumStages]; | 111 GrEffectStage stages[GrDrawState::kNumStages]; |
| 120 | 112 |
| 121 int currAttribIndex = GrDrawState::kAttribIndexCount; | 113 int currAttribIndex = 1; // we need to always leave room for position |
| 122 int attribIndices[2]; | 114 int attribIndices[2]; |
| 123 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; | 115 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; |
| 124 for (int s = 0; s < maxStages; ++s) { | 116 for (int s = 0; s < maxStages; ++s) { |
| 125 // enable the stage? | 117 // enable the stage? |
| 126 if (random.nextBool()) { | 118 if (random.nextBool()) { |
| 127 SkAutoTUnref<const GrEffectRef> effect(GrEffectTestFactory::Crea
teStage( | 119 SkAutoTUnref<const GrEffectRef> effect(GrEffectTestFactory::Crea
teStage( |
| 128
&random, | 120
&random, |
| 129
this->getContext(), | 121
this->getContext(), |
| 130
*this->caps(), | 122
*this->caps(), |
| 131
dummyTextures)); | 123
dummyTextures)); |
| 132 int numAttribs = (*effect)->numVertexAttribs(); | 124 int numAttribs = (*effect)->numVertexAttribs(); |
| 133 | 125 |
| 134 // If adding this effect would cause to exceed the max attrib co
unt then generate a | 126 // If adding this effect would exceed the max attrib count then
generate a |
| 135 // new random effect. The explanation for why this check is corr
ect is a bit | 127 // new random effect. |
| 136 // convoluted and this code will be removed soon. | 128 if (currAttribIndex + numAttribs > GrDrawState::kMaxVertexAttrib
Cnt) { |
| 137 if (currAttribIndex + numAttribs > GrDrawState::kCoverageOverrid
eAttribIndexValue) { | |
| 138 --s; | 129 --s; |
| 139 continue; | 130 continue; |
| 140 } | 131 } |
| 141 for (int i = 0; i < numAttribs; ++i) { | 132 for (int i = 0; i < numAttribs; ++i) { |
| 142 attribIndices[i] = currAttribIndex++; | 133 attribIndices[i] = currAttribIndex++; |
| 143 } | 134 } |
| 144 stages[s].setEffect(effect.get(), attribIndices[0], attribIndice
s[1]); | 135 stages[s].setEffect(effect.get(), attribIndices[0], attribIndice
s[1]); |
| 145 } | 136 } |
| 146 } | 137 } |
| 147 const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dum
myTextures[1]; | 138 const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dum
myTextures[1]; |
| 148 pdesc.setRandom(&random, this, dstTexture, stages); | 139 pdesc.setRandom(&random, this, dstTexture, stages, currAttribIndex); |
| 149 | 140 |
| 150 const GrEffectStage* stagePtrs[GrDrawState::kNumStages]; | 141 const GrEffectStage* stagePtrs[GrDrawState::kNumStages]; |
| 151 for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 142 for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| 152 stagePtrs[s] = &stages[s]; | 143 stagePtrs[s] = &stages[s]; |
| 153 } | 144 } |
| 154 SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this->glContext(), | 145 SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this->glContext(), |
| 155 pdesc, | 146 pdesc, |
| 156 stagePtrs)); | 147 stagePtrs)); |
| 157 if (NULL == program.get()) { | 148 if (NULL == program.get()) { |
| 158 return false; | 149 return false; |
| 159 } | 150 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 SkMagnifierImageFilter mag(SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar
1); | 188 SkMagnifierImageFilter mag(SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar
1); |
| 198 GrConfigConversionEffect::Create(NULL, | 189 GrConfigConversionEffect::Create(NULL, |
| 199 false, | 190 false, |
| 200 GrConfigConversionEffect::kNone_PMConversio
n, | 191 GrConfigConversionEffect::kNone_PMConversio
n, |
| 201 SkMatrix::I()); | 192 SkMatrix::I()); |
| 202 SkScalar matrix[20]; | 193 SkScalar matrix[20]; |
| 203 SkColorMatrixFilter cmf(matrix); | 194 SkColorMatrixFilter cmf(matrix); |
| 204 } | 195 } |
| 205 | 196 |
| 206 #endif | 197 #endif |
| OLD | NEW |