Hide GrNonAANinePatchBatch::Geometry and rename to Patch
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2111943002 Review-Url: https://codereview.chromium.org/2111943002
This commit is contained in:
parent
50c56a39db
commit
a71b89866d
@ -31,27 +31,20 @@ public:
|
||||
static const int kIndicesPerRect = 6;
|
||||
static const int kRectsPerInstance = 9; // We could skip empty rects
|
||||
|
||||
struct Geometry {
|
||||
SkMatrix fViewMatrix;
|
||||
SkIRect fCenter;
|
||||
SkRect fDst;
|
||||
GrColor fColor;
|
||||
};
|
||||
|
||||
GrNonAANinePatchBatch(GrColor color, const SkMatrix& viewMatrix, int imageWidth,
|
||||
int imageHeight, const SkIRect& center, const SkRect &dst)
|
||||
: INHERITED(ClassID()) {
|
||||
Geometry& geo = fGeoData.push_back();
|
||||
geo.fViewMatrix = viewMatrix;
|
||||
geo.fColor = color;
|
||||
geo.fCenter = center;
|
||||
geo.fDst = dst;
|
||||
Patch& patch = fPatches.push_back();
|
||||
patch.fViewMatrix = viewMatrix;
|
||||
patch.fColor = color;
|
||||
patch.fCenter = center;
|
||||
patch.fDst = dst;
|
||||
|
||||
fImageWidth = imageWidth;
|
||||
fImageHeight = imageHeight;
|
||||
|
||||
// setup bounds
|
||||
geo.fViewMatrix.mapRect(&fBounds, geo.fDst);
|
||||
patch.fViewMatrix.mapRect(&fBounds, patch.fDst);
|
||||
}
|
||||
|
||||
const char* name() const override { return "NonAANinePatchBatch"; }
|
||||
@ -59,15 +52,15 @@ public:
|
||||
SkString dumpInfo() const override {
|
||||
SkString str;
|
||||
|
||||
for (int i = 0; i < fGeoData.count(); ++i) {
|
||||
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",
|
||||
i,
|
||||
fGeoData[i].fColor,
|
||||
fGeoData[i].fCenter.fLeft, fGeoData[i].fCenter.fTop,
|
||||
fGeoData[i].fCenter.fRight, fGeoData[i].fCenter.fBottom,
|
||||
fGeoData[i].fDst.fLeft, fGeoData[i].fDst.fTop,
|
||||
fGeoData[i].fDst.fRight, fGeoData[i].fDst.fBottom);
|
||||
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);
|
||||
}
|
||||
|
||||
str.append(INHERITED::dumpInfo());
|
||||
@ -81,8 +74,6 @@ public:
|
||||
coverage->setKnownSingleComponent(0xff);
|
||||
}
|
||||
|
||||
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
|
||||
|
||||
private:
|
||||
void onPrepareDraws(Target* target) const override {
|
||||
sk_sp<GrGeometryProcessor> gp(create_gp(fOverrides.readsCoverage()));
|
||||
@ -92,25 +83,25 @@ private:
|
||||
}
|
||||
|
||||
size_t vertexStride = gp->getVertexStride();
|
||||
int instanceCount = fGeoData.count();
|
||||
int patchCnt = fPatches.count();
|
||||
|
||||
SkAutoTUnref<const GrBuffer> indexBuffer(
|
||||
target->resourceProvider()->refQuadIndexBuffer());
|
||||
InstancedHelper helper;
|
||||
void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexStride,
|
||||
indexBuffer, kVertsPerRect,
|
||||
kIndicesPerRect, instanceCount * kRectsPerInstance);
|
||||
kIndicesPerRect, patchCnt * kRectsPerInstance);
|
||||
if (!vertices || !indexBuffer) {
|
||||
SkDebugf("Could not allocate vertices\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < instanceCount; i++) {
|
||||
for (int i = 0; i < patchCnt; i++) {
|
||||
intptr_t verts = reinterpret_cast<intptr_t>(vertices) +
|
||||
i * kRectsPerInstance * kVertsPerRect * vertexStride;
|
||||
|
||||
const Geometry& geo = fGeoData[i];
|
||||
SkNinePatchIter iter(fImageWidth, fImageHeight, geo.fCenter, geo.fDst);
|
||||
const Patch& patch = fPatches[i];
|
||||
SkNinePatchIter iter(fImageWidth, fImageHeight, patch.fCenter, patch.fDst);
|
||||
|
||||
SkRect srcR, dstR;
|
||||
while (iter.next(&srcR, &dstR)) {
|
||||
@ -119,8 +110,8 @@ private:
|
||||
positions->setRectFan(dstR.fLeft, dstR.fTop,
|
||||
dstR.fRight, dstR.fBottom, vertexStride);
|
||||
|
||||
SkASSERT(!geo.fViewMatrix.hasPerspective());
|
||||
geo.fViewMatrix.mapPointsWithStride(positions, vertexStride, kVertsPerRect);
|
||||
SkASSERT(!patch.fViewMatrix.hasPerspective());
|
||||
patch.fViewMatrix.mapPointsWithStride(positions, vertexStride, kVertsPerRect);
|
||||
|
||||
// Setup local coords
|
||||
static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor);
|
||||
@ -130,7 +121,7 @@ private:
|
||||
static const int kColorOffset = sizeof(SkPoint);
|
||||
GrColor* vertColor = reinterpret_cast<GrColor*>(verts + kColorOffset);
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
*vertColor = geo.fColor;
|
||||
*vertColor = patch.fColor;
|
||||
vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride);
|
||||
}
|
||||
verts += kVertsPerRect * vertexStride;
|
||||
@ -140,7 +131,7 @@ private:
|
||||
}
|
||||
|
||||
void initBatchTracker(const GrXPOverridesForBatch& overrides) override {
|
||||
overrides.getOverrideColorIfSet(&fGeoData[0].fColor);
|
||||
overrides.getOverrideColorIfSet(&fPatches[0].fColor);
|
||||
fOverrides = overrides;
|
||||
}
|
||||
|
||||
@ -160,15 +151,22 @@ private:
|
||||
fOverrides = that->fOverrides;
|
||||
}
|
||||
|
||||
fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin());
|
||||
fPatches.push_back_n(that->fPatches.count(), that->fPatches.begin());
|
||||
this->joinBounds(that->bounds());
|
||||
return true;
|
||||
}
|
||||
|
||||
struct Patch {
|
||||
SkMatrix fViewMatrix;
|
||||
SkIRect fCenter;
|
||||
SkRect fDst;
|
||||
GrColor fColor;
|
||||
};
|
||||
|
||||
GrXPOverridesForBatch fOverrides;
|
||||
int fImageWidth;
|
||||
int fImageHeight;
|
||||
SkSTArray<1, Geometry, true> fGeoData;
|
||||
SkSTArray<1, Patch, true> fPatches;
|
||||
|
||||
typedef GrVertexBatch INHERITED;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user