#include "SkBenchmark.h"
#include "SkCanvas.h"
#include "SkPathUtils.h"
#include "SkRandom.h"
#include "SkTime.h"
#include "SkString.h"
#define H 16
#define W 16
#define STRIDE 2
static void fillRandomBits( int chars, char* bits ){
    SkRandom rand(SkTime::GetMSecs());
    for (int i = 0; i < chars; ++i){
        bits[i] = rand.nextU();
    }
}
static void path_proc(char* bits, SkPath* path) {
    SkPathUtils::BitsToPath_Path(path, bits, H, W, STRIDE);
}
static void region_proc(char* bits, SkPath* path) {
    SkPathUtils::BitsToPath_Region(path, bits, H, W, STRIDE);
}
class PathUtilsBench : public SkBenchmark {
    typedef void (*Proc)(char*, SkPath*);
    Proc fProc;
    SkString fName;
    char* bits[H * STRIDE];
public:
    PathUtilsBench(Proc proc, const char name[])  {
        fProc = proc;
        fName.printf("pathUtils_%s", name);
    }
protected:
    virtual const char* onGetName() { return fName.c_str(); }
    virtual void onDraw(const int loops, SkCanvas* canvas) {
        for (int i = 0; i < loops; ++i){
                        fillRandomBits(H * STRIDE, (char*) &bits);
                        SkPath path;
            fProc( (char*) &bits, &path);
        }
    }
private:
    typedef SkBenchmark INHERITED;
};
DEF_BENCH( return SkNEW_ARGS(PathUtilsBench, (path_proc, "path")); )
DEF_BENCH( return SkNEW_ARGS(PathUtilsBench, (region_proc, "region")); )