OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 // This is a GPU-backend specific test. It relies on static intializers to work | 8 // This is a GPU-backend specific test. It relies on static intializers to work |
9 | 9 |
10 #include "SkTypes.h" | 10 #include "SkTypes.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 return nullptr; | 177 return nullptr; |
178 } | 178 } |
179 | 179 |
180 // TODO: need a real way to do this via the drawContext | 180 // TODO: need a real way to do this via the drawContext |
181 texture = drawContext->asTexture(); | 181 texture = drawContext->asTexture(); |
182 context->textureProvider()->assignUniqueKeyToTexture(key, texture.get()); | 182 context->textureProvider()->assignUniqueKeyToTexture(key, texture.get()); |
183 | 183 |
184 return drawContext; | 184 return drawContext; |
185 } | 185 } |
186 | 186 |
187 static void set_random_xpf(GrPipelineBuilder* pipelineBuilder, GrProcessorTestDa
ta* d) { | 187 static void set_random_xpf(GrPaint* paint, GrProcessorTestData* d) { |
188 sk_sp<GrXPFactory> xpf(GrProcessorTestFactory<GrXPFactory>::Make(d)); | 188 sk_sp<GrXPFactory> xpf(GrProcessorTestFactory<GrXPFactory>::Make(d)); |
189 SkASSERT(xpf); | 189 SkASSERT(xpf); |
190 pipelineBuilder->setXPFactory(std::move(xpf)); | 190 paint->setXPFactory(std::move(xpf)); |
191 } | 191 } |
192 | 192 |
193 static sk_sp<GrFragmentProcessor> create_random_proc_tree(GrProcessorTestData* d
, | 193 static sk_sp<GrFragmentProcessor> create_random_proc_tree(GrProcessorTestData* d
, |
194 int minLevels, int max
Levels) { | 194 int minLevels, int max
Levels) { |
195 SkASSERT(1 <= minLevels); | 195 SkASSERT(1 <= minLevels); |
196 SkASSERT(minLevels <= maxLevels); | 196 SkASSERT(minLevels <= maxLevels); |
197 | 197 |
198 // Return a leaf node if maxLevels is 1 or if we randomly chose to terminate
. | 198 // Return a leaf node if maxLevels is 1 or if we randomly chose to terminate
. |
199 // If returning a leaf node, make sure that it doesn't have children (e.g. a
nother | 199 // If returning a leaf node, make sure that it doesn't have children (e.g. a
nother |
200 // GrComposeEffect) | 200 // GrComposeEffect) |
(...skipping 28 matching lines...) Expand all Loading... |
229 std::move(otherC
hild), mode); | 229 std::move(otherC
hild), mode); |
230 SkASSERT(fp); | 230 SkASSERT(fp); |
231 } else { | 231 } else { |
232 fp = GrXfermodeFragmentProcessor::MakeFromTwoProcessors(std::move(otherC
hild), | 232 fp = GrXfermodeFragmentProcessor::MakeFromTwoProcessors(std::move(otherC
hild), |
233 std::move(minLev
elsChild), mode); | 233 std::move(minLev
elsChild), mode); |
234 SkASSERT(fp); | 234 SkASSERT(fp); |
235 } | 235 } |
236 return fp; | 236 return fp; |
237 } | 237 } |
238 | 238 |
239 static void set_random_color_coverage_stages(GrPipelineBuilder* pipelineBuilder, | 239 static void set_random_color_coverage_stages(GrPaint* paint, |
240 GrProcessorTestData* d, int maxStag
es) { | 240 GrProcessorTestData* d, |
| 241 int maxStages) { |
241 // Randomly choose to either create a linear pipeline of procs or create one
proc tree | 242 // Randomly choose to either create a linear pipeline of procs or create one
proc tree |
242 const float procTreeProbability = 0.5f; | 243 const float procTreeProbability = 0.5f; |
243 if (d->fRandom->nextF() < procTreeProbability) { | 244 if (d->fRandom->nextF() < procTreeProbability) { |
244 // A full tree with 5 levels (31 nodes) may exceed the max allowed lengt
h of the gl | 245 // A full tree with 5 levels (31 nodes) may exceed the max allowed lengt
h of the gl |
245 // processor key; maxTreeLevels should be a number from 1 to 4 inclusive
. | 246 // processor key; maxTreeLevels should be a number from 1 to 4 inclusive
. |
246 const int maxTreeLevels = 4; | 247 const int maxTreeLevels = 4; |
247 sk_sp<GrFragmentProcessor> fp(create_random_proc_tree(d, 2, maxTreeLevel
s)); | 248 sk_sp<GrFragmentProcessor> fp(create_random_proc_tree(d, 2, maxTreeLevel
s)); |
248 pipelineBuilder->addColorFragmentProcessor(std::move(fp)); | 249 paint->addColorFragmentProcessor(std::move(fp)); |
249 } else { | 250 } else { |
250 int numProcs = d->fRandom->nextULessThan(maxStages + 1); | 251 int numProcs = d->fRandom->nextULessThan(maxStages + 1); |
251 int numColorProcs = d->fRandom->nextULessThan(numProcs + 1); | 252 int numColorProcs = d->fRandom->nextULessThan(numProcs + 1); |
252 | 253 |
253 for (int s = 0; s < numProcs;) { | 254 for (int s = 0; s < numProcs;) { |
254 sk_sp<GrFragmentProcessor> fp(GrProcessorTestFactory<GrFragmentProce
ssor>::Make(d)); | 255 sk_sp<GrFragmentProcessor> fp(GrProcessorTestFactory<GrFragmentProce
ssor>::Make(d)); |
255 SkASSERT(fp); | 256 SkASSERT(fp); |
256 | 257 |
257 // finally add the stage to the correct pipeline in the drawstate | 258 // finally add the stage to the correct pipeline in the drawstate |
258 if (s < numColorProcs) { | 259 if (s < numColorProcs) { |
259 pipelineBuilder->addColorFragmentProcessor(std::move(fp)); | 260 paint->addColorFragmentProcessor(std::move(fp)); |
260 } else { | 261 } else { |
261 pipelineBuilder->addCoverageFragmentProcessor(std::move(fp)); | 262 paint->addCoverageFragmentProcessor(std::move(fp)); |
262 } | 263 } |
263 ++s; | 264 ++s; |
264 } | 265 } |
265 } | 266 } |
266 } | 267 } |
267 | 268 |
268 static void set_random_state(GrPipelineBuilder* pipelineBuilder, | 269 static bool set_random_state(GrPaint* paint, SkRandom* random) { |
269 GrDrawContext* drawContext, | 270 if (random->nextBool()) { |
270 SkRandom* random) { | 271 paint->setDisableOutputConversionToSRGB(true); |
271 int state = 0; | |
272 for (int i = 1; i <= GrPipelineBuilder::kLast_Flag; i <<= 1) { | |
273 state |= random->nextBool() * i; | |
274 } | 272 } |
275 | 273 if (random->nextBool()) { |
276 // If we don't have an MSAA rendertarget then we have to disable useHWAA | 274 paint->setAllowSRGBInputs(true); |
277 if ((state | GrPipelineBuilder::kHWAntialias_Flag) && !drawContext->isUnifie
dMultisampled()) { | |
278 state &= ~GrPipelineBuilder::kHWAntialias_Flag; | |
279 } | 275 } |
280 pipelineBuilder->enableState(state); | 276 if (random->nextBool()) { |
| 277 paint->setAntiAlias(true); |
| 278 } |
| 279 return random->nextBool(); |
281 } | 280 } |
282 | 281 |
283 // right now, the only thing we seem to care about in drawState's stencil is 'do
esWrite()' | 282 // right now, the only thing we seem to care about in drawState's stencil is 'do
esWrite()' |
284 static void set_random_stencil(GrPipelineBuilder* pipelineBuilder, SkRandom* ran
dom) { | 283 static const GrUserStencilSettings* get_random_stencil(SkRandom* random) { |
285 static constexpr GrUserStencilSettings kDoesWriteStencil( | 284 static constexpr GrUserStencilSettings kDoesWriteStencil( |
286 GrUserStencilSettings::StaticInit< | 285 GrUserStencilSettings::StaticInit< |
287 0xffff, | 286 0xffff, |
288 GrUserStencilTest::kAlways, | 287 GrUserStencilTest::kAlways, |
289 0xffff, | 288 0xffff, |
290 GrUserStencilOp::kReplace, | 289 GrUserStencilOp::kReplace, |
291 GrUserStencilOp::kReplace, | 290 GrUserStencilOp::kReplace, |
292 0xffff>() | 291 0xffff>() |
293 ); | 292 ); |
294 static constexpr GrUserStencilSettings kDoesNotWriteStencil( | 293 static constexpr GrUserStencilSettings kDoesNotWriteStencil( |
295 GrUserStencilSettings::StaticInit< | 294 GrUserStencilSettings::StaticInit< |
296 0xffff, | 295 0xffff, |
297 GrUserStencilTest::kNever, | 296 GrUserStencilTest::kNever, |
298 0xffff, | 297 0xffff, |
299 GrUserStencilOp::kKeep, | 298 GrUserStencilOp::kKeep, |
300 GrUserStencilOp::kKeep, | 299 GrUserStencilOp::kKeep, |
301 0xffff>() | 300 0xffff>() |
302 ); | 301 ); |
303 | 302 |
304 if (random->nextBool()) { | 303 if (random->nextBool()) { |
305 pipelineBuilder->setUserStencil(&kDoesWriteStencil); | 304 return &kDoesWriteStencil; |
306 } else { | 305 } else { |
307 pipelineBuilder->setUserStencil(&kDoesNotWriteStencil); | 306 return &kDoesNotWriteStencil; |
308 } | 307 } |
309 } | 308 } |
310 | 309 |
311 bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages) { | 310 bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages) { |
312 GrDrawingManager* drawingManager = context->drawingManager(); | 311 GrDrawingManager* drawingManager = context->drawingManager(); |
313 | 312 |
314 // setup dummy textures | 313 // setup dummy textures |
315 GrSurfaceDesc dummyDesc; | 314 GrSurfaceDesc dummyDesc; |
316 dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag; | 315 dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
317 dummyDesc.fConfig = kSkia8888_GrPixelConfig; | 316 dummyDesc.fConfig = kSkia8888_GrPixelConfig; |
(...skipping 21 matching lines...) Expand all Loading... |
339 SkRandom random; | 338 SkRandom random; |
340 static const int NUM_TESTS = 1024; | 339 static const int NUM_TESTS = 1024; |
341 for (int t = 0; t < NUM_TESTS; t++) { | 340 for (int t = 0; t < NUM_TESTS; t++) { |
342 // setup random render target(can fail) | 341 // setup random render target(can fail) |
343 sk_sp<GrDrawContext> drawContext(random_draw_context(context, &random, c
ontext->caps())); | 342 sk_sp<GrDrawContext> drawContext(random_draw_context(context, &random, c
ontext->caps())); |
344 if (!drawContext) { | 343 if (!drawContext) { |
345 SkDebugf("Could not allocate drawContext"); | 344 SkDebugf("Could not allocate drawContext"); |
346 return false; | 345 return false; |
347 } | 346 } |
348 | 347 |
349 GrPipelineBuilder pipelineBuilder; | 348 GrPaint grPaint; |
350 | 349 |
351 SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context)); | 350 SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context)); |
352 SkASSERT(batch); | 351 SkASSERT(batch); |
353 | 352 |
354 GrProcessorTestData ptd(&random, context, context->caps(), | 353 GrProcessorTestData ptd(&random, context, context->caps(), |
355 drawContext.get(), dummyTextures); | 354 drawContext.get(), dummyTextures); |
356 set_random_color_coverage_stages(&pipelineBuilder, &ptd, maxStages); | 355 set_random_color_coverage_stages(&grPaint, &ptd, maxStages); |
357 set_random_xpf(&pipelineBuilder, &ptd); | 356 set_random_xpf(&grPaint, &ptd); |
358 set_random_state(&pipelineBuilder, drawContext.get(), &random); | 357 bool snapToCenters = set_random_state(&grPaint, &random); |
359 set_random_stencil(&pipelineBuilder, &random); | 358 const GrUserStencilSettings* uss = get_random_stencil(&random); |
360 | 359 |
361 drawContext->drawContextPriv().testingOnly_drawBatch(pipelineBuilder, ba
tch); | 360 drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch, uss
, snapToCenters); |
362 } | 361 } |
363 // Flush everything, test passes if flush is successful(ie, no asserts are h
it, no crashes) | 362 // Flush everything, test passes if flush is successful(ie, no asserts are h
it, no crashes) |
364 drawingManager->flush(); | 363 drawingManager->flush(); |
365 | 364 |
366 // Validate that GrFPs work correctly without an input. | 365 // Validate that GrFPs work correctly without an input. |
367 sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kExac
t, | 366 sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kExac
t, |
368 kRenderTargetWidth, | 367 kRenderTargetWidth, |
369 kRenderTargetHeight
, | 368 kRenderTargetHeight
, |
370 kRGBA_8888_GrPixelC
onfig)); | 369 kRGBA_8888_GrPixelC
onfig)); |
371 if (!drawContext) { | 370 if (!drawContext) { |
372 SkDebugf("Could not allocate a drawContext"); | 371 SkDebugf("Could not allocate a drawContext"); |
373 return false; | 372 return false; |
374 } | 373 } |
375 | 374 |
376 int fpFactoryCnt = GrProcessorTestFactory<GrFragmentProcessor>::Count(); | 375 int fpFactoryCnt = GrProcessorTestFactory<GrFragmentProcessor>::Count(); |
377 for (int i = 0; i < fpFactoryCnt; ++i) { | 376 for (int i = 0; i < fpFactoryCnt; ++i) { |
378 // Since FP factories internally randomize, call each 10 times. | 377 // Since FP factories internally randomize, call each 10 times. |
379 for (int j = 0; j < 10; ++j) { | 378 for (int j = 0; j < 10; ++j) { |
380 SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context))
; | 379 SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context))
; |
381 SkASSERT(batch); | 380 SkASSERT(batch); |
382 GrProcessorTestData ptd(&random, context, context->caps(), | 381 GrProcessorTestData ptd(&random, context, context->caps(), |
383 drawContext.get(), dummyTextures); | 382 drawContext.get(), dummyTextures); |
384 GrPipelineBuilder builder; | 383 GrPaint grPaint; |
385 builder.setXPFactory(GrPorterDuffXPFactory::Make(SkXfermode::kSrc_Mo
de)); | 384 grPaint.setXPFactory(GrPorterDuffXPFactory::Make(SkXfermode::kSrc_Mo
de)); |
386 | 385 |
387 sk_sp<GrFragmentProcessor> fp( | 386 sk_sp<GrFragmentProcessor> fp( |
388 GrProcessorTestFactory<GrFragmentProcessor>::MakeIdx(i, &ptd)); | 387 GrProcessorTestFactory<GrFragmentProcessor>::MakeIdx(i, &ptd)); |
389 sk_sp<GrFragmentProcessor> blockFP( | 388 sk_sp<GrFragmentProcessor> blockFP( |
390 BlockInputFragmentProcessor::Make(std::move(fp))); | 389 BlockInputFragmentProcessor::Make(std::move(fp))); |
391 builder.addColorFragmentProcessor(std::move(blockFP)); | 390 grPaint.addColorFragmentProcessor(std::move(blockFP)); |
392 | 391 |
393 drawContext->drawContextPriv().testingOnly_drawBatch(builder, batch)
; | 392 drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch)
; |
394 drawingManager->flush(); | 393 drawingManager->flush(); |
395 } | 394 } |
396 } | 395 } |
397 | 396 |
398 return true; | 397 return true; |
399 } | 398 } |
400 | 399 |
401 static int get_glprograms_max_stages(GrContext* context) { | 400 static int get_glprograms_max_stages(GrContext* context) { |
402 GrGLGpu* gpu = static_cast<GrGLGpu*>(context->getGpu()); | 401 GrGLGpu* gpu = static_cast<GrGLGpu*>(context->getGpu()); |
403 /* | 402 /* |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 GrContextOptions opts; | 461 GrContextOptions opts; |
463 opts.fSuppressPrints = true; | 462 opts.fSuppressPrints = true; |
464 sk_gpu_test::GrContextFactory debugFactory(opts); | 463 sk_gpu_test::GrContextFactory debugFactory(opts); |
465 skiatest::RunWithGPUTestContexts(test_glprograms_native, &is_native_gl_conte
xt_type, | 464 skiatest::RunWithGPUTestContexts(test_glprograms_native, &is_native_gl_conte
xt_type, |
466 reporter, &debugFactory); | 465 reporter, &debugFactory); |
467 skiatest::RunWithGPUTestContexts(test_glprograms_other_contexts, | 466 skiatest::RunWithGPUTestContexts(test_glprograms_other_contexts, |
468 &is_other_rendering_gl_context_type, report
er, &debugFactory); | 467 &is_other_rendering_gl_context_type, report
er, &debugFactory); |
469 } | 468 } |
470 | 469 |
471 #endif | 470 #endif |
OLD | NEW |