aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/batches/GrNinePatch.cpp
diff options
context:
space:
mode:
authorGravatar msarett <msarett@google.com>2016-08-18 13:11:48 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-08-18 13:11:48 -0700
commit93242c4ae50dfcc0d922cdb3ba80bbc7b4bbe93d (patch)
treed7b490c01fd5570351244b65fe7ec110d02a699b /src/gpu/batches/GrNinePatch.cpp
parent3aafe111b6cc388400092851cc53bbbdfcb8a81c (diff)
Batched implementation of drawLattice() for GPU
Bechmarks (Nexus 6P): Src=100x100, Dst=250x250, NumRects=9 Android 77.7us Skia (without patch) 57.2us Skia (with patch) 34.7us Src=100x100, Dst=500x500, NumRects=9 Android 77.0us Skia (without patch) 56.9us Skia (with patch) 44.5us Src=100x100, Dst=1000x1000, NumRects=9 Android 180us Skia (without patch) 96.8us Skia (with patch) 70.5us Src=100x100, Dst=250x250, NumRects=15 Android 208us Skia (without patch) 155us Skia (with patch) 55.9us Src=100x100, Dst=500x500, NumRects=15 Android 207us Skia (without patch) 152us Skia (with patch) 63.0us Src=100x100, Dst=1000x1000, NumRects=15 Android 233us Skia (without patch) 156us Skia (with patch) 99.9us BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2255963002 Review-Url: https://codereview.chromium.org/2255963002
Diffstat (limited to 'src/gpu/batches/GrNinePatch.cpp')
-rw-r--r--src/gpu/batches/GrNinePatch.cpp51
1 files changed, 30 insertions, 21 deletions
diff --git a/src/gpu/batches/GrNinePatch.cpp b/src/gpu/batches/GrNinePatch.cpp
index cde3d266ca..729d27ecac 100644
--- a/src/gpu/batches/GrNinePatch.cpp
+++ b/src/gpu/batches/GrNinePatch.cpp
@@ -29,15 +29,14 @@ public:
static const int kVertsPerRect = 4;
static const int kIndicesPerRect = 6;
- static const int kRectsPerInstance = 9; // We could skip empty rects
GrNonAANinePatchBatch(GrColor color, const SkMatrix& viewMatrix, int imageWidth,
- int imageHeight, const SkIRect& center, const SkRect &dst)
+ int imageHeight, std::unique_ptr<SkLatticeIter> iter, const SkRect &dst)
: INHERITED(ClassID()) {
Patch& patch = fPatches.push_back();
patch.fViewMatrix = viewMatrix;
patch.fColor = color;
- patch.fCenter = center;
+ patch.fIter = std::move(iter);
patch.fDst = dst;
fImageWidth = imageWidth;
@@ -53,12 +52,9 @@ public:
SkString str;
for (int i = 0; i < fPatches.count(); ++i) {
- str.appendf("%d: Color: 0x%08x Center [L: %d, T: %d, R: %d, B: %d], "
- "Dst [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
+ str.appendf("%d: Color: 0x%08x Dst [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
i,
fPatches[i].fColor,
- fPatches[i].fCenter.fLeft, fPatches[i].fCenter.fTop,
- fPatches[i].fCenter.fRight, fPatches[i].fCenter.fBottom,
fPatches[i].fDst.fLeft, fPatches[i].fDst.fTop,
fPatches[i].fDst.fRight, fPatches[i].fDst.fBottom);
}
@@ -84,35 +80,40 @@ private:
size_t vertexStride = gp->getVertexStride();
int patchCnt = fPatches.count();
+ int numRects = 0;
+ for (int i = 0; i < patchCnt; i++) {
+ numRects += fPatches[i].fIter->numRects();
+ }
SkAutoTUnref<const GrBuffer> indexBuffer(
target->resourceProvider()->refQuadIndexBuffer());
InstancedHelper helper;
void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexStride,
indexBuffer, kVertsPerRect,
- kIndicesPerRect, patchCnt * kRectsPerInstance);
+ kIndicesPerRect, patchCnt * numRects);
if (!vertices || !indexBuffer) {
SkDebugf("Could not allocate vertices\n");
return;
}
+ intptr_t verts = reinterpret_cast<intptr_t>(vertices);
for (int i = 0; i < patchCnt; i++) {
- intptr_t verts = reinterpret_cast<intptr_t>(vertices) +
- i * kRectsPerInstance * kVertsPerRect * vertexStride;
-
const Patch& patch = fPatches[i];
- SkLatticeIter iter(fImageWidth, fImageHeight, patch.fCenter, patch.fDst);
+
+ // Apply the view matrix here if it is scale-translate. Otherwise, we need to
+ // wait until we've created the dst rects.
+ bool isScaleTranslate = patch.fViewMatrix.isScaleTranslate();
+ if (isScaleTranslate) {
+ patch.fIter->mapDstScaleTranslate(patch.fViewMatrix);
+ }
SkRect srcR, dstR;
- while (iter.next(&srcR, &dstR)) {
+ intptr_t patchVerts = verts;
+ while (patch.fIter->next(&srcR, &dstR)) {
SkPoint* positions = reinterpret_cast<SkPoint*>(verts);
-
positions->setRectFan(dstR.fLeft, dstR.fTop,
dstR.fRight, dstR.fBottom, vertexStride);
- SkASSERT(!patch.fViewMatrix.hasPerspective());
- patch.fViewMatrix.mapPointsWithStride(positions, vertexStride, kVertsPerRect);
-
// Setup local coords
static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor);
SkPoint* coords = reinterpret_cast<SkPoint*>(verts + kLocalOffset);
@@ -126,6 +127,13 @@ private:
}
verts += kVertsPerRect * vertexStride;
}
+
+ // If we didn't handle it above, apply the matrix here.
+ if (!isScaleTranslate) {
+ SkPoint* positions = reinterpret_cast<SkPoint*>(patchVerts);
+ patch.fViewMatrix.mapPointsWithStride(positions, vertexStride,
+ kVertsPerRect * patch.fIter->numRects());
+ }
}
helper.recordDraw(target, gp.get());
}
@@ -151,14 +159,14 @@ private:
fOverrides = that->fOverrides;
}
- fPatches.push_back_n(that->fPatches.count(), that->fPatches.begin());
+ fPatches.move_back_n(that->fPatches.count(), that->fPatches.begin());
this->joinBounds(*that);
return true;
}
struct Patch {
SkMatrix fViewMatrix;
- SkIRect fCenter;
+ std::unique_ptr<SkLatticeIter> fIter;
SkRect fDst;
GrColor fColor;
};
@@ -173,7 +181,8 @@ private:
namespace GrNinePatch {
GrDrawBatch* CreateNonAA(GrColor color, const SkMatrix& viewMatrix, int imageWidth, int imageHeight,
- const SkIRect& center, const SkRect& dst) {
- return new GrNonAANinePatchBatch(color, viewMatrix, imageWidth, imageHeight, center, dst);
+ std::unique_ptr<SkLatticeIter> iter, const SkRect& dst) {
+ return new GrNonAANinePatchBatch(color, viewMatrix, imageWidth, imageHeight, std::move(iter),
+ dst);
}
};