| 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 "GrAutoLocaleSetter.h" | 15 #include "GrAutoLocaleSetter.h" |
| 16 #include "GrBatchTest.h" | 16 #include "GrBatchTest.h" |
| 17 #include "GrContextFactory.h" | 17 #include "GrContextFactory.h" |
| 18 #include "GrDrawingManager.h" |
| 18 #include "GrInvariantOutput.h" | 19 #include "GrInvariantOutput.h" |
| 19 #include "GrPipeline.h" | 20 #include "GrPipeline.h" |
| 20 #include "GrResourceProvider.h" | 21 #include "GrResourceProvider.h" |
| 21 #include "GrTest.h" | 22 #include "GrTest.h" |
| 22 #include "GrXferProcessor.h" | 23 #include "GrXferProcessor.h" |
| 23 #include "SkChecksum.h" | 24 #include "SkChecksum.h" |
| 24 #include "SkRandom.h" | 25 #include "SkRandom.h" |
| 25 #include "Test.h" | 26 #include "Test.h" |
| 26 | 27 |
| 27 #include "batches/GrDrawBatch.h" | 28 #include "batches/GrDrawBatch.h" |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 0xffff, | 294 0xffff, |
| 294 0xffff); | 295 0xffff); |
| 295 | 296 |
| 296 if (random->nextBool()) { | 297 if (random->nextBool()) { |
| 297 pipelineBuilder->setStencil(kDoesWriteStencil); | 298 pipelineBuilder->setStencil(kDoesWriteStencil); |
| 298 } else { | 299 } else { |
| 299 pipelineBuilder->setStencil(kDoesNotWriteStencil); | 300 pipelineBuilder->setStencil(kDoesNotWriteStencil); |
| 300 } | 301 } |
| 301 } | 302 } |
| 302 | 303 |
| 303 bool GrDrawTarget::programUnitTest(GrContext* context, int maxStages) { | 304 bool GrDrawingManager::ProgramUnitTest(GrContext* context, GrDrawTarget* drawTar
get, int maxStages) { |
| 305 |
| 306 GrDrawingManager* drawingManager = context->drawingManager(); |
| 307 |
| 304 // setup dummy textures | 308 // setup dummy textures |
| 305 GrSurfaceDesc dummyDesc; | 309 GrSurfaceDesc dummyDesc; |
| 306 dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag; | 310 dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 307 dummyDesc.fConfig = kSkia8888_GrPixelConfig; | 311 dummyDesc.fConfig = kSkia8888_GrPixelConfig; |
| 308 dummyDesc.fWidth = 34; | 312 dummyDesc.fWidth = 34; |
| 309 dummyDesc.fHeight = 18; | 313 dummyDesc.fHeight = 18; |
| 310 SkAutoTUnref<GrTexture> dummyTexture1( | 314 SkAutoTUnref<GrTexture> dummyTexture1( |
| 311 context->textureProvider()->createTexture(dummyDesc, false, nullptr, 0))
; | 315 context->textureProvider()->createTexture(dummyDesc, false, nullptr, 0))
; |
| 312 dummyDesc.fFlags = kNone_GrSurfaceFlags; | 316 dummyDesc.fFlags = kNone_GrSurfaceFlags; |
| 313 dummyDesc.fConfig = kAlpha_8_GrPixelConfig; | 317 dummyDesc.fConfig = kAlpha_8_GrPixelConfig; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 327 GrScissorState scissor; | 331 GrScissorState scissor; |
| 328 | 332 |
| 329 // wide open clip | 333 // wide open clip |
| 330 GrClip clip; | 334 GrClip clip; |
| 331 | 335 |
| 332 SkRandom random; | 336 SkRandom random; |
| 333 static const int NUM_TESTS = 2048; | 337 static const int NUM_TESTS = 2048; |
| 334 for (int t = 0; t < NUM_TESTS; t++) { | 338 for (int t = 0; t < NUM_TESTS; t++) { |
| 335 // setup random render target(can fail) | 339 // setup random render target(can fail) |
| 336 SkAutoTUnref<GrRenderTarget> rt(random_render_target( | 340 SkAutoTUnref<GrRenderTarget> rt(random_render_target( |
| 337 context->textureProvider(), &random, this->caps())); | 341 context->textureProvider(), &random, context->caps())); |
| 338 if (!rt.get()) { | 342 if (!rt.get()) { |
| 339 SkDebugf("Could not allocate render target"); | 343 SkDebugf("Could not allocate render target"); |
| 340 return false; | 344 return false; |
| 341 } | 345 } |
| 342 | 346 |
| 343 GrPipelineBuilder pipelineBuilder; | 347 GrPipelineBuilder pipelineBuilder; |
| 344 pipelineBuilder.setRenderTarget(rt.get()); | 348 pipelineBuilder.setRenderTarget(rt.get()); |
| 345 pipelineBuilder.setClip(clip); | 349 pipelineBuilder.setClip(clip); |
| 346 | 350 |
| 347 SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context)); | 351 SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context)); |
| 348 SkASSERT(batch); | 352 SkASSERT(batch); |
| 349 | 353 |
| 350 GrProcessorTestData ptd(&random, context, fGpu->caps(), dummyTextures); | 354 GrProcessorTestData ptd(&random, context, context->caps(), dummyTextures
); |
| 351 set_random_color_coverage_stages(&pipelineBuilder, &ptd, maxStages); | 355 set_random_color_coverage_stages(&pipelineBuilder, &ptd, maxStages); |
| 352 set_random_xpf(&pipelineBuilder, &ptd); | 356 set_random_xpf(&pipelineBuilder, &ptd); |
| 353 set_random_state(&pipelineBuilder, &random); | 357 set_random_state(&pipelineBuilder, &random); |
| 354 set_random_stencil(&pipelineBuilder, &random); | 358 set_random_stencil(&pipelineBuilder, &random); |
| 355 | 359 |
| 356 this->drawBatch(pipelineBuilder, batch); | 360 drawTarget->drawBatch(pipelineBuilder, batch); |
| 357 } | 361 } |
| 358 // 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) |
| 359 this->flush(); | 363 drawingManager->flush(); |
| 360 | 364 |
| 361 // Validate that GrFPs work correctly without an input. | 365 // Validate that GrFPs work correctly without an input. |
| 362 GrSurfaceDesc rtDesc; | 366 GrSurfaceDesc rtDesc; |
| 363 rtDesc.fWidth = kRenderTargetWidth; | 367 rtDesc.fWidth = kRenderTargetWidth; |
| 364 rtDesc.fHeight = kRenderTargetHeight; | 368 rtDesc.fHeight = kRenderTargetHeight; |
| 365 rtDesc.fFlags = kRenderTarget_GrSurfaceFlag; | 369 rtDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 366 rtDesc.fConfig = kRGBA_8888_GrPixelConfig; | 370 rtDesc.fConfig = kRGBA_8888_GrPixelConfig; |
| 367 SkAutoTUnref<GrRenderTarget> rt( | 371 SkAutoTUnref<GrRenderTarget> rt( |
| 368 fContext->textureProvider()->createTexture(rtDesc, false)->asRenderTarge
t()); | 372 context->textureProvider()->createTexture(rtDesc, false)->asRenderTarget
()); |
| 369 int fpFactoryCnt = GrProcessorTestFactory<GrFragmentProcessor>::Count(); | 373 int fpFactoryCnt = GrProcessorTestFactory<GrFragmentProcessor>::Count(); |
| 370 for (int i = 0; i < fpFactoryCnt; ++i) { | 374 for (int i = 0; i < fpFactoryCnt; ++i) { |
| 371 // Since FP factories internally randomize, call each 10 times. | 375 // Since FP factories internally randomize, call each 10 times. |
| 372 for (int j = 0; j < 10; ++j) { | 376 for (int j = 0; j < 10; ++j) { |
| 373 SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context))
; | 377 SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context))
; |
| 374 SkASSERT(batch); | 378 SkASSERT(batch); |
| 375 GrProcessorTestData ptd(&random, context, this->caps(), dummyTexture
s); | 379 GrProcessorTestData ptd(&random, context, context->caps(), dummyText
ures); |
| 376 GrPipelineBuilder builder; | 380 GrPipelineBuilder builder; |
| 377 builder.setXPFactory(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_
Mode))->unref(); | 381 builder.setXPFactory(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_
Mode))->unref(); |
| 378 builder.setRenderTarget(rt); | 382 builder.setRenderTarget(rt); |
| 379 builder.setClip(clip); | 383 builder.setClip(clip); |
| 380 | 384 |
| 381 SkAutoTUnref<const GrFragmentProcessor> fp( | 385 SkAutoTUnref<const GrFragmentProcessor> fp( |
| 382 GrProcessorTestFactory<GrFragmentProcessor>::CreateIdx(i, &ptd))
; | 386 GrProcessorTestFactory<GrFragmentProcessor>::CreateIdx(i, &ptd))
; |
| 383 SkAutoTUnref<const GrFragmentProcessor> blockFP( | 387 SkAutoTUnref<const GrFragmentProcessor> blockFP( |
| 384 BlockInputFragmentProcessor::Create(fp)); | 388 BlockInputFragmentProcessor::Create(fp)); |
| 385 builder.addColorFragmentProcessor(blockFP); | 389 builder.addColorFragmentProcessor(blockFP); |
| 386 | 390 |
| 387 this->drawBatch(builder, batch); | 391 drawTarget->drawBatch(builder, batch); |
| 388 this->flush(); | 392 drawingManager->flush(); |
| 389 } | 393 } |
| 390 } | 394 } |
| 391 | 395 |
| 392 return true; | 396 return true; |
| 393 } | 397 } |
| 394 | 398 |
| 395 DEF_GPUTEST(GLPrograms, reporter, factory) { | 399 DEF_GPUTEST(GLPrograms, reporter, factory) { |
| 396 // Set a locale that would cause shader compilation to fail because of , as
decimal separator. | 400 // Set a locale that would cause shader compilation to fail because of , as
decimal separator. |
| 397 // skbug 3330 | 401 // skbug 3330 |
| 398 #ifdef SK_BUILD_FOR_WIN | 402 #ifdef SK_BUILD_FOR_WIN |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 maxStages = 2; | 435 maxStages = 2; |
| 432 } | 436 } |
| 433 #endif | 437 #endif |
| 434 #if SK_COMMAND_BUFFER | 438 #if SK_COMMAND_BUFFER |
| 435 // Some long shaders run out of temporary registers in the D3D compi
ler on ANGLE. | 439 // Some long shaders run out of temporary registers in the D3D compi
ler on ANGLE. |
| 436 // TODO(hendrikw): This only needs to happen with the ANGLE comand b
uffer backend. | 440 // TODO(hendrikw): This only needs to happen with the ANGLE comand b
uffer backend. |
| 437 if (type == GrContextFactory::kCommandBuffer_GLContextType) { | 441 if (type == GrContextFactory::kCommandBuffer_GLContextType) { |
| 438 maxStages = 2; | 442 maxStages = 2; |
| 439 } | 443 } |
| 440 #endif | 444 #endif |
| 441 GrTestTarget target; | 445 GrTestTarget testTarget; |
| 442 context->getTestTarget(&target); | 446 context->getTestTarget(&testTarget); |
| 443 REPORTER_ASSERT(reporter, target.target()->programUnitTest(context,
maxStages)); | 447 REPORTER_ASSERT(reporter, GrDrawingManager::ProgramUnitTest( |
| 448 context, testTarget.target(), maxSta
ges)); |
| 444 } | 449 } |
| 445 } | 450 } |
| 446 } | 451 } |
| 447 | 452 |
| 448 #endif | 453 #endif |
| OLD | NEW |