aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2015-09-18 13:03:25 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-09-18 13:03:25 -0700
commitaa37a96d554c5be7907ce04ee1ef843d0521eafb (patch)
tree71d7532775c9fd82feb6a8b762e1ad43af2ecb0a /src
parent2120b6f2cc3070b16800bfb2ff05cf114c8e40b9 (diff)
Create append methods in batch namespaces
Diffstat (limited to 'src')
-rw-r--r--src/gpu/batches/GrAAFillRectBatch.cpp60
-rw-r--r--src/gpu/batches/GrAAFillRectBatch.h14
-rw-r--r--src/gpu/batches/GrAAStrokeRectBatch.cpp83
-rw-r--r--src/gpu/batches/GrAAStrokeRectBatch.h9
-rw-r--r--src/gpu/batches/GrNonAAFillRectBatch.cpp91
-rw-r--r--src/gpu/batches/GrNonAAFillRectBatch.h6
-rw-r--r--src/gpu/batches/GrNonAAStrokeRectBatch.cpp85
-rw-r--r--src/gpu/batches/GrNonAAStrokeRectBatch.h6
-rw-r--r--src/gpu/batches/GrTInstanceBatch.h17
9 files changed, 280 insertions, 91 deletions
diff --git a/src/gpu/batches/GrAAFillRectBatch.cpp b/src/gpu/batches/GrAAFillRectBatch.cpp
index 69fd0ef65b..5b22422e10 100644
--- a/src/gpu/batches/GrAAFillRectBatch.cpp
+++ b/src/gpu/batches/GrAAFillRectBatch.cpp
@@ -199,6 +199,11 @@ public:
static void SetBounds(const Geometry& geo, SkRect* outBounds) {
*outBounds = geo.fDevRect;
}
+
+ template <class Geometry>
+ static void UpdateBoundsAfterAppend(const Geometry& geo, SkRect* outBounds) {
+ outBounds->join(geo.fDevRect);
+ }
};
class AAFillRectBatchNoLocalMatrixImp : public AAFillRectBatchBase {
@@ -283,6 +288,27 @@ public:
typedef GrTInstanceBatch<AAFillRectBatchNoLocalMatrixImp> AAFillRectBatchNoLocalMatrix;
typedef GrTInstanceBatch<AAFillRectBatchLocalMatrixImp> AAFillRectBatchLocalMatrix;
+inline static void append_to_batch(AAFillRectBatchNoLocalMatrix* batch, GrColor color,
+ const SkMatrix& viewMatrix, const SkRect& rect,
+ const SkRect& devRect) {
+ AAFillRectBatchNoLocalMatrix::Geometry& geo = batch->geoData()->push_back();
+ geo.fColor = color;
+ geo.fViewMatrix = viewMatrix;
+ geo.fRect = rect;
+ geo.fDevRect = devRect;
+}
+
+inline static void append_to_batch(AAFillRectBatchLocalMatrix* batch, GrColor color,
+ const SkMatrix& viewMatrix, const SkMatrix& localMatrix,
+ const SkRect& rect, const SkRect& devRect) {
+ AAFillRectBatchLocalMatrix::Geometry& geo = batch->geoData()->push_back();
+ geo.fColor = color;
+ geo.fViewMatrix = viewMatrix;
+ geo.fLocalMatrix = localMatrix;
+ geo.fRect = rect;
+ geo.fDevRect = devRect;
+}
+
namespace GrAAFillRectBatch {
GrDrawBatch* Create(GrColor color,
@@ -290,11 +316,7 @@ GrDrawBatch* Create(GrColor color,
const SkRect& rect,
const SkRect& devRect) {
AAFillRectBatchNoLocalMatrix* batch = AAFillRectBatchNoLocalMatrix::Create();
- AAFillRectBatchNoLocalMatrix::Geometry& geo = *batch->geometry();
- geo.fColor = color;
- geo.fViewMatrix = viewMatrix;
- geo.fRect = rect;
- geo.fDevRect = devRect;
+ append_to_batch(batch, color, viewMatrix, rect, devRect);
batch->init();
return batch;
}
@@ -305,16 +327,32 @@ GrDrawBatch* Create(GrColor color,
const SkRect& rect,
const SkRect& devRect) {
AAFillRectBatchLocalMatrix* batch = AAFillRectBatchLocalMatrix::Create();
- AAFillRectBatchLocalMatrix::Geometry& geo = *batch->geometry();
- geo.fColor = color;
- geo.fViewMatrix = viewMatrix;
- geo.fLocalMatrix = localMatrix;
- geo.fRect = rect;
- geo.fDevRect = devRect;
+ append_to_batch(batch, color, viewMatrix, localMatrix, rect, devRect);
batch->init();
return batch;
}
+void Append(GrBatch* origBatch,
+ GrColor color,
+ const SkMatrix& viewMatrix,
+ const SkRect& rect,
+ const SkRect& devRect) {
+ AAFillRectBatchNoLocalMatrix* batch = origBatch->cast<AAFillRectBatchNoLocalMatrix>();
+ append_to_batch(batch, color, viewMatrix, rect, devRect);
+ batch->updateBoundsAfterAppend();
+}
+
+void Append(GrBatch* origBatch,
+ GrColor color,
+ const SkMatrix& viewMatrix,
+ const SkMatrix& localMatrix,
+ const SkRect& rect,
+ const SkRect& devRect) {
+ AAFillRectBatchLocalMatrix* batch = origBatch->cast<AAFillRectBatchLocalMatrix>();
+ append_to_batch(batch, color, viewMatrix, localMatrix, rect, devRect);
+ batch->updateBoundsAfterAppend();
+}
+
};
///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/batches/GrAAFillRectBatch.h b/src/gpu/batches/GrAAFillRectBatch.h
index 5a657a3fa8..fcbae59058 100644
--- a/src/gpu/batches/GrAAFillRectBatch.h
+++ b/src/gpu/batches/GrAAFillRectBatch.h
@@ -10,6 +10,7 @@
#include "GrColor.h"
+class GrBatch;
class GrDrawBatch;
class SkMatrix;
struct SkRect;
@@ -25,6 +26,19 @@ GrDrawBatch* Create(GrColor color,
const SkMatrix& localMatrix,
const SkRect& rect,
const SkRect& devRect);
+
+void Append(GrBatch*,
+ GrColor,
+ const SkMatrix& viewMatrix,
+ const SkRect& rect,
+ const SkRect& devRect);
+
+void Append(GrBatch*,
+ GrColor,
+ const SkMatrix& viewMatrix,
+ const SkMatrix& localMatrix,
+ const SkRect& rect,
+ const SkRect& devRect);
};
#endif
diff --git a/src/gpu/batches/GrAAStrokeRectBatch.cpp b/src/gpu/batches/GrAAStrokeRectBatch.cpp
index 4472b0125b..0a9601f310 100644
--- a/src/gpu/batches/GrAAStrokeRectBatch.cpp
+++ b/src/gpu/batches/GrAAStrokeRectBatch.cpp
@@ -53,14 +53,10 @@ public:
SkRect fDevOutsideAssist;
SkRect fDevInside;
GrColor fColor;
- bool fMiterStroke;
};
- static GrDrawBatch* Create(GrColor color, const SkMatrix& viewMatrix, const SkRect& devOutside,
- const SkRect& devOutsideAssist, const SkRect& devInside,
- bool miterStroke) {
- return new AAStrokeRectBatch(color, viewMatrix, devOutside, devOutsideAssist, devInside,
- miterStroke);
+ static AAStrokeRectBatch* Create(const SkMatrix& viewMatrix, bool miterStroke) {
+ return new AAStrokeRectBatch(viewMatrix, miterStroke);
}
const char* name() const override { return "AAStrokeRect"; }
@@ -76,27 +72,46 @@ public:
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
-private:
- void onPrepareDraws(Target*) override;
- void initBatchTracker(const GrPipelineOptimizations&) override;
+ bool canAppend(const SkMatrix& viewMatrix, bool miterStroke) {
+ return fViewMatrix.cheapEqualTo(viewMatrix) && fMiterStroke == miterStroke;
+ }
- AAStrokeRectBatch(GrColor color, const SkMatrix& viewMatrix, const SkRect& devOutside,
- const SkRect& devOutsideAssist, const SkRect& devInside, bool miterStroke)
- : INHERITED(ClassID()) {
- fBatch.fViewMatrix = viewMatrix;
+ void append(GrColor color, const SkRect& devOutside, const SkRect& devOutsideAssist,
+ const SkRect& devInside) {
Geometry& geometry = fGeoData.push_back();
geometry.fColor = color;
geometry.fDevOutside = devOutside;
geometry.fDevOutsideAssist = devOutsideAssist;
geometry.fDevInside = devInside;
- geometry.fMiterStroke = miterStroke;
+ }
+ void appendAndUpdateBounds(GrColor color, const SkRect& devOutside,
+ const SkRect& devOutsideAssist, const SkRect& devInside) {
+ this->append(color, devOutside, devOutsideAssist, devInside);
+
+ SkRect bounds;
+ this->updateBounds(&bounds, fGeoData.back());
+ this->joinBounds(bounds);
+ }
+
+ void init() { this->updateBounds(&fBounds, fGeoData[0]); }
+
+private:
+ void updateBounds(SkRect* bounds, const Geometry& geo) {
// If we have miterstroke then we inset devOutside and outset devOutsideAssist, so we need
// the join for proper bounds
- fBounds = geometry.fDevOutside;
- fBounds.join(geometry.fDevOutsideAssist);
+ *bounds = geo.fDevOutside;
+ bounds->join(geo.fDevOutsideAssist);
}
+ void onPrepareDraws(Target*) override;
+ void initBatchTracker(const GrPipelineOptimizations&) override;
+
+ AAStrokeRectBatch(const SkMatrix& viewMatrix,bool miterStroke)
+ : INHERITED(ClassID()) {
+ fViewMatrix = viewMatrix;
+ fMiterStroke = miterStroke;
+ }
static const int kMiterIndexCnt = 3 * 24;
static const int kMiterVertexCnt = 16;
@@ -113,9 +128,10 @@ private:
bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; }
bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCoverage; }
bool colorIgnored() const { return fBatch.fColorIgnored; }
- const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; }
- bool miterStroke() const { return fBatch.fMiterStroke; }
bool coverageIgnored() const { return fBatch.fCoverageIgnored; }
+ const Geometry& geometry() const { return fGeoData[0]; }
+ const SkMatrix& viewMatrix() const { return fViewMatrix; }
+ bool miterStroke() const { return fMiterStroke; }
bool onCombineIfPossible(GrBatch* t, const GrCaps&) override;
@@ -132,17 +148,17 @@ private:
bool tweakAlphaForCoverage) const;
struct BatchTracker {
- SkMatrix fViewMatrix;
GrColor fColor;
bool fUsesLocalCoords;
bool fColorIgnored;
bool fCoverageIgnored;
- bool fMiterStroke;
bool fCanTweakAlphaForCoverage;
};
BatchTracker fBatch;
SkSTArray<1, Geometry, true> fGeoData;
+ SkMatrix fViewMatrix;
+ bool fMiterStroke;
typedef GrVertexBatch INHERITED;
};
@@ -159,7 +175,6 @@ void AAStrokeRectBatch::initBatchTracker(const GrPipelineOptimizations& opt) {
fBatch.fColor = fGeoData[0].fColor;
fBatch.fUsesLocalCoords = opt.readsLocalCoords();
fBatch.fCoverageIgnored = !opt.readsCoverage();
- fBatch.fMiterStroke = fGeoData[0].fMiterStroke;
fBatch.fCanTweakAlphaForCoverage = opt.canTweakAlphaForCoverage();
}
@@ -210,7 +225,7 @@ void AAStrokeRectBatch::onPrepareDraws(Target* target) {
args.fDevOutside,
args.fDevOutsideAssist,
args.fDevInside,
- args.fMiterStroke,
+ fMiterStroke,
canTweakAlphaForCoverage);
}
helper.recordDraw(target);
@@ -462,8 +477,28 @@ GrDrawBatch* Create(GrColor color,
const SkRect& devOutsideAssist,
const SkRect& devInside,
bool miterStroke) {
- return AAStrokeRectBatch::Create(color, viewMatrix, devOutside, devOutsideAssist, devInside,
- miterStroke);
+ AAStrokeRectBatch* batch = AAStrokeRectBatch::Create(viewMatrix, miterStroke);
+ batch->append(color, devOutside, devOutsideAssist, devInside);
+ batch->init();
+ return batch;
+}
+
+bool Append(GrBatch* origBatch,
+ GrColor color,
+ const SkMatrix& viewMatrix,
+ const SkRect& devOutside,
+ const SkRect& devOutsideAssist,
+ const SkRect& devInside,
+ bool miterStroke) {
+ AAStrokeRectBatch* batch = origBatch->cast<AAStrokeRectBatch>();
+
+ // we can't batch across vm changes
+ if (!batch->canAppend(viewMatrix, miterStroke)) {
+ return false;
+ }
+
+ batch->appendAndUpdateBounds(color, devOutside, devOutsideAssist, devInside);
+ return true;
}
};
diff --git a/src/gpu/batches/GrAAStrokeRectBatch.h b/src/gpu/batches/GrAAStrokeRectBatch.h
index 23f160ec9f..1af4f15dca 100644
--- a/src/gpu/batches/GrAAStrokeRectBatch.h
+++ b/src/gpu/batches/GrAAStrokeRectBatch.h
@@ -10,6 +10,7 @@
#include "GrColor.h"
+class GrBatch;
class GrDrawBatch;
class GrResourceProvider;
class SkMatrix;
@@ -24,6 +25,14 @@ GrDrawBatch* Create(GrColor color,
const SkRect& devInside,
bool miterStroke);
+bool Append(GrBatch*,
+ GrColor color,
+ const SkMatrix& viewMatrix,
+ const SkRect& devOutside,
+ const SkRect& devOutsideAssist,
+ const SkRect& devInside,
+ bool miterStroke);
+
};
#endif
diff --git a/src/gpu/batches/GrNonAAFillRectBatch.cpp b/src/gpu/batches/GrNonAAFillRectBatch.cpp
index 765d0dafa8..545bfdc973 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 UpdateBoundsAfterAppend(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
@@ -188,16 +195,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) {
+inline 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;
@@ -212,19 +214,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) {
+inline 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;
@@ -238,10 +234,67 @@ 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->updateBoundsAfterAppend();
+ } else {
+ NonAAFillRectBatchPerspective* batch = origBatch->cast<NonAAFillRectBatchPerspective>();
+ const NonAAFillRectBatchPerspective::Geometry& geo = batch->geoData()->back();
+
+ if (!geo.fViewMatrix.cheapEqualTo(viewMatrix) ||
+ geo.fHasLocalRect != SkToBool(localRect) ||
+ geo.fHasLocalMatrix != SkToBool(localMatrix) ||
+ (geo.fHasLocalMatrix && !geo.fLocalMatrix.cheapEqualTo(*localMatrix))) {
+ return false;
+ }
+
+ append_to_batch(batch, color, viewMatrix, rect, localRect, localMatrix);
+ batch->updateBoundsAfterAppend();
+ }
+
+ return true;
+}
+
};
///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/batches/GrNonAAFillRectBatch.h b/src/gpu/batches/GrNonAAFillRectBatch.h
index ac28d0fb46..aeb388f510 100644
--- a/src/gpu/batches/GrNonAAFillRectBatch.h
+++ b/src/gpu/batches/GrNonAAFillRectBatch.h
@@ -28,6 +28,12 @@ GrDrawBatch* CreateWithPerspective(GrColor color,
const SkRect* localRect,
const SkMatrix* localMatrix);
+bool Append(GrColor color,
+ const SkMatrix& viewMatrix,
+ const SkRect& rect,
+ const SkRect* localRect,
+ const SkMatrix* localMatrix);
+
};
#endif
diff --git a/src/gpu/batches/GrNonAAStrokeRectBatch.cpp b/src/gpu/batches/GrNonAAStrokeRectBatch.cpp
index 2c5194241a..a5de607c81 100644
--- a/src/gpu/batches/GrNonAAStrokeRectBatch.cpp
+++ b/src/gpu/batches/GrNonAAStrokeRectBatch.cpp
@@ -48,9 +48,8 @@ public:
GrColor fColor;
};
- static GrDrawBatch* Create(GrColor color, const SkMatrix& viewMatrix, const SkRect& rect,
- SkScalar strokeWidth, bool snapToPixelCenters) {
- return new NonAAStrokeRectBatch(color, viewMatrix, rect, strokeWidth, snapToPixelCenters);
+ static NonAAStrokeRectBatch* Create() {
+ return new NonAAStrokeRectBatch;
}
const char* name() const override { return "GrStrokeRectBatch"; }
@@ -64,7 +63,45 @@ public:
out->setKnownSingleComponent(0xff);
}
+ void append(GrColor color, const SkMatrix& viewMatrix, const SkRect& rect,
+ SkScalar strokeWidth) {
+ Geometry& geometry = fGeoData.push_back();
+ geometry.fViewMatrix = viewMatrix;
+ geometry.fRect = rect;
+ geometry.fStrokeWidth = strokeWidth;
+ geometry.fColor = color;
+ }
+
+ void appendAndUpdateBounds(GrColor color, const SkMatrix& viewMatrix, const SkRect& rect,
+ SkScalar strokeWidth, bool snapToPixelCenters) {
+ this->append(color, viewMatrix, rect, strokeWidth);
+
+ SkRect bounds;
+ this->setupBounds(&bounds, fGeoData.back(), snapToPixelCenters);
+ this->joinBounds(bounds);
+ }
+
+ void init(bool snapToPixelCenters) {
+ const Geometry& geo = fGeoData[0];
+ fBatch.fHairline = geo.fStrokeWidth == 0;
+
+ // setup bounds
+ this->setupBounds(&fBounds, geo, snapToPixelCenters);
+ }
+
private:
+ void setupBounds(SkRect* bounds, const Geometry& geo, bool snapToPixelCenters) {
+ *bounds = geo.fRect;
+ SkScalar rad = SkScalarHalf(geo.fStrokeWidth);
+ bounds->outset(rad, rad);
+ geo.fViewMatrix.mapRect(&fBounds);
+
+ // If our caller snaps to pixel centers then we have to round out the bounds
+ if (snapToPixelCenters) {
+ bounds->roundOut();
+ }
+ }
+
void onPrepareDraws(Target* target) override {
SkAutoTUnref<const GrGeometryProcessor> gp;
{
@@ -139,30 +176,7 @@ private:
fBatch.fCoverageIgnored = !opt.readsCoverage();
}
- NonAAStrokeRectBatch(GrColor color, const SkMatrix& viewMatrix, const SkRect& rect,
- SkScalar strokeWidth, bool snapToPixelCenters)
- : INHERITED(ClassID()) {
- Geometry& geometry = fGeoData.push_back();
- geometry.fViewMatrix = viewMatrix;
- geometry.fRect = rect;
- geometry.fStrokeWidth = strokeWidth;
- geometry.fColor = color;
-
- fBatch.fHairline = geometry.fStrokeWidth == 0;
-
- fGeoData.push_back(geometry);
-
- // setup bounds
- fBounds = geometry.fRect;
- SkScalar rad = SkScalarHalf(geometry.fStrokeWidth);
- fBounds.outset(rad, rad);
- geometry.fViewMatrix.mapRect(&fBounds);
-
- // If our caller snaps to pixel centers then we have to round out the bounds
- if (snapToPixelCenters) {
- fBounds.roundOut();
- }
- }
+ NonAAStrokeRectBatch() : INHERITED(ClassID()) {}
GrColor color() const { return fBatch.fColor; }
bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; }
@@ -207,7 +221,20 @@ GrDrawBatch* Create(GrColor color,
const SkRect& rect,
SkScalar strokeWidth,
bool snapToPixelCenters) {
- return NonAAStrokeRectBatch::Create(color, viewMatrix, rect, strokeWidth, snapToPixelCenters);
+ NonAAStrokeRectBatch* batch = NonAAStrokeRectBatch::Create();
+ batch->append(color, viewMatrix, rect, strokeWidth);
+ batch->init(snapToPixelCenters);
+ return batch;
+}
+
+void Append(GrBatch* origBatch,
+ GrColor color,
+ const SkMatrix& viewMatrix,
+ const SkRect& rect,
+ SkScalar strokeWidth,
+ bool snapToPixelCenters) {
+ NonAAStrokeRectBatch* batch = origBatch->cast<NonAAStrokeRectBatch>();
+ batch->appendAndUpdateBounds(color, viewMatrix, rect, strokeWidth, snapToPixelCenters);
}
};
@@ -220,7 +247,7 @@ DRAW_BATCH_TEST_DEFINE(NonAAStrokeRectBatch) {
SkRect rect = GrTest::TestRect(random);
SkScalar strokeWidth = random->nextBool() ? 0.0f : 1.0f;
- return NonAAStrokeRectBatch::Create(color, viewMatrix, rect, strokeWidth, random->nextBool());
+ return GrNonAAStrokeRectBatch::Create(color, viewMatrix, rect, strokeWidth, random->nextBool());
}
#endif
diff --git a/src/gpu/batches/GrNonAAStrokeRectBatch.h b/src/gpu/batches/GrNonAAStrokeRectBatch.h
index ed26353fb6..3cee47dedd 100644
--- a/src/gpu/batches/GrNonAAStrokeRectBatch.h
+++ b/src/gpu/batches/GrNonAAStrokeRectBatch.h
@@ -24,6 +24,12 @@ GrDrawBatch* Create(GrColor color,
SkScalar strokeWidth,
bool snapToPixelCenters);
+void Append(GrColor color,
+ const SkMatrix& viewMatrix,
+ const SkRect& rect,
+ SkScalar strokeWidth,
+ bool snapToPixelCenters);
+
};
#endif
diff --git a/src/gpu/batches/GrTInstanceBatch.h b/src/gpu/batches/GrTInstanceBatch.h
index 014ec125fe..b4bc0c084f 100644
--- a/src/gpu/batches/GrTInstanceBatch.h
+++ b/src/gpu/batches/GrTInstanceBatch.h
@@ -26,6 +26,8 @@
*
* void SetBounds(const Geometry& seedGeometry, SkRect* outBounds)
*
+ * void UpdateBoundsAfterAppend(const Geometry& lastGeometry, SkRect* currentBounds)
+ *
* bool CanCombine(const Geometry& mine, const Geometry& theirs,
* const GrPipelineOptimizations&)
*
@@ -64,21 +66,20 @@ public:
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
- // to avoid even the initial copy of the struct, we have a getter for the first item which
- // is used to seed the batch with its initial geometry. After seeding, the client should call
- // init() so the Batch can initialize itself
- Geometry* geometry() { return &fGeoData[0]; }
+ // After seeding, the client should call init() so the Batch can initialize itself
void init() {
const Geometry& geo = fGeoData[0];
Impl::SetBounds(geo, &fBounds);
}
-private:
- GrTInstanceBatch() : INHERITED(ClassID()) {
- // Push back an initial geometry
- fGeoData.push_back();
+ void updateBoundsAfterAppend() {
+ const Geometry& geo = fGeoData.back();
+ Impl::UpdateBoundsAfterAppend(geo, &fBounds);
}
+private:
+ GrTInstanceBatch() : INHERITED(ClassID()) {}
+
void onPrepareDraws(Target* target) override {
SkAutoTUnref<const GrGeometryProcessor> gp(Impl::CreateGP(this->seedGeometry(), fOpts));
if (!gp) {