| 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 "GrBackendEffectFactory.h" | 15 #include "GrBackendEffectFactory.h" |
| 16 #include "GrContextFactory.h" | 16 #include "GrContextFactory.h" |
| 17 #include "GrDrawEffect.h" | 17 #include "GrDrawEffect.h" |
| 18 #include "effects/GrConfigConversionEffect.h" | 18 #include "effects/GrConfigConversionEffect.h" |
| 19 #include "gl/GrGLPathRendering.h" | 19 #include "gl/GrGLPathRendering.h" |
| 20 #include "gl/GrGpuGL.h" | 20 #include "gl/GrGpuGL.h" |
| 21 #include "SkChecksum.h" | 21 #include "SkChecksum.h" |
| 22 #include "SkRandom.h" | 22 #include "SkRandom.h" |
| 23 #include "Test.h" | 23 #include "Test.h" |
| 24 | 24 |
| 25 bool GrGLProgramDesc::setRandom(SkRandom* random, | 25 bool GrGLProgramDesc::setRandom(SkRandom* random, |
| 26 const GrGpuGL* gpu, | 26 const GrGpuGL* gpu, |
| 27 const GrRenderTarget* dstRenderTarget, | 27 const GrRenderTarget* dstRenderTarget, |
| 28 const GrTexture* dstCopyTexture, | 28 const GrTexture* dstCopyTexture, |
| 29 const GrEffectStage* geometryProcessor, |
| 29 const GrEffectStage* stages[], | 30 const GrEffectStage* stages[], |
| 30 int numColorStages, | 31 int numColorStages, |
| 31 int numCoverageStages, | 32 int numCoverageStages, |
| 32 int currAttribIndex) { | 33 int currAttribIndex) { |
| 33 bool useLocalCoords = random->nextBool() && currAttribIndex < GrDrawState::k
MaxVertexAttribCnt; | 34 bool useLocalCoords = random->nextBool() && currAttribIndex < GrDrawState::k
MaxVertexAttribCnt; |
| 34 | 35 |
| 35 int numStages = numColorStages + numCoverageStages; | 36 int numStages = numColorStages + numCoverageStages; |
| 36 fKey.reset(); | 37 fKey.reset(); |
| 37 | 38 |
| 38 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); | 39 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); |
| 39 | 40 |
| 40 // Make room for everything up to and including the array of offsets to effe
ct keys. | 41 // Make room for everything up to and including the array of offsets to effe
ct keys. |
| 41 fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_t) * n
umStages); | 42 fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_t) * (
numStages + |
| 43 (geometryProcessor ? 1 : 0))); |
| 42 | 44 |
| 43 bool dstRead = false; | 45 bool dstRead = false; |
| 44 bool fragPos = false; | 46 bool fragPos = false; |
| 45 bool vertexShader = false; | 47 bool vertexShader = (NULL != geometryProcessor); |
| 46 for (int s = 0; s < numStages; ++s) { | 48 int offset = 0; |
| 49 if (NULL != geometryProcessor) { |
| 50 const GrEffectStage* stage = geometryProcessor; |
| 47 uint16_t* offsetAndSize = reinterpret_cast<uint16_t*>(fKey.begin() + | 51 uint16_t* offsetAndSize = reinterpret_cast<uint16_t*>(fKey.begin() + |
| 48 kEffectKeyOffsetsA
ndLengthOffset + | 52 kEffectKeyOffsetsA
ndLengthOffset + |
| 49 s * 2 * sizeof(uin
t16_t)); | 53 offset * 2 * sizeo
f(uint16_t)); |
| 50 uint32_t effectKeyOffset = fKey.count(); | 54 uint32_t effectKeyOffset = fKey.count(); |
| 51 if (effectKeyOffset > SK_MaxU16) { | 55 if (effectKeyOffset > SK_MaxU16) { |
| 52 fKey.reset(); | 56 fKey.reset(); |
| 53 return false; | 57 return false; |
| 54 } | 58 } |
| 55 GrDrawEffect drawEffect(*stages[s], useLocalCoords); | 59 GrDrawEffect drawEffect(*stage, useLocalCoords); |
| 56 GrEffectKeyBuilder b(&fKey); | 60 GrEffectKeyBuilder b(&fKey); |
| 57 uint16_t effectKeySize; | 61 uint16_t effectKeySize; |
| 58 if (!GetEffectKeyAndUpdateStats(*stages[s], gpu->glCaps(), useLocalCoord
s, &b, | 62 if (!GetEffectKeyAndUpdateStats(*stage, gpu->glCaps(), useLocalCoords, &
b, |
| 59 &effectKeySize, &dstRead, &fragPos, &ver
texShader)) { | 63 &effectKeySize, &dstRead, &fragPos, &ver
texShader)) { |
| 60 fKey.reset(); | 64 fKey.reset(); |
| 61 return false; | 65 return false; |
| 66 } |
| 67 offsetAndSize[0] = effectKeyOffset; |
| 68 offsetAndSize[1] = effectKeySize; |
| 69 offset++; |
| 70 } |
| 71 |
| 72 for (int s = 0; s < numStages; ++s, ++offset) { |
| 73 const GrEffectStage* stage = stages[s]; |
| 74 uint16_t* offsetAndSize = reinterpret_cast<uint16_t*>(fKey.begin() + |
| 75 kEffectKeyOffsetsA
ndLengthOffset + |
| 76 offset * 2 * sizeo
f(uint16_t)); |
| 77 uint32_t effectKeyOffset = fKey.count(); |
| 78 if (effectKeyOffset > SK_MaxU16) { |
| 79 fKey.reset(); |
| 80 return false; |
| 81 } |
| 82 GrDrawEffect drawEffect(*stage, useLocalCoords); |
| 83 GrEffectKeyBuilder b(&fKey); |
| 84 uint16_t effectKeySize; |
| 85 if (!GetEffectKeyAndUpdateStats(*stage, gpu->glCaps(), useLocalCoords, &
b, |
| 86 &effectKeySize, &dstRead, &fragPos, &ver
texShader)) { |
| 87 fKey.reset(); |
| 88 return false; |
| 62 } | 89 } |
| 63 offsetAndSize[0] = effectKeyOffset; | 90 offsetAndSize[0] = effectKeyOffset; |
| 64 offsetAndSize[1] = effectKeySize; | 91 offsetAndSize[1] = effectKeySize; |
| 65 } | 92 } |
| 66 | 93 |
| 67 KeyHeader* header = this->header(); | 94 KeyHeader* header = this->header(); |
| 68 memset(header, 0, kHeaderSize); | 95 memset(header, 0, kHeaderSize); |
| 69 header->fEmitsPointSize = random->nextBool(); | 96 header->fEmitsPointSize = random->nextBool(); |
| 70 | 97 |
| 71 header->fPositionAttributeIndex = 0; | 98 header->fPositionAttributeIndex = 0; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 header->fFragPosKey = SkToU8(GrGLFragmentShaderBuilder::KeyForFragmentPo
sition(dstRenderTarget, | 138 header->fFragPosKey = SkToU8(GrGLFragmentShaderBuilder::KeyForFragmentPo
sition(dstRenderTarget, |
| 112 g
pu->glCaps())); | 139 g
pu->glCaps())); |
| 113 } else { | 140 } else { |
| 114 header->fFragPosKey = 0; | 141 header->fFragPosKey = 0; |
| 115 } | 142 } |
| 116 | 143 |
| 117 header->fRequiresVertexShader = vertexShader || | 144 header->fRequiresVertexShader = vertexShader || |
| 118 useLocalCoords || | 145 useLocalCoords || |
| 119 kAttribute_ColorInput == header->fColorInput
|| | 146 kAttribute_ColorInput == header->fColorInput
|| |
| 120 kAttribute_ColorInput == header->fCoverageIn
put; | 147 kAttribute_ColorInput == header->fCoverageIn
put; |
| 148 header->fHasGeometryProcessor = vertexShader; |
| 121 | 149 |
| 122 CoverageOutput coverageOutput; | 150 CoverageOutput coverageOutput; |
| 123 bool illegalCoverageOutput; | 151 bool illegalCoverageOutput; |
| 124 do { | 152 do { |
| 125 coverageOutput = static_cast<CoverageOutput>(random->nextULessThan(kCove
rageOutputCnt)); | 153 coverageOutput = static_cast<CoverageOutput>(random->nextULessThan(kCove
rageOutputCnt)); |
| 126 illegalCoverageOutput = (!gpu->caps()->dualSourceBlendingSupport() && | 154 illegalCoverageOutput = (!gpu->caps()->dualSourceBlendingSupport() && |
| 127 CoverageOutputUsesSecondaryOutput(coverageOutpu
t)) || | 155 CoverageOutputUsesSecondaryOutput(coverageOutpu
t)) || |
| 128 (!dstRead && kCombineWithDst_CoverageOutput == c
overageOutput); | 156 (!dstRead && kCombineWithDst_CoverageOutput == c
overageOutput); |
| 129 } while (illegalCoverageOutput); | 157 } while (illegalCoverageOutput); |
| 130 | 158 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 int attribIndices[2] = { 0, 0 }; | 200 int attribIndices[2] = { 0, 0 }; |
| 173 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; | 201 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; |
| 174 | 202 |
| 175 int numStages = random.nextULessThan(maxStages + 1); | 203 int numStages = random.nextULessThan(maxStages + 1); |
| 176 int numColorStages = random.nextULessThan(numStages + 1); | 204 int numColorStages = random.nextULessThan(numStages + 1); |
| 177 int numCoverageStages = numStages - numColorStages; | 205 int numCoverageStages = numStages - numColorStages; |
| 178 | 206 |
| 179 SkAutoSTMalloc<8, const GrEffectStage*> stages(numStages); | 207 SkAutoSTMalloc<8, const GrEffectStage*> stages(numStages); |
| 180 | 208 |
| 181 bool useFixedFunctionPathRendering = this->glCaps().pathRenderingSupport
() && | 209 bool useFixedFunctionPathRendering = this->glCaps().pathRenderingSupport
() && |
| 182 this->glPathRendering()->texturingMode() == GrGLPathRendering::Fixed
Function_TexturingMode; | 210 this->glPathRendering()->texturingMode() == GrGLPathRendering::Fixed
Function_TexturingMode && |
| 211 random.nextBool(); |
| 183 | 212 |
| 213 SkAutoTDelete<GrEffectStage> geometryProcessor; |
| 214 bool hasGeometryProcessor = useFixedFunctionPathRendering ? false : rand
om.nextBool(); |
| 215 if (hasGeometryProcessor) { |
| 216 while (true) { |
| 217 SkAutoTUnref<const GrEffect> effect(GrEffectTestFactory::CreateS
tage( |
| 218
&random, |
| 219
this->getContext(), |
| 220
*this->caps(), |
| 221
dummyTextures)); |
| 222 SkASSERT(effect); |
| 223 |
| 224 // Only geometryProcessor can use vertex shader |
| 225 if (!effect->requiresVertexShader()) { |
| 226 continue; |
| 227 } |
| 228 |
| 229 int numAttribs = effect->numVertexAttribs(); |
| 230 for (int i = 0; i < numAttribs; ++i) { |
| 231 attribIndices[i] = currAttribIndex++; |
| 232 } |
| 233 GrEffectStage* stage = SkNEW_ARGS(GrEffectStage, |
| 234 (effect.get(), attribIndices[0
], attribIndices[1])); |
| 235 geometryProcessor.reset(stage); |
| 236 break; |
| 237 } |
| 238 } |
| 184 for (int s = 0; s < numStages;) { | 239 for (int s = 0; s < numStages;) { |
| 185 SkAutoTUnref<const GrEffect> effect(GrEffectTestFactory::CreateStage
( | 240 SkAutoTUnref<const GrEffect> effect(GrEffectTestFactory::CreateStage
( |
| 186 &ran
dom, | 241 &ran
dom, |
| 187 this
->getContext(), | 242 this
->getContext(), |
| 188 *thi
s->caps(), | 243 *thi
s->caps(), |
| 189 dumm
yTextures)); | 244 dumm
yTextures)); |
| 190 SkASSERT(effect); | 245 SkASSERT(effect); |
| 191 int numAttribs = effect->numVertexAttribs(); | |
| 192 | 246 |
| 193 // If adding this effect would exceed the max attrib count then gene
rate a | 247 // Only geometryProcessor can use vertex shader |
| 194 // new random effect. | 248 if (effect->requiresVertexShader()) { |
| 195 if (currAttribIndex + numAttribs > GrDrawState::kMaxVertexAttribCnt)
{ | |
| 196 continue; | 249 continue; |
| 197 } | 250 } |
| 198 | 251 |
| 199 | |
| 200 // If adding this effect would exceed the max texture coord set coun
t then generate a | 252 // If adding this effect would exceed the max texture coord set coun
t then generate a |
| 201 // new random effect. | 253 // new random effect. |
| 202 if (useFixedFunctionPathRendering && !effect->requiresVertexShader()
) { | 254 if (useFixedFunctionPathRendering) { |
| 203 int numTransforms = effect->numTransforms(); | 255 int numTransforms = effect->numTransforms(); |
| 204 if (currTextureCoordSet + numTransforms > this->glCaps().maxFixe
dFunctionTextureCoords()) { | 256 if (currTextureCoordSet + numTransforms > this->glCaps().maxFixe
dFunctionTextureCoords()) { |
| 205 continue; | 257 continue; |
| 206 } | 258 } |
| 207 currTextureCoordSet += numTransforms; | 259 currTextureCoordSet += numTransforms; |
| 208 } | 260 } |
| 209 | |
| 210 useFixedFunctionPathRendering = useFixedFunctionPathRendering && !ef
fect->requiresVertexShader(); | |
| 211 | |
| 212 for (int i = 0; i < numAttribs; ++i) { | |
| 213 attribIndices[i] = currAttribIndex++; | |
| 214 } | |
| 215 GrEffectStage* stage = SkNEW_ARGS(GrEffectStage, | 261 GrEffectStage* stage = SkNEW_ARGS(GrEffectStage, |
| 216 (effect.get(), attribIndices[0], a
ttribIndices[1])); | 262 (effect.get(), attribIndices[0], a
ttribIndices[1])); |
| 263 |
| 217 stages[s] = stage; | 264 stages[s] = stage; |
| 218 ++s; | 265 ++s; |
| 219 } | 266 } |
| 220 const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dum
myTextures[1]; | 267 const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dum
myTextures[1]; |
| 221 if (!pdesc.setRandom(&random, | 268 if (!pdesc.setRandom(&random, |
| 222 this, | 269 this, |
| 223 dummyTextures[0]->asRenderTarget(), | 270 dummyTextures[0]->asRenderTarget(), |
| 224 dstTexture, | 271 dstTexture, |
| 272 geometryProcessor.get(), |
| 225 stages.get(), | 273 stages.get(), |
| 226 numColorStages, | 274 numColorStages, |
| 227 numCoverageStages, | 275 numCoverageStages, |
| 228 currAttribIndex)) { | 276 currAttribIndex)) { |
| 229 return false; | 277 return false; |
| 230 } | 278 } |
| 231 | 279 |
| 232 SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this, | 280 SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this, |
| 233 pdesc, | 281 pdesc, |
| 282 geometryProcessor.
get(), |
| 234 stages, | 283 stages, |
| 235 stages + numColorS
tages)); | 284 stages + numColorS
tages)); |
| 236 for (int s = 0; s < numStages; ++s) { | 285 for (int s = 0; s < numStages; ++s) { |
| 237 SkDELETE(stages[s]); | 286 SkDELETE(stages[s]); |
| 238 } | 287 } |
| 239 if (NULL == program.get()) { | 288 if (NULL == program.get()) { |
| 240 return false; | 289 return false; |
| 241 } | 290 } |
| 242 } | 291 } |
| 243 return true; | 292 return true; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1)); | 328 SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1)); |
| 280 GrConfigConversionEffect::Create(NULL, | 329 GrConfigConversionEffect::Create(NULL, |
| 281 false, | 330 false, |
| 282 GrConfigConversionEffect::kNone_PMConversio
n, | 331 GrConfigConversionEffect::kNone_PMConversio
n, |
| 283 SkMatrix::I()); | 332 SkMatrix::I()); |
| 284 SkScalar matrix[20]; | 333 SkScalar matrix[20]; |
| 285 SkAutoTUnref<SkColorMatrixFilter> cmf(SkColorMatrixFilter::Create(matrix)); | 334 SkAutoTUnref<SkColorMatrixFilter> cmf(SkColorMatrixFilter::Create(matrix)); |
| 286 } | 335 } |
| 287 | 336 |
| 288 #endif | 337 #endif |
| OLD | NEW |