| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 GrTexture*[]) { | 91 GrTexture*[]) { |
| 92 return BigKeyProcessor::Create(); | 92 return BigKeyProcessor::Create(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 /* | 95 /* |
| 96 * Begin test code | 96 * Begin test code |
| 97 */ | 97 */ |
| 98 static const int kRenderTargetHeight = 1; | 98 static const int kRenderTargetHeight = 1; |
| 99 static const int kRenderTargetWidth = 1; | 99 static const int kRenderTargetWidth = 1; |
| 100 | 100 |
| 101 static GrRenderTarget* random_render_target(GrContext* context, | 101 static GrRenderTarget* random_render_target(GrContext* context, SkRandom* random
) { |
| 102 const GrCacheID& cacheId, | |
| 103 SkRandom* random) { | |
| 104 // setup render target | 102 // setup render target |
| 105 GrTextureParams params; | 103 GrTextureParams params; |
| 106 GrSurfaceDesc texDesc; | 104 GrSurfaceDesc texDesc; |
| 107 texDesc.fWidth = kRenderTargetWidth; | 105 texDesc.fWidth = kRenderTargetWidth; |
| 108 texDesc.fHeight = kRenderTargetHeight; | 106 texDesc.fHeight = kRenderTargetHeight; |
| 109 texDesc.fFlags = kRenderTarget_GrSurfaceFlag; | 107 texDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 110 texDesc.fConfig = kRGBA_8888_GrPixelConfig; | 108 texDesc.fConfig = kRGBA_8888_GrPixelConfig; |
| 111 texDesc.fOrigin = random->nextBool() == true ? kTopLeft_GrSurfaceOrigin : | 109 texDesc.fOrigin = random->nextBool() == true ? kTopLeft_GrSurfaceOrigin : |
| 112 kBottomLeft_GrSurfaceOrigin; | 110 kBottomLeft_GrSurfaceOrigin; |
| 111 GrContentKey key; |
| 112 static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain(); |
| 113 GrContentKey::Builder builder(&key, kDomain, 1); |
| 114 builder[0] = texDesc.fOrigin; |
| 115 builder.finish(); |
| 113 | 116 |
| 114 SkAutoTUnref<GrTexture> texture(context->findAndRefTexture(texDesc, cacheId,
¶ms)); | 117 SkAutoTUnref<GrTexture> texture(context->findAndRefTexture(texDesc, key, &pa
rams)); |
| 115 if (!texture) { | 118 if (!texture) { |
| 116 texture.reset(context->createTexture(¶ms, texDesc, cacheId, 0, 0)); | 119 texture.reset(context->createTexture(¶ms, texDesc, key, 0, 0)); |
| 117 if (!texture) { | 120 if (!texture) { |
| 118 return NULL; | 121 return NULL; |
| 119 } | 122 } |
| 120 } | 123 } |
| 121 return SkRef(texture->asRenderTarget()); | 124 return SkRef(texture->asRenderTarget()); |
| 122 } | 125 } |
| 123 | 126 |
| 124 static void set_random_xpf(GrContext* context, const GrDrawTargetCaps& caps, GrD
rawState* ds, | 127 static void set_random_xpf(GrContext* context, const GrDrawTargetCaps& caps, GrD
rawState* ds, |
| 125 SkRandom* random, GrTexture* dummyTextures[]) { | 128 SkRandom* random, GrTexture* dummyTextures[]) { |
| 126 SkAutoTUnref<const GrXPFactory> xpf( | 129 SkAutoTUnref<const GrXPFactory> xpf( |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 if (!dummyTexture1 || ! dummyTexture2) { | 232 if (!dummyTexture1 || ! dummyTexture2) { |
| 230 SkDebugf("Could not allocate dummy textures"); | 233 SkDebugf("Could not allocate dummy textures"); |
| 231 return false; | 234 return false; |
| 232 } | 235 } |
| 233 | 236 |
| 234 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; | 237 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; |
| 235 | 238 |
| 236 // dummy scissor state | 239 // dummy scissor state |
| 237 GrScissorState scissor; | 240 GrScissorState scissor; |
| 238 | 241 |
| 239 // Setup texture cache id key | |
| 240 const GrCacheID::Domain glProgramsDomain = GrCacheID::GenerateDomain(); | |
| 241 GrCacheID::Key key; | |
| 242 memset(&key, 0, sizeof(key)); | |
| 243 key.fData32[0] = kRenderTargetWidth; | |
| 244 key.fData32[1] = kRenderTargetHeight; | |
| 245 GrCacheID glProgramsCacheID(glProgramsDomain, key); | |
| 246 | |
| 247 // setup clip | 242 // setup clip |
| 248 SkRect screen = SkRect::MakeWH(SkIntToScalar(kRenderTargetWidth), | 243 SkRect screen = SkRect::MakeWH(SkIntToScalar(kRenderTargetWidth), |
| 249 SkIntToScalar(kRenderTargetHeight)); | 244 SkIntToScalar(kRenderTargetHeight)); |
| 250 | 245 |
| 251 SkClipStack stack; | 246 SkClipStack stack; |
| 252 stack.clipDevRect(screen, SkRegion::kReplace_Op, false); | 247 stack.clipDevRect(screen, SkRegion::kReplace_Op, false); |
| 253 | 248 |
| 254 // wrap the SkClipStack in a GrClipData | 249 // wrap the SkClipStack in a GrClipData |
| 255 GrClipData clipData; | 250 GrClipData clipData; |
| 256 clipData.fClipStack = &stack; | 251 clipData.fClipStack = &stack; |
| 257 this->setClip(&clipData); | 252 this->setClip(&clipData); |
| 258 | 253 |
| 259 SkRandom random; | 254 SkRandom random; |
| 260 static const int NUM_TESTS = 512; | 255 static const int NUM_TESTS = 512; |
| 261 for (int t = 0; t < NUM_TESTS;) { | 256 for (int t = 0; t < NUM_TESTS;) { |
| 262 // setup random render target(can fail) | 257 // setup random render target(can fail) |
| 263 SkAutoTUnref<GrRenderTarget> rt(random_render_target(fContext, glProgram
sCacheID, &random)); | 258 SkAutoTUnref<GrRenderTarget> rt(random_render_target(fContext, &random))
; |
| 264 if (!rt.get()) { | 259 if (!rt.get()) { |
| 265 SkDebugf("Could not allocate render target"); | 260 SkDebugf("Could not allocate render target"); |
| 266 return false; | 261 return false; |
| 267 } | 262 } |
| 268 | 263 |
| 269 GrDrawState ds; | 264 GrDrawState ds; |
| 270 ds.setRenderTarget(rt.get()); | 265 ds.setRenderTarget(rt.get()); |
| 271 | 266 |
| 272 // if path rendering we have to setup a couple of things like the draw t
ype | 267 // if path rendering we have to setup a couple of things like the draw t
ype |
| 273 bool usePathRendering = gpu->glCaps().pathRenderingSupport() && random.n
extBool(); | 268 bool usePathRendering = gpu->glCaps().pathRenderingSupport() && random.n
extBool(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 } | 360 } |
| 366 #endif | 361 #endif |
| 367 GrTestTarget target; | 362 GrTestTarget target; |
| 368 context->getTestTarget(&target); | 363 context->getTestTarget(&target); |
| 369 REPORTER_ASSERT(reporter, target.target()->programUnitTest(maxStages
)); | 364 REPORTER_ASSERT(reporter, target.target()->programUnitTest(maxStages
)); |
| 370 } | 365 } |
| 371 } | 366 } |
| 372 } | 367 } |
| 373 | 368 |
| 374 #endif | 369 #endif |
| OLD | NEW |