2013-07-01 17:50:29 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
#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
|
|
|
|
|
|
|
|
//this function is redefined for sample, test, and bench. is there anywhere
|
2013-07-02 07:00:59 +00:00
|
|
|
// I can put it to avoid code duplcation?
|
2013-07-01 17:50:29 +00:00
|
|
|
static void fillRandomBits( int chars, char* bits ){
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand(SkTime::GetMSecs());
|
2013-07-01 17:50:29 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < chars; ++i){
|
|
|
|
bits[i] = rand.nextU();
|
|
|
|
}
|
2013-07-02 07:00:59 +00:00
|
|
|
}
|
2013-07-01 17:50:29 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Emulates the mix of rects blitted by gmail during scrolling
|
|
|
|
class PathUtilsBench : public SkBenchmark {
|
|
|
|
typedef void (*Proc)(char*, SkPath*);
|
|
|
|
|
|
|
|
Proc fProc;
|
|
|
|
SkString fName;
|
|
|
|
char* bits[H * STRIDE];
|
2013-07-02 07:00:59 +00:00
|
|
|
|
2013-07-01 17:50:29 +00:00
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
PathUtilsBench(Proc proc, const char name[]) {
|
2013-07-01 17:50:29 +00:00
|
|
|
fProc = proc;
|
|
|
|
fName.printf("pathUtils_%s", name);
|
2013-07-02 07:00:59 +00:00
|
|
|
|
2013-07-01 17:50:29 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() { return fName.c_str(); }
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
|
|
|
2013-09-10 19:23:38 +00:00
|
|
|
for (int i = 0; i < this->getLoops(); ++i){
|
2013-07-01 17:50:29 +00:00
|
|
|
//create a random 16x16 bitmap
|
|
|
|
fillRandomBits(H * STRIDE, (char*) &bits);
|
2013-07-02 07:00:59 +00:00
|
|
|
|
2013-07-01 17:50:29 +00:00
|
|
|
//use passed function pointer to handle it
|
|
|
|
SkPath path;
|
|
|
|
fProc( (char*) &bits, &path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef SkBenchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return SkNEW_ARGS(PathUtilsBench, (path_proc, "path")); )
|
|
|
|
DEF_BENCH( return SkNEW_ARGS(PathUtilsBench, (region_proc, "region")); )
|