| 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 "GrBatch.h" | 16 #include "GrBatch.h" |
| 17 #include "GrBatchTest.h" | 17 #include "GrBatchTest.h" |
| 18 #include "GrContextFactory.h" | 18 #include "GrContextFactory.h" |
| 19 #include "GrInvariantOutput.h" | 19 #include "GrInvariantOutput.h" |
| 20 #include "GrPipeline.h" | 20 #include "GrPipeline.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 #include "effects/GrConfigConversionEffect.h" | 27 #include "effects/GrConfigConversionEffect.h" |
| 27 #include "effects/GrPorterDuffXferProcessor.h" | 28 #include "effects/GrPorterDuffXferProcessor.h" |
| 28 #include "gl/GrGLGpu.h" | 29 #include "gl/GrGLGpu.h" |
| 29 #include "gl/GrGLPathRendering.h" | 30 #include "gl/GrGLPathRendering.h" |
| 30 #include "gl/builders/GrGLProgramBuilder.h" | 31 #include "gl/builders/GrGLProgramBuilder.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 GrTexture*[]) { | 99 GrTexture*[]) { |
| 99 return BigKeyProcessor::Create(); | 100 return BigKeyProcessor::Create(); |
| 100 } | 101 } |
| 101 | 102 |
| 102 /* | 103 /* |
| 103 * Begin test code | 104 * Begin test code |
| 104 */ | 105 */ |
| 105 static const int kRenderTargetHeight = 1; | 106 static const int kRenderTargetHeight = 1; |
| 106 static const int kRenderTargetWidth = 1; | 107 static const int kRenderTargetWidth = 1; |
| 107 | 108 |
| 108 static GrRenderTarget* random_render_target(GrContext* context, SkRandom* random
, | 109 static GrRenderTarget* random_render_target(GrTextureProvider* textureProvider,
SkRandom* random, |
| 109 const GrCaps* caps) { | 110 const GrCaps* caps) { |
| 110 // setup render target | 111 // setup render target |
| 111 GrTextureParams params; | 112 GrTextureParams params; |
| 112 GrSurfaceDesc texDesc; | 113 GrSurfaceDesc texDesc; |
| 113 texDesc.fWidth = kRenderTargetWidth; | 114 texDesc.fWidth = kRenderTargetWidth; |
| 114 texDesc.fHeight = kRenderTargetHeight; | 115 texDesc.fHeight = kRenderTargetHeight; |
| 115 texDesc.fFlags = kRenderTarget_GrSurfaceFlag; | 116 texDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 116 texDesc.fConfig = kRGBA_8888_GrPixelConfig; | 117 texDesc.fConfig = kRGBA_8888_GrPixelConfig; |
| 117 texDesc.fOrigin = random->nextBool() == true ? kTopLeft_GrSurfaceOrigin : | 118 texDesc.fOrigin = random->nextBool() == true ? kTopLeft_GrSurfaceOrigin : |
| 118 kBottomLeft_GrSurfaceOrigin; | 119 kBottomLeft_GrSurfaceOrigin; |
| 119 texDesc.fSampleCnt = random->nextBool() == true ? SkTMin(4, caps->maxSampleC
ount()) : 0; | 120 texDesc.fSampleCnt = random->nextBool() == true ? SkTMin(4, caps->maxSampleC
ount()) : 0; |
| 120 | 121 |
| 121 GrUniqueKey key; | 122 GrUniqueKey key; |
| 122 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); | 123 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| 123 GrUniqueKey::Builder builder(&key, kDomain, 2); | 124 GrUniqueKey::Builder builder(&key, kDomain, 2); |
| 124 builder[0] = texDesc.fOrigin; | 125 builder[0] = texDesc.fOrigin; |
| 125 builder[1] = texDesc.fSampleCnt; | 126 builder[1] = texDesc.fSampleCnt; |
| 126 builder.finish(); | 127 builder.finish(); |
| 127 | 128 |
| 128 GrTexture* texture = context->textureProvider()->findAndRefTextureByUniqueKe
y(key); | 129 GrTexture* texture = textureProvider->findAndRefTextureByUniqueKey(key); |
| 129 if (!texture) { | 130 if (!texture) { |
| 130 texture = context->textureProvider()->createTexture(texDesc, true); | 131 texture = textureProvider->createTexture(texDesc, true); |
| 131 if (texture) { | 132 if (texture) { |
| 132 context->textureProvider()->assignUniqueKeyToTexture(key, texture); | 133 textureProvider->assignUniqueKeyToTexture(key, texture); |
| 133 } | 134 } |
| 134 } | 135 } |
| 135 return texture ? texture->asRenderTarget() : NULL; | 136 return texture ? texture->asRenderTarget() : NULL; |
| 136 } | 137 } |
| 137 | 138 |
| 138 static void set_random_xpf(GrContext* context, const GrCaps& caps, | 139 static void set_random_xpf(GrContext* context, const GrCaps& caps, |
| 139 GrPipelineBuilder* pipelineBuilder, SkRandom* random, | 140 GrPipelineBuilder* pipelineBuilder, SkRandom* random, |
| 140 GrTexture* dummyTextures[]) { | 141 GrTexture* dummyTextures[]) { |
| 141 SkAutoTUnref<const GrXPFactory> xpf( | 142 SkAutoTUnref<const GrXPFactory> xpf( |
| 142 GrProcessorTestFactory<GrXPFactory>::CreateStage(random, context, caps,
dummyTextures)); | 143 GrProcessorTestFactory<GrXPFactory>::CreateStage(random, context, caps,
dummyTextures)); |
| 143 SkASSERT(xpf); | 144 SkASSERT(xpf); |
| 144 pipelineBuilder->setXPFactory(xpf.get()); | 145 pipelineBuilder->setXPFactory(xpf.get()); |
| 145 } | 146 } |
| 146 | 147 |
| 147 static void set_random_color_coverage_stages(GrGLGpu* gpu, | 148 static void set_random_color_coverage_stages(GrGpu* gpu, |
| 148 GrPipelineBuilder* pipelineBuilder, | 149 GrPipelineBuilder* pipelineBuilder, |
| 149 int maxStages, | 150 int maxStages, |
| 150 SkRandom* random, | 151 SkRandom* random, |
| 151 GrTexture* dummyTextures[]) { | 152 GrTexture* dummyTextures[]) { |
| 152 int numProcs = random->nextULessThan(maxStages + 1); | 153 int numProcs = random->nextULessThan(maxStages + 1); |
| 153 int numColorProcs = random->nextULessThan(numProcs + 1); | 154 int numColorProcs = random->nextULessThan(numProcs + 1); |
| 154 | 155 |
| 155 for (int s = 0; s < numProcs;) { | 156 for (int s = 0; s < numProcs;) { |
| 156 SkAutoTUnref<const GrFragmentProcessor> fp( | 157 SkAutoTUnref<const GrFragmentProcessor> fp( |
| 157 GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(random, | 158 GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(random, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 0xffff, | 202 0xffff, |
| 202 0xffff); | 203 0xffff); |
| 203 | 204 |
| 204 if (random->nextBool()) { | 205 if (random->nextBool()) { |
| 205 pipelineBuilder->setStencil(kDoesWriteStencil); | 206 pipelineBuilder->setStencil(kDoesWriteStencil); |
| 206 } else { | 207 } else { |
| 207 pipelineBuilder->setStencil(kDoesNotWriteStencil); | 208 pipelineBuilder->setStencil(kDoesNotWriteStencil); |
| 208 } | 209 } |
| 209 } | 210 } |
| 210 | 211 |
| 211 bool GrDrawTarget::programUnitTest(int maxStages) { | 212 bool GrDrawTarget::programUnitTest(GrContext* context, int maxStages) { |
| 212 GrGLGpu* gpu = static_cast<GrGLGpu*>(fContext->getGpu()); | |
| 213 // setup dummy textures | 213 // setup dummy textures |
| 214 GrSurfaceDesc dummyDesc; | 214 GrSurfaceDesc dummyDesc; |
| 215 dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag; | 215 dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 216 dummyDesc.fConfig = kSkia8888_GrPixelConfig; | 216 dummyDesc.fConfig = kSkia8888_GrPixelConfig; |
| 217 dummyDesc.fWidth = 34; | 217 dummyDesc.fWidth = 34; |
| 218 dummyDesc.fHeight = 18; | 218 dummyDesc.fHeight = 18; |
| 219 SkAutoTUnref<GrTexture> dummyTexture1(gpu->createTexture(dummyDesc, false, N
ULL, 0)); | 219 SkAutoTUnref<GrTexture> dummyTexture1( |
| 220 fResourceProvider->createTexture(dummyDesc, false, NULL, 0)); |
| 220 dummyDesc.fFlags = kNone_GrSurfaceFlags; | 221 dummyDesc.fFlags = kNone_GrSurfaceFlags; |
| 221 dummyDesc.fConfig = kAlpha_8_GrPixelConfig; | 222 dummyDesc.fConfig = kAlpha_8_GrPixelConfig; |
| 222 dummyDesc.fWidth = 16; | 223 dummyDesc.fWidth = 16; |
| 223 dummyDesc.fHeight = 22; | 224 dummyDesc.fHeight = 22; |
| 224 SkAutoTUnref<GrTexture> dummyTexture2(gpu->createTexture(dummyDesc, false, N
ULL, 0)); | 225 SkAutoTUnref<GrTexture> dummyTexture2( |
| 226 fResourceProvider->createTexture(dummyDesc, false, NULL, 0)); |
| 225 | 227 |
| 226 if (!dummyTexture1 || ! dummyTexture2) { | 228 if (!dummyTexture1 || ! dummyTexture2) { |
| 227 SkDebugf("Could not allocate dummy textures"); | 229 SkDebugf("Could not allocate dummy textures"); |
| 228 return false; | 230 return false; |
| 229 } | 231 } |
| 230 | 232 |
| 231 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; | 233 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; |
| 232 | 234 |
| 233 // dummy scissor state | 235 // dummy scissor state |
| 234 GrScissorState scissor; | 236 GrScissorState scissor; |
| 235 | 237 |
| 236 // wide open clip | 238 // wide open clip |
| 237 GrClip clip; | 239 GrClip clip; |
| 238 | 240 |
| 239 SkRandom random; | 241 SkRandom random; |
| 240 static const int NUM_TESTS = 2048; | 242 static const int NUM_TESTS = 2048; |
| 241 for (int t = 0; t < NUM_TESTS; t++) { | 243 for (int t = 0; t < NUM_TESTS; t++) { |
| 242 // setup random render target(can fail) | 244 // setup random render target(can fail) |
| 243 SkAutoTUnref<GrRenderTarget> rt(random_render_target(fContext, &random,
this->caps())); | 245 SkAutoTUnref<GrRenderTarget> rt(random_render_target( |
| 246 fResourceProvider, &random, this->caps())); |
| 244 if (!rt.get()) { | 247 if (!rt.get()) { |
| 245 SkDebugf("Could not allocate render target"); | 248 SkDebugf("Could not allocate render target"); |
| 246 return false; | 249 return false; |
| 247 } | 250 } |
| 248 | 251 |
| 249 GrPipelineBuilder pipelineBuilder; | 252 GrPipelineBuilder pipelineBuilder; |
| 250 pipelineBuilder.setRenderTarget(rt.get()); | 253 pipelineBuilder.setRenderTarget(rt.get()); |
| 251 pipelineBuilder.setClip(clip); | 254 pipelineBuilder.setClip(clip); |
| 252 | 255 |
| 253 SkAutoTUnref<GrBatch> batch(GrRandomBatch(&random, fContext)); | 256 SkAutoTUnref<GrBatch> batch(GrRandomBatch(&random, context)); |
| 254 SkASSERT(batch); | 257 SkASSERT(batch); |
| 255 | 258 |
| 256 set_random_color_coverage_stages(gpu, | 259 set_random_color_coverage_stages(fGpu, |
| 257 &pipelineBuilder, | 260 &pipelineBuilder, |
| 258 maxStages, | 261 maxStages, |
| 259 &random, | 262 &random, |
| 260 dummyTextures); | 263 dummyTextures); |
| 261 | 264 |
| 262 // creates a random xfer processor factory on the draw state | 265 // creates a random xfer processor factory on the draw state |
| 263 set_random_xpf(fContext, gpu->glCaps(), &pipelineBuilder, &random, dummy
Textures); | 266 set_random_xpf(context, *fGpu->caps(), &pipelineBuilder, &random, dummyT
extures); |
| 264 | 267 |
| 265 set_random_state(&pipelineBuilder, &random); | 268 set_random_state(&pipelineBuilder, &random); |
| 266 set_random_stencil(&pipelineBuilder, &random); | 269 set_random_stencil(&pipelineBuilder, &random); |
| 267 | 270 |
| 268 this->drawBatch(&pipelineBuilder, batch); | 271 this->drawBatch(&pipelineBuilder, batch); |
| 269 } | 272 } |
| 270 | 273 |
| 271 // Flush everything, test passes if flush is successful(ie, no asserts are h
it, no crashes) | 274 // Flush everything, test passes if flush is successful(ie, no asserts are h
it, no crashes) |
| 272 this->flush(); | 275 this->flush(); |
| 273 return true; | 276 return true; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 return; | 310 return; |
| 308 } | 311 } |
| 309 #if SK_ANGLE | 312 #if SK_ANGLE |
| 310 // Some long shaders run out of temporary registers in the D3D compi
ler on ANGLE. | 313 // Some long shaders run out of temporary registers in the D3D compi
ler on ANGLE. |
| 311 if (type == GrContextFactory::kANGLE_GLContextType) { | 314 if (type == GrContextFactory::kANGLE_GLContextType) { |
| 312 maxStages = 2; | 315 maxStages = 2; |
| 313 } | 316 } |
| 314 #endif | 317 #endif |
| 315 GrTestTarget target; | 318 GrTestTarget target; |
| 316 context->getTestTarget(&target); | 319 context->getTestTarget(&target); |
| 317 REPORTER_ASSERT(reporter, target.target()->programUnitTest(maxStages
)); | 320 REPORTER_ASSERT(reporter, target.target()->programUnitTest(context,
maxStages)); |
| 318 } | 321 } |
| 319 } | 322 } |
| 320 } | 323 } |
| 321 | 324 |
| 322 #endif | 325 #endif |
| OLD | NEW |