diff options
author | tomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-08-25 19:56:04 +0000 |
---|---|---|
committer | tomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-08-25 19:56:04 +0000 |
commit | 3f088e36516ad6bf4fe9c04dfc5a49c0aafef372 (patch) | |
tree | b0c2b58e93d5277d52ab3a516945d010bcd3eca9 | |
parent | 8185f33b38e2a5e0408e7645744d68e3b87a6c8e (diff) |
Move multiple calls to random() out of parameter lists so that the
evaluation order is consistent across compilers.
git-svn-id: http://skia.googlecode.com/svn/trunk@2173 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | gm/points.cpp | 10 | ||||
-rw-r--r-- | gm/strokerects.cpp | 4 | ||||
-rw-r--r-- | gm/strokes.cpp | 4 |
3 files changed, 14 insertions, 4 deletions
diff --git a/gm/points.cpp b/gm/points.cpp index ff535cd24d..4aa65975b6 100644 --- a/gm/points.cpp +++ b/gm/points.cpp @@ -28,8 +28,14 @@ protected: } static void fill_pts(SkPoint pts[], size_t n, SkRandom* rand) { - for (size_t i = 0; i < n; i++) - pts[i].set(rand->nextUScalar1() * 640, rand->nextUScalar1() * 480); + for (size_t i = 0; i < n; i++) { + // Compute these independently and store in variables, rather + // than in the parameter-passing expression, to get consistent + // evaluation order across compilers. + float y = rand->nextUScalar1() * 480; + float x = rand->nextUScalar1() * 640; + pts[i].set(x, y); + } } virtual void onDraw(SkCanvas* canvas) { diff --git a/gm/strokerects.cpp b/gm/strokerects.cpp index 29d8cb0ae8..44c012029c 100644 --- a/gm/strokerects.cpp +++ b/gm/strokerects.cpp @@ -38,9 +38,11 @@ protected: SkScalar y = rand.nextUScalar1() * H; SkScalar w = rand.nextUScalar1() * (W >> 2); SkScalar h = rand.nextUScalar1() * (H >> 2); + SkScalar hoffset = rand.nextSScalar1(); + SkScalar woffset = rand.nextSScalar1(); r->set(x, y, x + w, y + h); - r->offset(-w/2 + rand.nextSScalar1(), -h/2 + + rand.nextSScalar1()); + r->offset(-w/2 + woffset, -h/2 + hoffset); } virtual void onDraw(SkCanvas* canvas) { diff --git a/gm/strokes.cpp b/gm/strokes.cpp index 862a517d5f..d8b21b2f2e 100644 --- a/gm/strokes.cpp +++ b/gm/strokes.cpp @@ -25,9 +25,11 @@ static void rnd_rect(SkRect* r, SkPaint* paint, SkRandom& rand) { SkScalar y = rand.nextUScalar1() * H; SkScalar w = rand.nextUScalar1() * (W >> 2); SkScalar h = rand.nextUScalar1() * (H >> 2); + SkScalar hoffset = rand.nextSScalar1(); + SkScalar woffset = rand.nextSScalar1(); r->set(x, y, x + w, y + h); - r->offset(-w/2 + rand.nextSScalar1(), -h/2 + + rand.nextSScalar1()); + r->offset(-w/2 + woffset, -h/2 + hoffset); paint->setColor(rand.nextU()); paint->setAlpha(0xFF); |