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

Side by Side Diff: tests/GLProgramsTest.cpp

Issue 2041113004: sk_sp for gpu. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Reserve correctly. Created 4 years, 6 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/image/SkImage_Gpu.cpp ('k') | tests/GpuColorFilterTest.cpp » ('j') | 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 b->add32(i); 59 b->add32(i);
60 } 60 }
61 } 61 }
62 62
63 private: 63 private:
64 typedef GrGLSLFragmentProcessor INHERITED; 64 typedef GrGLSLFragmentProcessor INHERITED;
65 }; 65 };
66 66
67 class BigKeyProcessor : public GrFragmentProcessor { 67 class BigKeyProcessor : public GrFragmentProcessor {
68 public: 68 public:
69 static GrFragmentProcessor* Create() { 69 static sk_sp<GrFragmentProcessor> Make() {
70 return new BigKeyProcessor; 70 return sk_sp<GrFragmentProcessor>(new BigKeyProcessor);
71 } 71 }
72 72
73 const char* name() const override { return "Big Ole Key"; } 73 const char* name() const override { return "Big Ole Key"; }
74 74
75 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { 75 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
76 return new GLBigKeyProcessor; 76 return new GLBigKeyProcessor;
77 } 77 }
78 78
79 private: 79 private:
80 BigKeyProcessor() { 80 BigKeyProcessor() {
81 this->initClassID<BigKeyProcessor>(); 81 this->initClassID<BigKeyProcessor>();
82 } 82 }
83 virtual void onGetGLSLProcessorKey(const GrGLSLCaps& caps, 83 virtual void onGetGLSLProcessorKey(const GrGLSLCaps& caps,
84 GrProcessorKeyBuilder* b) const override { 84 GrProcessorKeyBuilder* b) const override {
85 GLBigKeyProcessor::GenKey(*this, caps, b); 85 GLBigKeyProcessor::GenKey(*this, caps, b);
86 } 86 }
87 bool onIsEqual(const GrFragmentProcessor&) const override { return true; } 87 bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
88 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { } 88 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { }
89 89
90 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 90 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
91 91
92 typedef GrFragmentProcessor INHERITED; 92 typedef GrFragmentProcessor INHERITED;
93 }; 93 };
94 94
95 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(BigKeyProcessor); 95 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(BigKeyProcessor);
96 96
97 const GrFragmentProcessor* BigKeyProcessor::TestCreate(GrProcessorTestData*) { 97 sk_sp<GrFragmentProcessor> BigKeyProcessor::TestCreate(GrProcessorTestData*) {
98 return BigKeyProcessor::Create(); 98 return BigKeyProcessor::Make();
99 } 99 }
100 100
101 ////////////////////////////////////////////////////////////////////////////// 101 //////////////////////////////////////////////////////////////////////////////
102 102
103 class BlockInputFragmentProcessor : public GrFragmentProcessor { 103 class BlockInputFragmentProcessor : public GrFragmentProcessor {
104 public: 104 public:
105 static GrFragmentProcessor* Create(const GrFragmentProcessor* fp) { 105 static sk_sp<GrFragmentProcessor> Make(sk_sp<GrFragmentProcessor> fp) {
106 return new BlockInputFragmentProcessor(fp); 106 return sk_sp<GrFragmentProcessor>(new BlockInputFragmentProcessor(fp));
107 } 107 }
108 108
109 const char* name() const override { return "Block Input"; } 109 const char* name() const override { return "Block Input"; }
110 110
111 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLFP; } 111 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLFP; }
112 112
113 private: 113 private:
114 class GLFP : public GrGLSLFragmentProcessor { 114 class GLFP : public GrGLSLFragmentProcessor {
115 public: 115 public:
116 void emitCode(EmitArgs& args) override { 116 void emitCode(EmitArgs& args) override {
117 this->emitChild(0, nullptr, args); 117 this->emitChild(0, nullptr, args);
118 } 118 }
119 119
120 private: 120 private:
121 typedef GrGLSLFragmentProcessor INHERITED; 121 typedef GrGLSLFragmentProcessor INHERITED;
122 }; 122 };
123 123
124 BlockInputFragmentProcessor(const GrFragmentProcessor* child) { 124 BlockInputFragmentProcessor(sk_sp<GrFragmentProcessor> child) {
125 this->initClassID<BlockInputFragmentProcessor>(); 125 this->initClassID<BlockInputFragmentProcessor>();
126 this->registerChildProcessor(child); 126 this->registerChildProcessor(std::move(child));
127 } 127 }
128 128
129 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override {} 129 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override {}
130 130
131 bool onIsEqual(const GrFragmentProcessor&) const override { return true; } 131 bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
132 132
133 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { 133 void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
134 inout->setToOther(kRGBA_GrColorComponentFlags, GrColor_WHITE, 134 inout->setToOther(kRGBA_GrColorComponentFlags, GrColor_WHITE,
135 GrInvariantOutput::kWillNot_ReadInput); 135 GrInvariantOutput::kWillNot_ReadInput);
136 this->childProcessor(0).computeInvariantOutput(inout); 136 this->childProcessor(0).computeInvariantOutput(inout);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 178 }
179 179
180 // TODO: need a real way to do this via the drawContext 180 // TODO: need a real way to do this via the drawContext
181 texture = drawContext->asTexture(); 181 texture = drawContext->asTexture();
182 context->textureProvider()->assignUniqueKeyToTexture(key, texture.get()); 182 context->textureProvider()->assignUniqueKeyToTexture(key, texture.get());
183 183
184 return drawContext; 184 return drawContext;
185 } 185 }
186 186
187 static void set_random_xpf(GrPipelineBuilder* pipelineBuilder, GrProcessorTestDa ta* d) { 187 static void set_random_xpf(GrPipelineBuilder* pipelineBuilder, GrProcessorTestDa ta* d) {
188 SkAutoTUnref<const GrXPFactory> xpf(GrProcessorTestFactory<GrXPFactory>::Cre ate(d)); 188 sk_sp<GrXPFactory> xpf(GrProcessorTestFactory<GrXPFactory>::Make(d));
189 SkASSERT(xpf); 189 SkASSERT(xpf);
190 pipelineBuilder->setXPFactory(xpf.get()); 190 pipelineBuilder->setXPFactory(std::move(xpf));
191 } 191 }
192 192
193 static const GrFragmentProcessor* create_random_proc_tree(GrProcessorTestData* d , 193 static sk_sp<GrFragmentProcessor> create_random_proc_tree(GrProcessorTestData* d ,
194 int minLevels, int ma xLevels) { 194 int minLevels, int max Levels) {
195 SkASSERT(1 <= minLevels); 195 SkASSERT(1 <= minLevels);
196 SkASSERT(minLevels <= maxLevels); 196 SkASSERT(minLevels <= maxLevels);
197 197
198 // Return a leaf node if maxLevels is 1 or if we randomly chose to terminate . 198 // Return a leaf node if maxLevels is 1 or if we randomly chose to terminate .
199 // If returning a leaf node, make sure that it doesn't have children (e.g. a nother 199 // If returning a leaf node, make sure that it doesn't have children (e.g. a nother
200 // GrComposeEffect) 200 // GrComposeEffect)
201 const float terminateProbability = 0.3f; 201 const float terminateProbability = 0.3f;
202 if (1 == minLevels) { 202 if (1 == minLevels) {
203 bool terminate = (1 == maxLevels) || (d->fRandom->nextF() < terminatePro bability); 203 bool terminate = (1 == maxLevels) || (d->fRandom->nextF() < terminatePro bability);
204 if (terminate) { 204 if (terminate) {
205 const GrFragmentProcessor* fp; 205 sk_sp<GrFragmentProcessor> fp;
206 while (true) { 206 while (true) {
207 fp = GrProcessorTestFactory<GrFragmentProcessor>::Create(d); 207 fp = GrProcessorTestFactory<GrFragmentProcessor>::Make(d);
208 SkASSERT(fp); 208 SkASSERT(fp);
209 if (0 == fp->numChildProcessors()) { 209 if (0 == fp->numChildProcessors()) {
210 break; 210 break;
211 } 211 }
212 fp->unref();
213 } 212 }
214 return fp; 213 return fp;
215 } 214 }
216 } 215 }
217 // If we didn't terminate, choose either the left or right subtree to fulfil l 216 // If we didn't terminate, choose either the left or right subtree to fulfil l
218 // the minLevels requirement of this tree; the other child can have as few l evels as it wants. 217 // the minLevels requirement of this tree; the other child can have as few l evels as it wants.
219 // Also choose a random xfer mode that's supported by CreateFrom2Procs(). 218 // Also choose a random xfer mode that's supported by CreateFrom2Procs().
220 if (minLevels > 1) { 219 if (minLevels > 1) {
221 --minLevels; 220 --minLevels;
222 } 221 }
223 SkAutoTUnref<const GrFragmentProcessor> minLevelsChild(create_random_proc_tr ee(d, minLevels, 222 sk_sp<GrFragmentProcessor> minLevelsChild(create_random_proc_tree(d, minLeve ls, maxLevels - 1));
224 maxLevels - 1)); 223 sk_sp<GrFragmentProcessor> otherChild(create_random_proc_tree(d, 1, maxLevel s - 1));
225 SkAutoTUnref<const GrFragmentProcessor> otherChild(create_random_proc_tree(d , 1,
226 m axLevels - 1));
227 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(d->fRandom->nextRangeU (0, 224 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(d->fRandom->nextRangeU (0,
228 SkXfermode::kLastCoeff Mode)); 225 SkXfermode::kLastCoeff Mode));
229 const GrFragmentProcessor* fp; 226 sk_sp<GrFragmentProcessor> fp;
230 if (d->fRandom->nextF() < 0.5f) { 227 if (d->fRandom->nextF() < 0.5f) {
231 fp = GrXfermodeFragmentProcessor::CreateFromTwoProcessors(minLevelsChild , otherChild, mode); 228 fp = GrXfermodeFragmentProcessor::MakeFromTwoProcessors(std::move(minLev elsChild),
229 std::move(otherC hild), mode);
232 SkASSERT(fp); 230 SkASSERT(fp);
233 } else { 231 } else {
234 fp = GrXfermodeFragmentProcessor::CreateFromTwoProcessors(otherChild, mi nLevelsChild, mode); 232 fp = GrXfermodeFragmentProcessor::MakeFromTwoProcessors(std::move(otherC hild),
233 std::move(minLev elsChild), mode);
235 SkASSERT(fp); 234 SkASSERT(fp);
236 } 235 }
237 return fp; 236 return fp;
238 } 237 }
239 238
240 static void set_random_color_coverage_stages(GrPipelineBuilder* pipelineBuilder, 239 static void set_random_color_coverage_stages(GrPipelineBuilder* pipelineBuilder,
241 GrProcessorTestData* d, int maxStag es) { 240 GrProcessorTestData* d, int maxStag es) {
242 // Randomly choose to either create a linear pipeline of procs or create one proc tree 241 // Randomly choose to either create a linear pipeline of procs or create one proc tree
243 const float procTreeProbability = 0.5f; 242 const float procTreeProbability = 0.5f;
244 if (d->fRandom->nextF() < procTreeProbability) { 243 if (d->fRandom->nextF() < procTreeProbability) {
245 // A full tree with 5 levels (31 nodes) may exceed the max allowed lengt h of the gl 244 // A full tree with 5 levels (31 nodes) may exceed the max allowed lengt h of the gl
246 // processor key; maxTreeLevels should be a number from 1 to 4 inclusive . 245 // processor key; maxTreeLevels should be a number from 1 to 4 inclusive .
247 const int maxTreeLevels = 4; 246 const int maxTreeLevels = 4;
248 SkAutoTUnref<const GrFragmentProcessor> fp( 247 sk_sp<GrFragmentProcessor> fp(create_random_proc_tree(d, 2, maxTreeLevel s));
249 create_random_proc_tree(d, 2, maxTreeLev els)); 248 pipelineBuilder->addColorFragmentProcessor(std::move(fp));
250 pipelineBuilder->addColorFragmentProcessor(fp);
251 } else { 249 } else {
252 int numProcs = d->fRandom->nextULessThan(maxStages + 1); 250 int numProcs = d->fRandom->nextULessThan(maxStages + 1);
253 int numColorProcs = d->fRandom->nextULessThan(numProcs + 1); 251 int numColorProcs = d->fRandom->nextULessThan(numProcs + 1);
254 252
255 for (int s = 0; s < numProcs;) { 253 for (int s = 0; s < numProcs;) {
256 SkAutoTUnref<const GrFragmentProcessor> fp( 254 sk_sp<GrFragmentProcessor> fp(GrProcessorTestFactory<GrFragmentProce ssor>::Make(d));
257 GrProcessorTestFactory<GrFragmentProcessor>::Create(d));
258 SkASSERT(fp); 255 SkASSERT(fp);
259 256
260 // finally add the stage to the correct pipeline in the drawstate 257 // finally add the stage to the correct pipeline in the drawstate
261 if (s < numColorProcs) { 258 if (s < numColorProcs) {
262 pipelineBuilder->addColorFragmentProcessor(fp); 259 pipelineBuilder->addColorFragmentProcessor(std::move(fp));
263 } else { 260 } else {
264 pipelineBuilder->addCoverageFragmentProcessor(fp); 261 pipelineBuilder->addCoverageFragmentProcessor(std::move(fp));
265 } 262 }
266 ++s; 263 ++s;
267 } 264 }
268 } 265 }
269 } 266 }
270 267
271 static void set_random_state(GrPipelineBuilder* pipelineBuilder, 268 static void set_random_state(GrPipelineBuilder* pipelineBuilder,
272 GrDrawContext* drawContext, 269 GrDrawContext* drawContext,
273 SkRandom* random) { 270 SkRandom* random) {
274 int state = 0; 271 int state = 0;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 375
379 int fpFactoryCnt = GrProcessorTestFactory<GrFragmentProcessor>::Count(); 376 int fpFactoryCnt = GrProcessorTestFactory<GrFragmentProcessor>::Count();
380 for (int i = 0; i < fpFactoryCnt; ++i) { 377 for (int i = 0; i < fpFactoryCnt; ++i) {
381 // Since FP factories internally randomize, call each 10 times. 378 // Since FP factories internally randomize, call each 10 times.
382 for (int j = 0; j < 10; ++j) { 379 for (int j = 0; j < 10; ++j) {
383 SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context)) ; 380 SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context)) ;
384 SkASSERT(batch); 381 SkASSERT(batch);
385 GrProcessorTestData ptd(&random, context, context->caps(), 382 GrProcessorTestData ptd(&random, context, context->caps(),
386 drawContext.get(), dummyTextures); 383 drawContext.get(), dummyTextures);
387 GrPipelineBuilder builder; 384 GrPipelineBuilder builder;
388 builder.setXPFactory(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_ Mode))->unref(); 385 builder.setXPFactory(GrPorterDuffXPFactory::Make(SkXfermode::kSrc_Mo de));
389 386
390 SkAutoTUnref<const GrFragmentProcessor> fp( 387 sk_sp<GrFragmentProcessor> fp(
391 GrProcessorTestFactory<GrFragmentProcessor>::CreateIdx(i, &ptd)) ; 388 GrProcessorTestFactory<GrFragmentProcessor>::MakeIdx(i, &ptd));
392 SkAutoTUnref<const GrFragmentProcessor> blockFP( 389 sk_sp<GrFragmentProcessor> blockFP(
393 BlockInputFragmentProcessor::Create(fp)); 390 BlockInputFragmentProcessor::Make(std::move(fp)));
394 builder.addColorFragmentProcessor(blockFP); 391 builder.addColorFragmentProcessor(std::move(blockFP));
395 392
396 drawContext->drawContextPriv().testingOnly_drawBatch(builder, batch) ; 393 drawContext->drawContextPriv().testingOnly_drawBatch(builder, batch) ;
397 drawingManager->flush(); 394 drawingManager->flush();
398 } 395 }
399 } 396 }
400 397
401 return true; 398 return true;
402 } 399 }
403 400
404 static int get_glprograms_max_stages(GrContext* context) { 401 static int get_glprograms_max_stages(GrContext* context) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 GrContextOptions opts; 462 GrContextOptions opts;
466 opts.fSuppressPrints = true; 463 opts.fSuppressPrints = true;
467 sk_gpu_test::GrContextFactory debugFactory(opts); 464 sk_gpu_test::GrContextFactory debugFactory(opts);
468 skiatest::RunWithGPUTestContexts(test_glprograms_native, &is_native_gl_conte xt_type, 465 skiatest::RunWithGPUTestContexts(test_glprograms_native, &is_native_gl_conte xt_type,
469 reporter, &debugFactory); 466 reporter, &debugFactory);
470 skiatest::RunWithGPUTestContexts(test_glprograms_other_contexts, 467 skiatest::RunWithGPUTestContexts(test_glprograms_other_contexts,
471 &is_other_rendering_gl_context_type, report er, &debugFactory); 468 &is_other_rendering_gl_context_type, report er, &debugFactory);
472 } 469 }
473 470
474 #endif 471 #endif
OLDNEW
« no previous file with comments | « src/image/SkImage_Gpu.cpp ('k') | tests/GpuColorFilterTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698