| 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 "GrBWFillRectBatch.h" | 8 #include "GrNonAAFillRectBatch.h" |
| 9 | 9 |
| 10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
| 11 #include "GrColor.h" | 11 #include "GrColor.h" |
| 12 #include "GrDefaultGeoProcFactory.h" | 12 #include "GrDefaultGeoProcFactory.h" |
| 13 #include "GrPrimitiveProcessor.h" | 13 #include "GrPrimitiveProcessor.h" |
| 14 #include "GrResourceProvider.h" | 14 #include "GrResourceProvider.h" |
| 15 #include "GrTInstanceBatch.h" | 15 #include "GrTInstanceBatch.h" |
| 16 #include "GrQuad.h" | 16 #include "GrQuad.h" |
| 17 #include "GrVertexBatch.h" | 17 #include "GrVertexBatch.h" |
| 18 | 18 |
| 19 // Common functions | 19 // Common functions |
| 20 class BWFillRectBatchBase { | 20 class NonAAFillRectBatchBase { |
| 21 public: | 21 public: |
| 22 static const int kVertsPerInstance = 4; | 22 static const int kVertsPerInstance = 4; |
| 23 static const int kIndicesPerInstance = 6; | 23 static const int kIndicesPerInstance = 6; |
| 24 | 24 |
| 25 static void InitInvariantOutputCoverage(GrInitInvariantOutput* out) { | 25 static void InitInvariantOutputCoverage(GrInitInvariantOutput* out) { |
| 26 out->setKnownSingleComponent(0xff); | 26 out->setKnownSingleComponent(0xff); |
| 27 } | 27 } |
| 28 | 28 |
| 29 static const GrIndexBuffer* GetIndexBuffer(GrResourceProvider* rp) { | 29 static const GrIndexBuffer* GetIndexBuffer(GrResourceProvider* rp) { |
| 30 return rp->refQuadIndexBuffer(); | 30 return rp->refQuadIndexBuffer(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 const SkMatrix& viewMatrix, | 77 const SkMatrix& viewMatrix, |
| 78 const SkRect& rect, | 78 const SkRect& rect, |
| 79 const GrQuad* localQuad) { | 79 const GrQuad* localQuad) { |
| 80 SkPoint* positions = reinterpret_cast<SkPoint*>(vertices); | 80 SkPoint* positions = reinterpret_cast<SkPoint*>(vertices); |
| 81 | 81 |
| 82 positions->setRectFan(rect.fLeft, rect.fTop, | 82 positions->setRectFan(rect.fLeft, rect.fTop, |
| 83 rect.fRight, rect.fBottom, vertexStride); | 83 rect.fRight, rect.fBottom, vertexStride); |
| 84 | 84 |
| 85 if (!viewMatrix.hasPerspective()) { | 85 if (!viewMatrix.hasPerspective()) { |
| 86 viewMatrix.mapPointsWithStride(positions, vertexStride, | 86 viewMatrix.mapPointsWithStride(positions, vertexStride, |
| 87 BWFillRectBatchBase::kVertsPerInstance); | 87 NonAAFillRectBatchBase::kVertsPerInstance
); |
| 88 } | 88 } |
| 89 | 89 |
| 90 // Setup local coords | 90 // Setup local coords |
| 91 // TODO we should only do this if local coords are being read | 91 // TODO we should only do this if local coords are being read |
| 92 if (localQuad) { | 92 if (localQuad) { |
| 93 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor); | 93 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor); |
| 94 for (int i = 0; i < BWFillRectBatchBase::kVertsPerInstance; i++) { | 94 for (int i = 0; i < NonAAFillRectBatchBase::kVertsPerInstance; i++) { |
| 95 SkPoint* coords = reinterpret_cast<SkPoint*>(vertices + kLocalOffset
+ | 95 SkPoint* coords = reinterpret_cast<SkPoint*>(vertices + kLocalOffset
+ |
| 96 i * vertexStride); | 96 i * vertexStride); |
| 97 *coords = localQuad->point(i); | 97 *coords = localQuad->point(i); |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 | 100 |
| 101 static const int kColorOffset = sizeof(SkPoint); | 101 static const int kColorOffset = sizeof(SkPoint); |
| 102 GrColor* vertColor = reinterpret_cast<GrColor*>(vertices + kColorOffset); | 102 GrColor* vertColor = reinterpret_cast<GrColor*>(vertices + kColorOffset); |
| 103 for (int j = 0; j < 4; ++j) { | 103 for (int j = 0; j < 4; ++j) { |
| 104 *vertColor = color; | 104 *vertColor = color; |
| 105 vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride); | 105 vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride); |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 | 108 |
| 109 class BWFillRectBatchNoLocalMatrixImp : public BWFillRectBatchBase { | 109 class NonAAFillRectBatchImp : public NonAAFillRectBatchBase { |
| 110 public: | 110 public: |
| 111 struct Geometry { | 111 struct Geometry { |
| 112 SkMatrix fViewMatrix; | 112 SkMatrix fViewMatrix; |
| 113 SkRect fRect; | 113 SkRect fRect; |
| 114 GrQuad fLocalQuad; | 114 GrQuad fLocalQuad; |
| 115 GrColor fColor; | 115 GrColor fColor; |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 static const char* Name() { return "BWFillRectBatchNoLocalMatrix"; } | 118 static const char* Name() { return "NonAAFillRectBatch"; } |
| 119 | 119 |
| 120 static bool CanCombine(const Geometry& mine, const Geometry& theirs, | 120 static bool CanCombine(const Geometry& mine, const Geometry& theirs, |
| 121 const GrPipelineOptimizations& opts) { | 121 const GrPipelineOptimizations& opts) { |
| 122 return true; | 122 return true; |
| 123 } | 123 } |
| 124 | 124 |
| 125 static const GrGeometryProcessor* CreateGP(const Geometry& geo, | 125 static const GrGeometryProcessor* CreateGP(const Geometry& geo, |
| 126 const GrPipelineOptimizations& op
ts) { | 126 const GrPipelineOptimizations& op
ts) { |
| 127 const GrGeometryProcessor* gp = create_gp(geo.fViewMatrix, opts.readsCov
erage(), true, | 127 const GrGeometryProcessor* gp = create_gp(geo.fViewMatrix, opts.readsCov
erage(), true, |
| 128 nullptr); | 128 nullptr); |
| 129 | 129 |
| 130 SkASSERT(gp->getVertexStride() == | 130 SkASSERT(gp->getVertexStride() == |
| 131 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr)); | 131 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr)); |
| 132 return gp; | 132 return gp; |
| 133 } | 133 } |
| 134 | 134 |
| 135 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry
& geo, | 135 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry
& geo, |
| 136 const GrPipelineOptimizations& opts) { | 136 const GrPipelineOptimizations& opts) { |
| 137 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.fRect
, &geo.fLocalQuad); | 137 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.fRect
, &geo.fLocalQuad); |
| 138 } | 138 } |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 // We handle perspective in the local matrix or viewmatrix with special batches | 141 // We handle perspective in the local matrix or viewmatrix with special batches |
| 142 class BWFillRectBatchPerspectiveImp : public BWFillRectBatchBase { | 142 class NonAAFillRectBatchPerspectiveImp : public NonAAFillRectBatchBase { |
| 143 public: | 143 public: |
| 144 struct Geometry { | 144 struct Geometry { |
| 145 SkMatrix fViewMatrix; | 145 SkMatrix fViewMatrix; |
| 146 SkMatrix fLocalMatrix; | 146 SkMatrix fLocalMatrix; |
| 147 SkRect fRect; | 147 SkRect fRect; |
| 148 SkRect fLocalRect; | 148 SkRect fLocalRect; |
| 149 GrColor fColor; | 149 GrColor fColor; |
| 150 bool fHasLocalMatrix; | 150 bool fHasLocalMatrix; |
| 151 bool fHasLocalRect; | 151 bool fHasLocalRect; |
| 152 }; | 152 }; |
| 153 | 153 |
| 154 static const char* Name() { return "BWFillRectBatchPerspective"; } | 154 static const char* Name() { return "NonAAFillRectBatchPerspective"; } |
| 155 | 155 |
| 156 static bool CanCombine(const Geometry& mine, const Geometry& theirs, | 156 static bool CanCombine(const Geometry& mine, const Geometry& theirs, |
| 157 const GrPipelineOptimizations& opts) { | 157 const GrPipelineOptimizations& opts) { |
| 158 // We could batch across perspective vm changes if we really wanted to | 158 // We could batch across perspective vm changes if we really wanted to |
| 159 return mine.fViewMatrix.cheapEqualTo(theirs.fViewMatrix) && | 159 return mine.fViewMatrix.cheapEqualTo(theirs.fViewMatrix) && |
| 160 (!mine.fHasLocalMatrix || mine.fLocalMatrix.cheapEqualTo(theirs.f
LocalMatrix)); | 160 (!mine.fHasLocalMatrix || mine.fLocalMatrix.cheapEqualTo(theirs.f
LocalMatrix)); |
| 161 } | 161 } |
| 162 | 162 |
| 163 static const GrGeometryProcessor* CreateGP(const Geometry& geo, | 163 static const GrGeometryProcessor* CreateGP(const Geometry& geo, |
| 164 const GrPipelineOptimizations& op
ts) { | 164 const GrPipelineOptimizations& op
ts) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 177 const GrPipelineOptimizations& opts) { | 177 const GrPipelineOptimizations& opts) { |
| 178 if (geo.fHasLocalRect) { | 178 if (geo.fHasLocalRect) { |
| 179 GrQuad quad(geo.fLocalRect); | 179 GrQuad quad(geo.fLocalRect); |
| 180 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.f
Rect, &quad); | 180 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.f
Rect, &quad); |
| 181 } else { | 181 } else { |
| 182 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.f
Rect, nullptr); | 182 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.f
Rect, nullptr); |
| 183 } | 183 } |
| 184 } | 184 } |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 typedef GrTInstanceBatch<BWFillRectBatchNoLocalMatrixImp> BWFillRectBatchSimple; | 187 typedef GrTInstanceBatch<NonAAFillRectBatchImp> NonAAFillRectBatchSimple; |
| 188 typedef GrTInstanceBatch<BWFillRectBatchPerspectiveImp> BWFillRectBatchPerspecti
ve; | 188 typedef GrTInstanceBatch<NonAAFillRectBatchPerspectiveImp> NonAAFillRectBatchPer
spective; |
| 189 | 189 |
| 190 namespace GrBWFillRectBatch { | 190 namespace GrNonAAFillRectBatch { |
| 191 GrDrawBatch* Create(GrColor color, | 191 GrDrawBatch* Create(GrColor color, |
| 192 const SkMatrix& viewMatrix, | 192 const SkMatrix& viewMatrix, |
| 193 const SkRect& rect, | 193 const SkRect& rect, |
| 194 const SkRect* localRect, | 194 const SkRect* localRect, |
| 195 const SkMatrix* localMatrix) { | 195 const SkMatrix* localMatrix) { |
| 196 | 196 |
| 197 /* Perspective has to be handled in a slow path for now */ | 197 /* Perspective has to be handled in a slow path for now */ |
| 198 if (viewMatrix.hasPerspective() || (localMatrix && localMatrix->hasPerspecti
ve())) { | 198 if (viewMatrix.hasPerspective() || (localMatrix && localMatrix->hasPerspecti
ve())) { |
| 199 BWFillRectBatchPerspective* batch = BWFillRectBatchPerspective::Create()
; | 199 NonAAFillRectBatchPerspective* batch = NonAAFillRectBatchPerspective::Cr
eate(); |
| 200 BWFillRectBatchPerspective::Geometry& geo = *batch->geometry(); | 200 NonAAFillRectBatchPerspective::Geometry& geo = *batch->geometry(); |
| 201 | 201 |
| 202 geo.fColor = color; | 202 geo.fColor = color; |
| 203 geo.fViewMatrix = viewMatrix; | 203 geo.fViewMatrix = viewMatrix; |
| 204 geo.fRect = rect; | 204 geo.fRect = rect; |
| 205 geo.fHasLocalRect = SkToBool(localRect); | 205 geo.fHasLocalRect = SkToBool(localRect); |
| 206 geo.fHasLocalMatrix = SkToBool(localMatrix); | 206 geo.fHasLocalMatrix = SkToBool(localMatrix); |
| 207 if (localMatrix) { | 207 if (localMatrix) { |
| 208 geo.fLocalMatrix = *localMatrix; | 208 geo.fLocalMatrix = *localMatrix; |
| 209 } | 209 } |
| 210 if (localRect) { | 210 if (localRect) { |
| 211 geo.fLocalRect = *localRect; | 211 geo.fLocalRect = *localRect; |
| 212 } | 212 } |
| 213 | 213 |
| 214 batch->init(); | 214 batch->init(); |
| 215 return batch; | 215 return batch; |
| 216 } else { | 216 } else { |
| 217 // TODO bubble these up as separate calls | 217 // TODO bubble these up as separate calls |
| 218 BWFillRectBatchSimple* batch = BWFillRectBatchSimple::Create(); | 218 NonAAFillRectBatchSimple* batch = NonAAFillRectBatchSimple::Create(); |
| 219 BWFillRectBatchSimple::Geometry& geo = *batch->geometry(); | 219 NonAAFillRectBatchSimple::Geometry& geo = *batch->geometry(); |
| 220 | 220 |
| 221 geo.fColor = color; | 221 geo.fColor = color; |
| 222 geo.fViewMatrix = viewMatrix; | 222 geo.fViewMatrix = viewMatrix; |
| 223 geo.fRect = rect; | 223 geo.fRect = rect; |
| 224 | 224 |
| 225 if (localRect && localMatrix) { | 225 if (localRect && localMatrix) { |
| 226 geo.fLocalQuad.setFromMappedRect(*localRect, *localMatrix); | 226 geo.fLocalQuad.setFromMappedRect(*localRect, *localMatrix); |
| 227 } else if (localRect) { | 227 } else if (localRect) { |
| 228 geo.fLocalQuad.set(*localRect); | 228 geo.fLocalQuad.set(*localRect); |
| 229 } else if (localMatrix) { | 229 } else if (localMatrix) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 246 | 246 |
| 247 DRAW_BATCH_TEST_DEFINE(RectBatch) { | 247 DRAW_BATCH_TEST_DEFINE(RectBatch) { |
| 248 GrColor color = GrRandomColor(random); | 248 GrColor color = GrRandomColor(random); |
| 249 SkRect rect = GrTest::TestRect(random); | 249 SkRect rect = GrTest::TestRect(random); |
| 250 SkRect localRect = GrTest::TestRect(random); | 250 SkRect localRect = GrTest::TestRect(random); |
| 251 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); | 251 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
| 252 SkMatrix localMatrix = GrTest::TestMatrix(random); | 252 SkMatrix localMatrix = GrTest::TestMatrix(random); |
| 253 | 253 |
| 254 bool hasLocalRect = random->nextBool(); | 254 bool hasLocalRect = random->nextBool(); |
| 255 bool hasLocalMatrix = random->nextBool(); | 255 bool hasLocalMatrix = random->nextBool(); |
| 256 return GrBWFillRectBatch::Create(color, viewMatrix, rect, hasLocalRect ? &lo
calRect : nullptr, | 256 return GrNonAAFillRectBatch::Create(color, viewMatrix, rect, |
| 257 hasLocalMatrix ? &localMatrix : nullptr); | 257 hasLocalRect ? &localRect : nullptr, |
| 258 hasLocalMatrix ? &localMatrix : nullptr)
; |
| 258 } | 259 } |
| 259 | 260 |
| 260 #endif | 261 #endif |
| OLD | NEW |