Chromium Code Reviews| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 for (int j = 0; j < 4; ++j) { | 84 for (int j = 0; j < 4; ++j) { |
| 85 *vertColor = color; | 85 *vertColor = color; |
| 86 vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride); | 86 vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride); |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 | 89 |
| 90 class NonAAFillRectBatch : public GrVertexBatch { | 90 class NonAAFillRectBatch : public GrVertexBatch { |
| 91 public: | 91 public: |
| 92 DEFINE_BATCH_CLASS_ID | 92 DEFINE_BATCH_CLASS_ID |
| 93 | 93 |
| 94 struct Geometry { | 94 NonAAFillRectBatch(GrColor color, const SkMatrix& viewMatrix, const SkRect& rect, |
| 95 SkMatrix fViewMatrix; | 95 const SkRect* localRect, const SkMatrix* localMatrix) |
| 96 SkRect fRect; | 96 : INHERITED(ClassID()) { |
|
robertphillips
2016/07/01 14:14:16
SkASSERT(!viewMatrix.hasPerspective() && (!localMa
bsalomon
2016/07/01 14:41:31
Done.
| |
| 97 GrQuad fLocalQuad; | 97 RectInfo& info = fRects.push_back(); |
| 98 GrColor fColor; | 98 info.fColor = color; |
| 99 }; | 99 info.fViewMatrix = viewMatrix; |
| 100 | 100 info.fRect = rect; |
| 101 static NonAAFillRectBatch* Create() { return new NonAAFillRectBatch; } | 101 if (localRect && localMatrix) { |
| 102 info.fLocalQuad.setFromMappedRect(*localRect, *localMatrix); | |
| 103 } else if (localRect) { | |
| 104 info.fLocalQuad.set(*localRect); | |
| 105 } else if (localMatrix) { | |
| 106 info.fLocalQuad.setFromMappedRect(rect, *localMatrix); | |
| 107 } else { | |
| 108 info.fLocalQuad.set(rect); | |
| 109 } | |
| 110 viewMatrix.mapRect(&fBounds, fRects[0].fRect); | |
| 111 } | |
| 102 | 112 |
| 103 const char* name() const override { return "NonAAFillRectBatch"; } | 113 const char* name() const override { return "NonAAFillRectBatch"; } |
| 104 | 114 |
| 105 SkString dumpInfo() const override { | 115 SkString dumpInfo() const override { |
| 106 SkString str; | 116 SkString str; |
| 107 str.appendf("# batched: %d\n", fGeoData.count()); | 117 str.appendf("# batched: %d\n", fRects.count()); |
| 108 for (int i = 0; i < fGeoData.count(); ++i) { | 118 for (int i = 0; i < fRects.count(); ++i) { |
| 109 const Geometry& geo = fGeoData[i]; | 119 const RectInfo& info = fRects[i]; |
| 110 str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", | 120 str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", |
| 111 i, geo.fColor, | 121 i, info.fColor, |
| 112 geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight, geo.f Rect.fBottom); | 122 info.fRect.fLeft, info.fRect.fTop, info.fRect.fRight, in fo.fRect.fBottom); |
| 113 } | 123 } |
| 114 str.append(INHERITED::dumpInfo()); | 124 str.append(INHERITED::dumpInfo()); |
| 115 return str; | 125 return str; |
| 116 } | 126 } |
| 117 | 127 |
| 118 void computePipelineOptimizations(GrInitInvariantOutput* color, | 128 void computePipelineOptimizations(GrInitInvariantOutput* color, |
| 119 GrInitInvariantOutput* coverage, | 129 GrInitInvariantOutput* coverage, |
| 120 GrBatchToXPOverrides* overrides) const ove rride { | 130 GrBatchToXPOverrides* overrides) const ove rride { |
| 121 // When this is called on a batch, there is only one geometry bundle | 131 // When this is called on a batch, there is only one geometry bundle |
| 122 color->setKnownFourComponents(fGeoData[0].fColor); | 132 color->setKnownFourComponents(fRects[0].fColor); |
| 123 coverage->setKnownSingleComponent(0xff); | 133 coverage->setKnownSingleComponent(0xff); |
| 124 } | 134 } |
| 125 | 135 |
| 126 void initBatchTracker(const GrXPOverridesForBatch& overrides) override { | 136 void initBatchTracker(const GrXPOverridesForBatch& overrides) override { |
| 127 overrides.getOverrideColorIfSet(&fGeoData[0].fColor); | 137 overrides.getOverrideColorIfSet(&fRects[0].fColor); |
| 128 fOverrides = overrides; | 138 fOverrides = overrides; |
| 129 } | 139 } |
| 130 | 140 |
| 131 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | |
| 132 | |
| 133 // After seeding, the client should call init() so the Batch can initialize itself | |
| 134 void init() { fGeoData[0].fViewMatrix.mapRect(&fBounds, fGeoData[0].fRect); } | |
| 135 | |
| 136 private: | 141 private: |
| 137 NonAAFillRectBatch() : INHERITED(ClassID()) {} | 142 NonAAFillRectBatch() : INHERITED(ClassID()) {} |
| 138 | 143 |
| 139 void onPrepareDraws(Target* target) const override { | 144 void onPrepareDraws(Target* target) const override { |
| 140 sk_sp<GrGeometryProcessor> gp = make_gp(fGeoData[0].fViewMatrix, fOverri des.readsCoverage(), | 145 sk_sp<GrGeometryProcessor> gp = make_gp(fRects[0].fViewMatrix, fOverride s.readsCoverage(), |
| 141 true, nullptr); | 146 true, nullptr); |
| 142 if (!gp) { | 147 if (!gp) { |
| 143 SkDebugf("Couldn't create GrGeometryProcessor\n"); | 148 SkDebugf("Couldn't create GrGeometryProcessor\n"); |
| 144 return; | 149 return; |
| 145 } | 150 } |
| 146 SkASSERT(gp->getVertexStride() == | 151 SkASSERT(gp->getVertexStride() == |
| 147 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr)); | 152 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr)); |
| 148 | 153 |
| 149 size_t vertexStride = gp->getVertexStride(); | 154 size_t vertexStride = gp->getVertexStride(); |
| 150 int instanceCount = fGeoData.count(); | 155 int instanceCount = fRects.count(); |
| 151 | 156 |
| 152 SkAutoTUnref<const GrBuffer> indexBuffer(target->resourceProvider()->ref QuadIndexBuffer()); | 157 SkAutoTUnref<const GrBuffer> indexBuffer(target->resourceProvider()->ref QuadIndexBuffer()); |
| 153 InstancedHelper helper; | 158 InstancedHelper helper; |
| 154 void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexS tride, | 159 void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexS tride, |
| 155 indexBuffer, kVertsPerInstance, | 160 indexBuffer, kVertsPerInstance, |
| 156 kIndicesPerInstance, instanceCount); | 161 kIndicesPerInstance, instanceCount); |
| 157 if (!vertices || !indexBuffer) { | 162 if (!vertices || !indexBuffer) { |
| 158 SkDebugf("Could not allocate vertices\n"); | 163 SkDebugf("Could not allocate vertices\n"); |
| 159 return; | 164 return; |
| 160 } | 165 } |
| 161 | 166 |
| 162 for (int i = 0; i < instanceCount; i++) { | 167 for (int i = 0; i < instanceCount; i++) { |
| 163 intptr_t verts = reinterpret_cast<intptr_t>(vertices) + | 168 intptr_t verts = reinterpret_cast<intptr_t>(vertices) + |
| 164 i * kVertsPerInstance * vertexStride; | 169 i * kVertsPerInstance * vertexStride; |
| 165 tesselate(verts, vertexStride, fGeoData[i].fColor, fGeoData[i].fView Matrix, | 170 tesselate(verts, vertexStride, fRects[i].fColor, fRects[i].fViewMatr ix, |
| 166 fGeoData[i].fRect, &fGeoData[i].fLocalQuad); | 171 fRects[i].fRect, &fRects[i].fLocalQuad); |
| 167 } | 172 } |
| 168 helper.recordDraw(target, gp.get()); | 173 helper.recordDraw(target, gp.get()); |
| 169 } | 174 } |
| 170 | 175 |
| 171 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 176 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
| 172 NonAAFillRectBatch* that = t->cast<NonAAFillRectBatch>(); | 177 NonAAFillRectBatch* that = t->cast<NonAAFillRectBatch>(); |
| 173 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi peline(), | 178 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi peline(), |
| 174 that->bounds(), caps)) { | 179 that->bounds(), caps)) { |
| 175 return false; | 180 return false; |
| 176 } | 181 } |
| 177 | 182 |
| 178 // In the event of two batches, one who can tweak, one who cannot, we ju st fall back to | 183 // In the event of two batches, one who can tweak, one who cannot, we ju st fall back to |
| 179 // not tweaking | 184 // not tweaking |
| 180 if (fOverrides.canTweakAlphaForCoverage() && !that->fOverrides.canTweakA lphaForCoverage()) { | 185 if (fOverrides.canTweakAlphaForCoverage() && !that->fOverrides.canTweakA lphaForCoverage()) { |
| 181 fOverrides = that->fOverrides; | 186 fOverrides = that->fOverrides; |
| 182 } | 187 } |
| 183 | 188 |
| 184 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()) ; | 189 fRects.push_back_n(that->fRects.count(), that->fRects.begin()); |
| 185 this->joinBounds(that->bounds()); | 190 this->joinBounds(that->bounds()); |
| 186 return true; | 191 return true; |
| 187 } | 192 } |
| 188 | 193 |
| 194 struct RectInfo { | |
| 195 GrColor fColor; | |
| 196 SkMatrix fViewMatrix; | |
| 197 SkRect fRect; | |
| 198 GrQuad fLocalQuad; | |
| 199 }; | |
| 200 | |
| 189 GrXPOverridesForBatch fOverrides; | 201 GrXPOverridesForBatch fOverrides; |
| 190 SkSTArray<1, Geometry, true> fGeoData; | 202 SkSTArray<1, RectInfo, true> fRects; |
| 191 | 203 |
| 192 typedef GrVertexBatch INHERITED; | 204 typedef GrVertexBatch INHERITED; |
| 193 }; | 205 }; |
| 194 | 206 |
| 195 // We handle perspective in the local matrix or viewmatrix with special batches | 207 // We handle perspective in the local matrix or viewmatrix with special batches |
| 196 class NonAAFillRectPerspectiveBatch : public GrVertexBatch { | 208 class NonAAFillRectPerspectiveBatch : public GrVertexBatch { |
| 197 public: | 209 public: |
| 198 DEFINE_BATCH_CLASS_ID | 210 DEFINE_BATCH_CLASS_ID |
| 199 | 211 |
| 200 struct Geometry { | 212 NonAAFillRectPerspectiveBatch(GrColor color, const SkMatrix& viewMatrix, con st SkRect& rect, |
| 201 SkMatrix fViewMatrix; | 213 const SkRect* localRect, const SkMatrix* local Matrix) |
| 202 SkMatrix fLocalMatrix; | 214 : INHERITED(ClassID()) |
| 203 SkRect fRect; | 215 , fViewMatrix(viewMatrix) { |
|
robertphillips
2016/07/01 14:14:16
SkASSERT(viewMatrix.hasPerspective() || (localMatr
bsalomon
2016/07/01 14:41:31
Done.
| |
| 204 SkRect fLocalRect; | 216 RectInfo& info = fRects.push_back(); |
| 205 GrColor fColor; | 217 info.fColor = color; |
| 206 bool fHasLocalMatrix; | 218 info.fRect = rect; |
| 207 bool fHasLocalRect; | 219 fHasLocalRect = SkToBool(localRect); |
| 208 }; | 220 fHasLocalMatrix = SkToBool(localMatrix); |
| 209 | 221 if (fHasLocalMatrix) { |
| 210 static NonAAFillRectPerspectiveBatch* Create() { return new NonAAFillRectPer spectiveBatch; } | 222 fLocalMatrix = *localMatrix; |
| 223 } | |
| 224 if (fHasLocalRect) { | |
| 225 info.fLocalRect = *localRect; | |
| 226 } | |
| 227 viewMatrix.mapRect(&fBounds, rect); | |
| 228 } | |
| 211 | 229 |
| 212 const char* name() const override { return "NonAAFillRectPerspectiveBatch"; } | 230 const char* name() const override { return "NonAAFillRectPerspectiveBatch"; } |
| 213 | 231 |
| 214 SkString dumpInfo() const override { | 232 SkString dumpInfo() const override { |
| 215 SkString str; | 233 SkString str; |
| 216 str.appendf("# batched: %d\n", fGeoData.count()); | 234 str.appendf("# batched: %d\n", fRects.count()); |
| 217 for (int i = 0; i < fGeoData.count(); ++i) { | 235 for (int i = 0; i < fRects.count(); ++i) { |
| 218 const Geometry& geo = fGeoData[0]; | 236 const RectInfo& geo = fRects[0]; |
| 219 str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", | 237 str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", |
| 220 i, geo.fColor, | 238 i, geo.fColor, |
| 221 geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight, geo.f Rect.fBottom); | 239 geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight, geo.f Rect.fBottom); |
| 222 } | 240 } |
| 223 str.append(INHERITED::dumpInfo()); | 241 str.append(INHERITED::dumpInfo()); |
| 224 return str; | 242 return str; |
| 225 } | 243 } |
| 226 | 244 |
| 227 void computePipelineOptimizations(GrInitInvariantOutput* color, | 245 void computePipelineOptimizations(GrInitInvariantOutput* color, |
| 228 GrInitInvariantOutput* coverage, | 246 GrInitInvariantOutput* coverage, |
| 229 GrBatchToXPOverrides* overrides) const ove rride { | 247 GrBatchToXPOverrides* overrides) const ove rride { |
| 230 // When this is called on a batch, there is only one geometry bundle | 248 // When this is called on a batch, there is only one geometry bundle |
| 231 color->setKnownFourComponents(fGeoData[0].fColor); | 249 color->setKnownFourComponents(fRects[0].fColor); |
| 232 coverage->setKnownSingleComponent(0xff); | 250 coverage->setKnownSingleComponent(0xff); |
| 233 } | 251 } |
| 234 | 252 |
| 235 void initBatchTracker(const GrXPOverridesForBatch& overrides) override { | 253 void initBatchTracker(const GrXPOverridesForBatch& overrides) override { |
| 236 overrides.getOverrideColorIfSet(&fGeoData[0].fColor); | 254 overrides.getOverrideColorIfSet(&fRects[0].fColor); |
| 237 fOverrides = overrides; | 255 fOverrides = overrides; |
| 238 } | 256 } |
| 239 | 257 |
| 240 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | |
| 241 | |
| 242 // After seeding, the client should call init() so the Batch can initialize itself | |
| 243 void init() { fGeoData[0].fViewMatrix.mapRect(&fBounds, fGeoData[0].fRect); } | |
| 244 | |
| 245 private: | 258 private: |
| 246 NonAAFillRectPerspectiveBatch() : INHERITED(ClassID()) {} | 259 NonAAFillRectPerspectiveBatch() : INHERITED(ClassID()) {} |
| 247 | 260 |
| 248 void onPrepareDraws(Target* target) const override { | 261 void onPrepareDraws(Target* target) const override { |
| 249 sk_sp<GrGeometryProcessor> gp = make_gp(fGeoData[0].fViewMatrix, fOverri des.readsCoverage(), | 262 sk_sp<GrGeometryProcessor> gp = make_gp(fViewMatrix, fOverrides.readsCov erage(), |
| 250 fGeoData[0].fHasLocalRect, | 263 fHasLocalRect, |
| 251 fGeoData[0].fHasLocalMatrix | 264 fHasLocalMatrix ? &fLocalMatrix : nullptr); |
| 252 ? &fGeoData[0].fLocalMatrix | |
| 253 : nullptr); | |
| 254 if (!gp) { | 265 if (!gp) { |
| 255 SkDebugf("Couldn't create GrGeometryProcessor\n"); | 266 SkDebugf("Couldn't create GrGeometryProcessor\n"); |
| 256 return; | 267 return; |
| 257 } | 268 } |
| 258 SkASSERT(fGeoData[0].fHasLocalRect | 269 SkASSERT(fHasLocalRect |
| 259 ? gp->getVertexStride() == | 270 ? gp->getVertexStride() == |
| 260 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoord Attr) | 271 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoord Attr) |
| 261 : gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory:: PositionColorAttr)); | 272 : gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory:: PositionColorAttr)); |
| 262 | 273 |
| 263 size_t vertexStride = gp->getVertexStride(); | 274 size_t vertexStride = gp->getVertexStride(); |
| 264 int instanceCount = fGeoData.count(); | 275 int instanceCount = fRects.count(); |
| 265 | 276 |
| 266 SkAutoTUnref<const GrBuffer> indexBuffer(target->resourceProvider()->ref QuadIndexBuffer()); | 277 SkAutoTUnref<const GrBuffer> indexBuffer(target->resourceProvider()->ref QuadIndexBuffer()); |
| 267 InstancedHelper helper; | 278 InstancedHelper helper; |
| 268 void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexS tride, | 279 void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexS tride, |
| 269 indexBuffer, kVertsPerInstance, | 280 indexBuffer, kVertsPerInstance, |
| 270 kIndicesPerInstance, instanceCount); | 281 kIndicesPerInstance, instanceCount); |
| 271 if (!vertices || !indexBuffer) { | 282 if (!vertices || !indexBuffer) { |
| 272 SkDebugf("Could not allocate vertices\n"); | 283 SkDebugf("Could not allocate vertices\n"); |
| 273 return; | 284 return; |
| 274 } | 285 } |
| 275 | 286 |
| 276 for (int i = 0; i < instanceCount; i++) { | 287 for (int i = 0; i < instanceCount; i++) { |
| 277 const Geometry& geo = fGeoData[i]; | 288 const RectInfo& info = fRects[i]; |
| 278 intptr_t verts = reinterpret_cast<intptr_t>(vertices) + | 289 intptr_t verts = reinterpret_cast<intptr_t>(vertices) + |
| 279 i * kVertsPerInstance * vertexStride; | 290 i * kVertsPerInstance * vertexStride; |
| 280 if (geo.fHasLocalRect) { | 291 if (fHasLocalRect) { |
| 281 GrQuad quad(geo.fLocalRect); | 292 GrQuad quad(info.fLocalRect); |
| 282 tesselate(verts, vertexStride, geo.fColor, geo.fViewMatrix, geo. fRect, &quad); | 293 tesselate(verts, vertexStride, info.fColor, fViewMatrix, info.fR ect, &quad); |
| 283 } else { | 294 } else { |
| 284 tesselate(verts, vertexStride, geo.fColor, geo.fViewMatrix, geo. fRect, nullptr); | 295 tesselate(verts, vertexStride, info.fColor, fViewMatrix, info.fR ect, nullptr); |
| 285 } | 296 } |
| 286 } | 297 } |
| 287 helper.recordDraw(target, gp.get()); | 298 helper.recordDraw(target, gp.get()); |
| 288 } | 299 } |
| 289 | 300 |
| 290 const Geometry& seedGeometry() const { return fGeoData[0]; } | |
| 291 | |
| 292 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 301 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
| 293 NonAAFillRectPerspectiveBatch* that = t->cast<NonAAFillRectPerspectiveBa tch>(); | 302 NonAAFillRectPerspectiveBatch* that = t->cast<NonAAFillRectPerspectiveBa tch>(); |
| 294 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi peline(), | 303 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi peline(), |
| 295 that->bounds(), caps)) { | 304 that->bounds(), caps)) { |
| 296 return false; | 305 return false; |
| 297 } | 306 } |
| 298 | 307 |
| 299 // We could batch across perspective vm changes if we really wanted to | 308 // We could batch across perspective vm changes if we really wanted to |
| 300 if (!fGeoData[0].fViewMatrix.cheapEqualTo(that->fGeoData[0].fViewMatrix) ) { | 309 if (!fViewMatrix.cheapEqualTo(that->fViewMatrix)) { |
| 301 return false; | 310 return false; |
| 302 } | 311 } |
| 303 if (fGeoData[0].fHasLocalRect != that->fGeoData[0].fHasLocalRect) { | 312 if (fHasLocalRect != that->fHasLocalRect) { |
| 304 return false; | 313 return false; |
| 305 } | 314 } |
| 306 if (fGeoData[0].fHasLocalMatrix && | 315 if (fHasLocalMatrix && !fLocalMatrix.cheapEqualTo(that->fLocalMatrix)) { |
| 307 !fGeoData[0].fLocalMatrix.cheapEqualTo(that->fGeoData[0].fLocalMatri x)) { | |
| 308 return false; | 316 return false; |
| 309 } | 317 } |
| 310 | 318 |
| 311 // In the event of two batches, one who can tweak, one who cannot, we ju st fall back to | 319 // In the event of two batches, one who can tweak, one who cannot, we ju st fall back to |
| 312 // not tweaking | 320 // not tweaking |
| 313 if (fOverrides.canTweakAlphaForCoverage() && !that->fOverrides.canTweakA lphaForCoverage()) { | 321 if (fOverrides.canTweakAlphaForCoverage() && !that->fOverrides.canTweakA lphaForCoverage()) { |
| 314 fOverrides = that->fOverrides; | 322 fOverrides = that->fOverrides; |
| 315 } | 323 } |
| 316 | 324 |
| 317 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()) ; | 325 fRects.push_back_n(that->fRects.count(), that->fRects.begin()); |
| 318 this->joinBounds(that->bounds()); | 326 this->joinBounds(that->bounds()); |
| 319 return true; | 327 return true; |
| 320 } | 328 } |
| 321 | 329 |
| 330 struct RectInfo { | |
| 331 SkRect fRect; | |
| 332 GrColor fColor; | |
| 333 SkRect fLocalRect; | |
| 334 }; | |
| 335 | |
| 322 GrXPOverridesForBatch fOverrides; | 336 GrXPOverridesForBatch fOverrides; |
| 323 SkSTArray<1, Geometry, true> fGeoData; | 337 SkSTArray<1, RectInfo, true> fRects; |
| 338 bool fHasLocalMatrix; | |
| 339 bool fHasLocalRect; | |
| 340 SkMatrix fLocalMatrix; | |
| 341 SkMatrix fViewMatrix; | |
| 324 | 342 |
| 325 typedef GrVertexBatch INHERITED; | 343 typedef GrVertexBatch INHERITED; |
| 326 }; | 344 }; |
| 327 | 345 |
| 328 namespace GrNonAAFillRectBatch { | 346 namespace GrNonAAFillRectBatch { |
| 329 | 347 |
| 330 GrDrawBatch* Create(GrColor color, | 348 GrDrawBatch* Create(GrColor color, |
| 331 const SkMatrix& viewMatrix, | 349 const SkMatrix& viewMatrix, |
| 332 const SkRect& rect, | 350 const SkRect& rect, |
| 333 const SkRect* localRect, | 351 const SkRect* localRect, |
| 334 const SkMatrix* localMatrix) { | 352 const SkMatrix* localMatrix) { |
| 335 NonAAFillRectBatch* batch = NonAAFillRectBatch::Create(); | 353 return new NonAAFillRectBatch(color, viewMatrix, rect, localRect, localMatri x); |
| 336 SkASSERT(!viewMatrix.hasPerspective() && (!localMatrix || !localMatrix->hasP erspective())); | |
| 337 NonAAFillRectBatch::Geometry& geo = batch->geoData()->push_back(); | |
| 338 | |
| 339 geo.fColor = color; | |
| 340 geo.fViewMatrix = viewMatrix; | |
| 341 geo.fRect = rect; | |
| 342 | |
| 343 if (localRect && localMatrix) { | |
| 344 geo.fLocalQuad.setFromMappedRect(*localRect, *localMatrix); | |
| 345 } else if (localRect) { | |
| 346 geo.fLocalQuad.set(*localRect); | |
| 347 } else if (localMatrix) { | |
| 348 geo.fLocalQuad.setFromMappedRect(rect, *localMatrix); | |
| 349 } else { | |
| 350 geo.fLocalQuad.set(rect); | |
| 351 } | |
| 352 batch->init(); | |
| 353 return batch; | |
| 354 } | 354 } |
| 355 | 355 |
| 356 GrDrawBatch* CreateWithPerspective(GrColor color, | 356 GrDrawBatch* CreateWithPerspective(GrColor color, |
| 357 const SkMatrix& viewMatrix, | 357 const SkMatrix& viewMatrix, |
| 358 const SkRect& rect, | 358 const SkRect& rect, |
| 359 const SkRect* localRect, | 359 const SkRect* localRect, |
| 360 const SkMatrix* localMatrix) { | 360 const SkMatrix* localMatrix) { |
| 361 NonAAFillRectPerspectiveBatch* batch = NonAAFillRectPerspectiveBatch::Create (); | 361 return new NonAAFillRectPerspectiveBatch(color, viewMatrix, rect, localRect, localMatrix); |
| 362 SkASSERT(viewMatrix.hasPerspective() || (localMatrix && localMatrix->hasPers pective())); | |
| 363 NonAAFillRectPerspectiveBatch::Geometry& geo = batch->geoData()->push_back() ; | |
| 364 | |
| 365 geo.fColor = color; | |
| 366 geo.fViewMatrix = viewMatrix; | |
| 367 geo.fRect = rect; | |
| 368 geo.fHasLocalRect = SkToBool(localRect); | |
| 369 geo.fHasLocalMatrix = SkToBool(localMatrix); | |
| 370 if (localMatrix) { | |
| 371 geo.fLocalMatrix = *localMatrix; | |
| 372 } | |
| 373 if (localRect) { | |
| 374 geo.fLocalRect = *localRect; | |
| 375 } | |
| 376 batch->init(); | |
| 377 return batch; | |
| 378 } | 362 } |
| 379 | 363 |
| 380 }; | 364 }; |
| 381 | 365 |
| 382 //////////////////////////////////////////////////////////////////////////////// /////////////////// | 366 //////////////////////////////////////////////////////////////////////////////// /////////////////// |
| 383 | 367 |
| 384 #ifdef GR_TEST_UTILS | 368 #ifdef GR_TEST_UTILS |
| 385 | 369 |
| 386 #include "GrBatchTest.h" | 370 #include "GrBatchTest.h" |
| 387 | 371 |
| 388 DRAW_BATCH_TEST_DEFINE(RectBatch) { | 372 DRAW_BATCH_TEST_DEFINE(RectBatch) { |
| 389 GrColor color = GrRandomColor(random); | 373 GrColor color = GrRandomColor(random); |
| 390 SkRect rect = GrTest::TestRect(random); | 374 SkRect rect = GrTest::TestRect(random); |
| 391 SkRect localRect = GrTest::TestRect(random); | 375 SkRect localRect = GrTest::TestRect(random); |
| 392 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); | 376 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
| 393 SkMatrix localMatrix = GrTest::TestMatrix(random); | 377 SkMatrix localMatrix = GrTest::TestMatrix(random); |
| 394 | 378 |
| 395 bool hasLocalRect = random->nextBool(); | 379 bool hasLocalRect = random->nextBool(); |
| 396 bool hasLocalMatrix = random->nextBool(); | 380 bool hasLocalMatrix = random->nextBool(); |
| 397 return GrNonAAFillRectBatch::Create(color, viewMatrix, rect, | 381 return GrNonAAFillRectBatch::Create(color, viewMatrix, rect, |
| 398 hasLocalRect ? &localRect : nullptr, | 382 hasLocalRect ? &localRect : nullptr, |
| 399 hasLocalMatrix ? &localMatrix : nullptr) ; | 383 hasLocalMatrix ? &localMatrix : nullptr) ; |
| 400 } | 384 } |
| 401 | 385 |
| 402 #endif | 386 #endif |
| OLD | NEW |