Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: tests/GLProgramsTest.cpp

Issue 685883003: Clip in grdrawtarget (Closed) Base URL: https://skia.googlesource.com/skia.git@drawtarget_on_clip_manager
Patch Set: add ccclip to ignore Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/gl/GrGpuGL_program.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "GrTBackendProcessorFactory.h"
16 #include "GrContextFactory.h" 15 #include "GrContextFactory.h"
17 #include "GrOptDrawState.h" 16 #include "GrOptDrawState.h"
18 #include "effects/GrConfigConversionEffect.h" 17 #include "GrTBackendProcessorFactory.h"
19 #include "gl/builders/GrGLProgramBuilder.h" 18 #include "GrTest.h"
20 #include "gl/GrGLPathRendering.h"
21 #include "gl/GrGpuGL.h"
22 #include "SkChecksum.h" 19 #include "SkChecksum.h"
23 #include "SkRandom.h" 20 #include "SkRandom.h"
24 #include "Test.h" 21 #include "Test.h"
22 #include "effects/GrConfigConversionEffect.h"
23 #include "gl/GrGLPathRendering.h"
24 #include "gl/GrGpuGL.h"
25 #include "gl/builders/GrGLProgramBuilder.h"
25 26
26 /* 27 /*
27 * A dummy processor which just tries to insert a massive key and verify that it can retrieve the 28 * A dummy processor which just tries to insert a massive key and verify that it can retrieve the
28 * whole thing correctly 29 * whole thing correctly
29 */ 30 */
30 static const uint32_t kMaxKeySize = 1024; 31 static const uint32_t kMaxKeySize = 1024;
31 32
32 class GLBigKeyProcessor; 33 class GLBigKeyProcessor;
33 34
34 class BigKeyProcessor : public GrFragmentProcessor { 35 class BigKeyProcessor : public GrFragmentProcessor {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 private: 92 private:
92 typedef GrGLFragmentProcessor INHERITED; 93 typedef GrGLFragmentProcessor INHERITED;
93 }; 94 };
94 95
95 /* 96 /*
96 * Begin test code 97 * Begin test code
97 */ 98 */
98 static const int kRenderTargetHeight = 1; 99 static const int kRenderTargetHeight = 1;
99 static const int kRenderTargetWidth = 1; 100 static const int kRenderTargetWidth = 1;
100 101
101 static GrRenderTarget* random_render_target(GrGpuGL* gpu, 102 static GrRenderTarget* random_render_target(GrContext* context,
102 const GrCacheID& cacheId, 103 const GrCacheID& cacheId,
103 SkRandom* random) { 104 SkRandom* random) {
104 // setup render target 105 // setup render target
105 GrTextureParams params; 106 GrTextureParams params;
106 GrSurfaceDesc texDesc; 107 GrSurfaceDesc texDesc;
107 texDesc.fWidth = kRenderTargetWidth; 108 texDesc.fWidth = kRenderTargetWidth;
108 texDesc.fHeight = kRenderTargetHeight; 109 texDesc.fHeight = kRenderTargetHeight;
109 texDesc.fFlags = kRenderTarget_GrSurfaceFlag; 110 texDesc.fFlags = kRenderTarget_GrSurfaceFlag;
110 texDesc.fConfig = kRGBA_8888_GrPixelConfig; 111 texDesc.fConfig = kRGBA_8888_GrPixelConfig;
111 texDesc.fOrigin = random->nextBool() == true ? kTopLeft_GrSurfaceOrigin : 112 texDesc.fOrigin = random->nextBool() == true ? kTopLeft_GrSurfaceOrigin :
112 kBottomLeft_GrSurfaceOrigin; 113 kBottomLeft_GrSurfaceOrigin;
113 114
114 SkAutoTUnref<GrTexture> texture( 115 SkAutoTUnref<GrTexture> texture(context->findAndRefTexture(texDesc, cacheId, &params));
115 gpu->getContext()->findAndRefTexture(texDesc, cacheId, &params));
116 if (!texture) { 116 if (!texture) {
117 texture.reset(gpu->getContext()->createTexture(&params, texDesc, cacheId , 0, 0)); 117 texture.reset(context->createTexture(&params, texDesc, cacheId, 0, 0));
118 if (!texture) { 118 if (!texture) {
119 return NULL; 119 return NULL;
120 } 120 }
121 } 121 }
122 return SkRef(texture->asRenderTarget()); 122 return SkRef(texture->asRenderTarget());
123 } 123 }
124 124
125 // TODO clean this up, we have to do this to test geometry processors but there has got to be 125 // TODO clean this up, we have to do this to test geometry processors but there has got to be
126 // a better way. In the mean time, we actually fill out these generic vertex at tribs below with 126 // a better way. In the mean time, we actually fill out these generic vertex at tribs below with
127 // the correct vertex attribs from the GP. We have to ensure, however, we don't try to add more 127 // the correct vertex attribs from the GP. We have to ensure, however, we don't try to add more
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 static void setup_random_ff_attribute(GrVertexAttribBinding binding, GrVertexAtt ribType type, 159 static void setup_random_ff_attribute(GrVertexAttribBinding binding, GrVertexAtt ribType type,
160 SkRandom* random, int* attribIndex, int* r unningStride) { 160 SkRandom* random, int* attribIndex, int* r unningStride) {
161 if (random->nextBool()) { 161 if (random->nextBool()) {
162 kGenericVertexAttribs[*attribIndex].fType = type; 162 kGenericVertexAttribs[*attribIndex].fType = type;
163 kGenericVertexAttribs[*attribIndex].fOffset = *runningStride; 163 kGenericVertexAttribs[*attribIndex].fOffset = *runningStride;
164 kGenericVertexAttribs[*attribIndex].fBinding = binding; 164 kGenericVertexAttribs[*attribIndex].fBinding = binding;
165 *runningStride += GrVertexAttribTypeSize(kGenericVertexAttribs[(*attribI ndex)++].fType); 165 *runningStride += GrVertexAttribTypeSize(kGenericVertexAttribs[(*attribI ndex)++].fType);
166 } 166 }
167 } 167 }
168 168
169 static void set_random_gp(GrGpuGL* gpu, SkRandom* random, GrTexture* dummyTextur es[]) { 169 static void set_random_gp(GrContext* context,
170 const GrDrawTargetCaps& caps,
171 GrDrawState* ds,
172 SkRandom* random,
173 GrTexture* dummyTextures[]) {
170 GrProgramElementRef<const GrGeometryProcessor> gp( 174 GrProgramElementRef<const GrGeometryProcessor> gp(
171 GrProcessorTestFactory<GrGeometryProcessor>::CreateStage(random, 175 GrProcessorTestFactory<GrGeometryProcessor>::CreateStage(random,
172 gpu->getCon text(), 176 context,
173 *gpu->caps( ), 177 caps,
174 dummyTextur es)); 178 dummyTextur es));
175 SkASSERT(gp); 179 SkASSERT(gp);
176 180
177 // we have to set dummy vertex attributes, first we setup the fixed function attributes 181 // we have to set dummy vertex attributes, first we setup the fixed function attributes
178 // always leave the position attribute untouched in the array 182 // always leave the position attribute untouched in the array
179 int attribIndex = 1; 183 int attribIndex = 1;
180 int runningStride = GrVertexAttribTypeSize(kGenericVertexAttribs[0].fType); 184 int runningStride = GrVertexAttribTypeSize(kGenericVertexAttribs[0].fType);
181 185
182 // local coords 186 // local coords
183 setup_random_ff_attribute(kLocalCoord_GrVertexAttribBinding, kVec2f_GrVertex AttribType, 187 setup_random_ff_attribute(kLocalCoord_GrVertexAttribBinding, kVec2f_GrVertex AttribType,
(...skipping 17 matching lines...) Expand all
201 int maxIndex = SK_ARRAY_COUNT(kGenericVertexAttribs); 205 int maxIndex = SK_ARRAY_COUNT(kGenericVertexAttribs);
202 for (int i = 0; i < numGPAttribs && i + attribIndex < maxIndex; i++) { 206 for (int i = 0; i < numGPAttribs && i + attribIndex < maxIndex; i++) {
203 kGenericVertexAttribs[i + attribIndex].fType = 207 kGenericVertexAttribs[i + attribIndex].fType =
204 convert_sltype_to_attribtype(v[i].getType()); 208 convert_sltype_to_attribtype(v[i].getType());
205 kGenericVertexAttribs[i + attribIndex].fOffset = runningStride; 209 kGenericVertexAttribs[i + attribIndex].fOffset = runningStride;
206 kGenericVertexAttribs[i + attribIndex].fBinding = kGeometryProcessor_GrV ertexAttribBinding; 210 kGenericVertexAttribs[i + attribIndex].fBinding = kGeometryProcessor_GrV ertexAttribBinding;
207 runningStride += GrVertexAttribTypeSize(kGenericVertexAttribs[i + attrib Index].fType); 211 runningStride += GrVertexAttribTypeSize(kGenericVertexAttribs[i + attrib Index].fType);
208 } 212 }
209 213
210 // update the vertex attributes with the ds 214 // update the vertex attributes with the ds
211 GrDrawState* ds = gpu->drawState();
212 ds->setVertexAttribs<kGenericVertexAttribs>(attribIndex + numGPAttribs, runn ingStride); 215 ds->setVertexAttribs<kGenericVertexAttribs>(attribIndex + numGPAttribs, runn ingStride);
213 ds->setGeometryProcessor(gp); 216 ds->setGeometryProcessor(gp);
214 } 217 }
215 218
216 static void set_random_color_coverage_stages(GrGpuGL* gpu, 219 static void set_random_color_coverage_stages(GrGpuGL* gpu,
220 GrDrawState* ds,
217 int maxStages, 221 int maxStages,
218 bool usePathRendering, 222 bool usePathRendering,
219 SkRandom* random, 223 SkRandom* random,
220 GrTexture* dummyTextures[]) { 224 GrTexture* dummyTextures[]) {
221 int numProcs = random->nextULessThan(maxStages + 1); 225 int numProcs = random->nextULessThan(maxStages + 1);
222 int numColorProcs = random->nextULessThan(numProcs + 1); 226 int numColorProcs = random->nextULessThan(numProcs + 1);
223 227
224 int currTextureCoordSet = 0; 228 int currTextureCoordSet = 0;
225 for (int s = 0; s < numProcs;) { 229 for (int s = 0; s < numProcs;) {
226 GrProgramElementRef<GrFragmentProcessor> fp( 230 GrProgramElementRef<GrFragmentProcessor> fp(
(...skipping 14 matching lines...) Expand all
241 GrGLPathRendering::FixedFunction_TexturingMode) {; 245 GrGLPathRendering::FixedFunction_TexturingMode) {;
242 int numTransforms = fp->numTransforms(); 246 int numTransforms = fp->numTransforms();
243 if (currTextureCoordSet + numTransforms > 247 if (currTextureCoordSet + numTransforms >
244 gpu->glCaps().maxFixedFunctionTextureCoords()) { 248 gpu->glCaps().maxFixedFunctionTextureCoords()) {
245 continue; 249 continue;
246 } 250 }
247 currTextureCoordSet += numTransforms; 251 currTextureCoordSet += numTransforms;
248 } 252 }
249 253
250 // finally add the stage to the correct pipeline in the drawstate 254 // finally add the stage to the correct pipeline in the drawstate
251 GrDrawState* ds = gpu->drawState();
252 if (s < numColorProcs) { 255 if (s < numColorProcs) {
253 ds->addColorProcessor(fp); 256 ds->addColorProcessor(fp);
254 } else { 257 } else {
255 ds->addCoverageProcessor(fp); 258 ds->addCoverageProcessor(fp);
256 } 259 }
257 ++s; 260 ++s;
258 } 261 }
259 } 262 }
260 263
261 // There are only a few cases of random colors which interest us 264 // There are only a few cases of random colors which interest us
262 enum ColorMode { 265 enum ColorMode {
263 kAllOnes_ColorMode, 266 kAllOnes_ColorMode,
264 kAllZeros_ColorMode, 267 kAllZeros_ColorMode,
265 kAlphaOne_ColorMode, 268 kAlphaOne_ColorMode,
266 kRandom_ColorMode, 269 kRandom_ColorMode,
267 kLast_ColorMode = kRandom_ColorMode 270 kLast_ColorMode = kRandom_ColorMode
268 }; 271 };
269 272
270 static void set_random_color(GrGpuGL* gpu, SkRandom* random) { 273 static void set_random_color(GrDrawState* ds, SkRandom* random) {
271 ColorMode colorMode = ColorMode(random->nextULessThan(kLast_ColorMode + 1)); 274 ColorMode colorMode = ColorMode(random->nextULessThan(kLast_ColorMode + 1));
272 GrColor color; 275 GrColor color;
273 switch (colorMode) { 276 switch (colorMode) {
274 case kAllOnes_ColorMode: 277 case kAllOnes_ColorMode:
275 color = GrColorPackRGBA(0xFF, 0xFF, 0xFF, 0xFF); 278 color = GrColorPackRGBA(0xFF, 0xFF, 0xFF, 0xFF);
276 break; 279 break;
277 case kAllZeros_ColorMode: 280 case kAllZeros_ColorMode:
278 color = GrColorPackRGBA(0, 0, 0, 0); 281 color = GrColorPackRGBA(0, 0, 0, 0);
279 break; 282 break;
280 case kAlphaOne_ColorMode: 283 case kAlphaOne_ColorMode:
281 color = GrColorPackRGBA(random->nextULessThan(256), 284 color = GrColorPackRGBA(random->nextULessThan(256),
282 random->nextULessThan(256), 285 random->nextULessThan(256),
283 random->nextULessThan(256), 286 random->nextULessThan(256),
284 0xFF); 287 0xFF);
285 break; 288 break;
286 case kRandom_ColorMode: 289 case kRandom_ColorMode:
287 uint8_t alpha = random->nextULessThan(256); 290 uint8_t alpha = random->nextULessThan(256);
288 color = GrColorPackRGBA(random->nextRangeU(0, alpha), 291 color = GrColorPackRGBA(random->nextRangeU(0, alpha),
289 random->nextRangeU(0, alpha), 292 random->nextRangeU(0, alpha),
290 random->nextRangeU(0, alpha), 293 random->nextRangeU(0, alpha),
291 alpha); 294 alpha);
292 break; 295 break;
293 } 296 }
294 GrColorIsPMAssert(color); 297 GrColorIsPMAssert(color);
295 gpu->drawState()->setColor(color); 298 ds->setColor(color);
296 } 299 }
297 300
298 // There are only a few cases of random coverages which interest us 301 // There are only a few cases of random coverages which interest us
299 enum CoverageMode { 302 enum CoverageMode {
300 kZero_CoverageMode, 303 kZero_CoverageMode,
301 kFF_CoverageMode, 304 kFF_CoverageMode,
302 kRandom_CoverageMode, 305 kRandom_CoverageMode,
303 kLast_CoverageMode = kRandom_CoverageMode 306 kLast_CoverageMode = kRandom_CoverageMode
304 }; 307 };
305 308
306 static void set_random_coverage(GrGpuGL* gpu, SkRandom* random) { 309 static void set_random_coverage(GrDrawState* ds, SkRandom* random) {
307 CoverageMode coverageMode = CoverageMode(random->nextULessThan(kLast_Coverag eMode + 1)); 310 CoverageMode coverageMode = CoverageMode(random->nextULessThan(kLast_Coverag eMode + 1));
308 uint8_t coverage; 311 uint8_t coverage;
309 switch (coverageMode) { 312 switch (coverageMode) {
310 case kZero_CoverageMode: 313 case kZero_CoverageMode:
311 coverage = 0; 314 coverage = 0;
312 break; 315 break;
313 case kFF_CoverageMode: 316 case kFF_CoverageMode:
314 coverage = 0xFF; 317 coverage = 0xFF;
315 break; 318 break;
316 case kRandom_CoverageMode: 319 case kRandom_CoverageMode:
317 coverage = uint8_t(random->nextU()); 320 coverage = uint8_t(random->nextU());
318 break; 321 break;
319 } 322 }
320 gpu->drawState()->setCoverage(coverage); 323 ds->setCoverage(coverage);
321 } 324 }
322 325
323 static void set_random_hints(GrGpuGL* gpu, SkRandom* random) { 326 static void set_random_hints(GrDrawState* ds, SkRandom* random) {
324 for (int i = 1; i <= GrDrawState::kLast_Hint; i <<= 1) { 327 for (int i = 1; i <= GrDrawState::kLast_Hint; i <<= 1) {
325 gpu->drawState()->setHint(GrDrawState::Hints(i), random->nextBool()); 328 ds->setHint(GrDrawState::Hints(i), random->nextBool());
326 } 329 }
327 } 330 }
328 331
329 static void set_random_state(GrGpuGL* gpu, SkRandom* random) { 332 static void set_random_state(GrDrawState* ds, SkRandom* random) {
330 int state = 0; 333 int state = 0;
331 for (int i = 1; i <= GrDrawState::kLast_StateBit; i <<= 1) { 334 for (int i = 1; i <= GrDrawState::kLast_StateBit; i <<= 1) {
332 state |= random->nextBool() * i; 335 state |= random->nextBool() * i;
333 } 336 }
334 gpu->drawState()->enableState(state); 337 ds->enableState(state);
335 } 338 }
336 339
337 // this function will randomly pick non-self referencing blend modes 340 // this function will randomly pick non-self referencing blend modes
338 static void set_random_blend_func(GrGpuGL* gpu, SkRandom* random) { 341 static void set_random_blend_func(GrDrawState* ds, SkRandom* random) {
339 GrBlendCoeff src; 342 GrBlendCoeff src;
340 do { 343 do {
341 src = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPub licGrBlendCoeff)); 344 src = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPub licGrBlendCoeff));
342 } while (GrBlendCoeffRefsSrc(src)); 345 } while (GrBlendCoeffRefsSrc(src));
343 346
344 GrBlendCoeff dst; 347 GrBlendCoeff dst;
345 do { 348 do {
346 dst = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPub licGrBlendCoeff)); 349 dst = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPub licGrBlendCoeff));
347 } while (GrBlendCoeffRefsDst(dst)); 350 } while (GrBlendCoeffRefsDst(dst));
348 351
349 gpu->drawState()->setBlendFunc(src, dst); 352 ds->setBlendFunc(src, dst);
350 } 353 }
351 354
352 // right now, the only thing we seem to care about in drawState's stencil is 'do esWrite()' 355 // right now, the only thing we seem to care about in drawState's stencil is 'do esWrite()'
353 static void set_random_stencil(GrGpuGL* gpu, SkRandom* random) { 356 static void set_random_stencil(GrDrawState* ds, SkRandom* random) {
354 GR_STATIC_CONST_SAME_STENCIL(kDoesWriteStencil, 357 GR_STATIC_CONST_SAME_STENCIL(kDoesWriteStencil,
355 kReplace_StencilOp, 358 kReplace_StencilOp,
356 kReplace_StencilOp, 359 kReplace_StencilOp,
357 kAlways_StencilFunc, 360 kAlways_StencilFunc,
358 0xffff, 361 0xffff,
359 0xffff, 362 0xffff,
360 0xffff); 363 0xffff);
361 GR_STATIC_CONST_SAME_STENCIL(kDoesNotWriteStencil, 364 GR_STATIC_CONST_SAME_STENCIL(kDoesNotWriteStencil,
362 kKeep_StencilOp, 365 kKeep_StencilOp,
363 kKeep_StencilOp, 366 kKeep_StencilOp,
364 kNever_StencilFunc, 367 kNever_StencilFunc,
365 0xffff, 368 0xffff,
366 0xffff, 369 0xffff,
367 0xffff); 370 0xffff);
368 371
369 if (random->nextBool()) { 372 if (random->nextBool()) {
370 gpu->drawState()->setStencil(kDoesWriteStencil); 373 ds->setStencil(kDoesWriteStencil);
371 } else { 374 } else {
372 gpu->drawState()->setStencil(kDoesNotWriteStencil); 375 ds->setStencil(kDoesNotWriteStencil);
373 } 376 }
374 } 377 }
375 378
376 bool GrGpuGL::programUnitTest(int maxStages) { 379 bool GrDrawTarget::programUnitTest(int maxStages) {
380 GrGpuGL* gpu = static_cast<GrGpuGL*>(fContext->getGpu());
377 // setup dummy textures 381 // setup dummy textures
378 GrSurfaceDesc dummyDesc; 382 GrSurfaceDesc dummyDesc;
379 dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag; 383 dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag;
380 dummyDesc.fConfig = kSkia8888_GrPixelConfig; 384 dummyDesc.fConfig = kSkia8888_GrPixelConfig;
381 dummyDesc.fWidth = 34; 385 dummyDesc.fWidth = 34;
382 dummyDesc.fHeight = 18; 386 dummyDesc.fHeight = 18;
383 SkAutoTUnref<GrTexture> dummyTexture1(this->createTexture(dummyDesc, NULL, 0 )); 387 SkAutoTUnref<GrTexture> dummyTexture1(gpu->createTexture(dummyDesc, NULL, 0) );
384 dummyDesc.fFlags = kNone_GrSurfaceFlags; 388 dummyDesc.fFlags = kNone_GrSurfaceFlags;
385 dummyDesc.fConfig = kAlpha_8_GrPixelConfig; 389 dummyDesc.fConfig = kAlpha_8_GrPixelConfig;
386 dummyDesc.fWidth = 16; 390 dummyDesc.fWidth = 16;
387 dummyDesc.fHeight = 22; 391 dummyDesc.fHeight = 22;
388 SkAutoTUnref<GrTexture> dummyTexture2(this->createTexture(dummyDesc, NULL, 0 )); 392 SkAutoTUnref<GrTexture> dummyTexture2(gpu->createTexture(dummyDesc, NULL, 0) );
389 393
390 if (!dummyTexture1 || ! dummyTexture2) { 394 if (!dummyTexture1 || ! dummyTexture2) {
391 SkDebugf("Could not allocate dummy textures"); 395 SkDebugf("Could not allocate dummy textures");
392 return false; 396 return false;
393 } 397 }
394 398
395 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; 399 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
396 400
397 // Setup texture cache id key 401 // Setup texture cache id key
398 const GrCacheID::Domain glProgramsDomain = GrCacheID::GenerateDomain(); 402 const GrCacheID::Domain glProgramsDomain = GrCacheID::GenerateDomain();
399 GrCacheID::Key key; 403 GrCacheID::Key key;
400 memset(&key, 0, sizeof(key)); 404 memset(&key, 0, sizeof(key));
401 key.fData32[0] = kRenderTargetWidth; 405 key.fData32[0] = kRenderTargetWidth;
402 key.fData32[1] = kRenderTargetHeight; 406 key.fData32[1] = kRenderTargetHeight;
403 GrCacheID glProgramsCacheID(glProgramsDomain, key); 407 GrCacheID glProgramsCacheID(glProgramsDomain, key);
404 408
405 // setup clip 409 // setup clip
406 SkRect screen = 410 SkRect screen = SkRect::MakeWH(SkIntToScalar(kRenderTargetWidth),
407 SkRect::MakeWH(SkIntToScalar(kRenderTargetWidth), SkIntToScalar(kRen derTargetHeight)); 411 SkIntToScalar(kRenderTargetHeight));
408 412
409 SkClipStack stack; 413 SkClipStack stack;
410 stack.clipDevRect(screen, SkRegion::kReplace_Op, false); 414 stack.clipDevRect(screen, SkRegion::kReplace_Op, false);
411 415
412 // wrap the SkClipStack in a GrClipData 416 // wrap the SkClipStack in a GrClipData
413 GrClipData clipData; 417 GrClipData clipData;
414 clipData.fClipStack = &stack; 418 clipData.fClipStack = &stack;
415 this->setClip(&clipData); 419 this->setClip(&clipData);
416 420
417 SkRandom random; 421 SkRandom random;
418 static const int NUM_TESTS = 512; 422 static const int NUM_TESTS = 512;
419 for (int t = 0; t < NUM_TESTS;) { 423 for (int t = 0; t < NUM_TESTS;) {
420 // setup random render target(can fail) 424 // setup random render target(can fail)
421 SkAutoTUnref<GrRenderTarget> rt(random_render_target(this, glProgramsCac heID, &random)); 425 SkAutoTUnref<GrRenderTarget> rt(random_render_target(fContext, glProgram sCacheID, &random));
422 if (!rt) { 426 if (!rt.get()) {
423 SkDebugf("Could not allocate render target"); 427 SkDebugf("Could not allocate render target");
424 return false; 428 return false;
425 } 429 }
426 430
427 GrDrawState* ds = this->drawState(); 431 GrDrawState* ds = this->drawState();
428 ds->setRenderTarget(rt.get()); 432 ds->setRenderTarget(rt.get());
429 433
430 // if path rendering we have to setup a couple of things like the draw t ype 434 // if path rendering we have to setup a couple of things like the draw t ype
431 bool usePathRendering = this->glCaps().pathRenderingSupport() && random. nextBool(); 435 bool usePathRendering = gpu->glCaps().pathRenderingSupport() && random.n extBool();
432 436
433 GrGpu::DrawType drawType = usePathRendering ? GrGpu::kDrawPath_DrawType : 437 GrGpu::DrawType drawType = usePathRendering ? GrGpu::kDrawPath_DrawType :
434 GrGpu::kDrawPoints_DrawTyp e; 438 GrGpu::kDrawPoints_DrawTyp e;
435 439
436 // twiddle drawstate knobs randomly 440 // twiddle drawstate knobs randomly
437 bool hasGeometryProcessor = usePathRendering ? false : random.nextBool() ; 441 bool hasGeometryProcessor = usePathRendering ? false : random.nextBool() ;
438 if (hasGeometryProcessor) { 442 if (hasGeometryProcessor) {
439 set_random_gp(this, &random, dummyTextures); 443 set_random_gp(fContext, gpu->glCaps(), ds, &random, dummyTextures);
440 } 444 }
441 set_random_color_coverage_stages(this, maxStages - hasGeometryProcessor, usePathRendering, 445 set_random_color_coverage_stages(gpu,
442 &random, dummyTextures); 446 ds,
443 set_random_color(this, &random); 447 maxStages - hasGeometryProcessor,
444 set_random_coverage(this, &random); 448 usePathRendering,
445 set_random_hints(this, &random); 449 &random,
446 set_random_state(this, &random); 450 dummyTextures);
447 set_random_blend_func(this, &random); 451 set_random_color(ds, &random);
448 set_random_stencil(this, &random); 452 set_random_coverage(ds, &random);
453 set_random_hints(ds, &random);
454 set_random_state(ds, &random);
455 set_random_blend_func(ds, &random);
456 set_random_stencil(ds, &random);
449 457
450 GrDeviceCoordTexture dstCopy; 458 GrDeviceCoordTexture dstCopy;
451 459
452 if (!this->setupDstReadIfNecessary(&dstCopy, NULL)) { 460 if (!this->setupDstReadIfNecessary(&dstCopy, NULL)) {
453 SkDebugf("Couldn't setup dst read texture"); 461 SkDebugf("Couldn't setup dst read texture");
454 return false; 462 return false;
455 } 463 }
456 464
457 // create optimized draw state, setup readDst texture if required, and b uild a descriptor 465 // create optimized draw state, setup readDst texture if required, and b uild a descriptor
458 // and program. ODS creation can fail, so we have to check 466 // and program. ODS creation can fail, so we have to check
459 SkAutoTUnref<GrOptDrawState> ods(GrOptDrawState::Create(this->getDrawSta te(), 467 SkAutoTUnref<GrOptDrawState> ods(GrOptDrawState::Create(this->getDrawSta te(),
460 this, 468 gpu,
461 &dstCopy, 469 &dstCopy,
462 drawType)); 470 drawType));
463 if (!ods.get()) { 471 if (!ods.get()) {
464 ds->reset(); 472 ds->reset();
465 continue; 473 continue;
466 } 474 }
467 SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(*ods , drawType, this)); 475 SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(*ods , drawType, gpu));
468 if (NULL == program.get()) { 476 if (NULL == program.get()) {
469 SkDebugf("Failed to create program!"); 477 SkDebugf("Failed to create program!");
470 return false; 478 return false;
471 } 479 }
472 480
473 // We have to reset the drawstate because we might have added a gp 481 // We have to reset the drawstate because we might have added a gp
474 ds->reset(); 482 ds->reset();
475 483
476 // because occasionally optimized drawstate creation will fail for valid reasons, we only 484 // because occasionally optimized drawstate creation will fail for valid reasons, we only
477 // want to increment on success 485 // want to increment on success
(...skipping 22 matching lines...) Expand all
500 maxStages = 1; 508 maxStages = 1;
501 } else { 509 } else {
502 return; 510 return;
503 } 511 }
504 #if SK_ANGLE 512 #if SK_ANGLE
505 // Some long shaders run out of temporary registers in the D3D compi ler on ANGLE. 513 // Some long shaders run out of temporary registers in the D3D compi ler on ANGLE.
506 if (type == GrContextFactory::kANGLE_GLContextType) { 514 if (type == GrContextFactory::kANGLE_GLContextType) {
507 maxStages = 3; 515 maxStages = 3;
508 } 516 }
509 #endif 517 #endif
510 REPORTER_ASSERT(reporter, gpu->programUnitTest(maxStages)); 518 GrTestTarget target;
519 context->getTestTarget(&target);
520 REPORTER_ASSERT(reporter, target.target()->programUnitTest(maxStages ));
511 } 521 }
512 } 522 }
513 } 523 }
514 524
515 #endif 525 #endif
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGpuGL_program.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698