| Index: src/gpu/batches/GrNinePatch.cpp
|
| diff --git a/src/gpu/batches/GrNinePatch.cpp b/src/gpu/batches/GrNinePatch.cpp
|
| index cde3d266ca6f26b18ba0e797dbb489c79c09a01f..3417c5c0951d4c6794e875253dfd821c54b323af 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, 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);
|
| }
|
| };
|
|
|