Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Unified Diff: src/gpu/batches/GrNinePatch.cpp

Issue 2255963002: Batched implementation of drawLattice() for GPU (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Speculative reland Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/batches/GrNinePatch.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
};
« no previous file with comments | « src/gpu/batches/GrNinePatch.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698