| 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 28 matching lines...) Expand all Loading... |
| 39 4, 5, 6, 6, 7, 4, | 39 4, 5, 6, 6, 7, 4, |
| 40 }; | 40 }; |
| 41 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gFillAARectIdx) == kIndicesPerAAFillRect); | 41 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gFillAARectIdx) == kIndicesPerAAFillRect); |
| 42 return resourceProvider->findOrCreateInstancedIndexBuffer(gFillAARectIdx, | 42 return resourceProvider->findOrCreateInstancedIndexBuffer(gFillAARectIdx, |
| 43 kIndicesPerAAFillRect, kNumAAFillRectsInIndexBuffer, kVertsPerAAFillRect
, | 43 kIndicesPerAAFillRect, kNumAAFillRectsInIndexBuffer, kVertsPerAAFillRect
, |
| 44 gAAFillRectIndexBufferKey); | 44 gAAFillRectIndexBufferKey); |
| 45 } | 45 } |
| 46 | 46 |
| 47 static const GrGeometryProcessor* create_fill_rect_gp( | 47 static const GrGeometryProcessor* create_fill_rect_gp( |
| 48 const SkMatrix& viewMatrix, | 48 const SkMatrix& viewMatrix, |
| 49 const GrPipelineOptimizations& opts, | 49 const GrXPOverridesForBatch& overrides, |
| 50 GrDefaultGeoProcFactory::LocalCoords::Typ
e localCoordsType) { | 50 GrDefaultGeoProcFactory::LocalCoords::Typ
e localCoordsType) { |
| 51 using namespace GrDefaultGeoProcFactory; | 51 using namespace GrDefaultGeoProcFactory; |
| 52 | 52 |
| 53 Color color(Color::kAttribute_Type); | 53 Color color(Color::kAttribute_Type); |
| 54 Coverage::Type coverageType; | 54 Coverage::Type coverageType; |
| 55 // TODO remove coverage if coverage is ignored | 55 // TODO remove coverage if coverage is ignored |
| 56 /*if (coverageIgnored) { | 56 /*if (coverageIgnored) { |
| 57 coverageType = Coverage::kNone_Type; | 57 coverageType = Coverage::kNone_Type; |
| 58 } else*/ if (opts.canTweakAlphaForCoverage()) { | 58 } else*/ if (overrides.canTweakAlphaForCoverage()) { |
| 59 coverageType = Coverage::kSolid_Type; | 59 coverageType = Coverage::kSolid_Type; |
| 60 } else { | 60 } else { |
| 61 coverageType = Coverage::kAttribute_Type; | 61 coverageType = Coverage::kAttribute_Type; |
| 62 } | 62 } |
| 63 Coverage coverage(coverageType); | 63 Coverage coverage(coverageType); |
| 64 | 64 |
| 65 // We assume the caller has inverted the viewmatrix | 65 // We assume the caller has inverted the viewmatrix |
| 66 if (LocalCoords::kHasExplicit_Type == localCoordsType) { | 66 if (LocalCoords::kHasExplicit_Type == localCoordsType) { |
| 67 LocalCoords localCoords(localCoordsType); | 67 LocalCoords localCoords(localCoordsType); |
| 68 return GrDefaultGeoProcFactory::Create(color, coverage, localCoords, SkM
atrix::I()); | 68 return GrDefaultGeoProcFactory::Create(color, coverage, localCoords, SkM
atrix::I()); |
| 69 } else { | 69 } else { |
| 70 LocalCoords localCoords(opts.readsLocalCoords() ? localCoordsType : | 70 LocalCoords localCoords(overrides.readsLocalCoords() ? localCoordsType : |
| 71 LocalCoords::kUnused_T
ype); | 71 LocalCoords::kUnu
sed_Type); |
| 72 return CreateForDeviceSpace(color, coverage, localCoords, viewMatrix); | 72 return CreateForDeviceSpace(color, coverage, localCoords, viewMatrix); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 static void generate_aa_fill_rect_geometry(intptr_t verts, | 76 static void generate_aa_fill_rect_geometry(intptr_t verts, |
| 77 size_t vertexStride, | 77 size_t vertexStride, |
| 78 GrColor color, | 78 GrColor color, |
| 79 const SkMatrix& viewMatrix, | 79 const SkMatrix& viewMatrix, |
| 80 const SkRect& rect, | 80 const SkRect& rect, |
| 81 const SkRect& devRect, | 81 const SkRect& devRect, |
| 82 const GrPipelineOptimizations& opts, | 82 const GrXPOverridesForBatch& override
s, |
| 83 const SkMatrix* localMatrix) { | 83 const SkMatrix* localMatrix) { |
| 84 SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts); | 84 SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts); |
| 85 SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + 4 * vertexStride); | 85 SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + 4 * vertexStride); |
| 86 | 86 |
| 87 SkScalar inset = SkMinScalar(devRect.width(), SK_Scalar1); | 87 SkScalar inset = SkMinScalar(devRect.width(), SK_Scalar1); |
| 88 inset = SK_ScalarHalf * SkMinScalar(inset, devRect.height()); | 88 inset = SK_ScalarHalf * SkMinScalar(inset, devRect.height()); |
| 89 | 89 |
| 90 if (viewMatrix.rectStaysRect()) { | 90 if (viewMatrix.rectStaysRect()) { |
| 91 set_inset_fan(fan0Pos, vertexStride, devRect, -SK_ScalarHalf, -SK_Scalar
Half); | 91 set_inset_fan(fan0Pos, vertexStride, devRect, -SK_ScalarHalf, -SK_Scalar
Half); |
| 92 set_inset_fan(fan1Pos, vertexStride, devRect, inset, inset); | 92 set_inset_fan(fan1Pos, vertexStride, devRect, inset, inset); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 if (!viewMatrix.invert(&invViewMatrix)) { | 133 if (!viewMatrix.invert(&invViewMatrix)) { |
| 134 SkASSERT(false); | 134 SkASSERT(false); |
| 135 invViewMatrix = SkMatrix::I(); | 135 invViewMatrix = SkMatrix::I(); |
| 136 } | 136 } |
| 137 SkMatrix localCoordMatrix; | 137 SkMatrix localCoordMatrix; |
| 138 localCoordMatrix.setConcat(*localMatrix, invViewMatrix); | 138 localCoordMatrix.setConcat(*localMatrix, invViewMatrix); |
| 139 SkPoint* fan0Loc = reinterpret_cast<SkPoint*>(verts + sizeof(SkPoint) +
sizeof(GrColor)); | 139 SkPoint* fan0Loc = reinterpret_cast<SkPoint*>(verts + sizeof(SkPoint) +
sizeof(GrColor)); |
| 140 localCoordMatrix.mapPointsWithStride(fan0Loc, fan0Pos, vertexStride, 8); | 140 localCoordMatrix.mapPointsWithStride(fan0Loc, fan0Pos, vertexStride, 8); |
| 141 } | 141 } |
| 142 | 142 |
| 143 bool tweakAlphaForCoverage = opts.canTweakAlphaForCoverage(); | 143 bool tweakAlphaForCoverage = overrides.canTweakAlphaForCoverage(); |
| 144 | 144 |
| 145 // Make verts point to vertex color and then set all the color and coverage
vertex attrs | 145 // Make verts point to vertex color and then set all the color and coverage
vertex attrs |
| 146 // values. | 146 // values. |
| 147 verts += sizeof(SkPoint); | 147 verts += sizeof(SkPoint); |
| 148 | 148 |
| 149 // The coverage offset is always the last vertex attribute | 149 // The coverage offset is always the last vertex attribute |
| 150 intptr_t coverageOffset = vertexStride - sizeof(GrColor) - sizeof(SkPoint); | 150 intptr_t coverageOffset = vertexStride - sizeof(GrColor) - sizeof(SkPoint); |
| 151 for (int i = 0; i < 4; ++i) { | 151 for (int i = 0; i < 4; ++i) { |
| 152 if (tweakAlphaForCoverage) { | 152 if (tweakAlphaForCoverage) { |
| 153 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = 0; | 153 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = 0; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 static SkString DumpInfo(const Geometry& geo, int index) { | 220 static SkString DumpInfo(const Geometry& geo, int index) { |
| 221 SkString str; | 221 SkString str; |
| 222 str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f
]\n", | 222 str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f
]\n", |
| 223 index, | 223 index, |
| 224 geo.fColor, | 224 geo.fColor, |
| 225 geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight, geo.fRect
.fBottom); | 225 geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight, geo.fRect
.fBottom); |
| 226 return str; | 226 return str; |
| 227 } | 227 } |
| 228 | 228 |
| 229 static bool CanCombine(const Geometry& mine, const Geometry& theirs, | 229 static bool CanCombine(const Geometry& mine, const Geometry& theirs, |
| 230 const GrPipelineOptimizations& opts) { | 230 const GrXPOverridesForBatch& overrides) { |
| 231 // We apply the viewmatrix to the rect points on the cpu. However, if t
he pipeline uses | 231 // We apply the viewmatrix to the rect points on the cpu. However, if t
he pipeline uses |
| 232 // local coords then we won't be able to batch. We could actually uploa
d the viewmatrix | 232 // local coords then we won't be able to batch. We could actually uploa
d the viewmatrix |
| 233 // using vertex attributes in these cases, but haven't investigated that | 233 // using vertex attributes in these cases, but haven't investigated that |
| 234 return !opts.readsLocalCoords() || mine.fViewMatrix.cheapEqualTo(theirs.
fViewMatrix); | 234 return !overrides.readsLocalCoords() || mine.fViewMatrix.cheapEqualTo(th
eirs.fViewMatrix); |
| 235 } | 235 } |
| 236 | 236 |
| 237 static const GrGeometryProcessor* CreateGP(const Geometry& geo, | 237 static const GrGeometryProcessor* CreateGP(const Geometry& geo, |
| 238 const GrPipelineOptimizations& op
ts) { | 238 const GrXPOverridesForBatch& over
rides) { |
| 239 const GrGeometryProcessor* gp = | 239 const GrGeometryProcessor* gp = |
| 240 create_fill_rect_gp(geo.fViewMatrix, opts, | 240 create_fill_rect_gp(geo.fViewMatrix, overrides, |
| 241 GrDefaultGeoProcFactory::LocalCoords::kUsePo
sition_Type); | 241 GrDefaultGeoProcFactory::LocalCoords::kUsePo
sition_Type); |
| 242 | 242 |
| 243 SkASSERT(opts.canTweakAlphaForCoverage() ? | 243 SkASSERT(overrides.canTweakAlphaForCoverage() ? |
| 244 gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::Positi
onColorAttr) : | 244 gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::Positi
onColorAttr) : |
| 245 gp->getVertexStride() == | 245 gp->getVertexStride() == |
| 246 sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAt
tr)); | 246 sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAt
tr)); |
| 247 return gp; | 247 return gp; |
| 248 } | 248 } |
| 249 | 249 |
| 250 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry
& geo, | 250 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry
& geo, |
| 251 const GrPipelineOptimizations& opts) { | 251 const GrXPOverridesForBatch& overrides) { |
| 252 generate_aa_fill_rect_geometry(vertices, vertexStride, | 252 generate_aa_fill_rect_geometry(vertices, vertexStride, |
| 253 geo.fColor, geo.fViewMatrix, geo.fRect, g
eo.fDevRect, opts, | 253 geo.fColor, geo.fViewMatrix, geo.fRect, g
eo.fDevRect, |
| 254 nullptr); | 254 overrides, nullptr); |
| 255 } | 255 } |
| 256 }; | 256 }; |
| 257 | 257 |
| 258 class AAFillRectBatchLocalMatrixImp : public AAFillRectBatchBase { | 258 class AAFillRectBatchLocalMatrixImp : public AAFillRectBatchBase { |
| 259 public: | 259 public: |
| 260 struct Geometry { | 260 struct Geometry { |
| 261 SkMatrix fViewMatrix; | 261 SkMatrix fViewMatrix; |
| 262 SkMatrix fLocalMatrix; | 262 SkMatrix fLocalMatrix; |
| 263 SkRect fRect; | 263 SkRect fRect; |
| 264 SkRect fDevRect; | 264 SkRect fDevRect; |
| 265 GrColor fColor; | 265 GrColor fColor; |
| 266 }; | 266 }; |
| 267 | 267 |
| 268 static const char* Name() { return "AAFillRectBatchLocalMatrix"; } | 268 static const char* Name() { return "AAFillRectBatchLocalMatrix"; } |
| 269 | 269 |
| 270 static SkString DumpInfo(const Geometry& geo, int index) { | 270 static SkString DumpInfo(const Geometry& geo, int index) { |
| 271 SkString str; | 271 SkString str; |
| 272 str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f
]\n", | 272 str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f
]\n", |
| 273 index, | 273 index, |
| 274 geo.fColor, | 274 geo.fColor, |
| 275 geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight, geo.fRect
.fBottom); | 275 geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight, geo.fRect
.fBottom); |
| 276 return str; | 276 return str; |
| 277 } | 277 } |
| 278 | 278 |
| 279 static bool CanCombine(const Geometry& mine, const Geometry& theirs, | 279 static bool CanCombine(const Geometry& mine, const Geometry& theirs, |
| 280 const GrPipelineOptimizations&) { | 280 const GrXPOverridesForBatch& overrides) { |
| 281 return true; | 281 return true; |
| 282 } | 282 } |
| 283 | 283 |
| 284 static const GrGeometryProcessor* CreateGP(const Geometry& geo, | 284 static const GrGeometryProcessor* CreateGP(const Geometry& geo, |
| 285 const GrPipelineOptimizations& op
ts) { | 285 const GrXPOverridesForBatch& over
rides) { |
| 286 const GrGeometryProcessor* gp = | 286 const GrGeometryProcessor* gp = |
| 287 create_fill_rect_gp(geo.fViewMatrix, opts, | 287 create_fill_rect_gp(geo.fViewMatrix, overrides, |
| 288 GrDefaultGeoProcFactory::LocalCoords::kHasEx
plicit_Type); | 288 GrDefaultGeoProcFactory::LocalCoords::kHasEx
plicit_Type); |
| 289 | 289 |
| 290 SkASSERT(opts.canTweakAlphaForCoverage() ? | 290 SkASSERT(overrides.canTweakAlphaForCoverage() ? |
| 291 gp->getVertexStride() == | 291 gp->getVertexStride() == |
| 292 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoord
Attr) : | 292 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoord
Attr) : |
| 293 gp->getVertexStride() == | 293 gp->getVertexStride() == |
| 294 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoord
Coverage)); | 294 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoord
Coverage)); |
| 295 return gp; | 295 return gp; |
| 296 } | 296 } |
| 297 | 297 |
| 298 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry
& geo, | 298 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry
& geo, |
| 299 const GrPipelineOptimizations& opts) { | 299 const GrXPOverridesForBatch& overrides) { |
| 300 generate_aa_fill_rect_geometry(vertices, vertexStride, | 300 generate_aa_fill_rect_geometry(vertices, vertexStride, |
| 301 geo.fColor, geo.fViewMatrix, geo.fRect, g
eo.fDevRect, opts, | 301 geo.fColor, geo.fViewMatrix, geo.fRect, g
eo.fDevRect, |
| 302 &geo.fLocalMatrix); | 302 overrides, &geo.fLocalMatrix); |
| 303 } | 303 } |
| 304 }; | 304 }; |
| 305 | 305 |
| 306 typedef GrTInstanceBatch<AAFillRectBatchNoLocalMatrixImp> AAFillRectBatchNoLocal
Matrix; | 306 typedef GrTInstanceBatch<AAFillRectBatchNoLocalMatrixImp> AAFillRectBatchNoLocal
Matrix; |
| 307 typedef GrTInstanceBatch<AAFillRectBatchLocalMatrixImp> AAFillRectBatchLocalMatr
ix; | 307 typedef GrTInstanceBatch<AAFillRectBatchLocalMatrixImp> AAFillRectBatchLocalMatr
ix; |
| 308 | 308 |
| 309 inline static void append_to_batch(AAFillRectBatchNoLocalMatrix* batch, GrColor
color, | 309 inline static void append_to_batch(AAFillRectBatchNoLocalMatrix* batch, GrColor
color, |
| 310 const SkMatrix& viewMatrix, const SkRect& rec
t, | 310 const SkMatrix& viewMatrix, const SkRect& rec
t, |
| 311 const SkRect& devRect) { | 311 const SkRect& devRect) { |
| 312 AAFillRectBatchNoLocalMatrix::Geometry& geo = batch->geoData()->push_back(); | 312 AAFillRectBatchNoLocalMatrix::Geometry& geo = batch->geoData()->push_back(); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 DRAW_BATCH_TEST_DEFINE(AAFillRectBatchLocalMatrix) { | 412 DRAW_BATCH_TEST_DEFINE(AAFillRectBatchLocalMatrix) { |
| 413 GrColor color = GrRandomColor(random); | 413 GrColor color = GrRandomColor(random); |
| 414 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); | 414 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
| 415 SkMatrix localMatrix = GrTest::TestMatrix(random); | 415 SkMatrix localMatrix = GrTest::TestMatrix(random); |
| 416 SkRect rect = GrTest::TestRect(random); | 416 SkRect rect = GrTest::TestRect(random); |
| 417 SkRect devRect = GrTest::TestRect(random); | 417 SkRect devRect = GrTest::TestRect(random); |
| 418 return GrAAFillRectBatch::Create(color, viewMatrix, localMatrix, rect, devRe
ct); | 418 return GrAAFillRectBatch::Create(color, viewMatrix, localMatrix, rect, devRe
ct); |
| 419 } | 419 } |
| 420 | 420 |
| 421 #endif | 421 #endif |
| OLD | NEW |