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

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: Improve bench 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
« src/gpu/SkGpuDevice.cpp ('K') | « 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..d529e304447b3e4b1bed2c79eb257553e6c6e215 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,27 +80,27 @@ 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);
-
SkRect srcR, dstR;
- while (iter.next(&srcR, &dstR)) {
+ while (patch.fIter->next(&srcR, &dstR)) {
SkPoint* positions = reinterpret_cast<SkPoint*>(verts);
positions->setRectFan(dstR.fLeft, dstR.fTop,
@@ -151,14 +147,16 @@ private:
fOverrides = that->fOverrides;
}
- fPatches.push_back_n(that->fPatches.count(), that->fPatches.begin());
+ for (int i = 0; i < that->fPatches.count(); i++) {
+ fPatches.push_back(std::move(that->fPatches[i]));
bsalomon 2016/08/18 15:40:26 Should we have a bulk mover? move_back_n(T*, int)
msarett 2016/08/18 17:49:20 Yes! I've added one.
+ }
this->joinBounds(*that);
return true;
}
struct Patch {
SkMatrix fViewMatrix;
- SkIRect fCenter;
+ std::unique_ptr<SkLatticeIter> fIter;
SkRect fDst;
GrColor fColor;
};
@@ -173,7 +171,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);
}
};
« src/gpu/SkGpuDevice.cpp ('K') | « src/gpu/batches/GrNinePatch.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698