aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-08-22 18:25:11 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-08-23 15:24:55 +0000
commit3cf781d0e0afc0bbd8a9cb18ad4b126ebcafbbe5 (patch)
treec07558809a9ab8b078c017b6e7b8cdcc81c18089
parentf9eaea6f466d1c3d3317a2daa7a5239bf7976253 (diff)
Switch GrSmallPath renderer over to always using integer texture coordinates
As a preface to having all the atlas texture coordinates be absolute they must all first be integers. In the case of the small path renderer that means that the rect for the DF case must be bloated out a bit. Change-Id: I9969fcfe9d3ae3247a2964e2ca79cad522ccad9e Reviewed-on: https://skia-review.googlesource.com/37360 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
-rw-r--r--src/gpu/ops/GrSmallPathRenderer.cpp59
-rw-r--r--src/gpu/ops/GrSmallPathRenderer.h7
2 files changed, 23 insertions, 43 deletions
diff --git a/src/gpu/ops/GrSmallPathRenderer.cpp b/src/gpu/ops/GrSmallPathRenderer.cpp
index adccdb55a4..69cd669abb 100644
--- a/src/gpu/ops/GrSmallPathRenderer.cpp
+++ b/src/gpu/ops/GrSmallPathRenderer.cpp
@@ -277,10 +277,9 @@ private:
const Entry& args = fShapes[i];
ShapeData* shapeData;
- SkScalar maxScale;
if (fUsesDistanceField) {
// get mip level
- maxScale = SkScalarAbs(this->viewMatrix().getMaxScale());
+ SkScalar maxScale = SkScalarAbs(this->viewMatrix().getMaxScale());
const SkRect& bounds = args.fShape.bounds();
SkScalar maxDim = SkMaxScalar(bounds.width(), bounds.height());
// We try to create the DF at a 2^n scaled path resolution (1/2, 1, 2, 4, etc.)
@@ -361,7 +360,6 @@ private:
continue;
}
}
- maxScale = 1;
}
atlas->setLastUseToken(shapeData->fID, target->nextDrawToken());
@@ -371,7 +369,6 @@ private:
offset,
args.fColor,
vertexStride,
- maxScale,
args.fTranslate,
shapeData);
offset += kVerticesPerQuad * vertexStride;
@@ -407,11 +404,13 @@ private:
int width = devPathBounds.width() + 2*intPad;
int height = devPathBounds.height() + 2*intPad;
devPathBounds = SkIRect::MakeWH(width, height);
+ SkScalar translateX = intPad - dx;
+ SkScalar translateY = intPad - dy;
// draw path to bitmap
SkMatrix drawMatrix;
drawMatrix.setScale(scale, scale);
- drawMatrix.postTranslate(intPad - dx, intPad - dy);
+ drawMatrix.postTranslate(translateX, translateY);
SkASSERT(devPathBounds.fLeft == 0);
SkASSERT(devPathBounds.fTop == 0);
@@ -481,14 +480,17 @@ private:
shapeData->fID = id;
// set the bounds rect to the original bounds
- shapeData->fBounds = bounds;
+ shapeData->fBounds = SkRect::Make(devPathBounds);
+ shapeData->fBounds.offset(-translateX, -translateY);
+ shapeData->fBounds.fLeft /= scale;
+ shapeData->fBounds.fTop /= scale;
+ shapeData->fBounds.fRight /= scale;
+ shapeData->fBounds.fBottom /= scale;
- // set up path to texture coordinate transform
- shapeData->fScale = scale;
- dx -= SK_DistanceFieldPad + kAntiAliasPad;
- dy -= SK_DistanceFieldPad + kAntiAliasPad;
- shapeData->fTranslate.fX = atlasLocation.fX - dx;
- shapeData->fTranslate.fY = atlasLocation.fY - dy;
+ shapeData->fTextureCoords.set(atlasLocation.fX+SK_DistanceFieldPad,
+ atlasLocation.fY+SK_DistanceFieldPad,
+ atlasLocation.fX+SK_DistanceFieldPad+devPathBounds.width(),
+ atlasLocation.fY+SK_DistanceFieldPad+devPathBounds.height());
fShapeCache->add(shapeData);
fShapeList->addToTail(shapeData);
@@ -573,14 +575,11 @@ private:
shapeData->fKey.set(shape, ctm);
shapeData->fID = id;
- // set the bounds rect to the original bounds
shapeData->fBounds = SkRect::Make(devPathBounds);
shapeData->fBounds.offset(-translateX, -translateY);
- // set up path to texture coordinate transform
- shapeData->fScale = SK_Scalar1;
- shapeData->fTranslate.fX = atlasLocation.fX + translateX;
- shapeData->fTranslate.fY = atlasLocation.fY + translateY;
+ shapeData->fTextureCoords.set(atlasLocation.fX, atlasLocation.fY,
+ atlasLocation.fX+width, atlasLocation.fY+height);
fShapeCache->add(shapeData);
fShapeList->addToTail(shapeData);
@@ -595,17 +594,11 @@ private:
intptr_t offset,
GrColor color,
size_t vertexStride,
- SkScalar maxScale,
const SkVector& preTranslate,
const ShapeData* shapeData) const {
SkPoint* positions = reinterpret_cast<SkPoint*>(offset);
SkRect bounds = shapeData->fBounds;
- if (fUsesDistanceField) {
- // outset bounds to include ~1 pixel of AA in device space
- SkScalar outset = SkScalarInvert(maxScale);
- bounds.outset(outset, outset);
- }
// vertex positions
// TODO make the vertex attributes a struct
@@ -622,22 +615,10 @@ private:
}
// set up texture coordinates
- SkScalar texLeft = bounds.fLeft;
- SkScalar texTop = bounds.fTop;
- SkScalar texRight = bounds.fRight;
- SkScalar texBottom = bounds.fBottom;
-
- // transform original path's bounds to texture space
- SkScalar scale = shapeData->fScale;
- const SkVector& translate = shapeData->fTranslate;
- texLeft *= scale;
- texTop *= scale;
- texRight *= scale;
- texBottom *= scale;
- texLeft += translate.fX;
- texTop += translate.fY;
- texRight += translate.fX;
- texBottom += translate.fY;
+ SkScalar texLeft = shapeData->fTextureCoords.fLeft;
+ SkScalar texTop = shapeData->fTextureCoords.fTop;
+ SkScalar texRight = shapeData->fTextureCoords.fRight;
+ SkScalar texBottom = shapeData->fTextureCoords.fBottom;
// convert texcoords to unsigned short format
sk_sp<GrTextureProxy> proxy = atlas->getProxy();
diff --git a/src/gpu/ops/GrSmallPathRenderer.h b/src/gpu/ops/GrSmallPathRenderer.h
index 59006159f4..d10c4baa86 100644
--- a/src/gpu/ops/GrSmallPathRenderer.h
+++ b/src/gpu/ops/GrSmallPathRenderer.h
@@ -105,11 +105,10 @@ private:
// the matrix for the path with only fractional translation.
SkAutoSTArray<24, uint32_t> fKey;
};
- Key fKey;
+ Key fKey;
GrDrawOpAtlas::AtlasID fID;
- SkRect fBounds;
- SkScalar fScale;
- SkVector fTranslate;
+ SkRect fBounds;
+ GrIRect16 fTextureCoords;
SK_DECLARE_INTERNAL_LLIST_INTERFACE(ShapeData);
static inline const Key& GetKey(const ShapeData& data) {