Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Unified Diff: src/effects/SkDashPathEffect.cpp

Issue 212103010: Add asADash entry point into SkPathEffect to allow extracting Dash info from PathEffects (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Flatten Updates Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/effects/SkDashPathEffect.cpp
diff --git a/src/effects/SkDashPathEffect.cpp b/src/effects/SkDashPathEffect.cpp
index 58706c5b78f52d55bbead6d4f7a8f3634bd838c6..cab90736c4fc20aceef8becd50c2fdbd473da05d 100644
--- a/src/effects/SkDashPathEffect.cpp
+++ b/src/effects/SkDashPathEffect.cpp
@@ -34,20 +34,10 @@ static SkScalar FindFirstInterval(const SkScalar intervals[], SkScalar phase,
return intervals[0];
}
-SkDashPathEffect::SkDashPathEffect(const SkScalar intervals[], int count,
- SkScalar phase, bool scaleToFit)
- : fScaleToFit(scaleToFit) {
- SkASSERT(intervals);
- SkASSERT(count > 1 && SkAlign2(count) == count);
-
- fIntervals = (SkScalar*)sk_malloc_throw(sizeof(SkScalar) * count);
- fCount = count;
-
+void SkDashPathEffect::setInternalMembers(SkScalar phase) {
SkScalar len = 0;
- for (int i = 0; i < count; i++) {
- SkASSERT(intervals[i] >= 0);
- fIntervals[i] = intervals[i];
- len += intervals[i];
+ for (int i = 0; i < fCount; i++) {
+ len += fIntervals[i];
}
fIntervalLength = len;
@@ -75,8 +65,10 @@ SkDashPathEffect::SkDashPathEffect(const SkScalar intervals[], int count,
}
SkASSERT(phase >= 0 && phase < len);
- fInitialDashLength = FindFirstInterval(intervals, phase,
- &fInitialDashIndex, count);
+ fPhase = phase;
+
+ fInitialDashLength = FindFirstInterval(fIntervals, fPhase,
+ &fInitialDashIndex, fCount);
SkASSERT(fInitialDashLength >= 0);
SkASSERT(fInitialDashIndex >= 0 && fInitialDashIndex < fCount);
@@ -85,6 +77,22 @@ SkDashPathEffect::SkDashPathEffect(const SkScalar intervals[], int count,
}
}
+SkDashPathEffect::SkDashPathEffect(const SkScalar intervals[], int count,
+ SkScalar phase, bool scaleToFit)
+ : fScaleToFit(scaleToFit) {
+ SkASSERT(intervals);
+ SkASSERT(count > 1 && SkAlign2(count) == count);
+
+ fIntervals = (SkScalar*)sk_malloc_throw(sizeof(SkScalar) * count);
+ fCount = count;
+ for (int i = 0; i < count; i++) {
+ SkASSERT(intervals[i] >= 0);
+ fIntervals[i] = intervals[i];
+ }
+
+ this->setInternalMembers(phase);
+}
+
SkDashPathEffect::~SkDashPathEffect() {
sk_free(fIntervals);
}
@@ -529,15 +537,35 @@ bool SkDashPathEffect::asPoints(PointData* results,
return true;
}
+SkPathEffect::DashType SkDashPathEffect::asADash(DashInfo* info) const {
+ if (info) {
+ if (info->fCount >= fCount) {
+ if (info->fIntervals) {
+ memcpy(info->fIntervals, fIntervals, fCount * sizeof(SkScalar));
+ }
+ }
+ info->fCount = fCount;
+ info->fPhase = fPhase;
+ info->fScaleToFit = fScaleToFit;
+ }
+ return kDash_DashType;
+}
+
+#define NEW_FLATTEN_VERSION 123
+
SkFlattenable::Factory SkDashPathEffect::getFactory() const {
return CreateProc;
}
void SkDashPathEffect::flatten(SkWriteBuffer& buffer) const {
this->INHERITED::flatten(buffer);
- buffer.writeInt(fInitialDashIndex);
- buffer.writeScalar(fInitialDashLength);
- buffer.writeScalar(fIntervalLength);
+ if (buffer.pictureVersion() < NEW_FLATTEN_VERSION) {
bsalomon 2014/03/28 14:57:22 Do we need this? Will we ever write an old picture
+ buffer.writeInt(fInitialDashIndex);
+ buffer.writeScalar(fInitialDashLength);
+ buffer.writeScalar(fIntervalLength);
+ } else {
+ buffer.writeScalar(fPhase);
+ }
buffer.writeBool(fScaleToFit);
buffer.writeScalarArray(fIntervals, fCount);
}
@@ -547,9 +575,14 @@ SkFlattenable* SkDashPathEffect::CreateProc(SkReadBuffer& buffer) {
}
SkDashPathEffect::SkDashPathEffect(SkReadBuffer& buffer) : INHERITED(buffer) {
- fInitialDashIndex = buffer.readInt();
- fInitialDashLength = buffer.readScalar();
- fIntervalLength = buffer.readScalar();
+ if (buffer.pictureVersion() < NEW_FLATTEN_VERSION) {
+ fInitialDashIndex = buffer.readInt();
+ fInitialDashLength = buffer.readScalar();
+ fIntervalLength = buffer.readScalar();
+ } else {
+ fPhase = buffer.readScalar();
+ }
+
fScaleToFit = buffer.readBool();
fCount = buffer.getArrayCount();
@@ -560,4 +593,14 @@ SkDashPathEffect::SkDashPathEffect(SkReadBuffer& buffer) : INHERITED(buffer) {
} else {
fIntervals = NULL;
}
+
+ if (buffer.pictureVersion() < NEW_FLATTEN_VERSION) {
+ fPhase = 0.0;
+ for (int i = 0; i < fInitialDashIndex; ++i) {
+ fPhase += fIntervals[i];
+ }
+ fPhase += fInitialDashLength;
+ } else {
+ this->setInternalMembers(fPhase);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698