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

Side by Side Diff: src/gpu/GrStrokeRectBatch.h

Issue 1275633003: Move impl of stroke rect batch from h to cpp (Closed) Base URL: https://skia.googlesource.com/skia.git@strokerect
Patch Set: remove unused function Created 5 years, 4 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 | src/gpu/GrStrokeRectBatch.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 2015 Google Inc. 2 * Copyright 2015 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 #ifndef GrStrokeRectBatch_DEFINED 8 #ifndef GrStrokeRectBatch_DEFINED
9 #define GrStrokeRectBatch_DEFINED 9 #define GrStrokeRectBatch_DEFINED
10 10
(...skipping 18 matching lines...) Expand all
29 29
30 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { 30 void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
31 // When this is called on a batch, there is only one geometry bundle 31 // When this is called on a batch, there is only one geometry bundle
32 out->setKnownFourComponents(fGeoData[0].fColor); 32 out->setKnownFourComponents(fGeoData[0].fColor);
33 } 33 }
34 34
35 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { 35 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override {
36 out->setKnownSingleComponent(0xff); 36 out->setKnownSingleComponent(0xff);
37 } 37 }
38 38
39 void initBatchTracker(const GrPipelineInfo& init) override { 39 void initBatchTracker(const GrPipelineInfo& init) override;
40 // Handle any color overrides
41 if (!init.readsColor()) {
42 fGeoData[0].fColor = GrColor_ILLEGAL;
43 }
44 init.getOverrideColorIfSet(&fGeoData[0].fColor);
45 40
46 // setup batch properties 41 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline ) override;
47 fBatch.fColorIgnored = !init.readsColor();
48 fBatch.fColor = fGeoData[0].fColor;
49 fBatch.fUsesLocalCoords = init.readsLocalCoords();
50 fBatch.fCoverageIgnored = !init.readsCoverage();
51 }
52
53 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline ) override {
54 SkAutoTUnref<const GrGeometryProcessor> gp;
55 {
56 using namespace GrDefaultGeoProcFactory;
57 Color color(this->color());
58 Coverage coverage(this->coverageIgnored() ? Coverage::kSolid_Type :
59 Coverage::kNone_Type);
60 LocalCoords localCoords(this->usesLocalCoords() ? LocalCoords::kUseP osition_Type :
61 LocalCoords::kUnus ed_Type);
62 gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoord s,
63 this->viewMatrix()));
64 }
65
66 batchTarget->initDraw(gp, pipeline);
67
68 size_t vertexStride = gp->getVertexStride();
69
70 SkASSERT(vertexStride == sizeof(GrDefaultGeoProcFactory::PositionAttr));
71
72 Geometry& args = fGeoData[0];
73
74 int vertexCount = kVertsPerHairlineRect;
75 if (args.fStrokeWidth > 0) {
76 vertexCount = kVertsPerStrokeRect;
77 }
78
79 const GrVertexBuffer* vertexBuffer;
80 int firstVertex;
81
82 void* verts = batchTarget->makeVertSpace(vertexStride, vertexCount,
83 &vertexBuffer, &firstVertex);
84
85 if (!verts) {
86 SkDebugf("Could not allocate vertices\n");
87 return;
88 }
89
90 SkPoint* vertex = reinterpret_cast<SkPoint*>(verts);
91
92 GrPrimitiveType primType;
93
94 if (args.fStrokeWidth > 0) {;
95 primType = kTriangleStrip_GrPrimitiveType;
96 args.fRect.sort();
97 this->setStrokeRectStrip(vertex, args.fRect, args.fStrokeWidth);
98 } else {
99 // hairline
100 primType = kLineStrip_GrPrimitiveType;
101 vertex[0].set(args.fRect.fLeft, args.fRect.fTop);
102 vertex[1].set(args.fRect.fRight, args.fRect.fTop);
103 vertex[2].set(args.fRect.fRight, args.fRect.fBottom);
104 vertex[3].set(args.fRect.fLeft, args.fRect.fBottom);
105 vertex[4].set(args.fRect.fLeft, args.fRect.fTop);
106 }
107
108 GrVertices vertices;
109 vertices.init(primType, vertexBuffer, firstVertex, vertexCount);
110 batchTarget->draw(vertices);
111 }
112
113 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
114 42
115 private: 43 private:
116 GrStrokeRectBatch(const Geometry& geometry, bool snapToPixelCenters) { 44 GrStrokeRectBatch(const Geometry& geometry, bool snapToPixelCenters);
117 this->initClassID<GrStrokeRectBatch>();
118
119 fBatch.fHairline = geometry.fStrokeWidth == 0;
120
121 fGeoData.push_back(geometry);
122
123 // setup bounds
124 fBounds = geometry.fRect;
125 SkScalar rad = SkScalarHalf(geometry.fStrokeWidth);
126 fBounds.outset(rad, rad);
127 geometry.fViewMatrix.mapRect(&fBounds);
128
129 // If our caller snaps to pixel centers then we have to round out the bo unds
130 if (snapToPixelCenters) {
131 fBounds.roundOut();
132 }
133 }
134
135 /* create a triangle strip that strokes the specified rect. There are 8
136 unique vertices, but we repeat the last 2 to close up. Alternatively we
137 could use an indices array, and then only send 8 verts, but not sure that
138 would be faster.
139 */
140 void setStrokeRectStrip(SkPoint verts[10], const SkRect& rect, SkScalar widt h) {
141 const SkScalar rad = SkScalarHalf(width);
142 // TODO we should be able to enable this assert, but we'd have to filter these draws
143 // this is a bug
144 //SkASSERT(rad < rect.width() / 2 && rad < rect.height() / 2);
145
146 verts[0].set(rect.fLeft + rad, rect.fTop + rad);
147 verts[1].set(rect.fLeft - rad, rect.fTop - rad);
148 verts[2].set(rect.fRight - rad, rect.fTop + rad);
149 verts[3].set(rect.fRight + rad, rect.fTop - rad);
150 verts[4].set(rect.fRight - rad, rect.fBottom - rad);
151 verts[5].set(rect.fRight + rad, rect.fBottom + rad);
152 verts[6].set(rect.fLeft + rad, rect.fBottom - rad);
153 verts[7].set(rect.fLeft - rad, rect.fBottom + rad);
154 verts[8] = verts[0];
155 verts[9] = verts[1];
156 }
157
158 45
159 GrColor color() const { return fBatch.fColor; } 46 GrColor color() const { return fBatch.fColor; }
160 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } 47 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; }
161 bool colorIgnored() const { return fBatch.fColorIgnored; } 48 bool colorIgnored() const { return fBatch.fColorIgnored; }
162 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } 49 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; }
163 bool hairline() const { return fBatch.fHairline; } 50 bool hairline() const { return fBatch.fHairline; }
164 bool coverageIgnored() const { return fBatch.fCoverageIgnored; } 51 bool coverageIgnored() const { return fBatch.fCoverageIgnored; }
165 52
166 bool onCombineIfPossible(GrBatch* t) override { 53 bool onCombineIfPossible(GrBatch* t) override {
167 //if (!this->pipeline()->isEqual(*t->pipeline())) { 54 //if (!this->pipeline()->isEqual(*t->pipeline())) {
(...skipping 15 matching lines...) Expand all
183 }; 70 };
184 71
185 const static int kVertsPerHairlineRect = 5; 72 const static int kVertsPerHairlineRect = 5;
186 const static int kVertsPerStrokeRect = 10; 73 const static int kVertsPerStrokeRect = 10;
187 74
188 BatchTracker fBatch; 75 BatchTracker fBatch;
189 SkSTArray<1, Geometry, true> fGeoData; 76 SkSTArray<1, Geometry, true> fGeoData;
190 }; 77 };
191 78
192 #endif 79 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrStrokeRectBatch.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698