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

Side by Side Diff: tests/GLProgramsTest.cpp

Issue 858343002: Rename GrOptDrawState to GrPipeline and GrDrawState to GrPipelineBuilder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: some line length stuff Created 5 years, 11 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
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 "GrContextFactory.h" 15 #include "GrContextFactory.h"
16 #include "GrInvariantOutput.h" 16 #include "GrInvariantOutput.h"
17 #include "GrOptDrawState.h" 17 #include "GrPipeline.h"
18 #include "GrTest.h" 18 #include "GrTest.h"
19 #include "GrXferProcessor.h" 19 #include "GrXferProcessor.h"
20 #include "SkChecksum.h" 20 #include "SkChecksum.h"
21 #include "SkRandom.h" 21 #include "SkRandom.h"
22 #include "Test.h" 22 #include "Test.h"
23 #include "effects/GrConfigConversionEffect.h" 23 #include "effects/GrConfigConversionEffect.h"
24 #include "effects/GrPorterDuffXferProcessor.h" 24 #include "effects/GrPorterDuffXferProcessor.h"
25 #include "gl/GrGLGpu.h" 25 #include "gl/GrGLGpu.h"
26 #include "gl/GrGLPathRendering.h" 26 #include "gl/GrGLPathRendering.h"
27 #include "gl/builders/GrGLProgramBuilder.h" 27 #include "gl/builders/GrGLProgramBuilder.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 SkAutoTUnref<GrTexture> texture(context->findAndRefTexture(texDesc, cacheId, &params)); 114 SkAutoTUnref<GrTexture> texture(context->findAndRefTexture(texDesc, cacheId, &params));
115 if (!texture) { 115 if (!texture) {
116 texture.reset(context->createTexture(&params, texDesc, cacheId, 0, 0)); 116 texture.reset(context->createTexture(&params, texDesc, cacheId, 0, 0));
117 if (!texture) { 117 if (!texture) {
118 return NULL; 118 return NULL;
119 } 119 }
120 } 120 }
121 return SkRef(texture->asRenderTarget()); 121 return SkRef(texture->asRenderTarget());
122 } 122 }
123 123
124 static void set_random_xpf(GrContext* context, const GrDrawTargetCaps& caps, GrD rawState* ds, 124 static void set_random_xpf(GrContext* context, const GrDrawTargetCaps& caps, GrP ipelineBuilder* pipelineBuilder,
joshualitt 2015/01/22 15:55:08 \n
egdaniel 2015/01/22 16:28:56 Done.
125 SkRandom* random, GrTexture* dummyTextures[]) { 125 SkRandom* random, GrTexture* dummyTextures[]) {
126 SkAutoTUnref<const GrXPFactory> xpf( 126 SkAutoTUnref<const GrXPFactory> xpf(
127 GrProcessorTestFactory<GrXPFactory>::CreateStage(random, context, caps, dummyTextures)); 127 GrProcessorTestFactory<GrXPFactory>::CreateStage(random, context, caps, dummyTextures));
128 SkASSERT(xpf); 128 SkASSERT(xpf);
129 ds->setXPFactory(xpf.get()); 129 pipelineBuilder->setXPFactory(xpf.get());
130 } 130 }
131 131
132 static const GrGeometryProcessor* get_random_gp(GrContext* context, 132 static const GrGeometryProcessor* get_random_gp(GrContext* context,
133 const GrDrawTargetCaps& caps, 133 const GrDrawTargetCaps& caps,
134 SkRandom* random, 134 SkRandom* random,
135 GrTexture* dummyTextures[]) { 135 GrTexture* dummyTextures[]) {
136 return GrProcessorTestFactory<GrGeometryProcessor>::CreateStage(random, 136 return GrProcessorTestFactory<GrGeometryProcessor>::CreateStage(random,
137 context, 137 context,
138 caps, 138 caps,
139 dummyTexture s); 139 dummyTexture s);
140 } 140 }
141 141
142 static void set_random_color_coverage_stages(GrGLGpu* gpu, 142 static void set_random_color_coverage_stages(GrGLGpu* gpu,
143 GrDrawState* ds, 143 GrPipelineBuilder* pipelineBuilder,
144 int maxStages, 144 int maxStages,
145 bool usePathRendering, 145 bool usePathRendering,
146 SkRandom* random, 146 SkRandom* random,
147 GrTexture* dummyTextures[]) { 147 GrTexture* dummyTextures[]) {
148 int numProcs = random->nextULessThan(maxStages + 1); 148 int numProcs = random->nextULessThan(maxStages + 1);
149 int numColorProcs = random->nextULessThan(numProcs + 1); 149 int numColorProcs = random->nextULessThan(numProcs + 1);
150 150
151 int currTextureCoordSet = 0; 151 int currTextureCoordSet = 0;
152 for (int s = 0; s < numProcs;) { 152 for (int s = 0; s < numProcs;) {
153 SkAutoTUnref<const GrFragmentProcessor> fp( 153 SkAutoTUnref<const GrFragmentProcessor> fp(
(...skipping 10 matching lines...) Expand all
164 int numTransforms = fp->numTransforms(); 164 int numTransforms = fp->numTransforms();
165 if (currTextureCoordSet + numTransforms > 165 if (currTextureCoordSet + numTransforms >
166 gpu->glCaps().maxFixedFunctionTextureCoords()) { 166 gpu->glCaps().maxFixedFunctionTextureCoords()) {
167 continue; 167 continue;
168 } 168 }
169 currTextureCoordSet += numTransforms; 169 currTextureCoordSet += numTransforms;
170 } 170 }
171 171
172 // finally add the stage to the correct pipeline in the drawstate 172 // finally add the stage to the correct pipeline in the drawstate
173 if (s < numColorProcs) { 173 if (s < numColorProcs) {
174 ds->addColorProcessor(fp); 174 pipelineBuilder->addColorProcessor(fp);
175 } else { 175 } else {
176 ds->addCoverageProcessor(fp); 176 pipelineBuilder->addCoverageProcessor(fp);
177 } 177 }
178 ++s; 178 ++s;
179 } 179 }
180 } 180 }
181 181
182 static void set_random_state(GrDrawState* ds, SkRandom* random) { 182 static void set_random_state(GrPipelineBuilder* pipelineBuilder, SkRandom* rando m) {
183 int state = 0; 183 int state = 0;
184 for (int i = 1; i <= GrDrawState::kLast_StateBit; i <<= 1) { 184 for (int i = 1; i <= GrPipelineBuilder::kLast_StateBit; i <<= 1) {
185 state |= random->nextBool() * i; 185 state |= random->nextBool() * i;
186 } 186 }
187 ds->enableState(state); 187 pipelineBuilder->enableState(state);
188 } 188 }
189 189
190 // right now, the only thing we seem to care about in drawState's stencil is 'do esWrite()' 190 // right now, the only thing we seem to care about in drawState's stencil is 'do esWrite()'
191 static void set_random_stencil(GrDrawState* ds, SkRandom* random) { 191 static void set_random_stencil(GrPipelineBuilder* pipelineBuilder, SkRandom* ran dom) {
192 GR_STATIC_CONST_SAME_STENCIL(kDoesWriteStencil, 192 GR_STATIC_CONST_SAME_STENCIL(kDoesWriteStencil,
193 kReplace_StencilOp, 193 kReplace_StencilOp,
194 kReplace_StencilOp, 194 kReplace_StencilOp,
195 kAlways_StencilFunc, 195 kAlways_StencilFunc,
196 0xffff, 196 0xffff,
197 0xffff, 197 0xffff,
198 0xffff); 198 0xffff);
199 GR_STATIC_CONST_SAME_STENCIL(kDoesNotWriteStencil, 199 GR_STATIC_CONST_SAME_STENCIL(kDoesNotWriteStencil,
200 kKeep_StencilOp, 200 kKeep_StencilOp,
201 kKeep_StencilOp, 201 kKeep_StencilOp,
202 kNever_StencilFunc, 202 kNever_StencilFunc,
203 0xffff, 203 0xffff,
204 0xffff, 204 0xffff,
205 0xffff); 205 0xffff);
206 206
207 if (random->nextBool()) { 207 if (random->nextBool()) {
208 ds->setStencil(kDoesWriteStencil); 208 pipelineBuilder->setStencil(kDoesWriteStencil);
209 } else { 209 } else {
210 ds->setStencil(kDoesNotWriteStencil); 210 pipelineBuilder->setStencil(kDoesNotWriteStencil);
211 } 211 }
212 } 212 }
213 213
214 bool GrDrawTarget::programUnitTest(int maxStages) { 214 bool GrDrawTarget::programUnitTest(int maxStages) {
215 GrGLGpu* gpu = static_cast<GrGLGpu*>(fContext->getGpu()); 215 GrGLGpu* gpu = static_cast<GrGLGpu*>(fContext->getGpu());
216 // setup dummy textures 216 // setup dummy textures
217 GrSurfaceDesc dummyDesc; 217 GrSurfaceDesc dummyDesc;
218 dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag; 218 dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag;
219 dummyDesc.fConfig = kSkia8888_GrPixelConfig; 219 dummyDesc.fConfig = kSkia8888_GrPixelConfig;
220 dummyDesc.fWidth = 34; 220 dummyDesc.fWidth = 34;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 SkRandom random; 259 SkRandom random;
260 static const int NUM_TESTS = 512; 260 static const int NUM_TESTS = 512;
261 for (int t = 0; t < NUM_TESTS;) { 261 for (int t = 0; t < NUM_TESTS;) {
262 // setup random render target(can fail) 262 // setup random render target(can fail)
263 SkAutoTUnref<GrRenderTarget> rt(random_render_target(fContext, glProgram sCacheID, &random)); 263 SkAutoTUnref<GrRenderTarget> rt(random_render_target(fContext, glProgram sCacheID, &random));
264 if (!rt.get()) { 264 if (!rt.get()) {
265 SkDebugf("Could not allocate render target"); 265 SkDebugf("Could not allocate render target");
266 return false; 266 return false;
267 } 267 }
268 268
269 GrDrawState ds; 269 GrPipelineBuilder pipelineBuilder;
270 ds.setRenderTarget(rt.get()); 270 pipelineBuilder.setRenderTarget(rt.get());
271 271
272 // if path rendering we have to setup a couple of things like the draw t ype 272 // 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(); 273 bool usePathRendering = gpu->glCaps().pathRenderingSupport() && random.n extBool();
274 274
275 // twiddle drawstate knobs randomly 275 // twiddle drawstate knobs randomly
276 bool hasGeometryProcessor = !usePathRendering; 276 bool hasGeometryProcessor = !usePathRendering;
277 SkAutoTUnref<const GrGeometryProcessor> gp; 277 SkAutoTUnref<const GrGeometryProcessor> gp;
278 SkAutoTUnref<const GrPathProcessor> pathProc; 278 SkAutoTUnref<const GrPathProcessor> pathProc;
279 if (hasGeometryProcessor) { 279 if (hasGeometryProcessor) {
280 gp.reset(get_random_gp(fContext, gpu->glCaps(), &random, dummyTextur es)); 280 gp.reset(get_random_gp(fContext, gpu->glCaps(), &random, dummyTextur es));
281 } else { 281 } else {
282 pathProc.reset(GrPathProcessor::Create(GrColor_WHITE)); 282 pathProc.reset(GrPathProcessor::Create(GrColor_WHITE));
283 } 283 }
284 set_random_color_coverage_stages(gpu, 284 set_random_color_coverage_stages(gpu,
285 &ds, 285 &pipelineBuilder,
286 maxStages - hasGeometryProcessor, 286 maxStages - hasGeometryProcessor,
287 usePathRendering, 287 usePathRendering,
288 &random, 288 &random,
289 dummyTextures); 289 dummyTextures);
290 290
291 // creates a random xfer processor factory on the draw state 291 // creates a random xfer processor factory on the draw state
292 set_random_xpf(fContext, gpu->glCaps(), &ds, &random, dummyTextures); 292 set_random_xpf(fContext, gpu->glCaps(), &pipelineBuilder, &random, dummy Textures);
293 293
294 set_random_state(&ds, &random); 294 set_random_state(&pipelineBuilder, &random);
295 set_random_stencil(&ds, &random); 295 set_random_stencil(&pipelineBuilder, &random);
296 296
297 GrDeviceCoordTexture dstCopy; 297 GrDeviceCoordTexture dstCopy;
298 298
299 const GrPrimitiveProcessor* primProc; 299 const GrPrimitiveProcessor* primProc;
300 if (hasGeometryProcessor) { 300 if (hasGeometryProcessor) {
301 primProc = gp.get(); 301 primProc = gp.get();
302 } else { 302 } else {
303 primProc = pathProc.get(); 303 primProc = pathProc.get();
304 } 304 }
305 if (!this->setupDstReadIfNecessary(&ds, &dstCopy, NULL)) { 305 if (!this->setupDstReadIfNecessary(&pipelineBuilder, &dstCopy, NULL)) {
306 SkDebugf("Couldn't setup dst read texture"); 306 SkDebugf("Couldn't setup dst read texture");
307 return false; 307 return false;
308 } 308 }
309 309
310 // create optimized draw state, setup readDst texture if required, and b uild a descriptor 310 // create optimized draw state, setup readDst texture if required, and b uild a descriptor
311 // and program. ODS creation can fail, so we have to check 311 // and program. ODS creation can fail, so we have to check
312 GrOptDrawState ods(ds, primProc, *gpu->caps(), scissor, &dstCopy); 312 GrPipeline pipeline(pipelineBuilder, primProc, *gpu->caps(), scissor, &d stCopy);
313 if (ods.mustSkip()) { 313 if (pipeline.mustSkip()) {
314 continue; 314 continue;
315 } 315 }
316 GrBatchTracker bt; 316 GrBatchTracker bt;
317 primProc->initBatchTracker(&bt, ods.getInitBatchTracker()); 317 primProc->initBatchTracker(&bt, pipeline.getInitBatchTracker());
318 318
319 GrProgramDesc desc; 319 GrProgramDesc desc;
320 gpu->buildProgramDesc(&desc, *primProc, ods, ods.descInfo(), bt); 320 gpu->buildProgramDesc(&desc, *primProc, pipeline, pipeline.descInfo(), b t);
321 321
322 GrGpu::DrawArgs args(primProc, &ods, &desc, &bt); 322 GrGpu::DrawArgs args(primProc, &pipeline, &desc, &bt);
323 SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(args , gpu)); 323 SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(args , gpu));
324 324
325 if (NULL == program.get()) { 325 if (NULL == program.get()) {
326 SkDebugf("Failed to create program!"); 326 SkDebugf("Failed to create program!");
327 return false; 327 return false;
328 } 328 }
329 329
330 // because occasionally optimized drawstate creation will fail for valid reasons, we only 330 // because occasionally optimized drawstate creation will fail for valid reasons, we only
331 // want to increment on success 331 // want to increment on success
332 ++t; 332 ++t;
(...skipping 29 matching lines...) Expand all
362 } 362 }
363 #endif 363 #endif
364 GrTestTarget target; 364 GrTestTarget target;
365 context->getTestTarget(&target); 365 context->getTestTarget(&target);
366 REPORTER_ASSERT(reporter, target.target()->programUnitTest(maxStages )); 366 REPORTER_ASSERT(reporter, target.target()->programUnitTest(maxStages ));
367 } 367 }
368 } 368 }
369 } 369 }
370 370
371 #endif 371 #endif
OLDNEW
« src/gpu/GrPipelineBuilder.cpp ('K') | « src/gpu/gl/builders/GrGLProgramBuilder.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698