Remove GrRandom API in favor of SkRandom.
TEST=tests
R=bsalomon@google.com
Review URL: https://codereview.appspot.com/6855062
git-svn-id: http://skia.googlecode.com/svn/trunk@6539 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi
index 787ffc9..018a9d6 100644
--- a/gyp/gpu.gypi
+++ b/gyp/gpu.gypi
@@ -91,7 +91,6 @@
'<(skia_src_path)/gpu/GrPathUtils.cpp',
'<(skia_src_path)/gpu/GrPathUtils.h',
'<(skia_src_path)/gpu/GrPlotMgr.h',
- '<(skia_src_path)/gpu/GrRandom.h',
'<(skia_src_path)/gpu/GrRectanizer.cpp',
'<(skia_src_path)/gpu/GrRectanizer.h',
'<(skia_src_path)/gpu/GrRedBlackTree.h',
diff --git a/include/core/SkRandom.h b/include/core/SkRandom.h
index 4731bbe..c8d7199 100644
--- a/include/core/SkRandom.h
+++ b/include/core/SkRandom.h
@@ -40,6 +40,21 @@
*/
S16CPU nextS16() { return this->nextS() >> 16; }
+ /**
+ * Returns value [0...1) as a float
+ */
+ float nextF() {
+ // const is 1 / (2^32 - 1)
+ return (float)(this->nextU() * 2.32830644e-10);
+ }
+
+ /**
+ * Returns value [min...max) as a float
+ */
+ float nextRangeF(float min, float max) {
+ return min + this->nextF() * (max - min);
+ }
+
/** Return the next pseudo random number, as an unsigned value of
at most bitCount bits.
@param bitCount The maximum number of bits to be returned
diff --git a/src/gpu/GrClipMaskManager.cpp b/src/gpu/GrClipMaskManager.cpp
index 893bcb1..772ba56 100644
--- a/src/gpu/GrClipMaskManager.cpp
+++ b/src/gpu/GrClipMaskManager.cpp
@@ -242,8 +242,8 @@
#define VISUALIZE_COMPLEX_CLIP 0
#if VISUALIZE_COMPLEX_CLIP
- #include "GrRandom.h"
- GrRandom gRandom;
+ #include "SkRandom.h"
+ SkRandom gRandom;
#define SET_RANDOM_COLOR drawState->setColor(0xff000000 | gRandom.nextU());
#else
#define SET_RANDOM_COLOR
diff --git a/src/gpu/GrRandom.h b/src/gpu/GrRandom.h
deleted file mode 100644
index c98a8fb..0000000
--- a/src/gpu/GrRandom.h
+++ /dev/null
@@ -1,55 +0,0 @@
-
-/*
- * Copyright 2010 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-
-#ifndef GrRandom_DEFINED
-#define GrRandom_DEFINED
-
-class GrRandom {
-public:
- GrRandom() : fSeed(0) {}
- GrRandom(uint32_t seed) : fSeed(seed) {}
-
- uint32_t seed() const { return fSeed; }
-
- uint32_t nextU() {
- fSeed = fSeed * kMUL + kADD;
- return fSeed;
- }
-
- int32_t nextS() { return (int32_t)this->nextU(); }
-
- /**
- * Returns value [0...1) as a float
- */
- float nextF() {
- // const is 1 / (2^32 - 1)
- return (float)(this->nextU() * 2.32830644e-10);
- }
-
- /**
- * Returns value [min...max) as a float
- */
- float nextF(float min, float max) {
- return min + this->nextF() * (max - min);
- }
-
-private:
- /*
- * These constants taken from "Numerical Recipes in C", reprinted 1999
- */
- enum {
- kMUL = 1664525,
- kADD = 1013904223
- };
- uint32_t fSeed;
-};
-
-#endif
-
diff --git a/src/gpu/GrRedBlackTree.h b/src/gpu/GrRedBlackTree.h
index 8187d81..5038bb0 100644
--- a/src/gpu/GrRedBlackTree.h
+++ b/src/gpu/GrRedBlackTree.h
@@ -943,14 +943,14 @@
}
#endif
-#include "GrRandom.h"
+#include "SkRandom.h"
template <typename T, typename C>
void GrRedBlackTree<T,C>::UnitTest() {
GrRedBlackTree<int> tree;
typedef GrRedBlackTree<int>::Iter iter;
- GrRandom r;
+ SkRandom r;
int count[100] = {0};
// add 10K ints
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp
index a14c95c..1aaefbf 100644
--- a/tests/GLProgramsTest.cpp
+++ b/tests/GLProgramsTest.cpp
@@ -16,27 +16,25 @@
#include "GrBackendEffectFactory.h"
#include "effects/GrConfigConversionEffect.h"
-#include "GrRandom.h"
+#include "SkRandom.h"
#include "Test.h"
namespace {
-// GrRandoms nextU() values have patterns in the low bits
+// SkRandoms nextU() values have patterns in the low bits
// So using nextU() % array_count might never take some values.
-int random_int(GrRandom* r, int count) {
+int random_int(SkRandom* r, int count) {
return (int)(r->nextF() * count);
}
-bool random_bool(GrRandom* r) {
+bool random_bool(SkRandom* r) {
return r->nextF() > .5f;
}
-const GrEffect* create_random_effect(GrRandom* random,
+const GrEffect* create_random_effect(SkRandom* random,
GrContext* context,
GrTexture* dummyTextures[]) {
- // The new code uses SkRandom not GrRandom.
- // TODO: Remove GrRandom.
SkRandom sk_random;
sk_random.setSeed(random->nextU());
GrEffect* effect = GrEffectTestFactory::CreateStage(&sk_random, context, dummyTextures);
@@ -59,7 +57,7 @@
static const int NUM_TESTS = 512;
- GrRandom random;
+ SkRandom random;
for (int t = 0; t < NUM_TESTS; ++t) {
#if 0