Add initial support for simple concave shadows.
Adds support for spot shadow outlines. Since filling the penumbra still
needs to be done, this code is disabled for now.
Bug: skia:
Change-Id: I3369eb13832b47ad16dd29ce7c7d6a1a10b39aeb
Reviewed-on: https://skia-review.googlesource.com/22363
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/src/utils/SkOffsetPolygon.cpp b/src/utils/SkOffsetPolygon.cpp
index bfd12d2..94fe965 100755
--- a/src/utils/SkOffsetPolygon.cpp
+++ b/src/utils/SkOffsetPolygon.cpp
@@ -218,11 +218,26 @@
OffsetSegment fInset;
SkPoint fIntersection;
SkScalar fTValue;
+ uint16_t fStart;
+ uint16_t fEnd;
+ uint16_t fIndex;
bool fValid;
void init() {
fIntersection = fInset.fP0;
fTValue = SK_ScalarMin;
+ fStart = 0;
+ fEnd = 0;
+ fIndex = 0;
+ fValid = true;
+ }
+
+ void init(uint16_t start, uint16_t end) {
+ fIntersection = fInset.fP0;
+ fTValue = SK_ScalarMin;
+ fStart = start;
+ fEnd = end;
+ fIndex = start;
fValid = true;
}
};
@@ -571,7 +586,8 @@
// TODO: assuming a constant offset here -- do we want to support variable offset?
bool SkOffsetSimplePolygon(const SkPoint* inputPolygonVerts, int inputPolygonSize,
- SkScalar offset, SkTDArray<SkPoint>* offsetPolygon) {
+ SkScalar offset, SkTDArray<SkPoint>* offsetPolygon,
+ SkTDArray<int>* polygonIndices) {
if (inputPolygonSize < 3) {
return false;
}
@@ -625,20 +641,20 @@
EdgeData& edge = edgeData.push_back();
edge.fInset.fP0 = inputPolygonVerts[currIndex] + prevNormal;
edge.fInset.fP1 = inputPolygonVerts[currIndex] + currNormal;
- edge.init();
+ edge.init(currIndex, currIndex);
prevNormal = currNormal;
}
EdgeData& edge = edgeData.push_back();
edge.fInset.fP0 = inputPolygonVerts[currIndex] + prevNormal;
edge.fInset.fP1 = inputPolygonVerts[currIndex] + normals[currIndex];
- edge.init();
+ edge.init(currIndex, currIndex);
}
// Add the edge
EdgeData& edge = edgeData.push_back();
edge.fInset.fP0 = inputPolygonVerts[currIndex] + normals[currIndex];
edge.fInset.fP1 = inputPolygonVerts[nextIndex] + normals[currIndex];
- edge.init();
+ edge.init(currIndex, nextIndex);
prevIndex = currIndex;
currIndex++;
@@ -654,6 +670,10 @@
prevIndex = (prevIndex + edgeDataSize - 1) % edgeDataSize;
continue;
}
+ if (!edgeData[currIndex].fValid) {
+ currIndex = (currIndex + 1) % edgeDataSize;
+ continue;
+ }
SkScalar s, t;
SkPoint intersection;
@@ -676,6 +696,7 @@
// add intersection
edgeData[currIndex].fIntersection = intersection;
edgeData[currIndex].fTValue = t;
+ edgeData[currIndex].fIndex = edgeData[prevIndex].fEnd;
// go to next segment
prevIndex = currIndex;
@@ -714,6 +735,9 @@
(*offsetPolygon)[currIndex],
kCleanupTolerance))) {
*offsetPolygon->push() = edgeData[i].fIntersection;
+ if (polygonIndices) {
+ *polygonIndices->push() = edgeData[i].fIndex;
+ }
currIndex++;
}
}
@@ -722,6 +746,9 @@
SkPointPriv::EqualsWithinTolerance((*offsetPolygon)[0], (*offsetPolygon)[currIndex],
kCleanupTolerance)) {
offsetPolygon->pop();
+ if (polygonIndices) {
+ polygonIndices->pop();
+ }
}
// compute signed area to check winding (it should be same as the original polygon)