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

Side by Side Diff: tests/GLProgramsTest.cpp

Issue 1997773002: Retract GrRenderTarget from GLProgramsTest (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update Created 4 years, 7 months 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/effects/GrCoverageSetOpXP.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 * 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 }; 140 };
141 141
142 ////////////////////////////////////////////////////////////////////////////// 142 //////////////////////////////////////////////////////////////////////////////
143 143
144 /* 144 /*
145 * Begin test code 145 * Begin test code
146 */ 146 */
147 static const int kRenderTargetHeight = 1; 147 static const int kRenderTargetHeight = 1;
148 static const int kRenderTargetWidth = 1; 148 static const int kRenderTargetWidth = 1;
149 149
150 static GrRenderTarget* random_render_target(GrTextureProvider* textureProvider, SkRandom* random, 150 static sk_sp<GrDrawContext> random_draw_context(GrContext* context,
151 const GrCaps* caps) { 151 SkRandom* random,
152 // setup render target 152 const GrCaps* caps) {
153 GrTextureParams params; 153 GrSurfaceOrigin origin = random->nextBool() ? kTopLeft_GrSurfaceOrigin
154 GrSurfaceDesc texDesc; 154 : kBottomLeft_GrSurfaceOrigin;
155 texDesc.fWidth = kRenderTargetWidth; 155 int sampleCnt = random->nextBool() ? SkTMin(4, caps->maxSampleCount()) : 0;
156 texDesc.fHeight = kRenderTargetHeight;
157 texDesc.fFlags = kRenderTarget_GrSurfaceFlag;
158 texDesc.fConfig = kRGBA_8888_GrPixelConfig;
159 texDesc.fOrigin = random->nextBool() == true ? kTopLeft_GrSurfaceOrigin :
160 kBottomLeft_GrSurfaceOrigin;
161 texDesc.fSampleCnt = random->nextBool() == true ? SkTMin(4, caps->maxSampleC ount()) : 0;
162 156
163 GrUniqueKey key; 157 GrUniqueKey key;
164 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); 158 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
165 GrUniqueKey::Builder builder(&key, kDomain, 2); 159 GrUniqueKey::Builder builder(&key, kDomain, 2);
166 builder[0] = texDesc.fOrigin; 160 builder[0] = origin;
167 builder[1] = texDesc.fSampleCnt; 161 builder[1] = sampleCnt;
168 builder.finish(); 162 builder.finish();
169 163
170 GrTexture* texture = textureProvider->findAndRefTextureByUniqueKey(key); 164 sk_sp<GrTexture> texture(context->textureProvider()->findAndRefTextureByUniq ueKey(key));
171 if (!texture) { 165 if (texture) {
172 texture = textureProvider->createTexture(texDesc, SkBudgeted::kYes); 166 sk_sp<GrRenderTarget> rt(sk_ref_sp(texture->asRenderTarget()));
173 if (texture) { 167 return context->drawContext(std::move(rt));
174 textureProvider->assignUniqueKeyToTexture(key, texture);
175 }
176 } 168 }
177 return texture ? texture->asRenderTarget() : nullptr; 169
170 sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kExac t,
171 kRenderTargetWidth,
172 kRenderTargetHeight ,
173 kRGBA_8888_GrPixelC onfig,
174 sampleCnt,
175 origin));
176 if (!drawContext) {
177 return nullptr;
178 }
179
180 // TODO: need a real way to do this via the drawContext
181 texture = drawContext->asTexture();
182 context->textureProvider()->assignUniqueKeyToTexture(key, texture.get());
183
184 return drawContext;
178 } 185 }
179 186
180 static void set_random_xpf(GrPipelineBuilder* pipelineBuilder, GrProcessorTestDa ta* d) { 187 static void set_random_xpf(GrPipelineBuilder* pipelineBuilder, GrProcessorTestDa ta* d) {
181 SkAutoTUnref<const GrXPFactory> xpf(GrProcessorTestFactory<GrXPFactory>::Cre ate(d)); 188 SkAutoTUnref<const GrXPFactory> xpf(GrProcessorTestFactory<GrXPFactory>::Cre ate(d));
182 SkASSERT(xpf); 189 SkASSERT(xpf);
183 pipelineBuilder->setXPFactory(xpf.get()); 190 pipelineBuilder->setXPFactory(xpf.get());
184 } 191 }
185 192
186 static const GrFragmentProcessor* create_random_proc_tree(GrProcessorTestData* d , 193 static const GrFragmentProcessor* create_random_proc_tree(GrProcessorTestData* d ,
187 int minLevels, int ma xLevels) { 194 int minLevels, int ma xLevels) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 if (s < numColorProcs) { 261 if (s < numColorProcs) {
255 pipelineBuilder->addColorFragmentProcessor(fp); 262 pipelineBuilder->addColorFragmentProcessor(fp);
256 } else { 263 } else {
257 pipelineBuilder->addCoverageFragmentProcessor(fp); 264 pipelineBuilder->addCoverageFragmentProcessor(fp);
258 } 265 }
259 ++s; 266 ++s;
260 } 267 }
261 } 268 }
262 } 269 }
263 270
264 static void set_random_state(GrPipelineBuilder* pipelineBuilder, SkRandom* rando m) { 271 static void set_random_state(GrPipelineBuilder* pipelineBuilder,
272 GrDrawContext* drawContext,
273 SkRandom* random) {
265 int state = 0; 274 int state = 0;
266 for (int i = 1; i <= GrPipelineBuilder::kLast_Flag; i <<= 1) { 275 for (int i = 1; i <= GrPipelineBuilder::kLast_Flag; i <<= 1) {
267 state |= random->nextBool() * i; 276 state |= random->nextBool() * i;
268 } 277 }
269 278
270 // If we don't have an MSAA rendertarget then we have to disable useHWAA 279 // If we don't have an MSAA rendertarget then we have to disable useHWAA
271 if ((state | GrPipelineBuilder::kHWAntialias_Flag) && 280 if ((state | GrPipelineBuilder::kHWAntialias_Flag) && !drawContext->isUnifie dMultisampled()) {
272 !pipelineBuilder->getRenderTarget()->isUnifiedMultisampled()) {
273 state &= ~GrPipelineBuilder::kHWAntialias_Flag; 281 state &= ~GrPipelineBuilder::kHWAntialias_Flag;
274 } 282 }
275 pipelineBuilder->enableState(state); 283 pipelineBuilder->enableState(state);
276 } 284 }
277 285
278 // right now, the only thing we seem to care about in drawState's stencil is 'do esWrite()' 286 // right now, the only thing we seem to care about in drawState's stencil is 'do esWrite()'
279 static void set_random_stencil(GrPipelineBuilder* pipelineBuilder, SkRandom* ran dom) { 287 static void set_random_stencil(GrPipelineBuilder* pipelineBuilder, SkRandom* ran dom) {
280 static constexpr GrUserStencilSettings kDoesWriteStencil( 288 static constexpr GrUserStencilSettings kDoesWriteStencil(
281 GrUserStencilSettings::StaticInit< 289 GrUserStencilSettings::StaticInit<
282 0xffff, 290 0xffff,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 336
329 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; 337 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
330 338
331 // dummy scissor state 339 // dummy scissor state
332 GrScissorState scissor; 340 GrScissorState scissor;
333 341
334 SkRandom random; 342 SkRandom random;
335 static const int NUM_TESTS = 1024; 343 static const int NUM_TESTS = 1024;
336 for (int t = 0; t < NUM_TESTS; t++) { 344 for (int t = 0; t < NUM_TESTS; t++) {
337 // setup random render target(can fail) 345 // setup random render target(can fail)
338 sk_sp<GrRenderTarget> rt(random_render_target( 346 sk_sp<GrDrawContext> drawContext(random_draw_context(context, &random, c ontext->caps()));
339 context->textureProvider(), &random, context->caps())); 347 if (!drawContext) {
340 if (!rt.get()) { 348 SkDebugf("Could not allocate drawContext");
341 SkDebugf("Could not allocate render target");
342 return false; 349 return false;
343 } 350 }
344 351
345 GrPipelineBuilder pipelineBuilder; 352 GrPipelineBuilder pipelineBuilder;
346 pipelineBuilder.setRenderTarget(rt.get()); 353 pipelineBuilder.setRenderTarget(drawContext->accessRenderTarget());
347 354
348 SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context)); 355 SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context));
349 SkASSERT(batch); 356 SkASSERT(batch);
350 357
351 GrProcessorTestData ptd(&random, context, context->caps(), rt.get(), dum myTextures); 358 GrProcessorTestData ptd(&random, context, context->caps(),
359 drawContext.get(), dummyTextures);
352 set_random_color_coverage_stages(&pipelineBuilder, &ptd, maxStages); 360 set_random_color_coverage_stages(&pipelineBuilder, &ptd, maxStages);
353 set_random_xpf(&pipelineBuilder, &ptd); 361 set_random_xpf(&pipelineBuilder, &ptd);
354 set_random_state(&pipelineBuilder, &random); 362 set_random_state(&pipelineBuilder, drawContext.get(), &random);
355 set_random_stencil(&pipelineBuilder, &random); 363 set_random_stencil(&pipelineBuilder, &random);
356 364
357 sk_sp<GrDrawContext> drawContext(context->drawContext(rt));
358 if (!drawContext) {
359 SkDebugf("Could not allocate drawContext");
360 return false;
361 }
362
363 drawContext->drawContextPriv().testingOnly_drawBatch(pipelineBuilder, ba tch); 365 drawContext->drawContextPriv().testingOnly_drawBatch(pipelineBuilder, ba tch);
364 } 366 }
365 // Flush everything, test passes if flush is successful(ie, no asserts are h it, no crashes) 367 // Flush everything, test passes if flush is successful(ie, no asserts are h it, no crashes)
366 drawingManager->flush(); 368 drawingManager->flush();
367 369
368 // Validate that GrFPs work correctly without an input. 370 // Validate that GrFPs work correctly without an input.
369 GrSurfaceDesc rtDesc; 371 sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kExac t,
370 rtDesc.fWidth = kRenderTargetWidth; 372 kRenderTargetWidth,
371 rtDesc.fHeight = kRenderTargetHeight; 373 kRenderTargetHeight ,
372 rtDesc.fFlags = kRenderTarget_GrSurfaceFlag; 374 kRGBA_8888_GrPixelC onfig));
373 rtDesc.fConfig = kRGBA_8888_GrPixelConfig; 375 if (!drawContext) {
374 sk_sp<GrRenderTarget> rt( 376 SkDebugf("Could not allocate a drawContext");
375 context->textureProvider()->createTexture(rtDesc, SkBudgeted::kNo)->asRe nderTarget()); 377 return false;
378 }
379
376 int fpFactoryCnt = GrProcessorTestFactory<GrFragmentProcessor>::Count(); 380 int fpFactoryCnt = GrProcessorTestFactory<GrFragmentProcessor>::Count();
377 for (int i = 0; i < fpFactoryCnt; ++i) { 381 for (int i = 0; i < fpFactoryCnt; ++i) {
378 // Since FP factories internally randomize, call each 10 times. 382 // Since FP factories internally randomize, call each 10 times.
379 for (int j = 0; j < 10; ++j) { 383 for (int j = 0; j < 10; ++j) {
380 SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context)) ; 384 SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context)) ;
381 SkASSERT(batch); 385 SkASSERT(batch);
382 GrProcessorTestData ptd(&random, context, context->caps(), rt.get(), dummyTextures); 386 GrProcessorTestData ptd(&random, context, context->caps(),
387 drawContext.get(), dummyTextures);
383 GrPipelineBuilder builder; 388 GrPipelineBuilder builder;
384 builder.setXPFactory(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_ Mode))->unref(); 389 builder.setXPFactory(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_ Mode))->unref();
385 builder.setRenderTarget(rt.get()); 390 builder.setRenderTarget(drawContext->accessRenderTarget());
386 391
387 SkAutoTUnref<const GrFragmentProcessor> fp( 392 SkAutoTUnref<const GrFragmentProcessor> fp(
388 GrProcessorTestFactory<GrFragmentProcessor>::CreateIdx(i, &ptd)) ; 393 GrProcessorTestFactory<GrFragmentProcessor>::CreateIdx(i, &ptd)) ;
389 SkAutoTUnref<const GrFragmentProcessor> blockFP( 394 SkAutoTUnref<const GrFragmentProcessor> blockFP(
390 BlockInputFragmentProcessor::Create(fp)); 395 BlockInputFragmentProcessor::Create(fp));
391 builder.addColorFragmentProcessor(blockFP); 396 builder.addColorFragmentProcessor(blockFP);
392 397
393 sk_sp<GrDrawContext> drawContext(context->drawContext(rt));
394 if (!drawContext) {
395 SkDebugf("Could not allocate a drawcontext");
396 return false;
397 }
398
399 drawContext->drawContextPriv().testingOnly_drawBatch(builder, batch) ; 398 drawContext->drawContextPriv().testingOnly_drawBatch(builder, batch) ;
400 drawingManager->flush(); 399 drawingManager->flush();
401 } 400 }
402 } 401 }
403 402
404 return true; 403 return true;
405 } 404 }
406 405
407 static int get_glprograms_max_stages(GrContext* context) { 406 static int get_glprograms_max_stages(GrContext* context) {
408 GrGLGpu* gpu = static_cast<GrGLGpu*>(context->getGpu()); 407 GrGLGpu* gpu = static_cast<GrGLGpu*>(context->getGpu());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 GrContextOptions opts; 467 GrContextOptions opts;
469 opts.fSuppressPrints = true; 468 opts.fSuppressPrints = true;
470 sk_gpu_test::GrContextFactory debugFactory(opts); 469 sk_gpu_test::GrContextFactory debugFactory(opts);
471 skiatest::RunWithGPUTestContexts(test_glprograms_native, &is_native_gl_conte xt_type, 470 skiatest::RunWithGPUTestContexts(test_glprograms_native, &is_native_gl_conte xt_type,
472 reporter, &debugFactory); 471 reporter, &debugFactory);
473 skiatest::RunWithGPUTestContexts(test_glprograms_other_contexts, 472 skiatest::RunWithGPUTestContexts(test_glprograms_other_contexts,
474 &is_other_rendering_gl_context_type, report er, &debugFactory); 473 &is_other_rendering_gl_context_type, report er, &debugFactory);
475 } 474 }
476 475
477 #endif 476 #endif
OLDNEW
« no previous file with comments | « src/gpu/effects/GrCoverageSetOpXP.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698