Make onPrepareDraws const
BUG=skia: Review URL: https://codereview.chromium.org/1483103003
This commit is contained in:
parent
0cf5ecb67a
commit
144c3c8b7f
@ -70,7 +70,7 @@ private:
|
||||
return &fGeometry;
|
||||
}
|
||||
|
||||
void generateGeometry(Target* target) override {
|
||||
void generateGeometry(Target* target) const override {
|
||||
QuadHelper helper;
|
||||
size_t vertexStride = this->geometryProcessor()->getVertexStride();
|
||||
SkASSERT(vertexStride == sizeof(Vertex));
|
||||
@ -470,7 +470,7 @@ private:
|
||||
return &fGeometry;
|
||||
}
|
||||
|
||||
void generateGeometry(Target* target) override {
|
||||
void generateGeometry(Target* target) const override {
|
||||
QuadHelper helper;
|
||||
size_t vertexStride = this->geometryProcessor()->getVertexStride();
|
||||
SkASSERT(vertexStride == sizeof(Vertex));
|
||||
|
@ -45,6 +45,9 @@ private:
|
||||
ConvexPolyTestBatch(const GrGeometryProcessor* gp, const Geometry& geo)
|
||||
: INHERITED(ClassID(), gp, geo.fBounds)
|
||||
, fGeometry(geo) {
|
||||
// Make sure any artifacts around the exterior of path are visible by using overly
|
||||
// conservative bounding geometry.
|
||||
fGeometry.fBounds.outset(5.f, 5.f);
|
||||
}
|
||||
|
||||
Geometry* geoData(int index) override {
|
||||
@ -57,7 +60,7 @@ private:
|
||||
return &fGeometry;
|
||||
}
|
||||
|
||||
void generateGeometry(Target* target) override {
|
||||
void generateGeometry(Target* target) const override {
|
||||
size_t vertexStride = this->geometryProcessor()->getVertexStride();
|
||||
SkASSERT(vertexStride == sizeof(SkPoint));
|
||||
QuadHelper helper;
|
||||
@ -66,9 +69,6 @@ private:
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure any artifacts around the exterior of path are visible by using overly
|
||||
// conservative bounding geometry.
|
||||
fGeometry.fBounds.outset(5.f, 5.f);
|
||||
fGeometry.fBounds.toQuad(verts);
|
||||
|
||||
helper.recordDraw(target);
|
||||
|
@ -692,7 +692,7 @@ private:
|
||||
fBatch.fCoverageIgnored = !overrides.readsCoverage();
|
||||
}
|
||||
|
||||
void onPrepareDraws(Target* target) override {
|
||||
void onPrepareDraws(Target* target) const override {
|
||||
SkMatrix invert;
|
||||
if (!this->viewMatrix().invert(&invert)) {
|
||||
return;
|
||||
@ -717,7 +717,7 @@ private:
|
||||
}
|
||||
|
||||
for (int i = 0; i < instanceCount; i++) {
|
||||
Geometry& geom = fGeoData[i];
|
||||
const Geometry& geom = fGeoData[i];
|
||||
|
||||
SkScalar innerRadius = geom.fInnerRadius;
|
||||
SkScalar outerRadius = geom.fOuterRadius;
|
||||
@ -912,7 +912,7 @@ private:
|
||||
fBatch.fCoverageIgnored = !overrides.readsCoverage();
|
||||
}
|
||||
|
||||
void onPrepareDraws(Target* target) override {
|
||||
void onPrepareDraws(Target* target) const override {
|
||||
SkMatrix invert;
|
||||
if (!this->viewMatrix().invert(&invert)) {
|
||||
return;
|
||||
@ -937,7 +937,7 @@ private:
|
||||
}
|
||||
|
||||
for (int i = 0; i < instanceCount; i++) {
|
||||
Geometry& geom = fGeoData[i];
|
||||
const Geometry& geom = fGeoData[i];
|
||||
|
||||
SkScalar xRadius = geom.fXRadius;
|
||||
SkScalar yRadius = geom.fYRadius;
|
||||
@ -1185,7 +1185,7 @@ private:
|
||||
fBatch.fCoverageIgnored = !overrides.readsCoverage();
|
||||
}
|
||||
|
||||
void onPrepareDraws(Target* target) override {
|
||||
void onPrepareDraws(Target* target) const override {
|
||||
// Setup geometry processor
|
||||
SkAutoTUnref<GrGeometryProcessor> gp(DIEllipseEdgeEffect::Create(this->color(),
|
||||
this->viewMatrix(),
|
||||
@ -1205,7 +1205,7 @@ private:
|
||||
}
|
||||
|
||||
for (int i = 0; i < instanceCount; i++) {
|
||||
Geometry& geom = fGeoData[i];
|
||||
const Geometry& geom = fGeoData[i];
|
||||
|
||||
SkScalar xRadius = geom.fXRadius;
|
||||
SkScalar yRadius = geom.fYRadius;
|
||||
@ -1540,7 +1540,7 @@ private:
|
||||
fBatch.fCoverageIgnored = !overrides.readsCoverage();
|
||||
}
|
||||
|
||||
void onPrepareDraws(Target* target) override {
|
||||
void onPrepareDraws(Target* target) const override {
|
||||
// reset to device coordinates
|
||||
SkMatrix invert;
|
||||
if (!this->viewMatrix().invert(&invert)) {
|
||||
@ -1575,7 +1575,7 @@ private:
|
||||
}
|
||||
|
||||
for (int i = 0; i < instanceCount; i++) {
|
||||
Geometry& args = fGeoData[i];
|
||||
const Geometry& args = fGeoData[i];
|
||||
|
||||
SkScalar outerRadius = args.fOuterRadius;
|
||||
|
||||
@ -1720,7 +1720,7 @@ private:
|
||||
fBatch.fCoverageIgnored = !overrides.readsCoverage();
|
||||
}
|
||||
|
||||
void onPrepareDraws(Target* target) override {
|
||||
void onPrepareDraws(Target* target) const override {
|
||||
// reset to device coordinates
|
||||
SkMatrix invert;
|
||||
if (!this->viewMatrix().invert(&invert)) {
|
||||
@ -1755,7 +1755,7 @@ private:
|
||||
}
|
||||
|
||||
for (int i = 0; i < instanceCount; i++) {
|
||||
Geometry& args = fGeoData[i];
|
||||
const Geometry& args = fGeoData[i];
|
||||
|
||||
// Compute the reciprocals of the radii here to save time in the shader
|
||||
SkScalar xRadRecip = SkScalarInvert(args.fXRadius);
|
||||
|
@ -74,7 +74,7 @@ namespace GrPathUtils {
|
||||
* vertices is a pointer to the first vertex.
|
||||
*/
|
||||
template <int N, size_t STRIDE, size_t UV_OFFSET>
|
||||
void apply(const void* vertices) {
|
||||
void apply(const void* vertices) const {
|
||||
intptr_t xyPtr = reinterpret_cast<intptr_t>(vertices);
|
||||
intptr_t uvPtr = reinterpret_cast<intptr_t>(vertices) + UV_OFFSET;
|
||||
float sx = fM[0];
|
||||
|
@ -778,7 +778,7 @@ private:
|
||||
fBatch.fCanTweakAlphaForCoverage = overrides.canTweakAlphaForCoverage();
|
||||
}
|
||||
|
||||
void prepareLinesOnlyDraws(Target* target) {
|
||||
void prepareLinesOnlyDraws(Target* target) const {
|
||||
bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
|
||||
|
||||
// Setup GrGeometryProcessor
|
||||
@ -806,7 +806,7 @@ private:
|
||||
for (int i = 0; i < instanceCount; i++) {
|
||||
tess.rewind();
|
||||
|
||||
Geometry& args = fGeoData[i];
|
||||
const Geometry& args = fGeoData[i];
|
||||
|
||||
if (!tess.tessellate(args.fViewMatrix, args.fPath)) {
|
||||
continue;
|
||||
@ -842,7 +842,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void onPrepareDraws(Target* target) override {
|
||||
void onPrepareDraws(Target* target) const override {
|
||||
#ifndef SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS
|
||||
if (this->linesOnly()) {
|
||||
this->prepareLinesOnlyDraws(target);
|
||||
@ -866,15 +866,22 @@ private:
|
||||
|
||||
// TODO generate all segments for all paths and use one vertex buffer
|
||||
for (int i = 0; i < instanceCount; i++) {
|
||||
Geometry& args = fGeoData[i];
|
||||
const Geometry& args = fGeoData[i];
|
||||
|
||||
// We use the fact that SkPath::transform path does subdivision based on
|
||||
// perspective. Otherwise, we apply the view matrix when copying to the
|
||||
// segment representation.
|
||||
const SkMatrix* viewMatrix = &args.fViewMatrix;
|
||||
|
||||
// We avoid initializing the path unless we have to
|
||||
const SkPath* pathPtr = &args.fPath;
|
||||
SkTLazy<SkPath> tmpPath;
|
||||
if (viewMatrix->hasPerspective()) {
|
||||
args.fPath.transform(*viewMatrix);
|
||||
SkPath* tmpPathPtr = tmpPath.init(*pathPtr);
|
||||
tmpPathPtr->setIsVolatile(true);
|
||||
tmpPathPtr->transform(*viewMatrix);
|
||||
viewMatrix = &SkMatrix::I();
|
||||
pathPtr = tmpPathPtr;
|
||||
}
|
||||
|
||||
int vertexCount;
|
||||
@ -886,7 +893,7 @@ private:
|
||||
SkSTArray<kPreallocSegmentCnt, Segment, true> segments;
|
||||
SkPoint fanPt;
|
||||
|
||||
if (!get_segments(args.fPath, *viewMatrix, &segments, &fanPt, &vertexCount,
|
||||
if (!get_segments(*pathPtr, *viewMatrix, &segments, &fanPt, &vertexCount,
|
||||
&indexCount)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -143,7 +143,6 @@ public:
|
||||
uint32_t fGenID;
|
||||
SkStrokeRec fStroke;
|
||||
bool fAntiAlias;
|
||||
PathData* fPathData;
|
||||
};
|
||||
|
||||
static GrDrawBatch* Create(const Geometry& geometry, GrColor color, const SkMatrix& viewMatrix,
|
||||
@ -183,7 +182,7 @@ private:
|
||||
int fInstancesToFlush;
|
||||
};
|
||||
|
||||
void onPrepareDraws(Target* target) override {
|
||||
void onPrepareDraws(Target* target) const override {
|
||||
int instanceCount = fGeoData.count();
|
||||
|
||||
SkMatrix invert;
|
||||
@ -229,7 +228,7 @@ private:
|
||||
|
||||
flushInfo.fInstancesToFlush = 0;
|
||||
for (int i = 0; i < instanceCount; i++) {
|
||||
Geometry& args = fGeoData[i];
|
||||
const Geometry& args = fGeoData[i];
|
||||
|
||||
// get mip level
|
||||
SkScalar maxScale = this->viewMatrix().getMaxScale();
|
||||
@ -247,22 +246,22 @@ private:
|
||||
|
||||
// check to see if path is cached
|
||||
PathData::Key key(args.fGenID, desiredDimension, args.fStroke);
|
||||
args.fPathData = fPathCache->find(key);
|
||||
if (nullptr == args.fPathData || !atlas->hasID(args.fPathData->fID)) {
|
||||
PathData* pathData = fPathCache->find(key);
|
||||
if (nullptr == pathData || !atlas->hasID(pathData->fID)) {
|
||||
// Remove the stale cache entry
|
||||
if (args.fPathData) {
|
||||
fPathCache->remove(args.fPathData->fKey);
|
||||
fPathList->remove(args.fPathData);
|
||||
delete args.fPathData;
|
||||
if (pathData) {
|
||||
fPathCache->remove(pathData->fKey);
|
||||
fPathList->remove(pathData);
|
||||
delete pathData;
|
||||
}
|
||||
SkScalar scale = desiredDimension/maxDim;
|
||||
args.fPathData = new PathData;
|
||||
pathData = new PathData;
|
||||
if (!this->addPathToAtlas(target,
|
||||
dfProcessor,
|
||||
this->pipeline(),
|
||||
&flushInfo,
|
||||
atlas,
|
||||
args.fPathData,
|
||||
pathData,
|
||||
args.fPath,
|
||||
args.fGenID,
|
||||
args.fStroke,
|
||||
@ -274,7 +273,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
atlas->setLastUseToken(args.fPathData->fID, target->currentToken());
|
||||
atlas->setLastUseToken(pathData->fID, target->currentToken());
|
||||
|
||||
// Now set vertices
|
||||
intptr_t offset = reinterpret_cast<intptr_t>(vertices);
|
||||
@ -288,7 +287,7 @@ private:
|
||||
vertexStride,
|
||||
this->viewMatrix(),
|
||||
args.fPath,
|
||||
args.fPathData);
|
||||
pathData);
|
||||
flushInfo.fInstancesToFlush++;
|
||||
}
|
||||
|
||||
@ -304,7 +303,6 @@ private:
|
||||
fBatch.fColor = color;
|
||||
fBatch.fViewMatrix = viewMatrix;
|
||||
fGeoData.push_back(geometry);
|
||||
fGeoData.back().fPathData = nullptr;
|
||||
|
||||
fAtlas = atlas;
|
||||
fPathCache = pathCache;
|
||||
@ -326,7 +324,7 @@ private:
|
||||
const SkStrokeRec& stroke,
|
||||
bool antiAlias,
|
||||
uint32_t dimension,
|
||||
SkScalar scale) {
|
||||
SkScalar scale) const {
|
||||
const SkRect& bounds = path.getBounds();
|
||||
|
||||
// generate bounding rect for bitmap draw
|
||||
@ -443,7 +441,7 @@ private:
|
||||
size_t vertexStride,
|
||||
const SkMatrix& viewMatrix,
|
||||
const SkPath& path,
|
||||
const PathData* pathData) {
|
||||
const PathData* pathData) const {
|
||||
GrTexture* texture = atlas->getTexture();
|
||||
|
||||
SkScalar dx = pathData->fBounds.fLeft;
|
||||
@ -476,7 +474,7 @@ private:
|
||||
vertexStride);
|
||||
}
|
||||
|
||||
void flush(GrVertexBatch::Target* target, FlushInfo* flushInfo) {
|
||||
void flush(GrVertexBatch::Target* target, FlushInfo* flushInfo) const {
|
||||
GrVertices vertices;
|
||||
int maxInstancesPerDraw = flushInfo->fIndexBuffer->maxQuads();
|
||||
vertices.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer,
|
||||
|
@ -713,7 +713,7 @@ private:
|
||||
|
||||
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
|
||||
|
||||
void onPrepareDraws(Target*) override;
|
||||
void onPrepareDraws(Target*) const override;
|
||||
|
||||
typedef SkTArray<SkPoint, true> PtArray;
|
||||
typedef SkTArray<int, true> IntArray;
|
||||
@ -791,7 +791,7 @@ private:
|
||||
typedef GrVertexBatch INHERITED;
|
||||
};
|
||||
|
||||
void AAHairlineBatch::onPrepareDraws(Target* target) {
|
||||
void AAHairlineBatch::onPrepareDraws(Target* target) const {
|
||||
// Setup the viewmatrix and localmatrix for the GrGeometryProcessor.
|
||||
SkMatrix invert;
|
||||
if (!this->viewMatrix().invert(&invert)) {
|
||||
|
@ -162,7 +162,7 @@ private:
|
||||
}
|
||||
|
||||
void draw(GrVertexBatch::Target* target, const GrPipeline* pipeline, int vertexCount,
|
||||
size_t vertexStride, void* vertices, int indexCount, uint16_t* indices) {
|
||||
size_t vertexStride, void* vertices, int indexCount, uint16_t* indices) const {
|
||||
if (vertexCount == 0 || indexCount == 0) {
|
||||
return;
|
||||
}
|
||||
@ -190,7 +190,7 @@ private:
|
||||
target->draw(info);
|
||||
}
|
||||
|
||||
void onPrepareDraws(Target* target) override {
|
||||
void onPrepareDraws(Target* target) const override {
|
||||
bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
|
||||
|
||||
// Setup GrGeometryProcessor
|
||||
@ -220,7 +220,7 @@ private:
|
||||
uint8_t* vertices = (uint8_t*) sk_malloc_throw(maxVertices * vertexStride);
|
||||
uint16_t* indices = (uint16_t*) sk_malloc_throw(maxIndices * sizeof(uint16_t));
|
||||
for (int i = 0; i < instanceCount; i++) {
|
||||
Geometry& args = fGeoData[i];
|
||||
const Geometry& args = fGeoData[i];
|
||||
GrAAConvexTessellator tess(args.fStrokeWidth, args.fJoin, args.fMiterLimit);
|
||||
|
||||
if (!tess.tessellate(args.fViewMatrix, args.fPath)) {
|
||||
@ -232,8 +232,8 @@ private:
|
||||
if (indexCount + currentIndices > UINT16_MAX) {
|
||||
// if we added the current instance, we would overflow the indices we can store in a
|
||||
// uint16_t. Draw what we've got so far and reset.
|
||||
draw(target, this->pipeline(), vertexCount, vertexStride, vertices, indexCount,
|
||||
indices);
|
||||
this->draw(target, this->pipeline(), vertexCount, vertexStride, vertices,
|
||||
indexCount, indices);
|
||||
vertexCount = 0;
|
||||
indexCount = 0;
|
||||
}
|
||||
@ -252,8 +252,8 @@ private:
|
||||
vertexCount += currentVertices;
|
||||
indexCount += currentIndices;
|
||||
}
|
||||
draw(target, this->pipeline(), vertexCount, vertexStride, vertices, indexCount,
|
||||
indices);
|
||||
this->draw(target, this->pipeline(), vertexCount, vertexStride, vertices, indexCount,
|
||||
indices);
|
||||
sk_free(vertices);
|
||||
sk_free(indices);
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ private:
|
||||
bounds->join(geo.fDevOutsideAssist);
|
||||
}
|
||||
|
||||
void onPrepareDraws(Target*) override;
|
||||
void onPrepareDraws(Target*) const override;
|
||||
void initBatchTracker(const GrXPOverridesForBatch&) override;
|
||||
|
||||
AAStrokeRectBatch(const SkMatrix& viewMatrix,bool miterStroke)
|
||||
@ -182,7 +182,7 @@ void AAStrokeRectBatch::initBatchTracker(const GrXPOverridesForBatch& overrides)
|
||||
fBatch.fCanTweakAlphaForCoverage = overrides.canTweakAlphaForCoverage();
|
||||
}
|
||||
|
||||
void AAStrokeRectBatch::onPrepareDraws(Target* target) {
|
||||
void AAStrokeRectBatch::onPrepareDraws(Target* target) const {
|
||||
bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
|
||||
|
||||
SkAutoTUnref<const GrGeometryProcessor> gp(create_stroke_rect_gp(canTweakAlphaForCoverage,
|
||||
|
@ -131,7 +131,7 @@ inline void GrAtlasTextBatch::regenBlob(Target* target, FlushInfo* flushInfo, Bl
|
||||
SkTypeface** typeface, GrFontScaler** scaler,
|
||||
const SkDescriptor** desc, const GrGeometryProcessor* gp,
|
||||
int glyphCount, size_t vertexStride,
|
||||
GrColor color, SkScalar transX, SkScalar transY) {
|
||||
GrColor color, SkScalar transX, SkScalar transY) const {
|
||||
static_assert(!regenGlyphs || regenTexCoords, "must regenTexCoords along regenGlyphs");
|
||||
GrBatchTextStrike* strike = nullptr;
|
||||
if (regenTexCoords) {
|
||||
@ -297,7 +297,7 @@ enum RegenMask {
|
||||
#define REGEN_ARGS target, &flushInfo, blob, &run, &info, &cache, &typeface, &scaler, &desc, gp, \
|
||||
glyphCount, vertexStride, args.fColor, args.fTransX, args.fTransY
|
||||
|
||||
void GrAtlasTextBatch::onPrepareDraws(Target* target) {
|
||||
void GrAtlasTextBatch::onPrepareDraws(Target* target) const {
|
||||
// if we have RGB, then we won't have any SkShaders so no need to use a localmatrix.
|
||||
// TODO actually only invert if we don't have RGBA
|
||||
SkMatrix localMatrix;
|
||||
@ -363,7 +363,7 @@ void GrAtlasTextBatch::onPrepareDraws(Target* target) {
|
||||
SkTypeface* typeface = nullptr;
|
||||
|
||||
for (int i = 0; i < fGeoCount; i++) {
|
||||
Geometry& args = fGeoData[i];
|
||||
const Geometry& args = fGeoData[i];
|
||||
Blob* blob = args.fBlob;
|
||||
Run& run = blob->fRuns[args.fRun];
|
||||
TextInfo& info = run.fSubRunInfo[args.fSubRun];
|
||||
@ -434,7 +434,7 @@ void GrAtlasTextBatch::onPrepareDraws(Target* target) {
|
||||
this->flush(target, &flushInfo);
|
||||
}
|
||||
|
||||
void GrAtlasTextBatch::flush(GrVertexBatch::Target* target, FlushInfo* flushInfo) {
|
||||
void GrAtlasTextBatch::flush(GrVertexBatch::Target* target, FlushInfo* flushInfo) const {
|
||||
GrVertices vertices;
|
||||
int maxGlyphsPerDraw = flushInfo->fIndexBuffer->maxQuads();
|
||||
vertices.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer,
|
||||
@ -518,7 +518,7 @@ bool GrAtlasTextBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) {
|
||||
// TODO trying to figure out why lcd is so whack
|
||||
GrGeometryProcessor* GrAtlasTextBatch::setupDfProcessor(const SkMatrix& viewMatrix,
|
||||
SkColor filteredColor,
|
||||
GrColor color, GrTexture* texture) {
|
||||
GrColor color, GrTexture* texture) const {
|
||||
GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBilerp_FilterMode);
|
||||
bool isLCD = this->isLCD();
|
||||
// set up any flags
|
||||
|
@ -138,7 +138,7 @@ private:
|
||||
int fVertexOffset;
|
||||
};
|
||||
|
||||
void onPrepareDraws(Target* target) override;
|
||||
void onPrepareDraws(Target* target) const override;
|
||||
|
||||
GrAtlasTextBatch() : INHERITED(ClassID()) {} // initialized in factory functions.
|
||||
|
||||
@ -177,9 +177,9 @@ private:
|
||||
TextInfo* info, SkGlyphCache** cache,
|
||||
SkTypeface** typeface, GrFontScaler** scaler, const SkDescriptor** desc,
|
||||
const GrGeometryProcessor* gp, int glyphCount, size_t vertexStride,
|
||||
GrColor color, SkScalar transX, SkScalar transY);
|
||||
GrColor color, SkScalar transX, SkScalar transY) const;
|
||||
|
||||
inline void flush(GrVertexBatch::Target* target, FlushInfo* flushInfo);
|
||||
inline void flush(GrVertexBatch::Target* target, FlushInfo* flushInfo) const;
|
||||
|
||||
GrColor color() const { return fBatch.fColor; }
|
||||
const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; }
|
||||
@ -191,7 +191,7 @@ private:
|
||||
// TODO just use class params
|
||||
// TODO trying to figure out why lcd is so whack
|
||||
GrGeometryProcessor* setupDfProcessor(const SkMatrix& viewMatrix, SkColor filteredColor,
|
||||
GrColor color, GrTexture* texture);
|
||||
GrColor color, GrTexture* texture) const;
|
||||
|
||||
struct BatchTracker {
|
||||
GrColor fColor;
|
||||
|
@ -251,7 +251,7 @@ private:
|
||||
fBatch.fCoverageIgnored = !overrides.readsCoverage();
|
||||
}
|
||||
|
||||
void onPrepareDraws(Target* target) override {
|
||||
void onPrepareDraws(Target* target) const override {
|
||||
SkAutoTUnref<const GrGeometryProcessor> gp;
|
||||
{
|
||||
using namespace GrDefaultGeoProcFactory;
|
||||
@ -279,7 +279,7 @@ private:
|
||||
// We will use index buffers if we have multiple paths or one path with multiple contours
|
||||
bool isIndexed = instanceCount > 1;
|
||||
for (int i = 0; i < instanceCount; i++) {
|
||||
Geometry& args = fGeoData[i];
|
||||
const Geometry& args = fGeoData[i];
|
||||
|
||||
int contourCount;
|
||||
maxVertices += GrPathUtils::worstCasePointCount(args.fPath, &contourCount,
|
||||
@ -341,7 +341,7 @@ private:
|
||||
int vertexOffset = 0;
|
||||
int indexOffset = 0;
|
||||
for (int i = 0; i < instanceCount; i++) {
|
||||
Geometry& args = fGeoData[i];
|
||||
const Geometry& args = fGeoData[i];
|
||||
|
||||
int vertexCnt = 0;
|
||||
int indexCnt = 0;
|
||||
@ -431,7 +431,7 @@ private:
|
||||
int* indexCnt,
|
||||
const SkPath& path,
|
||||
SkScalar srcSpaceTol,
|
||||
bool isIndexed) {
|
||||
bool isIndexed) const {
|
||||
{
|
||||
SkScalar srcSpaceTolSqd = SkScalarMul(srcSpaceTol, srcSpaceTol);
|
||||
|
||||
|
@ -51,7 +51,7 @@ static const GrGeometryProcessor* set_vertex_attributes(bool hasColors,
|
||||
return GrDefaultGeoProcFactory::Create(gpColor, coverage, localCoords, viewMatrix);
|
||||
}
|
||||
|
||||
void GrDrawAtlasBatch::onPrepareDraws(Target* target) {
|
||||
void GrDrawAtlasBatch::onPrepareDraws(Target* target) const {
|
||||
// Setup geometry processor
|
||||
SkAutoTUnref<const GrGeometryProcessor> gp(set_vertex_attributes(this->hasColors(),
|
||||
this->color(),
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
|
||||
|
||||
private:
|
||||
void onPrepareDraws(Target*) override;
|
||||
void onPrepareDraws(Target*) const override;
|
||||
|
||||
void initBatchTracker(const GrXPOverridesForBatch&) override;
|
||||
|
||||
|
@ -92,7 +92,7 @@ void GrDrawVerticesBatch::initBatchTracker(const GrXPOverridesForBatch& override
|
||||
}
|
||||
}
|
||||
|
||||
void GrDrawVerticesBatch::onPrepareDraws(Target* target) {
|
||||
void GrDrawVerticesBatch::onPrepareDraws(Target* target) const {
|
||||
bool hasLocalCoords = !fGeoData[0].fLocalCoords.isEmpty();
|
||||
int colorOffset = -1, texOffset = -1;
|
||||
SkAutoTUnref<const GrGeometryProcessor> gp(
|
||||
|
@ -49,7 +49,7 @@ public:
|
||||
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
|
||||
|
||||
private:
|
||||
void onPrepareDraws(Target*) override;
|
||||
void onPrepareDraws(Target*) const override;
|
||||
void initBatchTracker(const GrXPOverridesForBatch&) override;
|
||||
|
||||
GrDrawVerticesBatch(const Geometry& geometry, GrPrimitiveType primitiveType,
|
||||
|
@ -85,7 +85,7 @@ public:
|
||||
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
|
||||
|
||||
private:
|
||||
void onPrepareDraws(Target* target) override {
|
||||
void onPrepareDraws(Target* target) const override {
|
||||
SkAutoTUnref<const GrGeometryProcessor> gp(create_gp(fOverrides.readsCoverage()));
|
||||
if (!gp) {
|
||||
SkDebugf("Couldn't create GrGeometryProcessor\n");
|
||||
@ -112,7 +112,7 @@ private:
|
||||
intptr_t verts = reinterpret_cast<intptr_t>(vertices) +
|
||||
i * kRectsPerInstance * kVertsPerRect * vertexStride;
|
||||
|
||||
Geometry& geo = fGeoData[i];
|
||||
const Geometry& geo = fGeoData[i];
|
||||
SkNinePatchIter iter(fImageWidth, fImageHeight, geo.fCenter, geo.fDst);
|
||||
|
||||
SkRect srcR, dstR;
|
||||
|
@ -70,6 +70,9 @@ public:
|
||||
geometry.fRect = rect;
|
||||
geometry.fStrokeWidth = strokeWidth;
|
||||
geometry.fColor = color;
|
||||
|
||||
// Sort the rect for hairlines
|
||||
geometry.fRect.sort();
|
||||
}
|
||||
|
||||
void appendAndUpdateBounds(GrColor color, const SkMatrix& viewMatrix, const SkRect& rect,
|
||||
@ -102,7 +105,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void onPrepareDraws(Target* target) override {
|
||||
void onPrepareDraws(Target* target) const override {
|
||||
SkAutoTUnref<const GrGeometryProcessor> gp;
|
||||
{
|
||||
using namespace GrDefaultGeoProcFactory;
|
||||
@ -121,7 +124,7 @@ private:
|
||||
|
||||
SkASSERT(vertexStride == sizeof(GrDefaultGeoProcFactory::PositionAttr));
|
||||
|
||||
Geometry& args = fGeoData[0];
|
||||
const Geometry& args = fGeoData[0];
|
||||
|
||||
int vertexCount = kVertsPerHairlineRect;
|
||||
if (args.fStrokeWidth > 0) {
|
||||
@ -142,10 +145,8 @@ private:
|
||||
SkPoint* vertex = reinterpret_cast<SkPoint*>(verts);
|
||||
|
||||
GrPrimitiveType primType;
|
||||
|
||||
if (args.fStrokeWidth > 0) {;
|
||||
primType = kTriangleStrip_GrPrimitiveType;
|
||||
args.fRect.sort();
|
||||
init_stroke_rect_strip(vertex, args.fRect, args.fStrokeWidth);
|
||||
} else {
|
||||
// hairline
|
||||
|
@ -89,7 +89,7 @@ public:
|
||||
private:
|
||||
GrTInstanceBatch() : INHERITED(ClassID()) {}
|
||||
|
||||
void onPrepareDraws(Target* target) override {
|
||||
void onPrepareDraws(Target* target) const override {
|
||||
SkAutoTUnref<const GrGeometryProcessor> gp(Impl::CreateGP(this->seedGeometry(),
|
||||
fOverrides));
|
||||
if (!gp) {
|
||||
|
@ -1418,7 +1418,7 @@ private:
|
||||
int tessellate(GrUniqueKey* key,
|
||||
GrResourceProvider* resourceProvider,
|
||||
SkAutoTUnref<GrVertexBuffer>& vertexBuffer,
|
||||
bool canMapVB) {
|
||||
bool canMapVB) const {
|
||||
SkPath path;
|
||||
GrStrokeInfo stroke(fStroke);
|
||||
if (stroke.isDashed()) {
|
||||
@ -1521,7 +1521,7 @@ private:
|
||||
return actualCount;
|
||||
}
|
||||
|
||||
void onPrepareDraws(Target* target) override {
|
||||
void onPrepareDraws(Target* target) const override {
|
||||
// construct a cache key from the path's genID and the view matrix
|
||||
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
|
||||
GrUniqueKey key;
|
||||
@ -1545,7 +1545,7 @@ private:
|
||||
screenSpaceTol, fViewMatrix, fPath.getBounds());
|
||||
if (!cache_match(vertexBuffer.get(), tol, &actualCount)) {
|
||||
bool canMapVB = GrCaps::kNone_MapFlags != target->caps().mapBufferFlags();
|
||||
actualCount = tessellate(&key, rp, vertexBuffer, canMapVB);
|
||||
actualCount = this->tessellate(&key, rp, vertexBuffer, canMapVB);
|
||||
}
|
||||
|
||||
if (actualCount == 0) {
|
||||
|
@ -60,7 +60,7 @@ protected:
|
||||
const GrGeometryProcessor* geometryProcessor() const { return fGeometryProcessor; }
|
||||
|
||||
private:
|
||||
void onPrepareDraws(Target* target) override {
|
||||
void onPrepareDraws(Target* target) const override {
|
||||
target->initDraw(fGeometryProcessor, this->pipeline());
|
||||
this->generateGeometry(target);
|
||||
}
|
||||
@ -72,7 +72,7 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void generateGeometry(Target*) = 0;
|
||||
virtual void generateGeometry(Target*) const = 0;
|
||||
|
||||
struct BatchTracker {
|
||||
GrColor fColor;
|
||||
|
@ -65,7 +65,7 @@ private:
|
||||
void onPrepare(GrBatchFlushState* state) final;
|
||||
void onDraw(GrBatchFlushState* state) final;
|
||||
|
||||
virtual void onPrepareDraws(Target*) = 0;
|
||||
virtual void onPrepareDraws(Target*) const = 0;
|
||||
|
||||
// A set of contiguous draws with no inline uploads between them that all use the same
|
||||
// primitive processor. All the draws in a DrawArray share a primitive processor and use the
|
||||
|
@ -316,6 +316,14 @@ private:
|
||||
}
|
||||
|
||||
struct DashDraw {
|
||||
DashDraw(const Geometry& geo) {
|
||||
memcpy(fPtsRot, geo.fPtsRot, sizeof(geo.fPtsRot));
|
||||
memcpy(fIntervals, geo.fIntervals, sizeof(geo.fIntervals));
|
||||
fPhase = geo.fPhase;
|
||||
}
|
||||
SkPoint fPtsRot[2];
|
||||
SkScalar fIntervals[2];
|
||||
SkScalar fPhase;
|
||||
SkScalar fStartOffset;
|
||||
SkScalar fStrokeWidth;
|
||||
SkScalar fLineLength;
|
||||
@ -327,7 +335,7 @@ private:
|
||||
bool fHasEndRect;
|
||||
};
|
||||
|
||||
void onPrepareDraws(Target* target) override {
|
||||
void onPrepareDraws(Target* target) const override {
|
||||
int instanceCount = fGeoData.count();
|
||||
SkPaint::Cap cap = this->cap();
|
||||
bool isRoundCap = SkPaint::kRound_Cap == cap;
|
||||
@ -362,14 +370,17 @@ private:
|
||||
// We do two passes over all of the dashes. First we setup the start, end, and bounds,
|
||||
// rectangles. We preserve all of this work in the rects / draws arrays below. Then we
|
||||
// iterate again over these decomposed dashes to generate vertices
|
||||
SkSTArray<128, SkRect, true> rects;
|
||||
SkSTArray<128, DashDraw, true> draws;
|
||||
static const int kNumStackDashes = 128;
|
||||
SkSTArray<kNumStackDashes, SkRect, true> rects;
|
||||
SkSTArray<kNumStackDashes, DashDraw, true> draws;
|
||||
|
||||
int totalRectCount = 0;
|
||||
int rectOffset = 0;
|
||||
rects.push_back_n(3 * instanceCount);
|
||||
for (int i = 0; i < instanceCount; i++) {
|
||||
Geometry& args = fGeoData[i];
|
||||
const Geometry& args = fGeoData[i];
|
||||
|
||||
DashDraw& draw = draws.push_back(args);
|
||||
|
||||
bool hasCap = SkPaint::kButt_Cap != cap && 0 != args.fSrcStrokeWidth;
|
||||
|
||||
@ -399,32 +410,32 @@ private:
|
||||
// If we are using AA, check to see if we are drawing a partial dash at the start. If so
|
||||
// draw it separately here and adjust our start point accordingly
|
||||
if (useAA) {
|
||||
if (args.fPhase > 0 && args.fPhase < args.fIntervals[0]) {
|
||||
if (draw.fPhase > 0 && draw.fPhase < draw.fIntervals[0]) {
|
||||
SkPoint startPts[2];
|
||||
startPts[0] = args.fPtsRot[0];
|
||||
startPts[0] = draw.fPtsRot[0];
|
||||
startPts[1].fY = startPts[0].fY;
|
||||
startPts[1].fX = SkMinScalar(startPts[0].fX + args.fIntervals[0] - args.fPhase,
|
||||
args.fPtsRot[1].fX);
|
||||
startPts[1].fX = SkMinScalar(startPts[0].fX + draw.fIntervals[0] - draw.fPhase,
|
||||
draw.fPtsRot[1].fX);
|
||||
startRect.set(startPts, 2);
|
||||
startRect.outset(strokeAdj, halfSrcStroke);
|
||||
|
||||
hasStartRect = true;
|
||||
startAdj = args.fIntervals[0] + args.fIntervals[1] - args.fPhase;
|
||||
startAdj = draw.fIntervals[0] + draw.fIntervals[1] - draw.fPhase;
|
||||
}
|
||||
}
|
||||
|
||||
// adjustments for start and end of bounding rect so we only draw dash intervals
|
||||
// contained in the original line segment.
|
||||
startAdj += calc_start_adjustment(args.fIntervals, args.fPhase);
|
||||
startAdj += calc_start_adjustment(draw.fIntervals, draw.fPhase);
|
||||
if (startAdj != 0) {
|
||||
args.fPtsRot[0].fX += startAdj;
|
||||
args.fPhase = 0;
|
||||
draw.fPtsRot[0].fX += startAdj;
|
||||
draw.fPhase = 0;
|
||||
}
|
||||
SkScalar endingInterval = 0;
|
||||
SkScalar endAdj = calc_end_adjustment(args.fIntervals, args.fPtsRot, args.fPhase,
|
||||
SkScalar endAdj = calc_end_adjustment(draw.fIntervals, draw.fPtsRot, draw.fPhase,
|
||||
&endingInterval);
|
||||
args.fPtsRot[1].fX -= endAdj;
|
||||
if (args.fPtsRot[0].fX >= args.fPtsRot[1].fX) {
|
||||
draw.fPtsRot[1].fX -= endAdj;
|
||||
if (draw.fPtsRot[0].fX >= draw.fPtsRot[1].fX) {
|
||||
lineDone = true;
|
||||
}
|
||||
|
||||
@ -435,9 +446,9 @@ private:
|
||||
// If we adjusted the end then we will not be drawing a partial dash at the end.
|
||||
// If we didn't adjust the end point then we just need to make sure the ending
|
||||
// dash isn't a full dash
|
||||
if (0 == endAdj && endingInterval != args.fIntervals[0]) {
|
||||
if (0 == endAdj && endingInterval != draw.fIntervals[0]) {
|
||||
SkPoint endPts[2];
|
||||
endPts[1] = args.fPtsRot[1];
|
||||
endPts[1] = draw.fPtsRot[1];
|
||||
endPts[0].fY = endPts[1].fY;
|
||||
endPts[0].fX = endPts[1].fX - endingInterval;
|
||||
|
||||
@ -445,24 +456,24 @@ private:
|
||||
endRect.outset(strokeAdj, halfSrcStroke);
|
||||
|
||||
hasEndRect = true;
|
||||
endAdj = endingInterval + args.fIntervals[1];
|
||||
endAdj = endingInterval + draw.fIntervals[1];
|
||||
|
||||
args.fPtsRot[1].fX -= endAdj;
|
||||
if (args.fPtsRot[0].fX >= args.fPtsRot[1].fX) {
|
||||
draw.fPtsRot[1].fX -= endAdj;
|
||||
if (draw.fPtsRot[0].fX >= draw.fPtsRot[1].fX) {
|
||||
lineDone = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (startAdj != 0) {
|
||||
args.fPhase = 0;
|
||||
draw.fPhase = 0;
|
||||
}
|
||||
|
||||
// Change the dashing info from src space into device space
|
||||
SkScalar* devIntervals = args.fIntervals;
|
||||
devIntervals[0] = args.fIntervals[0] * args.fParallelScale;
|
||||
devIntervals[1] = args.fIntervals[1] * args.fParallelScale;
|
||||
SkScalar devPhase = args.fPhase * args.fParallelScale;
|
||||
SkScalar* devIntervals = draw.fIntervals;
|
||||
devIntervals[0] = draw.fIntervals[0] * args.fParallelScale;
|
||||
devIntervals[1] = draw.fIntervals[1] * args.fParallelScale;
|
||||
SkScalar devPhase = draw.fPhase * args.fParallelScale;
|
||||
SkScalar strokeWidth = args.fSrcStrokeWidth * args.fPerpendicularScale;
|
||||
|
||||
if ((strokeWidth < 1.f && useAA) || 0.f == strokeWidth) {
|
||||
@ -492,16 +503,16 @@ private:
|
||||
// Reset the start rect to draw this single solid rect
|
||||
// but it requires to upload a new intervals uniform so we can mimic
|
||||
// one giant dash
|
||||
args.fPtsRot[0].fX -= hasStartRect ? startAdj : 0;
|
||||
args.fPtsRot[1].fX += hasEndRect ? endAdj : 0;
|
||||
startRect.set(args.fPtsRot, 2);
|
||||
draw.fPtsRot[0].fX -= hasStartRect ? startAdj : 0;
|
||||
draw.fPtsRot[1].fX += hasEndRect ? endAdj : 0;
|
||||
startRect.set(draw.fPtsRot, 2);
|
||||
startRect.outset(strokeAdj, halfSrcStroke);
|
||||
hasStartRect = true;
|
||||
hasEndRect = false;
|
||||
lineDone = true;
|
||||
|
||||
SkPoint devicePts[2];
|
||||
args.fViewMatrix.mapPoints(devicePts, args.fPtsRot, 2);
|
||||
args.fViewMatrix.mapPoints(devicePts, draw.fPtsRot, 2);
|
||||
SkScalar lineLength = SkPoint::Distance(devicePts[0], devicePts[1]);
|
||||
if (hasCap) {
|
||||
lineLength += 2.f * halfDevStroke;
|
||||
@ -519,17 +530,16 @@ private:
|
||||
startOffset -= halfDevStroke;
|
||||
}
|
||||
|
||||
DashDraw& draw = draws.push_back();
|
||||
if (!lineDone) {
|
||||
SkPoint devicePts[2];
|
||||
args.fViewMatrix.mapPoints(devicePts, args.fPtsRot, 2);
|
||||
args.fViewMatrix.mapPoints(devicePts, draw.fPtsRot, 2);
|
||||
draw.fLineLength = SkPoint::Distance(devicePts[0], devicePts[1]);
|
||||
if (hasCap) {
|
||||
draw.fLineLength += 2.f * halfDevStroke;
|
||||
}
|
||||
|
||||
bounds.set(args.fPtsRot[0].fX, args.fPtsRot[0].fY,
|
||||
args.fPtsRot[1].fX, args.fPtsRot[1].fY);
|
||||
bounds.set(draw.fPtsRot[0].fX, draw.fPtsRot[0].fY,
|
||||
draw.fPtsRot[1].fX, draw.fPtsRot[1].fY);
|
||||
bounds.outset(bloatX + strokeAdj, bloatY + halfSrcStroke);
|
||||
}
|
||||
|
||||
@ -566,15 +576,15 @@ private:
|
||||
int curVIdx = 0;
|
||||
int rectIndex = 0;
|
||||
for (int i = 0; i < instanceCount; i++) {
|
||||
Geometry& geom = fGeoData[i];
|
||||
const Geometry& geom = fGeoData[i];
|
||||
|
||||
if (!draws[i].fLineDone) {
|
||||
if (fullDash) {
|
||||
setup_dashed_rect(rects[rectIndex], vertices, curVIdx, geom.fSrcRotInv,
|
||||
draws[i].fStartOffset, draws[i].fDevBloatX,
|
||||
draws[i].fDevBloatY, draws[i].fLineLength,
|
||||
draws[i].fHalfDevStroke, geom.fIntervals[0],
|
||||
geom.fIntervals[1], draws[i].fStrokeWidth,
|
||||
draws[i].fHalfDevStroke, draws[i].fIntervals[0],
|
||||
draws[i].fIntervals[1], draws[i].fStrokeWidth,
|
||||
capType, gp->getVertexStride());
|
||||
} else {
|
||||
SkPoint* verts = reinterpret_cast<SkPoint*>(vertices);
|
||||
@ -589,9 +599,9 @@ private:
|
||||
if (fullDash) {
|
||||
setup_dashed_rect(rects[rectIndex], vertices, curVIdx, geom.fSrcRotInv,
|
||||
draws[i].fStartOffset, draws[i].fDevBloatX,
|
||||
draws[i].fDevBloatY, geom.fIntervals[0],
|
||||
draws[i].fHalfDevStroke, geom.fIntervals[0],
|
||||
geom.fIntervals[1], draws[i].fStrokeWidth, capType,
|
||||
draws[i].fDevBloatY, draws[i].fIntervals[0],
|
||||
draws[i].fHalfDevStroke, draws[i].fIntervals[0],
|
||||
draws[i].fIntervals[1], draws[i].fStrokeWidth, capType,
|
||||
gp->getVertexStride());
|
||||
} else {
|
||||
SkPoint* verts = reinterpret_cast<SkPoint*>(vertices);
|
||||
@ -606,9 +616,9 @@ private:
|
||||
if (fullDash) {
|
||||
setup_dashed_rect(rects[rectIndex], vertices, curVIdx, geom.fSrcRotInv,
|
||||
draws[i].fStartOffset, draws[i].fDevBloatX,
|
||||
draws[i].fDevBloatY, geom.fIntervals[0],
|
||||
draws[i].fHalfDevStroke, geom.fIntervals[0],
|
||||
geom.fIntervals[1], draws[i].fStrokeWidth, capType,
|
||||
draws[i].fDevBloatY, draws[i].fIntervals[0],
|
||||
draws[i].fHalfDevStroke, draws[i].fIntervals[0],
|
||||
draws[i].fIntervals[1], draws[i].fStrokeWidth, capType,
|
||||
gp->getVertexStride());
|
||||
} else {
|
||||
SkPoint* verts = reinterpret_cast<SkPoint*>(vertices);
|
||||
|
@ -1118,7 +1118,7 @@ static void test_lcd_coverage_fallback_case(skiatest::Reporter* reporter, const
|
||||
const char* name() const override { return "Test LCD Text Batch"; }
|
||||
void initBatchTracker(const GrXPOverridesForBatch&) override {}
|
||||
bool onCombineIfPossible(GrBatch*, const GrCaps&) override { return false; }
|
||||
void onPrepareDraws(Target*) override {};
|
||||
void onPrepareDraws(Target*) const override {};
|
||||
|
||||
typedef GrVertexBatch INHERITED;
|
||||
} testLCDCoverageBatch;
|
||||
|
Loading…
Reference in New Issue
Block a user