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

Side by Side Diff: src/gpu/GrAARectRenderer.cpp

Issue 1139723004: Preliminary attempt to remove batch tracker (Closed) Base URL: https://skia.googlesource.com/skia.git@cleanup5
Patch Set: tweaks 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 | « src/gpu/GrAAHairLinePathRenderer.cpp ('k') | src/gpu/GrAtlasTextContext.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 2012 Google Inc. 2 * Copyright 2012 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 #include "GrAARectRenderer.h" 8 #include "GrAARectRenderer.h"
9 #include "GrBatch.h" 9 #include "GrBatch.h"
10 #include "GrBatchTarget.h" 10 #include "GrBatchTarget.h"
(...skipping 13 matching lines...) Expand all
24 24
25 /////////////////////////////////////////////////////////////////////////////// 25 ///////////////////////////////////////////////////////////////////////////////
26 26
27 static void set_inset_fan(SkPoint* pts, size_t stride, 27 static void set_inset_fan(SkPoint* pts, size_t stride,
28 const SkRect& r, SkScalar dx, SkScalar dy) { 28 const SkRect& r, SkScalar dx, SkScalar dy) {
29 pts->setRectFan(r.fLeft + dx, r.fTop + dy, 29 pts->setRectFan(r.fLeft + dx, r.fTop + dy,
30 r.fRight - dx, r.fBottom - dy, stride); 30 r.fRight - dx, r.fBottom - dy, stride);
31 } 31 }
32 32
33 static const GrGeometryProcessor* create_fill_rect_gp(bool tweakAlphaForCoverage , 33 static const GrGeometryProcessor* create_fill_rect_gp(bool tweakAlphaForCoverage ,
34 const SkMatrix& localMatri x) { 34 const SkMatrix& localMatri x,
35 bool usesLocalCoords,
36 bool coverageIgnored) {
35 uint32_t flags = GrDefaultGeoProcFactory::kColor_GPType; 37 uint32_t flags = GrDefaultGeoProcFactory::kColor_GPType;
36 const GrGeometryProcessor* gp; 38 const GrGeometryProcessor* gp;
37 if (tweakAlphaForCoverage) { 39 if (tweakAlphaForCoverage) {
38 gp = GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, SkMatrix::I() , localMatrix); 40 gp = GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, usesLocalCoor ds, coverageIgnored,
41 SkMatrix::I(), localMatrix);
39 } else { 42 } else {
40 flags |= GrDefaultGeoProcFactory::kCoverage_GPType; 43 flags |= GrDefaultGeoProcFactory::kCoverage_GPType;
41 gp = GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, SkMatrix::I() , localMatrix); 44 gp = GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, usesLocalCoor ds, coverageIgnored,
45 SkMatrix::I(), localMatrix);
42 } 46 }
43 return gp; 47 return gp;
44 } 48 }
45 49
46 GR_DECLARE_STATIC_UNIQUE_KEY(gAAFillRectIndexBufferKey); 50 GR_DECLARE_STATIC_UNIQUE_KEY(gAAFillRectIndexBufferKey);
47 51
48 class AAFillRectBatch : public GrBatch { 52 class AAFillRectBatch : public GrBatch {
49 public: 53 public:
50 struct Geometry { 54 struct Geometry {
51 GrColor fColor; 55 GrColor fColor;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline ) override { 92 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline ) override {
89 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); 93 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
90 94
91 SkMatrix localMatrix; 95 SkMatrix localMatrix;
92 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix)) { 96 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix)) {
93 SkDebugf("Cannot invert\n"); 97 SkDebugf("Cannot invert\n");
94 return; 98 return;
95 } 99 }
96 100
97 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA lphaForCoverage, 101 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA lphaForCoverage,
98 localMatr ix)); 102 localMatr ix,
103 this->use sLocalCoords(),
104 this->cov erageIgnored()));
99 105
100 batchTarget->initDraw(gp, pipeline); 106 batchTarget->initDraw(gp, pipeline);
101 107
102 // TODO this is hacky, but the only way we have to initialize the GP is to use the
103 // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch
104 // everywhere we can remove this nastiness
105 GrPipelineInfo init;
106 init.fColorIgnored = fBatch.fColorIgnored;
107 init.fOverrideColor = GrColor_ILLEGAL;
108 init.fCoverageIgnored = fBatch.fCoverageIgnored;
109 init.fUsesLocalCoords = this->usesLocalCoords();
110 gp->initBatchTracker(batchTarget->currentBatchTracker(), init);
111
112 size_t vertexStride = gp->getVertexStride(); 108 size_t vertexStride = gp->getVertexStride();
113 SkASSERT(canTweakAlphaForCoverage ? 109 SkASSERT(canTweakAlphaForCoverage ?
114 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr) : 110 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr) :
115 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo verageAttr)); 111 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo verageAttr));
116 int instanceCount = fGeoData.count(); 112 int instanceCount = fGeoData.count();
117 113
118 SkAutoTUnref<const GrIndexBuffer> indexBuffer(this->getIndexBuffer( 114 SkAutoTUnref<const GrIndexBuffer> indexBuffer(this->getIndexBuffer(
119 batchTarget->resourceProvider())); 115 batchTarget->resourceProvider()));
120 InstancedHelper helper; 116 InstancedHelper helper;
121 void* vertices = helper.init(batchTarget, kTriangles_GrPrimitiveType, ve rtexStride, 117 void* vertices = helper.init(batchTarget, kTriangles_GrPrimitiveType, ve rtexStride,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 return resourceProvider->refOrCreateInstancedIndexBuffer(gFillAARectIdx, 165 return resourceProvider->refOrCreateInstancedIndexBuffer(gFillAARectIdx,
170 kIndicesPerAAFillRect, kNumAAFillRectsInIndexBuffer, kVertsPerAAFill Rect, 166 kIndicesPerAAFillRect, kNumAAFillRectsInIndexBuffer, kVertsPerAAFill Rect,
171 gAAFillRectIndexBufferKey); 167 gAAFillRectIndexBufferKey);
172 } 168 }
173 169
174 GrColor color() const { return fBatch.fColor; } 170 GrColor color() const { return fBatch.fColor; }
175 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } 171 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; }
176 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover age; } 172 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover age; }
177 bool colorIgnored() const { return fBatch.fColorIgnored; } 173 bool colorIgnored() const { return fBatch.fColorIgnored; }
178 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } 174 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; }
175 bool coverageIgnored() const { return fBatch.fCoverageIgnored; }
179 176
180 bool onCombineIfPossible(GrBatch* t) override { 177 bool onCombineIfPossible(GrBatch* t) override {
181 AAFillRectBatch* that = t->cast<AAFillRectBatch>(); 178 AAFillRectBatch* that = t->cast<AAFillRectBatch>();
182 179
183 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); 180 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords());
184 // We apply the viewmatrix to the rect points on the cpu. However, if t he pipeline uses 181 // We apply the viewmatrix to the rect points on the cpu. However, if t he pipeline uses
185 // local coords then we won't be able to batch. We could actually uploa d the viewmatrix 182 // local coords then we won't be able to batch. We could actually uploa d the viewmatrix
186 // using vertex attributes in these cases, but haven't investigated that 183 // using vertex attributes in these cases, but haven't investigated that
187 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi ewMatrix())) { 184 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi ewMatrix())) {
188 return false; 185 return false;
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 443
447 // Local matrix is ignored if we don't have local coords. If we have lo calcoords we only 444 // Local matrix is ignored if we don't have local coords. If we have lo calcoords we only
448 // batch with identical view matrices 445 // batch with identical view matrices
449 SkMatrix localMatrix; 446 SkMatrix localMatrix;
450 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix)) { 447 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix)) {
451 SkDebugf("Cannot invert\n"); 448 SkDebugf("Cannot invert\n");
452 return; 449 return;
453 } 450 }
454 451
455 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA lphaForCoverage, 452 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA lphaForCoverage,
456 localMatr ix)); 453 localMatr ix,
454 this->use sLocalCoords(),
455 this->cov erageIgnored()));
457 456
458 batchTarget->initDraw(gp, pipeline); 457 batchTarget->initDraw(gp, pipeline);
459 458
460 // TODO this is hacky, but the only way we have to initialize the GP is to use the
461 // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch
462 // everywhere we can remove this nastiness
463 GrPipelineInfo init;
464 init.fColorIgnored = fBatch.fColorIgnored;
465 init.fOverrideColor = GrColor_ILLEGAL;
466 init.fCoverageIgnored = fBatch.fCoverageIgnored;
467 init.fUsesLocalCoords = this->usesLocalCoords();
468 gp->initBatchTracker(batchTarget->currentBatchTracker(), init);
469
470 size_t vertexStride = gp->getVertexStride(); 459 size_t vertexStride = gp->getVertexStride();
471 460
472 SkASSERT(canTweakAlphaForCoverage ? 461 SkASSERT(canTweakAlphaForCoverage ?
473 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr) : 462 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr) :
474 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo verageAttr)); 463 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo verageAttr));
475 int innerVertexNum = 4; 464 int innerVertexNum = 4;
476 int outerVertexNum = this->miterStroke() ? 4 : 8; 465 int outerVertexNum = this->miterStroke() ? 4 : 8;
477 int verticesPerInstance = (outerVertexNum + innerVertexNum) * 2; 466 int verticesPerInstance = (outerVertexNum + innerVertexNum) * 2;
478 int indicesPerInstance = this->miterStroke() ? kMiterIndexCnt : kBevelIn dexCnt; 467 int indicesPerInstance = this->miterStroke() ? kMiterIndexCnt : kBevelIn dexCnt;
479 int instanceCount = fGeoData.count(); 468 int instanceCount = fGeoData.count();
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 gBevelIndexBufferKey); 608 gBevelIndexBufferKey);
620 } 609 }
621 } 610 }
622 611
623 GrColor color() const { return fBatch.fColor; } 612 GrColor color() const { return fBatch.fColor; }
624 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } 613 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; }
625 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover age; } 614 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover age; }
626 bool colorIgnored() const { return fBatch.fColorIgnored; } 615 bool colorIgnored() const { return fBatch.fColorIgnored; }
627 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } 616 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; }
628 bool miterStroke() const { return fBatch.fMiterStroke; } 617 bool miterStroke() const { return fBatch.fMiterStroke; }
618 bool coverageIgnored() const { return fBatch.fCoverageIgnored; }
629 619
630 bool onCombineIfPossible(GrBatch* t) override { 620 bool onCombineIfPossible(GrBatch* t) override {
631 AAStrokeRectBatch* that = t->cast<AAStrokeRectBatch>(); 621 AAStrokeRectBatch* that = t->cast<AAStrokeRectBatch>();
632 622
633 // TODO batch across miterstroke changes 623 // TODO batch across miterstroke changes
634 if (this->miterStroke() != that->miterStroke()) { 624 if (this->miterStroke() != that->miterStroke()) {
635 return false; 625 return false;
636 } 626 }
637 627
638 // We apply the viewmatrix to the rect points on the cpu. However, if t he pipeline uses 628 // We apply the viewmatrix to the rect points on the cpu. However, if t he pipeline uses
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 geo.fColor = GrRandomColor(random); 843 geo.fColor = GrRandomColor(random);
854 geo.fDevOutside = outside; 844 geo.fDevOutside = outside;
855 geo.fDevOutsideAssist = outsideAssist; 845 geo.fDevOutsideAssist = outsideAssist;
856 geo.fDevInside = inside; 846 geo.fDevInside = inside;
857 geo.fMiterStroke = miterStroke; 847 geo.fMiterStroke = miterStroke;
858 848
859 return AAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random)); 849 return AAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random));
860 } 850 }
861 851
862 #endif 852 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrAAHairLinePathRenderer.cpp ('k') | src/gpu/GrAtlasTextContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698