| 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 "GrBWFillRectBatch.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" |
| 15 #include "GrTInstanceBatch.h" |
| 14 #include "GrQuad.h" | 16 #include "GrQuad.h" |
| 15 #include "GrVertexBatch.h" | 17 #include "GrVertexBatch.h" |
| 16 | 18 |
| 17 class GrBatchFlushState; | 19 // Common functions |
| 18 class SkMatrix; | 20 class BWFillRectBatchBase { |
| 19 struct SkRect; | 21 public: |
| 20 | 22 static const int kVertsPerInstance = 4; |
| 21 class BWFillRectBatch : public GrVertexBatch { | 23 static const int kIndicesPerInstance = 6; |
| 24 |
| 25 static void InitInvariantOutputCoverage(GrInitInvariantOutput* out) { |
| 26 out->setKnownSingleComponent(0xff); |
| 27 } |
| 28 |
| 29 static const GrIndexBuffer* GetIndexBuffer(GrResourceProvider* rp) { |
| 30 return rp->refQuadIndexBuffer(); |
| 31 } |
| 32 |
| 33 template <typename Geometry> |
| 34 static void SetBounds(const Geometry& geo, SkRect* outBounds) { |
| 35 geo.fViewMatrix.mapRect(outBounds, geo.fRect); |
| 36 } |
| 37 }; |
| 38 |
| 39 /** We always use per-vertex colors so that rects can be batched across color ch
anges. Sometimes |
| 40 we have explicit local coords and sometimes not. We *could* always provide
explicit local |
| 41 coords and just duplicate the positions when the caller hasn't provided a lo
cal coord rect, |
| 42 but we haven't seen a use case which frequently switches between local rect
and no local |
| 43 rect draws. |
| 44 |
| 45 The vertex attrib order is always pos, color, [local coords]. |
| 46 */ |
| 47 static const GrGeometryProcessor* create_gp(const SkMatrix& viewMatrix, |
| 48 bool readsCoverage, |
| 49 bool hasExplicitLocalCoords, |
| 50 const SkMatrix* localMatrix) { |
| 51 using namespace GrDefaultGeoProcFactory; |
| 52 Color color(Color::kAttribute_Type); |
| 53 Coverage coverage(readsCoverage ? Coverage::kSolid_Type : Coverage::kNone_Ty
pe); |
| 54 |
| 55 // if we have a local rect, then we apply the localMatrix directly to the lo
calRect to |
| 56 // generate vertex local coords |
| 57 if (hasExplicitLocalCoords) { |
| 58 LocalCoords localCoords(LocalCoords::kHasExplicit_Type); |
| 59 return GrDefaultGeoProcFactory::Create(color, coverage, localCoords, SkM
atrix::I()); |
| 60 } else { |
| 61 LocalCoords localCoords(LocalCoords::kUsePosition_Type, localMatrix); |
| 62 return GrDefaultGeoProcFactory::CreateForDeviceSpace(color, coverage, lo
calCoords, |
| 63 viewMatrix); |
| 64 } |
| 65 } |
| 66 |
| 67 static void tesselate(intptr_t vertices, |
| 68 size_t vertexStride, |
| 69 GrColor color, |
| 70 const SkMatrix& viewMatrix, |
| 71 const SkRect& rect, |
| 72 const SkRect* localRect, |
| 73 const SkMatrix* localMatrix) { |
| 74 SkPoint* positions = reinterpret_cast<SkPoint*>(vertices); |
| 75 |
| 76 positions->setRectFan(rect.fLeft, rect.fTop, |
| 77 rect.fRight, rect.fBottom, vertexStride); |
| 78 viewMatrix.mapPointsWithStride(positions, vertexStride, BWFillRectBatchBase:
:kVertsPerInstance); |
| 79 |
| 80 // TODO we should only do this if local coords are being read |
| 81 if (localRect) { |
| 82 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor); |
| 83 SkPoint* coords = reinterpret_cast<SkPoint*>(vertices + kLocalOffset); |
| 84 coords->setRectFan(localRect->fLeft, localRect->fTop, |
| 85 localRect->fRight, localRect->fBottom, |
| 86 vertexStride); |
| 87 if (localMatrix) { |
| 88 localMatrix->mapPointsWithStride(coords, vertexStride, |
| 89 BWFillRectBatchBase::kVertsPerInsta
nce); |
| 90 } |
| 91 } |
| 92 |
| 93 static const int kColorOffset = sizeof(SkPoint); |
| 94 GrColor* vertColor = reinterpret_cast<GrColor*>(vertices + kColorOffset); |
| 95 for (int j = 0; j < 4; ++j) { |
| 96 *vertColor = color; |
| 97 vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride); |
| 98 } |
| 99 } |
| 100 |
| 101 class BWFillRectBatchNoLocalMatrixImp : public BWFillRectBatchBase { |
| 102 public: |
| 103 struct Geometry { |
| 104 SkMatrix fViewMatrix; |
| 105 SkRect fRect; |
| 106 GrColor fColor; |
| 107 }; |
| 108 |
| 109 static const char* Name() { return "BWFillRectBatchNoLocalMatrix"; } |
| 110 |
| 111 static bool CanCombine(const Geometry& mine, const Geometry& theirs, |
| 112 const GrPipelineOptimizations& opts) { |
| 113 // We apply the viewmatrix to the rect points on the cpu. However, if t
he pipeline uses |
| 114 // local coords then we won't be able to batch. We could actually uploa
d the viewmatrix |
| 115 // using vertex attributes in these cases, but haven't investigated that |
| 116 return !opts.readsLocalCoords() || mine.fViewMatrix.cheapEqualTo(theirs.
fViewMatrix); |
| 117 } |
| 118 |
| 119 static const GrGeometryProcessor* CreateGP(const Geometry& geo, |
| 120 const GrPipelineOptimizations& op
ts) { |
| 121 const GrGeometryProcessor* gp = create_gp(geo.fViewMatrix, opts.readsCov
erage(), false, |
| 122 NULL); |
| 123 |
| 124 SkASSERT(gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::Positi
onColorAttr)); |
| 125 return gp; |
| 126 } |
| 127 |
| 128 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry
& geo, |
| 129 const GrPipelineOptimizations& opts) { |
| 130 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.fRect
, NULL, NULL); |
| 131 } |
| 132 }; |
| 133 |
| 134 class BWFillRectBatchLocalMatrixImp : public BWFillRectBatchBase { |
| 135 public: |
| 136 struct Geometry { |
| 137 SkMatrix fViewMatrix; |
| 138 SkMatrix fLocalMatrix; |
| 139 SkRect fRect; |
| 140 GrColor fColor; |
| 141 }; |
| 142 |
| 143 static const char* Name() { return "BWFillRectBatchLocalMatrix"; } |
| 144 |
| 145 static bool CanCombine(const Geometry& mine, const Geometry& theirs, |
| 146 const GrPipelineOptimizations& opts) { |
| 147 // if we read local coords then we have to have the same viewmatrix and
localmatrix |
| 148 return !opts.readsLocalCoords() || |
| 149 (mine.fViewMatrix.cheapEqualTo(theirs.fViewMatrix) && |
| 150 mine.fLocalMatrix.cheapEqualTo(theirs.fLocalMatrix)); |
| 151 } |
| 152 |
| 153 static const GrGeometryProcessor* CreateGP(const Geometry& geo, |
| 154 const GrPipelineOptimizations& op
ts) { |
| 155 const GrGeometryProcessor* gp = create_gp(geo.fViewMatrix, opts.readsCov
erage(), false, |
| 156 &geo.fLocalMatrix); |
| 157 |
| 158 SkASSERT(gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::Positi
onColorAttr)); |
| 159 return gp; |
| 160 } |
| 161 |
| 162 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry
& geo, |
| 163 const GrPipelineOptimizations& opts) { |
| 164 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.fRect
, NULL, |
| 165 &geo.fLocalMatrix); |
| 166 } |
| 167 }; |
| 168 |
| 169 class BWFillRectBatchLocalRectImp : public BWFillRectBatchBase { |
| 22 public: | 170 public: |
| 23 struct Geometry { | 171 struct Geometry { |
| 24 SkMatrix fViewMatrix; | 172 SkMatrix fViewMatrix; |
| 25 SkRect fRect; | 173 SkRect fRect; |
| 26 SkRect fLocalRect; | 174 SkRect fLocalRect; |
| 175 GrColor fColor; |
| 176 }; |
| 177 |
| 178 static const char* Name() { return "BWFillRectBatchLocalRect"; } |
| 179 |
| 180 static bool CanCombine(const Geometry& mine, const Geometry& theirs, |
| 181 const GrPipelineOptimizations& opts) { |
| 182 return true; |
| 183 } |
| 184 |
| 185 static const GrGeometryProcessor* CreateGP(const Geometry& geo, |
| 186 const GrPipelineOptimizations& op
ts) { |
| 187 const GrGeometryProcessor* gp = create_gp(geo.fViewMatrix, opts.readsCov
erage(), true, |
| 188 NULL); |
| 189 |
| 190 SkASSERT(gp->getVertexStride() == |
| 191 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr)); |
| 192 return gp; |
| 193 } |
| 194 |
| 195 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry
& geo, |
| 196 const GrPipelineOptimizations& opts) { |
| 197 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.fRect
, &geo.fLocalRect, |
| 198 NULL); |
| 199 } |
| 200 }; |
| 201 |
| 202 class BWFillRectBatchLocalMatrixLocalRectImp : public BWFillRectBatchBase { |
| 203 public: |
| 204 struct Geometry { |
| 205 SkMatrix fViewMatrix; |
| 27 SkMatrix fLocalMatrix; | 206 SkMatrix fLocalMatrix; |
| 28 GrColor fColor; | 207 SkRect fRect; |
| 29 bool fHasLocalRect; | 208 SkRect fLocalRect; |
| 30 bool fHasLocalMatrix; | 209 GrColor fColor; |
| 31 }; | 210 }; |
| 32 | 211 |
| 33 static GrDrawBatch* Create(const Geometry& geometry) { | 212 static const char* Name() { return "BWFillRectBatchLocalMatrixLocalRect"; } |
| 34 return SkNEW_ARGS(BWFillRectBatch, (geometry)); | 213 |
| 35 } | 214 static bool CanCombine(const Geometry& mine, const Geometry& theirs, |
| 36 | 215 const GrPipelineOptimizations& opts) { |
| 37 const char* name() const override { return "RectBatch"; } | |
| 38 | |
| 39 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | |
| 40 // When this is called on a batch, there is only one geometry bundle | |
| 41 out->setKnownFourComponents(fGeoData[0].fColor); | |
| 42 } | |
| 43 | |
| 44 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { | |
| 45 out->setKnownSingleComponent(0xff); | |
| 46 } | |
| 47 | |
| 48 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | |
| 49 | |
| 50 private: | |
| 51 BWFillRectBatch(const Geometry& geometry) { | |
| 52 this->initClassID<BWFillRectBatch>(); | |
| 53 fGeoData.push_back(geometry); | |
| 54 | |
| 55 fBounds = geometry.fRect; | |
| 56 geometry.fViewMatrix.mapRect(&fBounds); | |
| 57 } | |
| 58 | |
| 59 GrColor color() const { return fBatch.fColor; } | |
| 60 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | |
| 61 bool colorIgnored() const { return fBatch.fColorIgnored; } | |
| 62 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } | |
| 63 const SkMatrix& localMatrix() const { return fGeoData[0].fLocalMatrix; } | |
| 64 bool hasLocalRect() const { return fGeoData[0].fHasLocalRect; } | |
| 65 bool hasLocalMatrix() const { return fGeoData[0].fHasLocalMatrix; } | |
| 66 bool coverageIgnored() const { return fBatch.fCoverageIgnored; } | |
| 67 | |
| 68 void initBatchTracker(const GrPipelineOptimizations& init) override { | |
| 69 // Handle any color overrides | |
| 70 if (!init.readsColor()) { | |
| 71 fGeoData[0].fColor = GrColor_ILLEGAL; | |
| 72 } | |
| 73 init.getOverrideColorIfSet(&fGeoData[0].fColor); | |
| 74 | |
| 75 // setup batch properties | |
| 76 fBatch.fColorIgnored = !init.readsColor(); | |
| 77 fBatch.fColor = fGeoData[0].fColor; | |
| 78 fBatch.fUsesLocalCoords = init.readsLocalCoords(); | |
| 79 fBatch.fCoverageIgnored = !init.readsCoverage(); | |
| 80 } | |
| 81 | |
| 82 void onPrepareDraws(Target* target) override { | |
| 83 SkAutoTUnref<const GrGeometryProcessor> gp(this->createRectGP()); | |
| 84 if (!gp) { | |
| 85 SkDebugf("Could not create GrGeometryProcessor\n"); | |
| 86 return; | |
| 87 } | |
| 88 | |
| 89 target->initDraw(gp, this->pipeline()); | |
| 90 | |
| 91 int instanceCount = fGeoData.count(); | |
| 92 size_t vertexStride = gp->getVertexStride(); | |
| 93 SkASSERT(this->hasLocalRect() ? | |
| 94 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorLo
calCoordAttr) : | |
| 95 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr)); | |
| 96 QuadHelper helper; | |
| 97 void* vertices = helper.init(target, vertexStride, instanceCount); | |
| 98 | |
| 99 if (!vertices) { | |
| 100 return; | |
| 101 } | |
| 102 | |
| 103 for (int i = 0; i < instanceCount; i++) { | |
| 104 const Geometry& geom = fGeoData[i]; | |
| 105 | |
| 106 intptr_t offset = reinterpret_cast<intptr_t>(vertices) + | |
| 107 kVerticesPerQuad * i * vertexStride; | |
| 108 SkPoint* positions = reinterpret_cast<SkPoint*>(offset); | |
| 109 | |
| 110 positions->setRectFan(geom.fRect.fLeft, geom.fRect.fTop, | |
| 111 geom.fRect.fRight, geom.fRect.fBottom, vertexS
tride); | |
| 112 geom.fViewMatrix.mapPointsWithStride(positions, vertexStride, kVerti
cesPerQuad); | |
| 113 | |
| 114 // TODO we should only do this if local coords are being read | |
| 115 if (geom.fHasLocalRect) { | |
| 116 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor
); | |
| 117 SkPoint* coords = reinterpret_cast<SkPoint*>(offset + kLocalOffs
et); | |
| 118 coords->setRectFan(geom.fLocalRect.fLeft, geom.fLocalRect.fTop, | |
| 119 geom.fLocalRect.fRight, geom.fLocalRect.fBott
om, | |
| 120 vertexStride); | |
| 121 if (geom.fHasLocalMatrix) { | |
| 122 geom.fLocalMatrix.mapPointsWithStride(coords, vertexStride,
kVerticesPerQuad); | |
| 123 } | |
| 124 } | |
| 125 | |
| 126 static const int kColorOffset = sizeof(SkPoint); | |
| 127 GrColor* vertColor = reinterpret_cast<GrColor*>(offset + kColorOffse
t); | |
| 128 for (int j = 0; j < 4; ++j) { | |
| 129 *vertColor = geom.fColor; | |
| 130 vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride); | |
| 131 } | |
| 132 } | |
| 133 | |
| 134 helper.recordDraw(target); | |
| 135 } | |
| 136 | |
| 137 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | |
| 138 BWFillRectBatch* that = t->cast<BWFillRectBatch>(); | |
| 139 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), | |
| 140 that->bounds(), caps)) { | |
| 141 return false; | |
| 142 } | |
| 143 | |
| 144 if (this->hasLocalRect() != that->hasLocalRect()) { | |
| 145 return false; | |
| 146 } | |
| 147 | |
| 148 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); | |
| 149 if (!this->hasLocalRect() && this->usesLocalCoords()) { | |
| 150 if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { | |
| 151 return false; | |
| 152 } | |
| 153 | |
| 154 if (this->hasLocalMatrix() != that->hasLocalMatrix()) { | |
| 155 return false; | |
| 156 } | |
| 157 | |
| 158 if (this->hasLocalMatrix() && !this->localMatrix().cheapEqualTo(that
->localMatrix())) { | |
| 159 return false; | |
| 160 } | |
| 161 } | |
| 162 | |
| 163 if (this->color() != that->color()) { | |
| 164 fBatch.fColor = GrColor_ILLEGAL; | |
| 165 } | |
| 166 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; | |
| 167 this->joinBounds(that->bounds()); | |
| 168 return true; | 216 return true; |
| 169 } | 217 } |
| 170 | 218 |
| 171 | 219 static const GrGeometryProcessor* CreateGP(const Geometry& geo, |
| 172 /** We always use per-vertex colors so that rects can be batched across colo
r changes. Sometimes | 220 const GrPipelineOptimizations& op
ts) { |
| 173 we have explicit local coords and sometimes not. We *could* always prov
ide explicit local | 221 const GrGeometryProcessor* gp = create_gp(geo.fViewMatrix, opts.readsCov
erage(), true, |
| 174 coords and just duplicate the positions when the caller hasn't provided
a local coord rect, | 222 NULL); |
| 175 but we haven't seen a use case which frequently switches between local r
ect and no local | 223 |
| 176 rect draws. | 224 SkASSERT(gp->getVertexStride() == |
| 177 | 225 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr)); |
| 178 The color param is used to determine whether the opaque hint can be set
on the draw state. | 226 return gp; |
| 179 The caller must populate the vertex colors itself. | 227 } |
| 180 | 228 |
| 181 The vertex attrib order is always pos, color, [local coords]. | 229 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry
& geo, |
| 182 */ | 230 const GrPipelineOptimizations& opts) { |
| 183 const GrGeometryProcessor* createRectGP() const { | 231 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.fRect
, &geo.fLocalRect, |
| 184 using namespace GrDefaultGeoProcFactory; | 232 &geo.fLocalMatrix); |
| 185 Color color(Color::kAttribute_Type); | 233 } |
| 186 Coverage coverage(this->coverageIgnored() ? Coverage::kNone_Type : Cover
age::kSolid_Type); | 234 }; |
| 187 | 235 |
| 188 // if we have a local rect, then we apply the localMatrix directly to th
e localRect to | 236 typedef GrTInstanceBatch<BWFillRectBatchNoLocalMatrixImp> BWFillRectBatchSimple; |
| 189 // generate vertex local coords | 237 typedef GrTInstanceBatch<BWFillRectBatchLocalMatrixImp> BWFillRectBatchLocalMatr
ix; |
| 190 if (this->hasLocalRect()) { | 238 typedef GrTInstanceBatch<BWFillRectBatchLocalRectImp> BWFillRectBatchLocalRect; |
| 191 LocalCoords localCoords(LocalCoords::kHasExplicit_Type); | 239 typedef GrTInstanceBatch<BWFillRectBatchLocalMatrixLocalRectImp> BWFillRectBatch
LocalMatrixLocalRect; |
| 192 return GrDefaultGeoProcFactory::Create(color, coverage, localCoords,
SkMatrix::I()); | |
| 193 } else { | |
| 194 LocalCoords localCoords(LocalCoords::kUsePosition_Type, | |
| 195 this->hasLocalMatrix() ? &this->localMatrix(
) : NULL); | |
| 196 return GrDefaultGeoProcFactory::CreateForDeviceSpace(color, coverage
, localCoords, | |
| 197 this->viewMatri
x()); | |
| 198 } | |
| 199 } | |
| 200 | |
| 201 struct BatchTracker { | |
| 202 GrColor fColor; | |
| 203 bool fUsesLocalCoords; | |
| 204 bool fColorIgnored; | |
| 205 bool fCoverageIgnored; | |
| 206 }; | |
| 207 | |
| 208 BatchTracker fBatch; | |
| 209 SkSTArray<1, Geometry, true> fGeoData; | |
| 210 }; | |
| 211 | 240 |
| 212 namespace GrBWFillRectBatch { | 241 namespace GrBWFillRectBatch { |
| 213 GrDrawBatch* Create(GrColor color, | 242 GrDrawBatch* Create(GrColor color, |
| 214 const SkMatrix& viewMatrix, | 243 const SkMatrix& viewMatrix, |
| 215 const SkRect& rect, | 244 const SkRect& rect, |
| 216 const SkRect* localRect, | 245 const SkRect* localRect, |
| 217 const SkMatrix* localMatrix) { | 246 const SkMatrix* localMatrix) { |
| 218 BWFillRectBatch::Geometry geometry; | 247 // TODO bubble these up as separate calls |
| 219 geometry.fColor = color; | 248 if (localRect && localMatrix) { |
| 220 geometry.fViewMatrix = viewMatrix; | 249 BWFillRectBatchLocalMatrixLocalRect* batch = BWFillRectBatchLocalMatrixL
ocalRect::Create(); |
| 221 geometry.fRect = rect; | 250 BWFillRectBatchLocalMatrixLocalRect::Geometry& geo = *batch->geometry(); |
| 222 | 251 geo.fColor = color; |
| 223 if (localRect) { | 252 geo.fViewMatrix = viewMatrix; |
| 224 geometry.fHasLocalRect = true; | 253 geo.fLocalMatrix = *localMatrix; |
| 225 geometry.fLocalRect = *localRect; | 254 geo.fRect = rect; |
| 255 geo.fLocalRect = *localRect; |
| 256 batch->init(); |
| 257 return batch; |
| 258 } else if (localRect) { |
| 259 BWFillRectBatchLocalRect* batch = BWFillRectBatchLocalRect::Create(); |
| 260 BWFillRectBatchLocalRect::Geometry& geo = *batch->geometry(); |
| 261 geo.fColor = color; |
| 262 geo.fViewMatrix = viewMatrix; |
| 263 geo.fRect = rect; |
| 264 geo.fLocalRect = *localRect; |
| 265 batch->init(); |
| 266 return batch; |
| 267 } else if (localMatrix) { |
| 268 BWFillRectBatchLocalMatrix* batch = BWFillRectBatchLocalMatrix::Create()
; |
| 269 BWFillRectBatchLocalMatrix::Geometry& geo = *batch->geometry(); |
| 270 geo.fColor = color; |
| 271 geo.fViewMatrix = viewMatrix; |
| 272 geo.fLocalMatrix = *localMatrix; |
| 273 geo.fRect = rect; |
| 274 batch->init(); |
| 275 return batch; |
| 226 } else { | 276 } else { |
| 227 geometry.fHasLocalRect = false; | 277 BWFillRectBatchSimple* batch = BWFillRectBatchSimple::Create(); |
| 228 } | 278 BWFillRectBatchSimple::Geometry& geo = *batch->geometry(); |
| 229 | 279 geo.fColor = color; |
| 230 if (localMatrix) { | 280 geo.fViewMatrix = viewMatrix; |
| 231 geometry.fHasLocalMatrix = true; | 281 geo.fRect = rect; |
| 232 geometry.fLocalMatrix = *localMatrix; | 282 batch->init(); |
| 233 } else { | 283 return batch; |
| 234 geometry.fHasLocalMatrix = false; | 284 } |
| 235 } | |
| 236 | |
| 237 return BWFillRectBatch::Create(geometry); | |
| 238 } | 285 } |
| 239 }; | 286 }; |
| 240 | 287 |
| 241 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 288 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 242 | 289 |
| 243 #ifdef GR_TEST_UTILS | 290 #ifdef GR_TEST_UTILS |
| 244 | 291 |
| 245 #include "GrBatchTest.h" | 292 #include "GrBatchTest.h" |
| 246 | 293 |
| 247 DRAW_BATCH_TEST_DEFINE(RectBatch) { | 294 DRAW_BATCH_TEST_DEFINE(RectBatch) { |
| 248 BWFillRectBatch::Geometry geometry; | 295 GrColor color = GrRandomColor(random); |
| 249 geometry.fColor = GrRandomColor(random); | 296 SkRect rect = GrTest::TestRect(random); |
| 297 SkRect localRect = GrTest::TestRect(random); |
| 298 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
| 299 SkMatrix localMatrix = GrTest::TestMatrix(random); |
| 250 | 300 |
| 251 geometry.fRect = GrTest::TestRect(random); | 301 bool hasLocalRect = random->nextBool(); |
| 252 geometry.fHasLocalRect = random->nextBool(); | 302 bool hasLocalMatrix = random->nextBool(); |
| 253 | 303 return GrBWFillRectBatch::Create(color, viewMatrix, rect, hasLocalRect ? &lo
calRect : nullptr, |
| 254 if (geometry.fHasLocalRect) { | 304 hasLocalMatrix ? &localMatrix : nullptr); |
| 255 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); | |
| 256 geometry.fLocalRect = GrTest::TestRect(random); | |
| 257 } else { | |
| 258 geometry.fViewMatrix = GrTest::TestMatrix(random); | |
| 259 } | |
| 260 | |
| 261 geometry.fHasLocalMatrix = random->nextBool(); | |
| 262 if (geometry.fHasLocalMatrix) { | |
| 263 geometry.fLocalMatrix = GrTest::TestMatrix(random); | |
| 264 } | |
| 265 | |
| 266 return BWFillRectBatch::Create(geometry); | |
| 267 } | 305 } |
| 268 | 306 |
| 269 #endif | 307 #endif |
| OLD | NEW |