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