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

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

Issue 1253393002: Cleanup Default Geo Proc API (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks 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 | « src/gpu/GrDefaultGeoProcFactory.cpp ('k') | no next file » | 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 #include "GrRectBatch.h" 8 #include "GrRectBatch.h"
9 9
10 #include "GrBatch.h" 10 #include "GrBatch.h"
11 #include "GrBatchTarget.h" 11 #include "GrBatchTarget.h"
12 #include "GrBatchTest.h" 12 #include "GrBatchTest.h"
13 #include "GrDefaultGeoProcFactory.h" 13 #include "GrDefaultGeoProcFactory.h"
14 #include "GrPrimitiveProcessor.h" 14 #include "GrPrimitiveProcessor.h"
15 15
16 /** We always use per-vertex colors so that rects can be batched across color ch anges. Sometimes we 16 /** We always use per-vertex colors so that rects can be batched across color ch anges. Sometimes we
17 have explicit local coords and sometimes not. We *could* always provide expl icit local coords 17 have explicit local coords and sometimes not. We *could* always provide expl icit local coords
18 and just duplicate the positions when the caller hasn't provided a local coo rd rect, but we 18 and just duplicate the positions when the caller hasn't provided a local coo rd rect, but we
19 haven't seen a use case which frequently switches between local rect and no local rect draws. 19 haven't seen a use case which frequently switches between local rect and no local rect draws.
20 20
21 The color param is used to determine whether the opaque hint can be set on t he draw state. 21 The color param is used to determine whether the opaque hint can be set on t he draw state.
22 The caller must populate the vertex colors itself. 22 The caller must populate the vertex colors itself.
23 23
24 The vertex attrib order is always pos, color, [local coords]. 24 The vertex attrib order is always pos, color, [local coords].
25 */ 25 */
26 static const GrGeometryProcessor* create_rect_gp(bool hasExplicitLocalCoords, 26 static const GrGeometryProcessor* create_rect_gp(bool hasExplicitLocalCoords,
27 const SkMatrix* localMatrix, 27 const SkMatrix* localMatrix,
28 bool usesLocalCoords,
29 bool coverageIgnored) { 28 bool coverageIgnored) {
30 // TODO remove color when we have ignored color from the XP 29 typedef GrDefaultGeoProcFactory::Color Color;
31 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | 30 typedef GrDefaultGeoProcFactory::Coverage Coverage;
32 GrDefaultGeoProcFactory::kColor_GPType; 31 typedef GrDefaultGeoProcFactory::LocalCoords LocalCoords;
33 flags |= hasExplicitLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPTyp e : 0; 32 Color color(Color::kAttribute_Type);
33 Coverage coverage(coverageIgnored ? Coverage::kNone_Type : Coverage::kSolid_ Type);
34 LocalCoords::Type localCoords;
35 if (hasExplicitLocalCoords) {
36 localCoords = LocalCoords::kHasExplicit_Type;
37 } else {
38 localCoords = LocalCoords::kUsePosition_Type;
39 }
40
34 if (localMatrix) { 41 if (localMatrix) {
35 return GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, usesLocalCo ords, 42 return GrDefaultGeoProcFactory::Create(color, coverage, localCoords, SkM atrix::I(),
36 coverageIgnored, SkMatrix::I(), * localMatrix); 43 *localMatrix);
37 } else { 44 } else {
38 return GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, usesLocalCo ords, 45 return GrDefaultGeoProcFactory::Create(color, coverage, localCoords);
39 coverageIgnored, SkMatrix::I(), S kMatrix::I());
40 } 46 }
41 } 47 }
42 48
43 class RectBatch : public GrBatch { 49 class RectBatch : public GrBatch {
44 public: 50 public:
45 struct Geometry { 51 struct Geometry {
46 SkMatrix fViewMatrix; 52 SkMatrix fViewMatrix;
47 SkRect fRect; 53 SkRect fRect;
48 SkRect fLocalRect; 54 SkRect fLocalRect;
49 SkMatrix fLocalMatrix; 55 SkMatrix fLocalMatrix;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 return; 100 return;
95 } 101 }
96 102
97 if (this->hasLocalMatrix()) { 103 if (this->hasLocalMatrix()) {
98 invert.preConcat(this->localMatrix()); 104 invert.preConcat(this->localMatrix());
99 } 105 }
100 } 106 }
101 107
102 SkAutoTUnref<const GrGeometryProcessor> gp(create_rect_gp(hasExplicitLoc alCoords, 108 SkAutoTUnref<const GrGeometryProcessor> gp(create_rect_gp(hasExplicitLoc alCoords,
103 &invert, 109 &invert,
104 this->usesLoca lCoords(),
105 this->coverage Ignored())); 110 this->coverage Ignored()));
106 111
107 batchTarget->initDraw(gp, pipeline); 112 batchTarget->initDraw(gp, pipeline);
108 113
109 int instanceCount = fGeoData.count(); 114 int instanceCount = fGeoData.count();
110 size_t vertexStride = gp->getVertexStride(); 115 size_t vertexStride = gp->getVertexStride();
111 SkASSERT(hasExplicitLocalCoords ? 116 SkASSERT(hasExplicitLocalCoords ?
112 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorLo calCoordAttr) : 117 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorLo calCoordAttr) :
113 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr)); 118 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr));
114 QuadHelper helper; 119 QuadHelper helper;
115 void* vertices = helper.init(batchTarget, vertexStride, instanceCount); 120 void* vertices = helper.init(batchTarget, vertexStride, instanceCount);
116 121
117 if (!vertices) { 122 if (!vertices) {
118 return; 123 return;
119 } 124 }
120 125
121 for (int i = 0; i < instanceCount; i++) { 126 for (int i = 0; i < instanceCount; i++) {
122 const Geometry& geom = fGeoData[i]; 127 const Geometry& geom = fGeoData[i];
123 128
124 intptr_t offset = reinterpret_cast<intptr_t>(vertices) + 129 intptr_t offset = reinterpret_cast<intptr_t>(vertices) +
125 kVerticesPerQuad * i * vertexStride; 130 kVerticesPerQuad * i * vertexStride;
126 SkPoint* positions = reinterpret_cast<SkPoint*>(offset); 131 SkPoint* positions = reinterpret_cast<SkPoint*>(offset);
127 132
128 positions->setRectFan(geom.fRect.fLeft, geom.fRect.fTop, 133 positions->setRectFan(geom.fRect.fLeft, geom.fRect.fTop,
129 geom.fRect.fRight, geom.fRect.fBottom, vertexS tride); 134 geom.fRect.fRight, geom.fRect.fBottom, vertexS tride);
130 geom.fViewMatrix.mapPointsWithStride(positions, vertexStride, kVerti cesPerQuad); 135 geom.fViewMatrix.mapPointsWithStride(positions, vertexStride, kVerti cesPerQuad);
131 136
137 // TODO we should only do this if local coords are being read
132 if (geom.fHasLocalRect) { 138 if (geom.fHasLocalRect) {
133 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor ); 139 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor );
134 SkPoint* coords = reinterpret_cast<SkPoint*>(offset + kLocalOffs et); 140 SkPoint* coords = reinterpret_cast<SkPoint*>(offset + kLocalOffs et);
135 coords->setRectFan(geom.fLocalRect.fLeft, geom.fLocalRect.fTop, 141 coords->setRectFan(geom.fLocalRect.fLeft, geom.fLocalRect.fTop,
136 geom.fLocalRect.fRight, geom.fLocalRect.fBott om, 142 geom.fLocalRect.fRight, geom.fLocalRect.fBott om,
137 vertexStride); 143 vertexStride);
138 if (geom.fHasLocalMatrix) { 144 if (geom.fHasLocalMatrix) {
139 geom.fLocalMatrix.mapPointsWithStride(coords, vertexStride, kVerticesPerQuad); 145 geom.fLocalMatrix.mapPointsWithStride(coords, vertexStride, kVerticesPerQuad);
140 } 146 }
141 } 147 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 if (hasLocalMatrix) { 277 if (hasLocalMatrix) {
272 localMatrix = GrTest::TestMatrix(random); 278 localMatrix = GrTest::TestMatrix(random);
273 } 279 }
274 280
275 return GrRectBatch::Create(color, viewMatrix, rect, 281 return GrRectBatch::Create(color, viewMatrix, rect,
276 hasLocalRect ? &localRect : NULL, 282 hasLocalRect ? &localRect : NULL,
277 hasLocalMatrix ? &localMatrix : NULL); 283 hasLocalMatrix ? &localMatrix : NULL);
278 } 284 }
279 285
280 #endif 286 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrDefaultGeoProcFactory.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698