| 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/GrGpuGL.h" | 20 #include "gl/GrGpuGL.h" |
| 20 | |
| 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* stages[], | 29 const GrEffectStage* stages[], |
| 30 int numColorStages, | 30 int numColorStages, |
| 31 int numCoverageStages, | 31 int numCoverageStages, |
| 32 int currAttribIndex) { | 32 int currAttribIndex) { |
| 33 bool useLocalCoords = random->nextBool() && currAttribIndex < GrDrawState::k
MaxVertexAttribCnt; | 33 bool useLocalCoords = random->nextBool() && currAttribIndex < GrDrawState::k
MaxVertexAttribCnt; |
| 34 | 34 |
| 35 int numStages = numColorStages + numCoverageStages; | 35 int numStages = numColorStages + numCoverageStages; |
| 36 fKey.reset(); | 36 fKey.reset(); |
| 37 | 37 |
| 38 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); | 38 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); |
| 39 | 39 |
| 40 // Make room for everything up to and including the array of offsets to effe
ct keys. | 40 // 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); | 41 fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_t) * n
umStages); |
| 42 | 42 |
| 43 bool dstRead = false; | 43 bool dstRead = false; |
| 44 bool fragPos = false; | 44 bool fragPos = false; |
| 45 bool vertexCode = false; | 45 bool vertexShader = false; |
| 46 for (int s = 0; s < numStages; ++s) { | 46 for (int s = 0; s < numStages; ++s) { |
| 47 uint16_t* offsetAndSize = reinterpret_cast<uint16_t*>(fKey.begin() + | 47 uint16_t* offsetAndSize = reinterpret_cast<uint16_t*>(fKey.begin() + |
| 48 kEffectKeyOffsetsA
ndLengthOffset + | 48 kEffectKeyOffsetsA
ndLengthOffset + |
| 49 s * 2 * sizeof(uin
t16_t)); | 49 s * 2 * sizeof(uin
t16_t)); |
| 50 uint32_t effectKeyOffset = fKey.count(); | 50 uint32_t effectKeyOffset = fKey.count(); |
| 51 if (effectKeyOffset > SK_MaxU16) { | 51 if (effectKeyOffset > SK_MaxU16) { |
| 52 fKey.reset(); | 52 fKey.reset(); |
| 53 return false; | 53 return false; |
| 54 } | 54 } |
| 55 GrDrawEffect drawEffect(*stages[s], useLocalCoords); | 55 GrDrawEffect drawEffect(*stages[s], useLocalCoords); |
| 56 GrEffectKeyBuilder b(&fKey); | 56 GrEffectKeyBuilder b(&fKey); |
| 57 uint16_t effectKeySize; | 57 uint16_t effectKeySize; |
| 58 if (!GetEffectKeyAndUpdateStats(*stages[s], gpu->glCaps(), useLocalCoord
s, &b, | 58 if (!GetEffectKeyAndUpdateStats(*stages[s], gpu->glCaps(), useLocalCoord
s, &b, |
| 59 &effectKeySize, &dstRead, &fragPos, &ver
texCode)) { | 59 &effectKeySize, &dstRead, &fragPos, &ver
texShader)) { |
| 60 fKey.reset(); | 60 fKey.reset(); |
| 61 return false; | 61 return false; |
| 62 } | 62 } |
| 63 offsetAndSize[0] = effectKeyOffset; | 63 offsetAndSize[0] = effectKeyOffset; |
| 64 offsetAndSize[1] = effectKeySize; | 64 offsetAndSize[1] = effectKeySize; |
| 65 } | 65 } |
| 66 | 66 |
| 67 KeyHeader* header = this->header(); | 67 KeyHeader* header = this->header(); |
| 68 memset(header, 0, kHeaderSize); | 68 memset(header, 0, kHeaderSize); |
| 69 header->fEmitsPointSize = random->nextBool(); | 69 header->fEmitsPointSize = random->nextBool(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } else { | 107 } else { |
| 108 header->fDstReadKey = 0; | 108 header->fDstReadKey = 0; |
| 109 } | 109 } |
| 110 if (fragPos) { | 110 if (fragPos) { |
| 111 header->fFragPosKey = SkToU8(GrGLFragmentShaderBuilder::KeyForFragmentPo
sition(dstRenderTarget, | 111 header->fFragPosKey = SkToU8(GrGLFragmentShaderBuilder::KeyForFragmentPo
sition(dstRenderTarget, |
| 112 g
pu->glCaps())); | 112 g
pu->glCaps())); |
| 113 } else { | 113 } else { |
| 114 header->fFragPosKey = 0; | 114 header->fFragPosKey = 0; |
| 115 } | 115 } |
| 116 | 116 |
| 117 header->fHasVertexCode = vertexCode || | 117 header->fRequiresVertexShader = vertexShader || |
| 118 useLocalCoords || | 118 useLocalCoords || |
| 119 kAttribute_ColorInput == header->fColorInput || | 119 kAttribute_ColorInput == header->fColorInput
|| |
| 120 kAttribute_ColorInput == header->fCoverageInput; | 120 kAttribute_ColorInput == header->fCoverageIn
put; |
| 121 | 121 |
| 122 CoverageOutput coverageOutput; | 122 CoverageOutput coverageOutput; |
| 123 bool illegalCoverageOutput; | 123 bool illegalCoverageOutput; |
| 124 do { | 124 do { |
| 125 coverageOutput = static_cast<CoverageOutput>(random->nextULessThan(kCove
rageOutputCnt)); | 125 coverageOutput = static_cast<CoverageOutput>(random->nextULessThan(kCove
rageOutputCnt)); |
| 126 illegalCoverageOutput = (!gpu->caps()->dualSourceBlendingSupport() && | 126 illegalCoverageOutput = (!gpu->caps()->dualSourceBlendingSupport() && |
| 127 CoverageOutputUsesSecondaryOutput(coverageOutpu
t)) || | 127 CoverageOutputUsesSecondaryOutput(coverageOutpu
t)) || |
| 128 (!dstRead && kCombineWithDst_CoverageOutput == c
overageOutput); | 128 (!dstRead && kCombineWithDst_CoverageOutput == c
overageOutput); |
| 129 } while (illegalCoverageOutput); | 129 } while (illegalCoverageOutput); |
| 130 | 130 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 int currTextureCoordSet = 0; | 171 int currTextureCoordSet = 0; |
| 172 int attribIndices[2] = { 0, 0 }; | 172 int attribIndices[2] = { 0, 0 }; |
| 173 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; | 173 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; |
| 174 | 174 |
| 175 int numStages = random.nextULessThan(maxStages + 1); | 175 int numStages = random.nextULessThan(maxStages + 1); |
| 176 int numColorStages = random.nextULessThan(numStages + 1); | 176 int numColorStages = random.nextULessThan(numStages + 1); |
| 177 int numCoverageStages = numStages - numColorStages; | 177 int numCoverageStages = numStages - numColorStages; |
| 178 | 178 |
| 179 SkAutoSTMalloc<8, const GrEffectStage*> stages(numStages); | 179 SkAutoSTMalloc<8, const GrEffectStage*> stages(numStages); |
| 180 | 180 |
| 181 bool useFixedFunctionTexturing = this->shouldUseFixedFunctionTexturing()
; | 181 bool useFixedFunctionPathRendering = this->glCaps().pathRenderingSupport
() && |
| 182 this->glPathRendering()->texturingMode() == GrGLPathRendering::Fixed
Function_TexturingMode; |
| 182 | 183 |
| 183 for (int s = 0; s < numStages;) { | 184 for (int s = 0; s < numStages;) { |
| 184 SkAutoTUnref<const GrEffect> effect(GrEffectTestFactory::CreateStage
( | 185 SkAutoTUnref<const GrEffect> effect(GrEffectTestFactory::CreateStage
( |
| 185 &ran
dom, | 186 &ran
dom, |
| 186 this
->getContext(), | 187 this
->getContext(), |
| 187 *thi
s->caps(), | 188 *thi
s->caps(), |
| 188 dumm
yTextures)); | 189 dumm
yTextures)); |
| 189 SkASSERT(effect); | 190 SkASSERT(effect); |
| 190 int numAttribs = effect->numVertexAttribs(); | 191 int numAttribs = effect->numVertexAttribs(); |
| 191 | 192 |
| 192 // If adding this effect would exceed the max attrib count then gene
rate a | 193 // If adding this effect would exceed the max attrib count then gene
rate a |
| 193 // new random effect. | 194 // new random effect. |
| 194 if (currAttribIndex + numAttribs > GrDrawState::kMaxVertexAttribCnt)
{ | 195 if (currAttribIndex + numAttribs > GrDrawState::kMaxVertexAttribCnt)
{ |
| 195 continue; | 196 continue; |
| 196 } | 197 } |
| 197 | 198 |
| 198 | 199 |
| 199 // If adding this effect would exceed the max texture coord set coun
t then generate a | 200 // If adding this effect would exceed the max texture coord set coun
t then generate a |
| 200 // new random effect. | 201 // new random effect. |
| 201 if (useFixedFunctionTexturing && !effect->hasVertexCode()) { | 202 if (useFixedFunctionPathRendering && !effect->requiresVertexShader()
) { |
| 202 int numTransforms = effect->numTransforms(); | 203 int numTransforms = effect->numTransforms(); |
| 203 if (currTextureCoordSet + numTransforms > this->glCaps().maxFixe
dFunctionTextureCoords()) { | 204 if (currTextureCoordSet + numTransforms > this->glCaps().maxFixe
dFunctionTextureCoords()) { |
| 204 continue; | 205 continue; |
| 205 } | 206 } |
| 206 currTextureCoordSet += numTransforms; | 207 currTextureCoordSet += numTransforms; |
| 207 } | 208 } |
| 208 | 209 |
| 209 useFixedFunctionTexturing = useFixedFunctionTexturing && !effect->ha
sVertexCode(); | 210 useFixedFunctionPathRendering = useFixedFunctionPathRendering && !ef
fect->requiresVertexShader(); |
| 210 | 211 |
| 211 for (int i = 0; i < numAttribs; ++i) { | 212 for (int i = 0; i < numAttribs; ++i) { |
| 212 attribIndices[i] = currAttribIndex++; | 213 attribIndices[i] = currAttribIndex++; |
| 213 } | 214 } |
| 214 GrEffectStage* stage = SkNEW_ARGS(GrEffectStage, | 215 GrEffectStage* stage = SkNEW_ARGS(GrEffectStage, |
| 215 (effect.get(), attribIndices[0], a
ttribIndices[1])); | 216 (effect.get(), attribIndices[0], a
ttribIndices[1])); |
| 216 stages[s] = stage; | 217 stages[s] = stage; |
| 217 ++s; | 218 ++s; |
| 218 } | 219 } |
| 219 const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dum
myTextures[1]; | 220 const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dum
myTextures[1]; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1)); | 279 SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1)); |
| 279 GrConfigConversionEffect::Create(NULL, | 280 GrConfigConversionEffect::Create(NULL, |
| 280 false, | 281 false, |
| 281 GrConfigConversionEffect::kNone_PMConversio
n, | 282 GrConfigConversionEffect::kNone_PMConversio
n, |
| 282 SkMatrix::I()); | 283 SkMatrix::I()); |
| 283 SkScalar matrix[20]; | 284 SkScalar matrix[20]; |
| 284 SkAutoTUnref<SkColorMatrixFilter> cmf(SkColorMatrixFilter::Create(matrix)); | 285 SkAutoTUnref<SkColorMatrixFilter> cmf(SkColorMatrixFilter::Create(matrix)); |
| 285 } | 286 } |
| 286 | 287 |
| 287 #endif | 288 #endif |
| OLD | NEW |