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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // finally add the stage to the correct pipeline in the drawstate | 174 // finally add the stage to the correct pipeline in the drawstate |
175 if (s < numColorProcs) { | 175 if (s < numColorProcs) { |
176 ds->addColorProcessor(fp); | 176 ds->addColorProcessor(fp); |
177 } else { | 177 } else { |
178 ds->addCoverageProcessor(fp); | 178 ds->addCoverageProcessor(fp); |
179 } | 179 } |
180 ++s; | 180 ++s; |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
184 // There are only a few cases of random colors which interest us | |
185 enum ColorMode { | |
186 kAllOnes_ColorMode, | |
187 kAllZeros_ColorMode, | |
188 kAlphaOne_ColorMode, | |
189 kRandom_ColorMode, | |
190 kLast_ColorMode = kRandom_ColorMode | |
191 }; | |
192 | |
193 static void set_random_color(GrDrawState* ds, SkRandom* random) { | |
194 ColorMode colorMode = ColorMode(random->nextULessThan(kLast_ColorMode + 1)); | |
195 GrColor color; | |
196 switch (colorMode) { | |
197 case kAllOnes_ColorMode: | |
198 color = GrColorPackRGBA(0xFF, 0xFF, 0xFF, 0xFF); | |
199 break; | |
200 case kAllZeros_ColorMode: | |
201 color = GrColorPackRGBA(0, 0, 0, 0); | |
202 break; | |
203 case kAlphaOne_ColorMode: | |
204 color = GrColorPackRGBA(random->nextULessThan(256), | |
205 random->nextULessThan(256), | |
206 random->nextULessThan(256), | |
207 0xFF); | |
208 break; | |
209 case kRandom_ColorMode: | |
210 uint8_t alpha = random->nextULessThan(256); | |
211 color = GrColorPackRGBA(random->nextRangeU(0, alpha), | |
212 random->nextRangeU(0, alpha), | |
213 random->nextRangeU(0, alpha), | |
214 alpha); | |
215 break; | |
216 } | |
217 GrColorIsPMAssert(color); | |
218 ds->setColor(color); | |
219 } | |
220 | |
221 // There are only a few cases of random coverages which interest us | |
222 enum CoverageMode { | |
223 kZero_CoverageMode, | |
224 kFF_CoverageMode, | |
225 kRandom_CoverageMode, | |
226 kLast_CoverageMode = kRandom_CoverageMode | |
227 }; | |
228 | |
229 static void set_random_coverage(GrDrawState* ds, SkRandom* random) { | |
230 CoverageMode coverageMode = CoverageMode(random->nextULessThan(kLast_Coverag
eMode + 1)); | |
231 uint8_t coverage; | |
232 switch (coverageMode) { | |
233 case kZero_CoverageMode: | |
234 coverage = 0; | |
235 break; | |
236 case kFF_CoverageMode: | |
237 coverage = 0xFF; | |
238 break; | |
239 case kRandom_CoverageMode: | |
240 coverage = uint8_t(random->nextU()); | |
241 break; | |
242 } | |
243 ds->setCoverage(coverage); | |
244 } | |
245 | |
246 static void set_random_hints(GrDrawState* ds, SkRandom* random) { | 184 static void set_random_hints(GrDrawState* ds, SkRandom* random) { |
247 for (int i = 1; i <= GrDrawState::kLast_Hint; i <<= 1) { | 185 for (int i = 1; i <= GrDrawState::kLast_Hint; i <<= 1) { |
248 ds->setHint(GrDrawState::Hints(i), random->nextBool()); | 186 ds->setHint(GrDrawState::Hints(i), random->nextBool()); |
249 } | 187 } |
250 } | 188 } |
251 | 189 |
252 static void set_random_state(GrDrawState* ds, SkRandom* random) { | 190 static void set_random_state(GrDrawState* ds, SkRandom* random) { |
253 int state = 0; | 191 int state = 0; |
254 for (int i = 1; i <= GrDrawState::kLast_StateBit; i <<= 1) { | 192 for (int i = 1; i <= GrDrawState::kLast_StateBit; i <<= 1) { |
255 state |= random->nextBool() * i; | 193 state |= random->nextBool() * i; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 bool hasGeometryProcessor = !usePathRendering; | 303 bool hasGeometryProcessor = !usePathRendering; |
366 if (hasGeometryProcessor) { | 304 if (hasGeometryProcessor) { |
367 set_random_gp(fContext, gpu->glCaps(), &ds, &random, dummyTextures); | 305 set_random_gp(fContext, gpu->glCaps(), &ds, &random, dummyTextures); |
368 } | 306 } |
369 set_random_color_coverage_stages(gpu, | 307 set_random_color_coverage_stages(gpu, |
370 &ds, | 308 &ds, |
371 maxStages - hasGeometryProcessor, | 309 maxStages - hasGeometryProcessor, |
372 usePathRendering, | 310 usePathRendering, |
373 &random, | 311 &random, |
374 dummyTextures); | 312 dummyTextures); |
375 set_random_color(&ds, &random); | |
376 set_random_coverage(&ds, &random); | |
377 set_random_hints(&ds, &random); | 313 set_random_hints(&ds, &random); |
378 set_random_state(&ds, &random); | 314 set_random_state(&ds, &random); |
379 set_random_blend_func(&ds, &random); | 315 set_random_blend_func(&ds, &random); |
380 set_random_stencil(&ds, &random); | 316 set_random_stencil(&ds, &random); |
381 | 317 |
382 GrDeviceCoordTexture dstCopy; | 318 GrDeviceCoordTexture dstCopy; |
383 | 319 |
384 if (!this->setupDstReadIfNecessary(&ds, &dstCopy, NULL)) { | 320 // TODO take color off the PP when its installed |
| 321 GrColor color = ds.hasGeometryProcessor() ? ds.getGeometryProcessor()->g
etColor() : |
| 322 GrColor_WHITE; |
| 323 uint8_t coverage = ds.hasGeometryProcessor() ? ds.getGeometryProcessor()
->getCoverage() : |
| 324 0xff; |
| 325 if (!this->setupDstReadIfNecessary(&ds, color, coverage, &dstCopy, NULL)
) { |
385 SkDebugf("Couldn't setup dst read texture"); | 326 SkDebugf("Couldn't setup dst read texture"); |
386 return false; | 327 return false; |
387 } | 328 } |
388 | 329 |
389 // create optimized draw state, setup readDst texture if required, and b
uild a descriptor | 330 // create optimized draw state, setup readDst texture if required, and b
uild a descriptor |
390 // and program. ODS creation can fail, so we have to check | 331 // and program. ODS creation can fail, so we have to check |
391 GrOptDrawState ods(ds, *gpu->caps(), scissor, &dstCopy, drawType); | 332 GrOptDrawState ods(ds, color, coverage, *gpu->caps(), scissor, &dstCopy,
drawType); |
392 if (ods.mustSkip()) { | 333 if (ods.mustSkip()) { |
393 continue; | 334 continue; |
394 } | 335 } |
395 ods.finalize(gpu); | 336 ods.finalize(gpu); |
396 SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(ods,
gpu)); | 337 SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(ods,
gpu)); |
397 if (NULL == program.get()) { | 338 if (NULL == program.get()) { |
398 SkDebugf("Failed to create program!"); | 339 SkDebugf("Failed to create program!"); |
399 return false; | 340 return false; |
400 } | 341 } |
401 | 342 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 } | 375 } |
435 #endif | 376 #endif |
436 GrTestTarget target; | 377 GrTestTarget target; |
437 context->getTestTarget(&target); | 378 context->getTestTarget(&target); |
438 REPORTER_ASSERT(reporter, target.target()->programUnitTest(maxStages
)); | 379 REPORTER_ASSERT(reporter, target.target()->programUnitTest(maxStages
)); |
439 } | 380 } |
440 } | 381 } |
441 } | 382 } |
442 | 383 |
443 #endif | 384 #endif |
OLD | NEW |