OLD | NEW |
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 "GrNonAAFillRectBatch.h" | 8 #include "GrNonAAFillRectBatch.h" |
9 | 9 |
10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 static SkString DumpInfo(const Geometry& geo, int index) { | 127 static SkString DumpInfo(const Geometry& geo, int index) { |
128 SkString str; | 128 SkString str; |
129 str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f
]\n", | 129 str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f
]\n", |
130 index, | 130 index, |
131 geo.fColor, | 131 geo.fColor, |
132 geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight, geo.fRect
.fBottom); | 132 geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight, geo.fRect
.fBottom); |
133 return str; | 133 return str; |
134 } | 134 } |
135 | 135 |
136 static bool CanCombine(const Geometry& mine, const Geometry& theirs, | 136 static bool CanCombine(const Geometry& mine, const Geometry& theirs, |
137 const GrPipelineOptimizations& opts) { | 137 const GrXPOverridesForBatch& overrides) { |
138 return true; | 138 return true; |
139 } | 139 } |
140 | 140 |
141 static const GrGeometryProcessor* CreateGP(const Geometry& geo, | 141 static const GrGeometryProcessor* CreateGP(const Geometry& geo, |
142 const GrPipelineOptimizations& op
ts) { | 142 const GrXPOverridesForBatch& over
rides) { |
143 const GrGeometryProcessor* gp = create_gp(geo.fViewMatrix, opts.readsCov
erage(), true, | 143 const GrGeometryProcessor* gp = create_gp(geo.fViewMatrix, overrides.rea
dsCoverage(), true, |
144 nullptr); | 144 nullptr); |
145 | 145 |
146 SkASSERT(gp->getVertexStride() == | 146 SkASSERT(gp->getVertexStride() == |
147 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr)); | 147 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr)); |
148 return gp; | 148 return gp; |
149 } | 149 } |
150 | 150 |
151 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry
& geo, | 151 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry
& geo, |
152 const GrPipelineOptimizations& opts) { | 152 const GrXPOverridesForBatch& overrides) { |
153 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.fRect
, &geo.fLocalQuad); | 153 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.fRect
, &geo.fLocalQuad); |
154 } | 154 } |
155 }; | 155 }; |
156 | 156 |
157 // We handle perspective in the local matrix or viewmatrix with special batches | 157 // We handle perspective in the local matrix or viewmatrix with special batches |
158 class NonAAFillRectBatchPerspectiveImp : public NonAAFillRectBatchBase { | 158 class NonAAFillRectBatchPerspectiveImp : public NonAAFillRectBatchBase { |
159 public: | 159 public: |
160 struct Geometry { | 160 struct Geometry { |
161 SkMatrix fViewMatrix; | 161 SkMatrix fViewMatrix; |
162 SkMatrix fLocalMatrix; | 162 SkMatrix fLocalMatrix; |
163 SkRect fRect; | 163 SkRect fRect; |
164 SkRect fLocalRect; | 164 SkRect fLocalRect; |
165 GrColor fColor; | 165 GrColor fColor; |
166 bool fHasLocalMatrix; | 166 bool fHasLocalMatrix; |
167 bool fHasLocalRect; | 167 bool fHasLocalRect; |
168 }; | 168 }; |
169 | 169 |
170 static const char* Name() { return "NonAAFillRectBatchPerspective"; } | 170 static const char* Name() { return "NonAAFillRectBatchPerspective"; } |
171 | 171 |
172 static SkString DumpInfo(const Geometry& geo, int index) { | 172 static SkString DumpInfo(const Geometry& geo, int index) { |
173 SkString str; | 173 SkString str; |
174 str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f
]\n", | 174 str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f
]\n", |
175 index, | 175 index, |
176 geo.fColor, | 176 geo.fColor, |
177 geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight, geo.fRect
.fBottom); | 177 geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight, geo.fRect
.fBottom); |
178 return str; | 178 return str; |
179 } | 179 } |
180 | 180 |
181 static bool CanCombine(const Geometry& mine, const Geometry& theirs, | 181 static bool CanCombine(const Geometry& mine, const Geometry& theirs, |
182 const GrPipelineOptimizations& opts) { | 182 const GrXPOverridesForBatch& overrides) { |
183 // We could batch across perspective vm changes if we really wanted to | 183 // We could batch across perspective vm changes if we really wanted to |
184 return mine.fViewMatrix.cheapEqualTo(theirs.fViewMatrix) && | 184 return mine.fViewMatrix.cheapEqualTo(theirs.fViewMatrix) && |
185 mine.fHasLocalRect == theirs.fHasLocalRect && | 185 mine.fHasLocalRect == theirs.fHasLocalRect && |
186 (!mine.fHasLocalMatrix || mine.fLocalMatrix.cheapEqualTo(theirs.f
LocalMatrix)); | 186 (!mine.fHasLocalMatrix || mine.fLocalMatrix.cheapEqualTo(theirs.f
LocalMatrix)); |
187 } | 187 } |
188 | 188 |
189 static const GrGeometryProcessor* CreateGP(const Geometry& geo, | 189 static const GrGeometryProcessor* CreateGP(const Geometry& geo, |
190 const GrPipelineOptimizations& op
ts) { | 190 const GrXPOverridesForBatch& over
rides) { |
191 const GrGeometryProcessor* gp = create_gp(geo.fViewMatrix, opts.readsCov
erage(), | 191 const GrGeometryProcessor* gp = create_gp(geo.fViewMatrix, overrides.rea
dsCoverage(), |
192 geo.fHasLocalRect, | 192 geo.fHasLocalRect, |
193 geo.fHasLocalMatrix ? &geo.fLo
calMatrix : | 193 geo.fHasLocalMatrix ? &geo.fLo
calMatrix : |
194 nullptr)
; | 194 nullptr)
; |
195 | 195 |
196 SkASSERT(geo.fHasLocalRect ? | 196 SkASSERT(geo.fHasLocalRect ? |
197 gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::PositionCo
lorLocalCoordAttr) : | 197 gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::PositionCo
lorLocalCoordAttr) : |
198 gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::PositionCo
lorAttr)); | 198 gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::PositionCo
lorAttr)); |
199 return gp; | 199 return gp; |
200 } | 200 } |
201 | 201 |
202 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry
& geo, | 202 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry
& geo, |
203 const GrPipelineOptimizations& opts) { | 203 const GrXPOverridesForBatch& overrides) { |
204 if (geo.fHasLocalRect) { | 204 if (geo.fHasLocalRect) { |
205 GrQuad quad(geo.fLocalRect); | 205 GrQuad quad(geo.fLocalRect); |
206 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.f
Rect, &quad); | 206 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.f
Rect, &quad); |
207 } else { | 207 } else { |
208 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.f
Rect, nullptr); | 208 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.f
Rect, nullptr); |
209 } | 209 } |
210 } | 210 } |
211 }; | 211 }; |
212 | 212 |
213 typedef GrTInstanceBatch<NonAAFillRectBatchImp> NonAAFillRectBatchSimple; | 213 typedef GrTInstanceBatch<NonAAFillRectBatchImp> NonAAFillRectBatchSimple; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 SkMatrix localMatrix = GrTest::TestMatrix(random); | 329 SkMatrix localMatrix = GrTest::TestMatrix(random); |
330 | 330 |
331 bool hasLocalRect = random->nextBool(); | 331 bool hasLocalRect = random->nextBool(); |
332 bool hasLocalMatrix = random->nextBool(); | 332 bool hasLocalMatrix = random->nextBool(); |
333 return GrNonAAFillRectBatch::Create(color, viewMatrix, rect, | 333 return GrNonAAFillRectBatch::Create(color, viewMatrix, rect, |
334 hasLocalRect ? &localRect : nullptr, | 334 hasLocalRect ? &localRect : nullptr, |
335 hasLocalMatrix ? &localMatrix : nullptr)
; | 335 hasLocalMatrix ? &localMatrix : nullptr)
; |
336 } | 336 } |
337 | 337 |
338 #endif | 338 #endif |
OLD | NEW |