aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils/SkShadowTessellator.cpp
diff options
context:
space:
mode:
authorGravatar Jim Van Verth <jvanverth@google.com>2018-05-14 11:20:58 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-05-14 15:53:49 +0000
commit8c2de8f76bc1f48702ca006c484ac9750dc8e3b0 (patch)
treefbfa3a4b609b585222bba91b04430798f07ba0c1 /src/utils/SkShadowTessellator.cpp
parent16ffdd4edec1e037cc04a167d5a2b634619e588b (diff)
Merge duplicate umbra points in spot shadow.
When we search for the closest umbra point at the end of the shadow creation process, we often find the umbra point we first added. Previously we would add this point again and patch up the result. This is causing issues with fixing the falloff, so this code handles this case better by reusing the original entry in fPositions. Bug: skia:6717 Change-Id: Ic44396f9430ecca8c67f06a6ffb37aae5a38c93b Reviewed-on: https://skia-review.googlesource.com/127964 Commit-Queue: Jim Van Verth <jvanverth@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/utils/SkShadowTessellator.cpp')
-rwxr-xr-xsrc/utils/SkShadowTessellator.cpp28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/utils/SkShadowTessellator.cpp b/src/utils/SkShadowTessellator.cpp
index 4990db92e7..ee2375ebf2 100755
--- a/src/utils/SkShadowTessellator.cpp
+++ b/src/utils/SkShadowTessellator.cpp
@@ -773,7 +773,7 @@ private:
bool handlePolyPoint(const SkPoint& p);
void mapPoints(SkScalar scale, const SkVector& xlate, SkPoint* pts, int count);
- bool addInnerPoint(const SkPoint& pathPoint);
+ bool addInnerPoint(const SkPoint& pathPoint, int* currUmbraIndex);
void addEdge(const SkVector& nextPoint, const SkVector& nextNormal);
void addToClip(const SkVector& nextPoint);
@@ -1452,8 +1452,7 @@ bool SkSpotShadowTessellator::handlePolyPoint(const SkPoint& p) {
fPrevPoint = fFirstPoint;
fPrevUmbraIndex = -1;
- this->addInnerPoint(fFirstPoint);
- fPrevUmbraIndex = fFirstVertexIndex;
+ this->addInnerPoint(fFirstPoint, &fPrevUmbraIndex);
if (!fTransparent) {
SkPoint clipPoint;
@@ -1494,7 +1493,7 @@ bool SkSpotShadowTessellator::handlePolyPoint(const SkPoint& p) {
return true;
}
-bool SkSpotShadowTessellator::addInnerPoint(const SkPoint& pathPoint) {
+bool SkSpotShadowTessellator::addInnerPoint(const SkPoint& pathPoint, int* currUmbraIndex) {
SkPoint umbraPoint;
if (!fValidUmbra) {
SkVector v = fCentroid - pathPoint;
@@ -1509,21 +1508,28 @@ bool SkSpotShadowTessellator::addInnerPoint(const SkPoint& pathPoint) {
// merge "close" points
if (fPrevUmbraIndex == -1 ||
!duplicate_pt(umbraPoint, fPositions[fPrevUmbraIndex])) {
- *fPositions.push() = umbraPoint;
- *fColors.push() = fUmbraColor;
-
+ // if we've wrapped around, don't add a new point
+ if (fPrevUmbraIndex >= 0 && duplicate_pt(umbraPoint, fPositions[fFirstVertexIndex])) {
+ *currUmbraIndex = fFirstVertexIndex;
+ } else {
+ *currUmbraIndex = fPositions.count();
+ *fPositions.push() = umbraPoint;
+ *fColors.push() = fUmbraColor;
+ }
return false;
} else {
+ *currUmbraIndex = fPrevUmbraIndex;
return true;
}
}
void SkSpotShadowTessellator::addEdge(const SkPoint& nextPoint, const SkVector& nextNormal) {
// add next umbra point
- bool duplicate = this->addInnerPoint(nextPoint);
- int prevPenumbraIndex = duplicate ? fPositions.count()-1 : fPositions.count()-2;
- int currUmbraIndex = duplicate ? fPrevUmbraIndex : fPositions.count()-1;
-
+ int currUmbraIndex;
+ bool duplicate = this->addInnerPoint(nextPoint, &currUmbraIndex);
+ int prevPenumbraIndex = duplicate || (currUmbraIndex == fFirstVertexIndex)
+ ? fPositions.count()-1
+ : fPositions.count()-2;
if (!duplicate) {
// add to center fan if transparent or centroid showing
if (fTransparent) {