| bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 9 | // This is a GPU-backend specific test. It relies on static intializers to work |
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 10 | |
| bsalomon@google.com | 2a48c3a | 2012-08-03 14:54:45 +0000 | [diff] [blame] | 11 | #include "SkTypes.h" |
| 12 | |
| 13 | #if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 14 | |
| bsalomon@google.com | 396e61f | 2012-10-25 19:00:29 +0000 | [diff] [blame] | 15 | #include "GrBackendEffectFactory.h" |
| bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 16 | #include "GrContextFactory.h" |
| bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 17 | #include "GrDrawEffect.h" |
| bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 18 | #include "effects/GrConfigConversionEffect.h" |
| kkinnunen | ec56e45 | 2014-08-25 22:21:16 -0700 | [diff] [blame] | 19 | #include "gl/GrGLPathRendering.h" |
| tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 20 | #include "gl/GrGpuGL.h" |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 21 | #include "SkChecksum.h" |
| tfarina@chromium.org | 223137f | 2012-11-21 22:38:36 +0000 | [diff] [blame] | 22 | #include "SkRandom.h" |
| bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 23 | #include "Test.h" |
| 24 | |
| bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 25 | bool GrGLProgramDesc::setRandom(SkRandom* random, |
| bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 26 | const GrGpuGL* gpu, |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 27 | const GrRenderTarget* dstRenderTarget, |
| 28 | const GrTexture* dstCopyTexture, |
| joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 29 | const GrEffectStage* geometryProcessor, |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 30 | const GrEffectStage* stages[], |
| 31 | int numColorStages, |
| 32 | int numCoverageStages, |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 33 | int currAttribIndex) { |
| bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 34 | bool useLocalCoords = random->nextBool() && currAttribIndex < GrDrawState::kMaxVertexAttribCnt; |
| 35 | |
| 36 | int numStages = numColorStages + numCoverageStages; |
| 37 | fKey.reset(); |
| 38 | |
| bsalomon | 929f29a | 2014-07-17 07:55:11 -0700 | [diff] [blame] | 39 | GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); |
| bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 40 | |
| 41 | // Make room for everything up to and including the array of offsets to effect keys. |
| joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 42 | fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_t) * (numStages + |
| 43 | (geometryProcessor ? 1 : 0))); |
| bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 44 | |
| 45 | bool dstRead = false; |
| 46 | bool fragPos = false; |
| bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame^] | 47 | bool vertexShader = SkToBool(geometryProcessor); |
| joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 48 | int offset = 0; |
| bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame^] | 49 | if (geometryProcessor) { |
| joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 50 | const GrEffectStage* stage = geometryProcessor; |
| bsalomon | 929f29a | 2014-07-17 07:55:11 -0700 | [diff] [blame] | 51 | uint16_t* offsetAndSize = reinterpret_cast<uint16_t*>(fKey.begin() + |
| 52 | kEffectKeyOffsetsAndLengthOffset + |
| joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 53 | offset * 2 * sizeof(uint16_t)); |
| bsalomon | 929f29a | 2014-07-17 07:55:11 -0700 | [diff] [blame] | 54 | uint32_t effectKeyOffset = fKey.count(); |
| 55 | if (effectKeyOffset > SK_MaxU16) { |
| bsalomon | c0ea398 | 2014-07-15 19:41:17 -0700 | [diff] [blame] | 56 | fKey.reset(); |
| 57 | return false; |
| bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 58 | } |
| joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 59 | GrDrawEffect drawEffect(*stage, useLocalCoords); |
| bsalomon | 929f29a | 2014-07-17 07:55:11 -0700 | [diff] [blame] | 60 | GrEffectKeyBuilder b(&fKey); |
| 61 | uint16_t effectKeySize; |
| joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 62 | if (!GetEffectKeyAndUpdateStats(*stage, gpu->glCaps(), useLocalCoords, &b, |
| 63 | &effectKeySize, &dstRead, &fragPos, &vertexShader)) { |
| 64 | fKey.reset(); |
| 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 | kEffectKeyOffsetsAndLengthOffset + |
| 76 | offset * 2 * sizeof(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, |
| kkinnunen | ec56e45 | 2014-08-25 22:21:16 -0700 | [diff] [blame] | 86 | &effectKeySize, &dstRead, &fragPos, &vertexShader)) { |
| bsalomon | 929f29a | 2014-07-17 07:55:11 -0700 | [diff] [blame] | 87 | fKey.reset(); |
| 88 | return false; |
| mtklein | 7940100 | 2014-07-16 06:16:43 -0700 | [diff] [blame] | 89 | } |
| bsalomon | 929f29a | 2014-07-17 07:55:11 -0700 | [diff] [blame] | 90 | offsetAndSize[0] = effectKeyOffset; |
| 91 | offsetAndSize[1] = effectKeySize; |
| bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 92 | } |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 93 | |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 94 | KeyHeader* header = this->header(); |
| bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 95 | memset(header, 0, kHeaderSize); |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 96 | header->fEmitsPointSize = random->nextBool(); |
| 97 | |
| 98 | header->fPositionAttributeIndex = 0; |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 99 | |
| skia.committer@gmail.com | 05a2ee0 | 2013-04-02 07:01:34 +0000 | [diff] [blame] | 100 | // if the effects have used up all off the available attributes, |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 101 | // don't try to use color or coverage attributes as input |
| 102 | do { |
| egdaniel | 02cafcc | 2014-07-21 11:37:28 -0700 | [diff] [blame] | 103 | uint32_t colorRand = random->nextULessThan(2); |
| 104 | header->fColorInput = (0 == colorRand) ? GrGLProgramDesc::kAttribute_ColorInput : |
| 105 | GrGLProgramDesc::kUniform_ColorInput; |
| skia.committer@gmail.com | 05a2ee0 | 2013-04-02 07:01:34 +0000 | [diff] [blame] | 106 | } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex && |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 107 | kAttribute_ColorInput == header->fColorInput); |
| bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 108 | |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 109 | header->fColorAttributeIndex = (header->fColorInput == kAttribute_ColorInput) ? |
| 110 | currAttribIndex++ : |
| 111 | -1; |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 112 | |
| 113 | do { |
| commit-bot@chromium.org | 949eef0 | 2013-10-01 18:43:29 +0000 | [diff] [blame] | 114 | header->fCoverageInput = static_cast<GrGLProgramDesc::ColorInput>( |
| 115 | random->nextULessThan(kColorInputCnt)); |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 116 | } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex && |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 117 | kAttribute_ColorInput == header->fCoverageInput); |
| 118 | header->fCoverageAttributeIndex = (header->fCoverageInput == kAttribute_ColorInput) ? |
| 119 | currAttribIndex++ : |
| 120 | -1; |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 121 | |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 122 | #if GR_GL_EXPERIMENTAL_GS |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 123 | header->fExperimentalGS = gpu->caps()->geometryShaderSupport() && random->nextBool(); |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 124 | #endif |
| 125 | |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 126 | header->fLocalCoordAttributeIndex = useLocalCoords ? currAttribIndex++ : -1; |
| 127 | |
| 128 | header->fColorEffectCnt = numColorStages; |
| 129 | header->fCoverageEffectCnt = numCoverageStages; |
| bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 130 | |
| bsalomon@google.com | b79d865 | 2013-03-29 20:30:50 +0000 | [diff] [blame] | 131 | if (dstRead) { |
| joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 132 | header->fDstReadKey = SkToU8(GrGLFragmentShaderBuilder::KeyForDstRead(dstCopyTexture, |
| bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 133 | gpu->glCaps())); |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 134 | } else { |
| 135 | header->fDstReadKey = 0; |
| 136 | } |
| 137 | if (fragPos) { |
| joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 138 | header->fFragPosKey = SkToU8(GrGLFragmentShaderBuilder::KeyForFragmentPosition(dstRenderTarget, |
| bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 139 | gpu->glCaps())); |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 140 | } else { |
| 141 | header->fFragPosKey = 0; |
| bsalomon@google.com | b79d865 | 2013-03-29 20:30:50 +0000 | [diff] [blame] | 142 | } |
| bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 143 | |
| kkinnunen | ec56e45 | 2014-08-25 22:21:16 -0700 | [diff] [blame] | 144 | header->fRequiresVertexShader = vertexShader || |
| 145 | useLocalCoords || |
| 146 | kAttribute_ColorInput == header->fColorInput || |
| 147 | kAttribute_ColorInput == header->fCoverageInput; |
| joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 148 | header->fHasGeometryProcessor = vertexShader; |
| commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 149 | |
| bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 150 | CoverageOutput coverageOutput; |
| 151 | bool illegalCoverageOutput; |
| 152 | do { |
| 153 | coverageOutput = static_cast<CoverageOutput>(random->nextULessThan(kCoverageOutputCnt)); |
| 154 | illegalCoverageOutput = (!gpu->caps()->dualSourceBlendingSupport() && |
| 155 | CoverageOutputUsesSecondaryOutput(coverageOutput)) || |
| bsalomon@google.com | 72993ab | 2013-04-19 13:25:28 +0000 | [diff] [blame] | 156 | (!dstRead && kCombineWithDst_CoverageOutput == coverageOutput); |
| bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 157 | } while (illegalCoverageOutput); |
| 158 | |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 159 | header->fCoverageOutput = coverageOutput; |
| 160 | |
| bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 161 | this->finalize(); |
| 162 | return true; |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| bsalomon@google.com | 042a286 | 2013-02-04 18:39:24 +0000 | [diff] [blame] | 165 | bool GrGpuGL::programUnitTest(int maxStages) { |
| 166 | |
| bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 167 | GrTextureDesc dummyDesc; |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 168 | dummyDesc.fFlags = kRenderTarget_GrTextureFlagBit; |
| bsalomon@google.com | fec0bc3 | 2013-02-07 14:43:04 +0000 | [diff] [blame] | 169 | dummyDesc.fConfig = kSkia8888_GrPixelConfig; |
| bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 170 | dummyDesc.fWidth = 34; |
| 171 | dummyDesc.fHeight = 18; |
| 172 | SkAutoTUnref<GrTexture> dummyTexture1(this->createTexture(dummyDesc, NULL, 0)); |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 173 | dummyDesc.fFlags = kNone_GrTextureFlags; |
| bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 174 | dummyDesc.fConfig = kAlpha_8_GrPixelConfig; |
| 175 | dummyDesc.fWidth = 16; |
| 176 | dummyDesc.fHeight = 22; |
| 177 | SkAutoTUnref<GrTexture> dummyTexture2(this->createTexture(dummyDesc, NULL, 0)); |
| 178 | |
| bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 179 | if (!dummyTexture1 || ! dummyTexture2) { |
| 180 | return false; |
| 181 | } |
| 182 | |
| bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 183 | static const int NUM_TESTS = 512; |
| 184 | |
| commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 185 | SkRandom random; |
| bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 186 | for (int t = 0; t < NUM_TESTS; ++t) { |
| 187 | |
| 188 | #if 0 |
| 189 | GrPrintf("\nTest Program %d\n-------------\n", t); |
| 190 | static const int stop = -1; |
| 191 | if (t == stop) { |
| 192 | int breakpointhere = 9; |
| 193 | } |
| 194 | #endif |
| 195 | |
| bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 196 | GrGLProgramDesc pdesc; |
| bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 197 | |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 198 | int currAttribIndex = 1; // we need to always leave room for position |
| commit-bot@chromium.org | 8e919ad | 2013-10-21 14:48:23 +0000 | [diff] [blame] | 199 | int currTextureCoordSet = 0; |
| commit-bot@chromium.org | 4324c3b | 2014-02-21 20:11:42 +0000 | [diff] [blame] | 200 | int attribIndices[2] = { 0, 0 }; |
| bsalomon@google.com | b79d865 | 2013-03-29 20:30:50 +0000 | [diff] [blame] | 201 | GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; |
| commit-bot@chromium.org | 9ae7850 | 2013-03-21 17:44:39 +0000 | [diff] [blame] | 202 | |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 203 | int numStages = random.nextULessThan(maxStages + 1); |
| 204 | int numColorStages = random.nextULessThan(numStages + 1); |
| 205 | int numCoverageStages = numStages - numColorStages; |
| 206 | |
| 207 | SkAutoSTMalloc<8, const GrEffectStage*> stages(numStages); |
| 208 | |
| kkinnunen | ec56e45 | 2014-08-25 22:21:16 -0700 | [diff] [blame] | 209 | bool useFixedFunctionPathRendering = this->glCaps().pathRenderingSupport() && |
| joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 210 | this->glPathRendering()->texturingMode() == GrGLPathRendering::FixedFunction_TexturingMode && |
| 211 | random.nextBool(); |
| commit-bot@chromium.org | 8e919ad | 2013-10-21 14:48:23 +0000 | [diff] [blame] | 212 | |
| joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 213 | SkAutoTDelete<GrEffectStage> geometryProcessor; |
| 214 | bool hasGeometryProcessor = useFixedFunctionPathRendering ? false : random.nextBool(); |
| 215 | if (hasGeometryProcessor) { |
| 216 | while (true) { |
| 217 | SkAutoTUnref<const GrEffect> effect(GrEffectTestFactory::CreateStage( |
| 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 | } |
| commit-bot@chromium.org | 8e919ad | 2013-10-21 14:48:23 +0000 | [diff] [blame] | 239 | for (int s = 0; s < numStages;) { |
| bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 240 | SkAutoTUnref<const GrEffect> effect(GrEffectTestFactory::CreateStage( |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 241 | &random, |
| 242 | this->getContext(), |
| 243 | *this->caps(), |
| 244 | dummyTextures)); |
| commit-bot@chromium.org | 65ee5f4 | 2014-02-04 17:49:48 +0000 | [diff] [blame] | 245 | SkASSERT(effect); |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 246 | |
| joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 247 | // Only geometryProcessor can use vertex shader |
| 248 | if (effect->requiresVertexShader()) { |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 249 | continue; |
| bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 250 | } |
| commit-bot@chromium.org | 8e919ad | 2013-10-21 14:48:23 +0000 | [diff] [blame] | 251 | |
| commit-bot@chromium.org | 8e919ad | 2013-10-21 14:48:23 +0000 | [diff] [blame] | 252 | // If adding this effect would exceed the max texture coord set count then generate a |
| 253 | // new random effect. |
| joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 254 | if (useFixedFunctionPathRendering) { |
| bsalomon | 97b9ab7 | 2014-07-08 06:52:35 -0700 | [diff] [blame] | 255 | int numTransforms = effect->numTransforms(); |
| commit-bot@chromium.org | 8e919ad | 2013-10-21 14:48:23 +0000 | [diff] [blame] | 256 | if (currTextureCoordSet + numTransforms > this->glCaps().maxFixedFunctionTextureCoords()) { |
| 257 | continue; |
| 258 | } |
| 259 | currTextureCoordSet += numTransforms; |
| 260 | } |
| commit-bot@chromium.org | 2d3b492 | 2013-07-15 13:54:06 +0000 | [diff] [blame] | 261 | GrEffectStage* stage = SkNEW_ARGS(GrEffectStage, |
| 262 | (effect.get(), attribIndices[0], attribIndices[1])); |
| joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 263 | |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 264 | stages[s] = stage; |
| commit-bot@chromium.org | 8e919ad | 2013-10-21 14:48:23 +0000 | [diff] [blame] | 265 | ++s; |
| bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 266 | } |
| bsalomon@google.com | b79d865 | 2013-03-29 20:30:50 +0000 | [diff] [blame] | 267 | const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dummyTextures[1]; |
| bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 268 | if (!pdesc.setRandom(&random, |
| 269 | this, |
| 270 | dummyTextures[0]->asRenderTarget(), |
| 271 | dstTexture, |
| joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 272 | geometryProcessor.get(), |
| bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 273 | stages.get(), |
| 274 | numColorStages, |
| 275 | numCoverageStages, |
| 276 | currAttribIndex)) { |
| 277 | return false; |
| 278 | } |
| skia.committer@gmail.com | 05a2ee0 | 2013-04-02 07:01:34 +0000 | [diff] [blame] | 279 | |
| commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 280 | SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this, |
| bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 281 | pdesc, |
| joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 282 | geometryProcessor.get(), |
| bsalomon@google.com | 2c84aa3 | 2013-06-06 20:28:57 +0000 | [diff] [blame] | 283 | stages, |
| 284 | stages + numColorStages)); |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 285 | for (int s = 0; s < numStages; ++s) { |
| bsalomon@google.com | 504976e | 2013-05-09 13:45:02 +0000 | [diff] [blame] | 286 | SkDELETE(stages[s]); |
| 287 | } |
| bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 288 | if (NULL == program.get()) { |
| 289 | return false; |
| 290 | } |
| 291 | } |
| 292 | return true; |
| 293 | } |
| bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 294 | |
| tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 295 | DEF_GPUTEST(GLPrograms, reporter, factory) { |
| bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 296 | for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
| 297 | GrContext* context = factory->get(static_cast<GrContextFactory::GLContextType>(type)); |
| bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame^] | 298 | if (context) { |
| bsalomon@google.com | 042a286 | 2013-02-04 18:39:24 +0000 | [diff] [blame] | 299 | GrGpuGL* gpu = static_cast<GrGpuGL*>(context->getGpu()); |
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 300 | int maxStages = 6; |
| bsalomon@google.com | 042a286 | 2013-02-04 18:39:24 +0000 | [diff] [blame] | 301 | #if SK_ANGLE |
| 302 | // Some long shaders run out of temporary registers in the D3D compiler on ANGLE. |
| 303 | if (type == GrContextFactory::kANGLE_GLContextType) { |
| 304 | maxStages = 3; |
| 305 | } |
| 306 | #endif |
| 307 | REPORTER_ASSERT(reporter, gpu->programUnitTest(maxStages)); |
| bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 308 | } |
| 309 | } |
| bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 312 | // This is evil evil evil. The linker may throw away whole translation units as dead code if it |
| bsalomon@google.com | 67e78c9 | 2012-10-17 13:36:14 +0000 | [diff] [blame] | 313 | // thinks none of the functions are called. It will do this even if there are static initializers |
| bsalomon@google.com | a1bf0ff | 2012-08-07 17:36:29 +0000 | [diff] [blame] | 314 | // in the unit that could pass pointers to functions from the unit out to other translation units! |
| 315 | // We force some of the effects that would otherwise be discarded to link here. |
| 316 | |
| commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 317 | #include "SkAlphaThresholdFilter.h" |
| tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 318 | #include "SkColorMatrixFilter.h" |
| bsalomon@google.com | a1bf0ff | 2012-08-07 17:36:29 +0000 | [diff] [blame] | 319 | #include "SkLightingImageFilter.h" |
| bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 320 | #include "SkMagnifierImageFilter.h" |
| bsalomon@google.com | a1bf0ff | 2012-08-07 17:36:29 +0000 | [diff] [blame] | 321 | |
| 322 | void forceLinking(); |
| 323 | |
| 324 | void forceLinking() { |
| 325 | SkLightingImageFilter::CreateDistantLitDiffuse(SkPoint3(0,0,0), 0, 0, 0); |
| commit-bot@chromium.org | 9109e18 | 2014-01-07 16:04:01 +0000 | [diff] [blame] | 326 | SkAlphaThresholdFilter::Create(SkRegion(), .5f, .5f); |
| reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 327 | SkAutoTUnref<SkImageFilter> mag(SkMagnifierImageFilter::Create( |
| commit-bot@chromium.org | cac5fd5 | 2014-03-10 10:51:58 +0000 | [diff] [blame] | 328 | SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1)); |
| bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 329 | GrConfigConversionEffect::Create(NULL, |
| 330 | false, |
| 331 | GrConfigConversionEffect::kNone_PMConversion, |
| 332 | SkMatrix::I()); |
| bsalomon@google.com | 67e78c9 | 2012-10-17 13:36:14 +0000 | [diff] [blame] | 333 | SkScalar matrix[20]; |
| commit-bot@chromium.org | 727a352 | 2014-02-21 18:46:30 +0000 | [diff] [blame] | 334 | SkAutoTUnref<SkColorMatrixFilter> cmf(SkColorMatrixFilter::Create(matrix)); |
| bsalomon@google.com | a1bf0ff | 2012-08-07 17:36:29 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 337 | #endif |