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
This commit is contained in:
tfarina@chromium.org 2012-11-21 22:38:36 +00:00
parent 729e1c46ce
commit 223137f49d
6 changed files with 25 additions and 68 deletions

View File

@ -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',

View File

@ -40,6 +40,21 @@ public:
*/
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

View File

@ -242,8 +242,8 @@ bool GrClipMaskManager::setupClipping(const GrClipData* clipDataIn) {
#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

View File

@ -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

View File

@ -943,14 +943,14 @@ bool GrRedBlackTree<T,C>::validateChildRelations(const Node* n,
}
#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

View File

@ -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 @@ bool GrGpuGL::programUnitTest() {
static const int NUM_TESTS = 512;
GrRandom random;
SkRandom random;
for (int t = 0; t < NUM_TESTS; ++t) {
#if 0