| 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 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 } | 28 } |
| 29 if (stage.getEffect()->willReadFragmentPosition()) { | 29 if (stage.getEffect()->willReadFragmentPosition()) { |
| 30 *readsFragPosition = true; | 30 *readsFragPosition = true; |
| 31 } | 31 } |
| 32 if (stage.getEffect()->requiresVertexShader()) { | 32 if (stage.getEffect()->requiresVertexShader()) { |
| 33 *requiresVertexShader = true; | 33 *requiresVertexShader = true; |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 | 36 |
| 37 bool GrGLProgramDesc::setRandom(SkRandom* random, | 37 bool GrGLProgramDesc::setRandom(SkRandom* random, |
| 38 const GrGpuGL* gpu, | 38 GrGpuGL* gpu, |
| 39 const GrRenderTarget* dstRenderTarget, | 39 const GrRenderTarget* dstRenderTarget, |
| 40 const GrTexture* dstCopyTexture, | 40 const GrTexture* dstCopyTexture, |
| 41 const GrEffectStage* geometryProcessor, | 41 const GrEffectStage* geometryProcessor, |
| 42 const GrEffectStage* stages[], | 42 const GrEffectStage* stages[], |
| 43 int numColorStages, | 43 int numColorStages, |
| 44 int numCoverageStages, | 44 int numCoverageStages, |
| 45 int currAttribIndex) { | 45 int currAttribIndex, |
| 46 bool useLocalCoords = random->nextBool() && currAttribIndex < GrDrawState::k
MaxVertexAttribCnt; | 46 GrGpu::DrawType drawType) { |
| 47 bool isPathRendering = GrGpu::IsPathRenderingDrawType(drawType); |
| 48 bool useLocalCoords = !isPathRendering && |
| 49 random->nextBool() && |
| 50 currAttribIndex < GrDrawState::kMaxVertexAttribCnt; |
| 47 | 51 |
| 48 int numStages = numColorStages + numCoverageStages; | 52 int numStages = numColorStages + numCoverageStages; |
| 49 fKey.reset(); | 53 fKey.reset(); |
| 50 | 54 |
| 51 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); | 55 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); |
| 52 | 56 |
| 53 // Make room for everything up to and including the array of offsets to effe
ct keys. | 57 // Make room for everything up to and including the array of offsets to effe
ct keys. |
| 54 fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_t) * (
numStages + | 58 fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_t) * (
numStages + |
| 55 (geometryProcessor ? 1 : 0))); | 59 (geometryProcessor ? 1 : 0))); |
| 56 | 60 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 107 |
| 104 KeyHeader* header = this->header(); | 108 KeyHeader* header = this->header(); |
| 105 memset(header, 0, kHeaderSize); | 109 memset(header, 0, kHeaderSize); |
| 106 header->fEmitsPointSize = random->nextBool(); | 110 header->fEmitsPointSize = random->nextBool(); |
| 107 | 111 |
| 108 header->fPositionAttributeIndex = 0; | 112 header->fPositionAttributeIndex = 0; |
| 109 | 113 |
| 110 // if the effects have used up all off the available attributes, | 114 // if the effects have used up all off the available attributes, |
| 111 // don't try to use color or coverage attributes as input | 115 // don't try to use color or coverage attributes as input |
| 112 do { | 116 do { |
| 113 uint32_t colorRand = random->nextULessThan(2); | 117 header->fColorInput = static_cast<GrGLProgramDesc::ColorInput>( |
| 114 header->fColorInput = (0 == colorRand) ? GrGLProgramDesc::kAttribute_Col
orInput : | 118 random->nextULessThan(kColorInputCnt)); |
| 115 GrGLProgramDesc::kUniform_Color
Input; | 119 } while ((GrDrawState::kMaxVertexAttribCnt <= currAttribIndex || isPathRende
ring) && |
| 116 } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex && | |
| 117 kAttribute_ColorInput == header->fColorInput); | 120 kAttribute_ColorInput == header->fColorInput); |
| 118 | |
| 119 header->fColorAttributeIndex = (header->fColorInput == kAttribute_ColorInput
) ? | 121 header->fColorAttributeIndex = (header->fColorInput == kAttribute_ColorInput
) ? |
| 120 currAttribIndex++ : | 122 currAttribIndex++ : |
| 121 -1; | 123 -1; |
| 122 | 124 |
| 123 do { | 125 do { |
| 124 header->fCoverageInput = static_cast<GrGLProgramDesc::ColorInput>( | 126 header->fCoverageInput = static_cast<GrGLProgramDesc::ColorInput>( |
| 125 random->nextULessThan(kColorInputCnt)); | 127 random->nextULessThan(kColorInputCnt)); |
| 126 } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex && | 128 } while ((GrDrawState::kMaxVertexAttribCnt <= currAttribIndex || isPathRende
ring) && |
| 127 kAttribute_ColorInput == header->fCoverageInput); | 129 kAttribute_ColorInput == header->fCoverageInput); |
| 128 header->fCoverageAttributeIndex = (header->fCoverageInput == kAttribute_Colo
rInput) ? | 130 header->fCoverageAttributeIndex = (header->fCoverageInput == kAttribute_Colo
rInput) ? |
| 129 currAttribIndex++ : | 131 currAttribIndex++ : |
| 130 -1; | 132 -1; |
| 131 bool useGS = random->nextBool(); | 133 bool useGS = random->nextBool(); |
| 132 #if GR_GL_EXPERIMENTAL_GS | 134 #if GR_GL_EXPERIMENTAL_GS |
| 133 header->fExperimentalGS = gpu->caps()->geometryShaderSupport() && useGS; | 135 header->fExperimentalGS = gpu->caps()->geometryShaderSupport() && useGS; |
| 134 #else | 136 #else |
| 135 (void) useGS; | 137 (void) useGS; |
| 136 #endif | 138 #endif |
| 137 | 139 |
| 138 header->fLocalCoordAttributeIndex = useLocalCoords ? currAttribIndex++ : -1; | 140 header->fLocalCoordAttributeIndex = useLocalCoords ? currAttribIndex++ : -1; |
| 139 | 141 |
| 140 header->fColorEffectCnt = numColorStages; | 142 header->fColorEffectCnt = numColorStages; |
| 141 header->fCoverageEffectCnt = numCoverageStages; | 143 header->fCoverageEffectCnt = numCoverageStages; |
| 142 | 144 |
| 143 if (dstRead) { | 145 if (dstRead) { |
| 144 header->fDstReadKey = SkToU8(GrGLFragmentShaderBuilder::KeyForDstRead(ds
tCopyTexture, | 146 header->fDstReadKey = SkToU8(GrGLFragmentShaderBuilder::KeyForDstRead(ds
tCopyTexture, |
| 145 gpu->glCap
s())); | 147 gpu->glCap
s())); |
| 146 } else { | 148 } else { |
| 147 header->fDstReadKey = 0; | 149 header->fDstReadKey = 0; |
| 148 } | 150 } |
| 149 if (fragPos) { | 151 if (fragPos) { |
| 150 header->fFragPosKey = SkToU8(GrGLFragmentShaderBuilder::KeyForFragmentPo
sition(dstRenderTarget, | 152 header->fFragPosKey = SkToU8(GrGLFragmentShaderBuilder::KeyForFragmentPo
sition(dstRenderTarget, |
| 151 g
pu->glCaps())); | 153 g
pu->glCaps())); |
| 152 } else { | 154 } else { |
| 153 header->fFragPosKey = 0; | 155 header->fFragPosKey = 0; |
| 154 } | 156 } |
| 155 | 157 |
| 156 header->fRequiresVertexShader = vertexShader || | 158 header->fUseFragShaderOnly = isPathRendering && gpu->glPathRendering()->text
uringMode() == |
| 157 useLocalCoords || | 159 GrGLPathRendering::FixedFunc
tion_TexturingMode; |
| 158 kAttribute_ColorInput == header->fColorInput
|| | |
| 159 kAttribute_ColorInput == header->fCoverageIn
put; | |
| 160 header->fHasGeometryProcessor = vertexShader; | 160 header->fHasGeometryProcessor = vertexShader; |
| 161 | 161 |
| 162 CoverageOutput coverageOutput; | 162 CoverageOutput coverageOutput; |
| 163 bool illegalCoverageOutput; | 163 bool illegalCoverageOutput; |
| 164 do { | 164 do { |
| 165 coverageOutput = static_cast<CoverageOutput>(random->nextULessThan(kCove
rageOutputCnt)); | 165 coverageOutput = static_cast<CoverageOutput>(random->nextULessThan(kCove
rageOutputCnt)); |
| 166 illegalCoverageOutput = (!gpu->caps()->dualSourceBlendingSupport() && | 166 illegalCoverageOutput = (!gpu->caps()->dualSourceBlendingSupport() && |
| 167 CoverageOutputUsesSecondaryOutput(coverageOutpu
t)) || | 167 CoverageOutputUsesSecondaryOutput(coverageOutpu
t)) || |
| 168 (!dstRead && kCombineWithDst_CoverageOutput == c
overageOutput); | 168 (!dstRead && kCombineWithDst_CoverageOutput == c
overageOutput); |
| 169 } while (illegalCoverageOutput); | 169 } while (illegalCoverageOutput); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 int currAttribIndex = 1; // we need to always leave room for position | 241 int currAttribIndex = 1; // we need to always leave room for position |
| 242 int currTextureCoordSet = 0; | 242 int currTextureCoordSet = 0; |
| 243 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; | 243 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; |
| 244 | 244 |
| 245 int numStages = random.nextULessThan(maxStages + 1); | 245 int numStages = random.nextULessThan(maxStages + 1); |
| 246 int numColorStages = random.nextULessThan(numStages + 1); | 246 int numColorStages = random.nextULessThan(numStages + 1); |
| 247 int numCoverageStages = numStages - numColorStages; | 247 int numCoverageStages = numStages - numColorStages; |
| 248 | 248 |
| 249 SkAutoSTMalloc<8, const GrEffectStage*> stages(numStages); | 249 SkAutoSTMalloc<8, const GrEffectStage*> stages(numStages); |
| 250 | 250 |
| 251 bool useFixedFunctionPathRendering = this->glCaps().pathRenderingSupport
() && | 251 bool usePathRendering = this->glCaps().pathRenderingSupport() && random.
nextBool(); |
| 252 this->glPathRendering()->texturingMode() == GrGLPathRendering::Fixed
Function_TexturingMode && | 252 |
| 253 random.nextBool(); | 253 GrGpu::DrawType drawType = usePathRendering ? GrGpu::kDrawPath_DrawType
: |
| 254 GrGpu::kDrawPoints_DrawTyp
e; |
| 254 | 255 |
| 255 SkAutoTDelete<GrEffectStage> geometryProcessor; | 256 SkAutoTDelete<GrEffectStage> geometryProcessor; |
| 256 bool hasGeometryProcessor = useFixedFunctionPathRendering ? false : rand
om.nextBool(); | 257 bool hasGeometryProcessor = usePathRendering ? false : random.nextBool()
; |
| 257 if (hasGeometryProcessor) { | 258 if (hasGeometryProcessor) { |
| 258 while (true) { | 259 while (true) { |
| 259 SkAutoTUnref<const GrEffect> effect(GrEffectTestFactory::CreateS
tage( | 260 SkAutoTUnref<const GrEffect> effect(GrEffectTestFactory::CreateS
tage( |
| 260
&random, | 261
&random, |
| 261
this->getContext(), | 262
this->getContext(), |
| 262
*this->caps(), | 263
*this->caps(), |
| 263
dummyTextures)); | 264
dummyTextures)); |
| 264 SkASSERT(effect); | 265 SkASSERT(effect); |
| 265 // Only geometryProcessor can use vertex shader | 266 // Only geometryProcessor can use vertex shader |
| 266 if (!effect->requiresVertexShader()) { | 267 if (!effect->requiresVertexShader()) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 dumm
yTextures)); | 300 dumm
yTextures)); |
| 300 SkASSERT(effect); | 301 SkASSERT(effect); |
| 301 | 302 |
| 302 // Only geometryProcessor can use vertex shader | 303 // Only geometryProcessor can use vertex shader |
| 303 if (effect->requiresVertexShader()) { | 304 if (effect->requiresVertexShader()) { |
| 304 continue; | 305 continue; |
| 305 } | 306 } |
| 306 | 307 |
| 307 // If adding this effect would exceed the max texture coord set coun
t then generate a | 308 // If adding this effect would exceed the max texture coord set coun
t then generate a |
| 308 // new random effect. | 309 // new random effect. |
| 309 if (useFixedFunctionPathRendering) { | 310 if (usePathRendering && this->glPathRendering()->texturingMode() == |
| 311 GrGLPathRendering::FixedFunction_TexturingMo
de) {; |
| 310 int numTransforms = effect->numTransforms(); | 312 int numTransforms = effect->numTransforms(); |
| 311 if (currTextureCoordSet + numTransforms > this->glCaps().maxFixe
dFunctionTextureCoords()) { | 313 if (currTextureCoordSet + numTransforms > this->glCaps().maxFixe
dFunctionTextureCoords()) { |
| 312 continue; | 314 continue; |
| 313 } | 315 } |
| 314 currTextureCoordSet += numTransforms; | 316 currTextureCoordSet += numTransforms; |
| 315 } | 317 } |
| 316 GrEffectStage* stage = SkNEW_ARGS(GrEffectStage, (effect.get())); | 318 GrEffectStage* stage = SkNEW_ARGS(GrEffectStage, (effect.get())); |
| 317 | 319 |
| 318 stages[s] = stage; | 320 stages[s] = stage; |
| 319 ++s; | 321 ++s; |
| 320 } | 322 } |
| 321 const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dum
myTextures[1]; | 323 const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dum
myTextures[1]; |
| 322 if (!pdesc.setRandom(&random, | 324 if (!pdesc.setRandom(&random, |
| 323 this, | 325 this, |
| 324 dummyTextures[0]->asRenderTarget(), | 326 dummyTextures[0]->asRenderTarget(), |
| 325 dstTexture, | 327 dstTexture, |
| 326 geometryProcessor.get(), | 328 geometryProcessor.get(), |
| 327 stages.get(), | 329 stages.get(), |
| 328 numColorStages, | 330 numColorStages, |
| 329 numCoverageStages, | 331 numCoverageStages, |
| 330 currAttribIndex)) { | 332 currAttribIndex, |
| 333 drawType)) { |
| 331 return false; | 334 return false; |
| 332 } | 335 } |
| 333 | 336 |
| 334 SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this, | 337 SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this, |
| 335 pdesc, | 338 pdesc, |
| 336 geometryProcessor.
get(), | 339 geometryProcessor.
get(), |
| 337 stages, | 340 stages, |
| 338 stages + numColorS
tages)); | 341 stages + numColorS
tages)); |
| 339 for (int s = 0; s < numStages; ++s) { | 342 for (int s = 0; s < numStages; ++s) { |
| 340 SkDELETE(stages[s]); | 343 SkDELETE(stages[s]); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1)); | 388 SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1)); |
| 386 GrConfigConversionEffect::Create(NULL, | 389 GrConfigConversionEffect::Create(NULL, |
| 387 false, | 390 false, |
| 388 GrConfigConversionEffect::kNone_PMConversio
n, | 391 GrConfigConversionEffect::kNone_PMConversio
n, |
| 389 SkMatrix::I()); | 392 SkMatrix::I()); |
| 390 SkScalar matrix[20]; | 393 SkScalar matrix[20]; |
| 391 SkAutoTUnref<SkColorMatrixFilter> cmf(SkColorMatrixFilter::Create(matrix)); | 394 SkAutoTUnref<SkColorMatrixFilter> cmf(SkColorMatrixFilter::Create(matrix)); |
| 392 } | 395 } |
| 393 | 396 |
| 394 #endif | 397 #endif |
| OLD | NEW |