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

Unified Diff: src/effects/SkDiscretePathEffect.cpp

Issue 311803002: Randomize seed for SkDiscretePathEffect::filterPath() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Remove unnecessary function Created 6 years, 6 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/SkDiscretePathEffect.cpp
diff --git a/src/effects/SkDiscretePathEffect.cpp b/src/effects/SkDiscretePathEffect.cpp
index de834424df34fc661638fcbb7026bdc8214571a7..8423842ed147df79632b1e48deec48e1aa3d9c68 100644
--- a/src/effects/SkDiscretePathEffect.cpp
+++ b/src/effects/SkDiscretePathEffect.cpp
@@ -12,6 +12,7 @@
#include "SkWriteBuffer.h"
#include "SkPathMeasure.h"
#include "SkRandom.h"
+#include "SkTime.h"
scroggo 2014/06/05 16:09:30 Not used. Please remove.
rs.prinja 2014/06/07 10:46:05 Done.
static void Perterb(SkPoint* p, const SkVector& tangent, SkScalar scale) {
SkVector normal = tangent;
@@ -20,10 +21,12 @@ static void Perterb(SkPoint* p, const SkVector& tangent, SkScalar scale) {
*p += normal;
}
+uint32_t SkDiscretePathEffect::fObjectIdGenerator = 0;
-SkDiscretePathEffect::SkDiscretePathEffect(SkScalar segLength, SkScalar deviation)
- : fSegLength(segLength), fPerterb(deviation)
+SkDiscretePathEffect::SkDiscretePathEffect(SkScalar segLength, SkScalar deviation, uint32_t seedAssist)
scroggo 2014/06/05 16:09:30 Over 100 chars.
rs.prinja 2014/06/07 10:46:05 Done.
+ : fSegLength(segLength), fPerterb(deviation), fSeedAssist(seedAssist)
{
+ fObjectId = fObjectIdGenerator++;
}
bool SkDiscretePathEffect::filterPath(SkPath* dst, const SkPath& src,
@@ -31,7 +34,17 @@ bool SkDiscretePathEffect::filterPath(SkPath* dst, const SkPath& src,
bool doFill = rec->isFillStyle();
SkPathMeasure meas(src, doFill);
- uint32_t seed = SkScalarRoundToInt(meas.getLength());
+
+ /* We want to have identical seeds for identical paths that share the same effect object
+ * but different seeds for identical paths that use different effect objects */
+ uint32_t seed = fObjectId + SkScalarRoundToInt(meas.getLength());
scroggo 2014/06/05 16:09:30 As stated elsewhere, please just use the length an
rs.prinja 2014/06/07 10:46:05 Done.
+
+ /* Also, across different runs of the same program, the same path should be seeded differently */
+ seed += SkTime::GetMSecs() / 1000;
scroggo 2014/06/05 16:09:30 Please remove.
rs.prinja 2014/06/07 10:46:05 Done.
+
+ /* Caller may supply their own seed assist, which by default is 1 */
+ seed *= fSeedAssist;
+
SkLCGRandom rand(seed ^ ((seed << 16) | (seed >> 16)));
SkScalar scale = fPerterb;
SkPoint p;
« include/effects/SkDiscretePathEffect.h ('K') | « include/effects/SkDiscretePathEffect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698