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

Side by Side Diff: gm/beziereffects.cpp

Issue 1140983002: remove color from GrGeometryProcessor (Closed) Base URL: https://skia.googlesource.com/skia.git@cleanup2
Patch Set: more Created 5 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 | « no previous file | gm/convexpolyeffect.cpp » ('j') | gm/convexpolyeffect.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 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 test only works with the GPU backend. 9 // This test only works with the GPU backend.
10 10
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 struct Vertex { 57 struct Vertex {
58 SkPoint fPosition; 58 SkPoint fPosition;
59 float fKLM[4]; // The last value is ignored. The effect expects a vec4 f. 59 float fKLM[4]; // The last value is ignored. The effect expects a vec4 f.
60 }; 60 };
61 61
62 Geometry* geoData(int index) override { 62 Geometry* geoData(int index) override {
63 SkASSERT(0 == index); 63 SkASSERT(0 == index);
64 return &fGeometry; 64 return &fGeometry;
65 } 65 }
66 66
67 const Geometry* geoData(int index) const override {
68 SkASSERT(0 == index);
69 return &fGeometry;
70 }
71
67 void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeli ne) override { 72 void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeli ne) override {
68 QuadHelper helper; 73 QuadHelper helper;
69 size_t vertexStride = this->geometryProcessor()->getVertexStride(); 74 size_t vertexStride = this->geometryProcessor()->getVertexStride();
70 SkASSERT(vertexStride == sizeof(Vertex)); 75 SkASSERT(vertexStride == sizeof(Vertex));
71 Vertex* verts = reinterpret_cast<Vertex*>(helper.init(batchTarget, verte xStride, 1)); 76 Vertex* verts = reinterpret_cast<Vertex*>(helper.init(batchTarget, verte xStride, 1));
72 if (!verts) { 77 if (!verts) {
73 return; 78 return;
74 } 79 }
75 80
76 verts[0].fPosition.setRectFan(fGeometry.fBounds.fLeft, fGeometry.fBounds .fTop, 81 verts[0].fPosition.setRectFan(fGeometry.fBounds.fLeft, fGeometry.fBounds .fTop,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 135
131 static const int kNumCubics = 15; 136 static const int kNumCubics = 15;
132 SkRandom rand; 137 SkRandom rand;
133 138
134 // Mult by 3 for each edge effect type 139 // Mult by 3 for each edge effect type
135 int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumCubics*3) )); 140 int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumCubics*3) ));
136 int numRows = SkScalarCeilToInt(SkIntToScalar(kNumCubics*3) / numCols); 141 int numRows = SkScalarCeilToInt(SkIntToScalar(kNumCubics*3) / numCols);
137 SkScalar w = SkIntToScalar(rt->width()) / numCols; 142 SkScalar w = SkIntToScalar(rt->width()) / numCols;
138 SkScalar h = SkIntToScalar(rt->height()) / numRows; 143 SkScalar h = SkIntToScalar(rt->height()) / numRows;
139 int row = 0; 144 int row = 0;
140 int col = 0; 145 int col = 0;
robertphillips 2015/05/13 20:33:50 Use SK_ColorBLACK ?
146 static const GrColor color = 0xff000000;
141 147
142 for (int i = 0; i < kNumCubics; ++i) { 148 for (int i = 0; i < kNumCubics; ++i) {
143 SkPoint baseControlPts[] = { 149 SkPoint baseControlPts[] = {
144 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, 150 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)},
145 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, 151 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)},
146 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, 152 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)},
147 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} 153 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}
148 }; 154 };
149 for(int edgeType = 0; edgeType < kGrProcessorEdgeTypeCnt; ++edgeType ) { 155 for(int edgeType = 0; edgeType < kGrProcessorEdgeTypeCnt; ++edgeType ) {
150 SkAutoTUnref<GrGeometryProcessor> gp; 156 SkAutoTUnref<GrGeometryProcessor> gp;
151 { // scope to contain GrTestTarget 157 { // scope to contain GrTestTarget
152 GrTestTarget tt; 158 GrTestTarget tt;
153 context->getTestTarget(&tt); 159 context->getTestTarget(&tt);
154 if (NULL == tt.target()) { 160 if (NULL == tt.target()) {
155 continue; 161 continue;
156 } 162 }
157 GrPrimitiveEdgeType et = (GrPrimitiveEdgeType)edgeType; 163 GrPrimitiveEdgeType et = (GrPrimitiveEdgeType)edgeType;
158 gp.reset(GrCubicEffect::Create(0xff000000, SkMatrix::I(), et , 164 gp.reset(GrCubicEffect::Create(color, SkMatrix::I(), et,
159 *tt.target()->caps())); 165 *tt.target()->caps()));
160 if (!gp) { 166 if (!gp) {
161 continue; 167 continue;
162 } 168 }
163 } 169 }
164 170
165 SkScalar x = SkScalarMul(col, w); 171 SkScalar x = SkScalarMul(col, w);
166 SkScalar y = SkScalarMul(row, h); 172 SkScalar y = SkScalarMul(row, h);
167 SkPoint controlPts[] = { 173 SkPoint controlPts[] = {
168 {x + baseControlPts[0].fX, y + baseControlPts[0].fY}, 174 {x + baseControlPts[0].fX, y + baseControlPts[0].fY},
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 canvas->drawRect(bounds, boundsPaint); 216 canvas->drawRect(bounds, boundsPaint);
211 217
212 GrTestTarget tt; 218 GrTestTarget tt;
213 context->getTestTarget(&tt); 219 context->getTestTarget(&tt);
214 SkASSERT(tt.target()); 220 SkASSERT(tt.target());
215 221
216 GrPipelineBuilder pipelineBuilder; 222 GrPipelineBuilder pipelineBuilder;
217 pipelineBuilder.setRenderTarget(rt); 223 pipelineBuilder.setRenderTarget(rt);
218 224
219 BezierCubicOrConicTestBatch::Geometry geometry; 225 BezierCubicOrConicTestBatch::Geometry geometry;
220 geometry.fColor = gp->color(); 226 geometry.fColor = color;
221 geometry.fBounds = bounds; 227 geometry.fBounds = bounds;
222 228
223 SkAutoTUnref<GrBatch> batch( 229 SkAutoTUnref<GrBatch> batch(
224 BezierCubicOrConicTestBatch::Create(gp, geometry, kl mEqs, klmSigns[c])); 230 BezierCubicOrConicTestBatch::Create(gp, geometry, kl mEqs, klmSigns[c]));
225 231
226 tt.target()->drawBatch(&pipelineBuilder, batch); 232 tt.target()->drawBatch(&pipelineBuilder, batch);
227 } 233 }
228 ++col; 234 ++col;
229 if (numCols == col) { 235 if (numCols == col) {
230 col = 0; 236 col = 0;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 283
278 static const int kNumConics = 10; 284 static const int kNumConics = 10;
279 SkRandom rand; 285 SkRandom rand;
280 286
281 // Mult by 3 for each edge effect type 287 // Mult by 3 for each edge effect type
282 int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumConics*3) )); 288 int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumConics*3) ));
283 int numRows = SkScalarCeilToInt(SkIntToScalar(kNumConics*3) / numCols); 289 int numRows = SkScalarCeilToInt(SkIntToScalar(kNumConics*3) / numCols);
284 SkScalar w = SkIntToScalar(rt->width()) / numCols; 290 SkScalar w = SkIntToScalar(rt->width()) / numCols;
285 SkScalar h = SkIntToScalar(rt->height()) / numRows; 291 SkScalar h = SkIntToScalar(rt->height()) / numRows;
286 int row = 0; 292 int row = 0;
287 int col = 0; 293 int col = 0;
robertphillips 2015/05/13 20:33:50 ditto ?
294 static const GrColor color = 0xff000000;
288 295
289 for (int i = 0; i < kNumConics; ++i) { 296 for (int i = 0; i < kNumConics; ++i) {
290 SkPoint baseControlPts[] = { 297 SkPoint baseControlPts[] = {
291 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, 298 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)},
292 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, 299 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)},
293 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} 300 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}
294 }; 301 };
295 SkScalar weight = rand.nextRangeF(0.f, 2.f); 302 SkScalar weight = rand.nextRangeF(0.f, 2.f);
296 for(int edgeType = 0; edgeType < kGrProcessorEdgeTypeCnt; ++edgeType ) { 303 for(int edgeType = 0; edgeType < kGrProcessorEdgeTypeCnt; ++edgeType ) {
297 SkAutoTUnref<GrGeometryProcessor> gp; 304 SkAutoTUnref<GrGeometryProcessor> gp;
298 { // scope to contain GrTestTarget 305 { // scope to contain GrTestTarget
299 GrTestTarget tt; 306 GrTestTarget tt;
300 context->getTestTarget(&tt); 307 context->getTestTarget(&tt);
301 if (NULL == tt.target()) { 308 if (NULL == tt.target()) {
302 continue; 309 continue;
303 } 310 }
304 GrPrimitiveEdgeType et = (GrPrimitiveEdgeType)edgeType; 311 GrPrimitiveEdgeType et = (GrPrimitiveEdgeType)edgeType;
305 gp.reset(GrConicEffect::Create(0xff000000, SkMatrix::I(), et , 312 gp.reset(GrConicEffect::Create(color, SkMatrix::I(), et,
306 *tt.target()->caps(), SkMatri x::I())); 313 *tt.target()->caps(), SkMatri x::I()));
307 if (!gp) { 314 if (!gp) {
308 continue; 315 continue;
309 } 316 }
310 } 317 }
311 318
312 SkScalar x = SkScalarMul(col, w); 319 SkScalar x = SkScalarMul(col, w);
313 SkScalar y = SkScalarMul(row, h); 320 SkScalar y = SkScalarMul(row, h);
314 SkPoint controlPts[] = { 321 SkPoint controlPts[] = {
315 {x + baseControlPts[0].fX, y + baseControlPts[0].fY}, 322 {x + baseControlPts[0].fX, y + baseControlPts[0].fY},
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 canvas->drawRect(bounds, boundsPaint); 361 canvas->drawRect(bounds, boundsPaint);
355 362
356 GrTestTarget tt; 363 GrTestTarget tt;
357 context->getTestTarget(&tt); 364 context->getTestTarget(&tt);
358 SkASSERT(tt.target()); 365 SkASSERT(tt.target());
359 366
360 GrPipelineBuilder pipelineBuilder; 367 GrPipelineBuilder pipelineBuilder;
361 pipelineBuilder.setRenderTarget(rt); 368 pipelineBuilder.setRenderTarget(rt);
362 369
363 BezierCubicOrConicTestBatch::Geometry geometry; 370 BezierCubicOrConicTestBatch::Geometry geometry;
364 geometry.fColor = gp->color(); 371 geometry.fColor = color;
365 geometry.fBounds = bounds; 372 geometry.fBounds = bounds;
366 373
367 SkAutoTUnref<GrBatch> batch( 374 SkAutoTUnref<GrBatch> batch(
368 BezierCubicOrConicTestBatch::Create(gp, geometry, kl mEqs, 1.f)); 375 BezierCubicOrConicTestBatch::Create(gp, geometry, kl mEqs, 1.f));
369 376
370 tt.target()->drawBatch(&pipelineBuilder, batch); 377 tt.target()->drawBatch(&pipelineBuilder, batch);
371 } 378 }
372 ++col; 379 ++col;
373 if (numCols == col) { 380 if (numCols == col) {
374 col = 0; 381 col = 0;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 struct Vertex { 452 struct Vertex {
446 SkPoint fPosition; 453 SkPoint fPosition;
447 float fKLM[4]; // The last value is ignored. The effect expects a vec4 f. 454 float fKLM[4]; // The last value is ignored. The effect expects a vec4 f.
448 }; 455 };
449 456
450 Geometry* geoData(int index) override { 457 Geometry* geoData(int index) override {
451 SkASSERT(0 == index); 458 SkASSERT(0 == index);
452 return &fGeometry; 459 return &fGeometry;
453 } 460 }
454 461
462 const Geometry* geoData(int index) const override {
463 SkASSERT(0 == index);
464 return &fGeometry;
465 }
466
455 void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeli ne) override { 467 void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeli ne) override {
456 QuadHelper helper; 468 QuadHelper helper;
457 size_t vertexStride = this->geometryProcessor()->getVertexStride(); 469 size_t vertexStride = this->geometryProcessor()->getVertexStride();
458 SkASSERT(vertexStride == sizeof(Vertex)); 470 SkASSERT(vertexStride == sizeof(Vertex));
459 Vertex* verts = reinterpret_cast<Vertex*>(helper.init(batchTarget, verte xStride, 1)); 471 Vertex* verts = reinterpret_cast<Vertex*>(helper.init(batchTarget, verte xStride, 1));
460 if (!verts) { 472 if (!verts) {
461 return; 473 return;
462 } 474 }
463 verts[0].fPosition.setRectFan(fGeometry.fBounds.fLeft, fGeometry.fBounds .fTop, 475 verts[0].fPosition.setRectFan(fGeometry.fBounds.fLeft, fGeometry.fBounds .fTop,
464 fGeometry.fBounds.fRight, fGeometry.fBound s.fBottom, 476 fGeometry.fBounds.fRight, fGeometry.fBound s.fBottom,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 }; 524 };
513 525
514 static const int kNumQuads = 5; 526 static const int kNumQuads = 5;
515 SkRandom rand; 527 SkRandom rand;
516 528
517 int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumQuads*3)) ); 529 int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumQuads*3)) );
518 int numRows = SkScalarCeilToInt(SkIntToScalar(kNumQuads*3) / numCols); 530 int numRows = SkScalarCeilToInt(SkIntToScalar(kNumQuads*3) / numCols);
519 SkScalar w = SkIntToScalar(rt->width()) / numCols; 531 SkScalar w = SkIntToScalar(rt->width()) / numCols;
520 SkScalar h = SkIntToScalar(rt->height()) / numRows; 532 SkScalar h = SkIntToScalar(rt->height()) / numRows;
521 int row = 0; 533 int row = 0;
522 int col = 0; 534 int col = 0;
robertphillips 2015/05/13 20:33:50 here too ?
535 static const GrColor color = 0xff000000;
523 536
524 for (int i = 0; i < kNumQuads; ++i) { 537 for (int i = 0; i < kNumQuads; ++i) {
525 SkPoint baseControlPts[] = { 538 SkPoint baseControlPts[] = {
526 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, 539 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)},
527 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, 540 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)},
528 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} 541 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}
529 }; 542 };
530 for(int edgeType = 0; edgeType < kGrProcessorEdgeTypeCnt; ++edgeType ) { 543 for(int edgeType = 0; edgeType < kGrProcessorEdgeTypeCnt; ++edgeType ) {
531 SkAutoTUnref<GrGeometryProcessor> gp; 544 SkAutoTUnref<GrGeometryProcessor> gp;
532 { // scope to contain GrTestTarget 545 { // scope to contain GrTestTarget
533 GrTestTarget tt; 546 GrTestTarget tt;
534 context->getTestTarget(&tt); 547 context->getTestTarget(&tt);
535 if (NULL == tt.target()) { 548 if (NULL == tt.target()) {
536 continue; 549 continue;
537 } 550 }
538 GrPrimitiveEdgeType et = (GrPrimitiveEdgeType)edgeType; 551 GrPrimitiveEdgeType et = (GrPrimitiveEdgeType)edgeType;
539 gp.reset(GrQuadEffect::Create(0xff000000, SkMatrix::I(), et, 552 gp.reset(GrQuadEffect::Create(color, SkMatrix::I(), et,
540 *tt.target()->caps(), SkMatrix ::I())); 553 *tt.target()->caps(), SkMatrix ::I()));
541 if (!gp) { 554 if (!gp) {
542 continue; 555 continue;
543 } 556 }
544 } 557 }
545 558
546 SkScalar x = SkScalarMul(col, w); 559 SkScalar x = SkScalarMul(col, w);
547 SkScalar y = SkScalarMul(row, h); 560 SkScalar y = SkScalarMul(row, h);
548 SkPoint controlPts[] = { 561 SkPoint controlPts[] = {
549 {x + baseControlPts[0].fX, y + baseControlPts[0].fY}, 562 {x + baseControlPts[0].fX, y + baseControlPts[0].fY},
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 GrTestTarget tt; 600 GrTestTarget tt;
588 context->getTestTarget(&tt); 601 context->getTestTarget(&tt);
589 SkASSERT(tt.target()); 602 SkASSERT(tt.target());
590 603
591 GrPipelineBuilder pipelineBuilder; 604 GrPipelineBuilder pipelineBuilder;
592 pipelineBuilder.setRenderTarget(rt); 605 pipelineBuilder.setRenderTarget(rt);
593 606
594 GrPathUtils::QuadUVMatrix DevToUV(pts); 607 GrPathUtils::QuadUVMatrix DevToUV(pts);
595 608
596 BezierQuadTestBatch::Geometry geometry; 609 BezierQuadTestBatch::Geometry geometry;
597 geometry.fColor = gp->color(); 610 geometry.fColor = color;
598 geometry.fBounds = bounds; 611 geometry.fBounds = bounds;
599 612
600 SkAutoTUnref<GrBatch> batch(BezierQuadTestBatch::Create(gp, geometry, DevToUV)); 613 SkAutoTUnref<GrBatch> batch(BezierQuadTestBatch::Create(gp, geometry, DevToUV));
601 614
602 tt.target()->drawBatch(&pipelineBuilder, batch); 615 tt.target()->drawBatch(&pipelineBuilder, batch);
603 } 616 }
604 ++col; 617 ++col;
605 if (numCols == col) { 618 if (numCols == col) {
606 col = 0; 619 col = 0;
607 ++row; 620 ++row;
608 } 621 }
609 } 622 }
610 } 623 }
611 } 624 }
612 625
613 private: 626 private:
614 typedef GM INHERITED; 627 typedef GM INHERITED;
615 }; 628 };
616 629
617 DEF_GM( return SkNEW(BezierCubicEffects); ) 630 DEF_GM( return SkNEW(BezierCubicEffects); )
618 DEF_GM( return SkNEW(BezierConicEffects); ) 631 DEF_GM( return SkNEW(BezierConicEffects); )
619 DEF_GM( return SkNEW(BezierQuadEffects); ) 632 DEF_GM( return SkNEW(BezierQuadEffects); )
620 633
621 } 634 }
622 635
623 #endif 636 #endif
OLDNEW
« no previous file with comments | « no previous file | gm/convexpolyeffect.cpp » ('j') | gm/convexpolyeffect.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698