| 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 "GrAAFillRectBatch.h" | 8 #include "GrAAFillRectBatch.h" |
| 9 | 9 |
| 10 #include "GrColor.h" | 10 #include "GrColor.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 | 183 |
| 184 // Common functions | 184 // Common functions |
| 185 class AAFillRectBatchBase { | 185 class AAFillRectBatchBase { |
| 186 public: | 186 public: |
| 187 static const int kVertsPerInstance = kVertsPerAAFillRect; | 187 static const int kVertsPerInstance = kVertsPerAAFillRect; |
| 188 static const int kIndicesPerInstance = kIndicesPerAAFillRect; | 188 static const int kIndicesPerInstance = kIndicesPerAAFillRect; |
| 189 | 189 |
| 190 inline static const GrIndexBuffer* GetIndexBuffer(GrResourceProvider* rp) { | 190 static void InitInvariantOutputCoverage(GrInitInvariantOutput* out) { |
| 191 out->setUnknownSingleComponent(); |
| 192 } |
| 193 |
| 194 static const GrIndexBuffer* GetIndexBuffer(GrResourceProvider* rp) { |
| 191 return get_index_buffer(rp); | 195 return get_index_buffer(rp); |
| 192 } | 196 } |
| 197 |
| 198 template <class Geometry> |
| 199 static void SetBounds(const Geometry& geo, SkRect* outBounds) { |
| 200 *outBounds = geo.fDevRect; |
| 201 } |
| 193 }; | 202 }; |
| 194 | 203 |
| 195 class AAFillRectBatchNoLocalMatrixImp : public AAFillRectBatchBase { | 204 class AAFillRectBatchNoLocalMatrixImp : public AAFillRectBatchBase { |
| 196 public: | 205 public: |
| 197 struct Geometry { | 206 struct Geometry { |
| 198 SkMatrix fViewMatrix; | 207 SkMatrix fViewMatrix; |
| 199 SkRect fRect; | 208 SkRect fRect; |
| 200 SkRect fDevRect; | 209 SkRect fDevRect; |
| 201 GrColor fColor; | 210 GrColor fColor; |
| 202 }; | 211 }; |
| 203 | 212 |
| 204 inline static const char* Name() { return "AAFillRectBatchNoLocalMatrix"; } | 213 static const char* Name() { return "AAFillRectBatchNoLocalMatrix"; } |
| 205 | 214 |
| 206 inline static bool CanCombine(const Geometry& mine, const Geometry& theirs, | 215 static bool CanCombine(const Geometry& mine, const Geometry& theirs, |
| 207 const GrPipelineOptimizations& opts) { | 216 const GrPipelineOptimizations& opts) { |
| 208 // We apply the viewmatrix to the rect points on the cpu. However, if t
he pipeline uses | 217 // We apply the viewmatrix to the rect points on the cpu. However, if t
he pipeline uses |
| 209 // local coords then we won't be able to batch. We could actually uploa
d the viewmatrix | 218 // local coords then we won't be able to batch. We could actually uploa
d the viewmatrix |
| 210 // using vertex attributes in these cases, but haven't investigated that | 219 // using vertex attributes in these cases, but haven't investigated that |
| 211 return !opts.readsLocalCoords() || mine.fViewMatrix.cheapEqualTo(theirs.
fViewMatrix); | 220 return !opts.readsLocalCoords() || mine.fViewMatrix.cheapEqualTo(theirs.
fViewMatrix); |
| 212 } | 221 } |
| 213 | 222 |
| 214 inline static const GrGeometryProcessor* CreateGP(const Geometry& geo, | 223 static const GrGeometryProcessor* CreateGP(const Geometry& geo, |
| 215 const GrPipelineOptimizati
ons& opts) { | 224 const GrPipelineOptimizations& op
ts) { |
| 216 const GrGeometryProcessor* gp = | 225 const GrGeometryProcessor* gp = |
| 217 create_fill_rect_gp(geo.fViewMatrix, opts, | 226 create_fill_rect_gp(geo.fViewMatrix, opts, |
| 218 GrDefaultGeoProcFactory::LocalCoords::kUsePo
sition_Type); | 227 GrDefaultGeoProcFactory::LocalCoords::kUsePo
sition_Type); |
| 219 | 228 |
| 220 SkASSERT(opts.canTweakAlphaForCoverage() ? | 229 SkASSERT(opts.canTweakAlphaForCoverage() ? |
| 221 gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::Positi
onColorAttr) : | 230 gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::Positi
onColorAttr) : |
| 222 gp->getVertexStride() == | 231 gp->getVertexStride() == |
| 223 sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAt
tr)); | 232 sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAt
tr)); |
| 224 return gp; | 233 return gp; |
| 225 } | 234 } |
| 226 | 235 |
| 227 inline static void Tesselate(intptr_t vertices, size_t vertexStride, const G
eometry& geo, | 236 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry
& geo, |
| 228 const GrPipelineOptimizations& opts) { | 237 const GrPipelineOptimizations& opts) { |
| 229 generate_aa_fill_rect_geometry(vertices, vertexStride, | 238 generate_aa_fill_rect_geometry(vertices, vertexStride, |
| 230 geo.fColor, geo.fViewMatrix, geo.fRect, g
eo.fDevRect, opts, | 239 geo.fColor, geo.fViewMatrix, geo.fRect, g
eo.fDevRect, opts, |
| 231 NULL); | 240 NULL); |
| 232 } | 241 } |
| 233 }; | 242 }; |
| 234 | 243 |
| 235 class AAFillRectBatchLocalMatrixImp : public AAFillRectBatchBase { | 244 class AAFillRectBatchLocalMatrixImp : public AAFillRectBatchBase { |
| 236 public: | 245 public: |
| 237 struct Geometry { | 246 struct Geometry { |
| 238 SkMatrix fViewMatrix; | 247 SkMatrix fViewMatrix; |
| 239 SkMatrix fLocalMatrix; | 248 SkMatrix fLocalMatrix; |
| 240 SkRect fRect; | 249 SkRect fRect; |
| 241 SkRect fDevRect; | 250 SkRect fDevRect; |
| 242 GrColor fColor; | 251 GrColor fColor; |
| 243 }; | 252 }; |
| 244 | 253 |
| 245 inline static const char* Name() { return "AAFillRectBatchLocalMatrix"; } | 254 static const char* Name() { return "AAFillRectBatchLocalMatrix"; } |
| 246 | 255 |
| 247 inline static bool CanCombine(const Geometry& mine, const Geometry& theirs, | 256 static bool CanCombine(const Geometry& mine, const Geometry& theirs, |
| 248 const GrPipelineOptimizations&) { | 257 const GrPipelineOptimizations&) { |
| 249 return true; | 258 return true; |
| 250 } | 259 } |
| 251 | 260 |
| 252 inline static const GrGeometryProcessor* CreateGP(const Geometry& geo, | 261 static const GrGeometryProcessor* CreateGP(const Geometry& geo, |
| 253 const GrPipelineOptimizati
ons& opts) { | 262 const GrPipelineOptimizations& op
ts) { |
| 254 const GrGeometryProcessor* gp = | 263 const GrGeometryProcessor* gp = |
| 255 create_fill_rect_gp(geo.fViewMatrix, opts, | 264 create_fill_rect_gp(geo.fViewMatrix, opts, |
| 256 GrDefaultGeoProcFactory::LocalCoords::kHasEx
plicit_Type); | 265 GrDefaultGeoProcFactory::LocalCoords::kHasEx
plicit_Type); |
| 257 | 266 |
| 258 SkASSERT(opts.canTweakAlphaForCoverage() ? | 267 SkASSERT(opts.canTweakAlphaForCoverage() ? |
| 259 gp->getVertexStride() == | 268 gp->getVertexStride() == |
| 260 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoord
Attr) : | 269 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoord
Attr) : |
| 261 gp->getVertexStride() == | 270 gp->getVertexStride() == |
| 262 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoord
Coverage)); | 271 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoord
Coverage)); |
| 263 return gp; | 272 return gp; |
| 264 } | 273 } |
| 265 | 274 |
| 266 inline static void Tesselate(intptr_t vertices, size_t vertexStride, const G
eometry& geo, | 275 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry
& geo, |
| 267 const GrPipelineOptimizations& opts) { | 276 const GrPipelineOptimizations& opts) { |
| 268 generate_aa_fill_rect_geometry(vertices, vertexStride, | 277 generate_aa_fill_rect_geometry(vertices, vertexStride, |
| 269 geo.fColor, geo.fViewMatrix, geo.fRect, g
eo.fDevRect, opts, | 278 geo.fColor, geo.fViewMatrix, geo.fRect, g
eo.fDevRect, opts, |
| 270 &geo.fLocalMatrix); | 279 &geo.fLocalMatrix); |
| 271 } | 280 } |
| 272 }; | 281 }; |
| 273 | 282 |
| 274 typedef GrTInstanceBatch<AAFillRectBatchNoLocalMatrixImp> AAFillRectBatchNoLocal
Matrix; | 283 typedef GrTInstanceBatch<AAFillRectBatchNoLocalMatrixImp> AAFillRectBatchNoLocal
Matrix; |
| 275 typedef GrTInstanceBatch<AAFillRectBatchLocalMatrixImp> AAFillRectBatchLocalMatr
ix; | 284 typedef GrTInstanceBatch<AAFillRectBatchLocalMatrixImp> AAFillRectBatchLocalMatr
ix; |
| 276 | 285 |
| 277 namespace GrAAFillRectBatch { | 286 namespace GrAAFillRectBatch { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 DRAW_BATCH_TEST_DEFINE(AAFillRectBatchLocalMatrix) { | 334 DRAW_BATCH_TEST_DEFINE(AAFillRectBatchLocalMatrix) { |
| 326 GrColor color = GrRandomColor(random); | 335 GrColor color = GrRandomColor(random); |
| 327 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); | 336 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
| 328 SkMatrix localMatrix = GrTest::TestMatrix(random); | 337 SkMatrix localMatrix = GrTest::TestMatrix(random); |
| 329 SkRect rect = GrTest::TestRect(random); | 338 SkRect rect = GrTest::TestRect(random); |
| 330 SkRect devRect = GrTest::TestRect(random); | 339 SkRect devRect = GrTest::TestRect(random); |
| 331 return GrAAFillRectBatch::Create(color, viewMatrix, localMatrix, rect, devRe
ct); | 340 return GrAAFillRectBatch::Create(color, viewMatrix, localMatrix, rect, devRe
ct); |
| 332 } | 341 } |
| 333 | 342 |
| 334 #endif | 343 #endif |
| OLD | NEW |