Chromium Code Reviews| Index: src/gpu/batches/GrNonAAFillRectBatch.cpp |
| diff --git a/src/gpu/batches/GrNonAAFillRectBatch.cpp b/src/gpu/batches/GrNonAAFillRectBatch.cpp |
| index 54edb7d7c925ed7eb58591e634862b5f3a36e796..63edbfbdff666d57a6d50cc52429dd8282520703 100644 |
| --- a/src/gpu/batches/GrNonAAFillRectBatch.cpp |
| +++ b/src/gpu/batches/GrNonAAFillRectBatch.cpp |
| @@ -34,6 +34,13 @@ public: |
| static void SetBounds(const Geometry& geo, SkRect* outBounds) { |
| geo.fViewMatrix.mapRect(outBounds, geo.fRect); |
| } |
| + |
| + template <typename Geometry> |
| + static void UpdateBounds(const Geometry& geo, SkRect* outBounds) { |
| + SkRect bounds = geo.fRect; |
| + geo.fViewMatrix.mapRect(&bounds); |
| + outBounds->join(bounds); |
| + } |
| }; |
| /** We always use per-vertex colors so that rects can be batched across color changes. Sometimes |
| @@ -187,16 +194,11 @@ public: |
| typedef GrTInstanceBatch<NonAAFillRectBatchImp> NonAAFillRectBatchSimple; |
| typedef GrTInstanceBatch<NonAAFillRectBatchPerspectiveImp> NonAAFillRectBatchPerspective; |
| -namespace GrNonAAFillRectBatch { |
| - |
| -GrDrawBatch* Create(GrColor color, |
| - const SkMatrix& viewMatrix, |
| - const SkRect& rect, |
| - const SkRect* localRect, |
| - const SkMatrix* localMatrix) { |
| +static void append_to_batch(NonAAFillRectBatchSimple* batch, GrColor color, |
| + const SkMatrix& viewMatrix, const SkRect& rect, const SkRect* localRect, |
| + const SkMatrix* localMatrix) { |
| SkASSERT(!viewMatrix.hasPerspective() && (!localMatrix || !localMatrix->hasPerspective())); |
| - NonAAFillRectBatchSimple* batch = NonAAFillRectBatchSimple::Create(); |
| - NonAAFillRectBatchSimple::Geometry& geo = *batch->geometry(); |
| + NonAAFillRectBatchSimple::Geometry& geo = batch->geoData()->push_back(); |
| geo.fColor = color; |
| geo.fViewMatrix = viewMatrix; |
| @@ -211,19 +213,13 @@ GrDrawBatch* Create(GrColor color, |
| } else { |
| geo.fLocalQuad.set(rect); |
| } |
| - |
| - batch->init(); |
| - return batch; |
| } |
| -GrDrawBatch* CreateWithPerspective(GrColor color, |
| - const SkMatrix& viewMatrix, |
| - const SkRect& rect, |
| - const SkRect* localRect, |
| - const SkMatrix* localMatrix) { |
| +static void append_to_batch(NonAAFillRectBatchPerspective* batch, GrColor color, |
| + const SkMatrix& viewMatrix, const SkRect& rect, const SkRect* localRect, |
| + const SkMatrix* localMatrix) { |
| SkASSERT(viewMatrix.hasPerspective() || (localMatrix && localMatrix->hasPerspective())); |
| - NonAAFillRectBatchPerspective* batch = NonAAFillRectBatchPerspective::Create(); |
| - NonAAFillRectBatchPerspective::Geometry& geo = *batch->geometry(); |
| + NonAAFillRectBatchPerspective::Geometry& geo = batch->geoData()->push_back(); |
| geo.fColor = color; |
| geo.fViewMatrix = viewMatrix; |
| @@ -237,10 +233,65 @@ GrDrawBatch* CreateWithPerspective(GrColor color, |
| geo.fLocalRect = *localRect; |
| } |
| +} |
| + |
| +namespace GrNonAAFillRectBatch { |
| + |
| +GrDrawBatch* Create(GrColor color, |
| + const SkMatrix& viewMatrix, |
| + const SkRect& rect, |
| + const SkRect* localRect, |
| + const SkMatrix* localMatrix) { |
| + NonAAFillRectBatchSimple* batch = NonAAFillRectBatchSimple::Create(); |
| + append_to_batch(batch, color, viewMatrix, rect, localRect, localMatrix); |
| + batch->init(); |
| + return batch; |
| +} |
| + |
| +GrDrawBatch* CreateWithPerspective(GrColor color, |
| + const SkMatrix& viewMatrix, |
| + const SkRect& rect, |
| + const SkRect* localRect, |
| + const SkMatrix* localMatrix) { |
| + NonAAFillRectBatchPerspective* batch = NonAAFillRectBatchPerspective::Create(); |
| + append_to_batch(batch, color, viewMatrix, rect, localRect, localMatrix); |
| batch->init(); |
| return batch; |
| } |
| +bool Append(GrBatch* origBatch, |
| + GrColor color, |
| + const SkMatrix& viewMatrix, |
| + const SkRect& rect, |
| + const SkRect* localRect, |
| + const SkMatrix* localMatrix) { |
| + bool usePerspective = viewMatrix.hasPerspective() || |
| + (localMatrix && localMatrix->hasPerspective()); |
| + |
| + if (usePerspective && origBatch->classID() != NonAAFillRectBatchPerspective::ClassID()) { |
| + return false; |
| + } |
| + |
| + if (!usePerspective) { |
| + NonAAFillRectBatchSimple* batch = origBatch->cast<NonAAFillRectBatchSimple>(); |
| + append_to_batch(batch, color, viewMatrix, rect, localRect, localMatrix); |
| + batch->updateBounds(); |
| + } else { |
| + NonAAFillRectBatchPerspective* batch = origBatch->cast<NonAAFillRectBatchPerspective>(); |
| + const NonAAFillRectBatchPerspective::Geometry& geo = batch->geoData()->back(); |
| + |
| + if (!geo.fViewMatrix.cheapEqualTo(viewMatrix) || |
|
robertphillips
2015/09/18 17:42:25
What happens if localMatrix is NULL but geo has on
joshualitt
2015/09/18 18:34:10
Acknowledged.
|
| + (geo.fHasLocalMatrix && !geo.fLocalMatrix.cheapEqualTo(*localMatrix))) { |
| + return false; |
| + } |
| + |
| + append_to_batch(batch, color, viewMatrix, rect, localRect, localMatrix); |
| + batch->updateBounds(); |
| + } |
| + |
| + return true; |
| +} |
| + |
| }; |
| /////////////////////////////////////////////////////////////////////////////////////////////////// |