OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 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 #include "GrAADistanceFieldPathRenderer.h" | 9 #include "GrAADistanceFieldPathRenderer.h" |
10 | 10 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 const SkRect& bounds = args.fPath->getBounds(); | 102 const SkRect& bounds = args.fPath->getBounds(); |
103 SkScalar maxDim = SkMaxScalar(bounds.width(), bounds.height()); | 103 SkScalar maxDim = SkMaxScalar(bounds.width(), bounds.height()); |
104 return maxDim < 64.f && maxDim * maxScale < 256.f; | 104 return maxDim < 64.f && maxDim * maxScale < 256.f; |
105 } | 105 } |
106 | 106 |
107 //////////////////////////////////////////////////////////////////////////////// | 107 //////////////////////////////////////////////////////////////////////////////// |
108 | 108 |
109 // padding around path bounds to allow for antialiased pixels | 109 // padding around path bounds to allow for antialiased pixels |
110 static const SkScalar kAntiAliasPad = 1.0f; | 110 static const SkScalar kAntiAliasPad = 1.0f; |
111 | 111 |
112 class AADistanceFieldPathBatch : public GrBatch { | 112 class AADistanceFieldPathBatch : public GrVertexBatch { |
113 public: | 113 public: |
114 typedef GrAADistanceFieldPathRenderer::PathData PathData; | 114 typedef GrAADistanceFieldPathRenderer::PathData PathData; |
115 typedef SkTDynamicHash<PathData, PathData::Key> PathCache; | 115 typedef SkTDynamicHash<PathData, PathData::Key> PathCache; |
116 typedef GrAADistanceFieldPathRenderer::PathDataList PathDataList; | 116 typedef GrAADistanceFieldPathRenderer::PathDataList PathDataList; |
117 | 117 |
118 struct Geometry { | 118 struct Geometry { |
119 Geometry(const SkStrokeRec& stroke) : fStroke(stroke) {} | 119 Geometry(const SkStrokeRec& stroke) : fStroke(stroke) {} |
120 SkPath fPath; | 120 SkPath fPath; |
121 SkStrokeRec fStroke; | 121 SkStrokeRec fStroke; |
122 bool fAntiAlias; | 122 bool fAntiAlias; |
123 PathData* fPathData; | 123 PathData* fPathData; |
124 }; | 124 }; |
125 | 125 |
126 static GrBatch* Create(const Geometry& geometry, GrColor color, const SkMatr
ix& viewMatrix, | 126 static GrDrawBatch* Create(const Geometry& geometry, GrColor color, const Sk
Matrix& viewMatrix, |
127 GrBatchAtlas* atlas, PathCache* pathCache, PathDataLi
st* pathList) { | 127 GrBatchAtlas* atlas, PathCache* pathCache, PathDa
taList* pathList) { |
128 return SkNEW_ARGS(AADistanceFieldPathBatch, (geometry, color, viewMatrix
, | 128 return SkNEW_ARGS(AADistanceFieldPathBatch, (geometry, color, viewMatrix
, |
129 atlas, pathCache, pathList)
); | 129 atlas, pathCache, pathList)
); |
130 } | 130 } |
131 | 131 |
132 const char* name() const override { return "AADistanceFieldPathBatch"; } | 132 const char* name() const override { return "AADistanceFieldPathBatch"; } |
133 | 133 |
134 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | 134 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
135 out->setKnownFourComponents(fBatch.fColor); | 135 out->setKnownFourComponents(fBatch.fColor); |
136 } | 136 } |
137 | 137 |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 batchTarget->draw(vertices); | 478 batchTarget->draw(vertices); |
479 flushInfo->fVertexOffset += kVerticesPerQuad * flushInfo->fInstancesToFl
ush; | 479 flushInfo->fVertexOffset += kVerticesPerQuad * flushInfo->fInstancesToFl
ush; |
480 flushInfo->fInstancesToFlush = 0; | 480 flushInfo->fInstancesToFlush = 0; |
481 } | 481 } |
482 | 482 |
483 GrColor color() const { return fBatch.fColor; } | 483 GrColor color() const { return fBatch.fColor; } |
484 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } | 484 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } |
485 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 485 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
486 | 486 |
487 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 487 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
488 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipel
ine(), t->bounds(), | 488 AADistanceFieldPathBatch* that = t->cast<AADistanceFieldPathBatch>(); |
489 caps)) { | 489 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), |
| 490 that->bounds(), caps)) { |
490 return false; | 491 return false; |
491 } | 492 } |
492 | 493 |
493 AADistanceFieldPathBatch* that = t->cast<AADistanceFieldPathBatch>(); | |
494 | |
495 // TODO we could actually probably do a bunch of this work on the CPU, i
e map viewMatrix, | 494 // TODO we could actually probably do a bunch of this work on the CPU, i
e map viewMatrix, |
496 // maybe upload color via attribute | 495 // maybe upload color via attribute |
497 if (this->color() != that->color()) { | 496 if (this->color() != that->color()) { |
498 return false; | 497 return false; |
499 } | 498 } |
500 | 499 |
501 if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { | 500 if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
502 return false; | 501 return false; |
503 } | 502 } |
504 | 503 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 (void*)this); | 535 (void*)this); |
537 if (!fAtlas) { | 536 if (!fAtlas) { |
538 return false; | 537 return false; |
539 } | 538 } |
540 } | 539 } |
541 | 540 |
542 AADistanceFieldPathBatch::Geometry geometry(*args.fStroke); | 541 AADistanceFieldPathBatch::Geometry geometry(*args.fStroke); |
543 geometry.fPath = *args.fPath; | 542 geometry.fPath = *args.fPath; |
544 geometry.fAntiAlias = args.fAntiAlias; | 543 geometry.fAntiAlias = args.fAntiAlias; |
545 | 544 |
546 SkAutoTUnref<GrBatch> batch(AADistanceFieldPathBatch::Create(geometry, args.
fColor, | 545 SkAutoTUnref<GrDrawBatch> batch(AADistanceFieldPathBatch::Create(geometry, a
rgs.fColor, |
547 *args.fViewMatr
ix, fAtlas, | 546 *args.fView
Matrix, fAtlas, |
548 &fPathCache, &f
PathList)); | 547 &fPathCache
, &fPathList)); |
549 args.fTarget->drawBatch(*args.fPipelineBuilder, batch); | 548 args.fTarget->drawBatch(*args.fPipelineBuilder, batch); |
550 | 549 |
551 return true; | 550 return true; |
552 } | 551 } |
553 | 552 |
554 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 553 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
555 | 554 |
556 #ifdef GR_TEST_UTILS | 555 #ifdef GR_TEST_UTILS |
557 | 556 |
558 struct PathTestStruct { | 557 struct PathTestStruct { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 } | 589 } |
591 } | 590 } |
592 } | 591 } |
593 | 592 |
594 uint32_t fContextID; | 593 uint32_t fContextID; |
595 GrBatchAtlas* fAtlas; | 594 GrBatchAtlas* fAtlas; |
596 PathCache fPathCache; | 595 PathCache fPathCache; |
597 PathDataList fPathList; | 596 PathDataList fPathList; |
598 }; | 597 }; |
599 | 598 |
600 BATCH_TEST_DEFINE(AADistanceFieldPathBatch) { | 599 DRAW_BATCH_TEST_DEFINE(AADistanceFieldPathBatch) { |
601 static PathTestStruct gTestStruct; | 600 static PathTestStruct gTestStruct; |
602 | 601 |
603 if (context->uniqueID() != gTestStruct.fContextID) { | 602 if (context->uniqueID() != gTestStruct.fContextID) { |
604 gTestStruct.fContextID = context->uniqueID(); | 603 gTestStruct.fContextID = context->uniqueID(); |
605 gTestStruct.reset(); | 604 gTestStruct.reset(); |
606 gTestStruct.fAtlas = | 605 gTestStruct.fAtlas = |
607 context->resourceProvider()->createAtlas(kAlpha_8_GrPixelConfig, | 606 context->resourceProvider()->createAtlas(kAlpha_8_GrPixelConfig, |
608 ATLAS_TEXTURE_WIDTH, ATLAS_
TEXTURE_HEIGHT, | 607 ATLAS_TEXTURE_WIDTH, ATLAS_
TEXTURE_HEIGHT, |
609 NUM_PLOTS_X, NUM_PLOTS_Y, | 608 NUM_PLOTS_X, NUM_PLOTS_Y, |
610 &PathTestStruct::HandleEvic
tion, | 609 &PathTestStruct::HandleEvic
tion, |
611 (void*)&gTestStruct); | 610 (void*)&gTestStruct); |
612 } | 611 } |
613 | 612 |
614 SkMatrix viewMatrix = GrTest::TestMatrix(random); | 613 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
615 GrColor color = GrRandomColor(random); | 614 GrColor color = GrRandomColor(random); |
616 | 615 |
617 AADistanceFieldPathBatch::Geometry geometry(GrTest::TestStrokeRec(random)); | 616 AADistanceFieldPathBatch::Geometry geometry(GrTest::TestStrokeRec(random)); |
618 geometry.fPath = GrTest::TestPath(random); | 617 geometry.fPath = GrTest::TestPath(random); |
619 geometry.fAntiAlias = random->nextBool(); | 618 geometry.fAntiAlias = random->nextBool(); |
620 | 619 |
621 return AADistanceFieldPathBatch::Create(geometry, color, viewMatrix, | 620 return AADistanceFieldPathBatch::Create(geometry, color, viewMatrix, |
622 gTestStruct.fAtlas, | 621 gTestStruct.fAtlas, |
623 &gTestStruct.fPathCache, | 622 &gTestStruct.fPathCache, |
624 &gTestStruct.fPathList); | 623 &gTestStruct.fPathList); |
625 } | 624 } |
626 | 625 |
627 #endif | 626 #endif |
OLD | NEW |