aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/PathUtilsBench.cpp
blob: 4231b72fab58370b69c3902a78ccd8df96e7aac3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
 * 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
// I can put it to avoid code duplcation?
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);
}

/// 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];

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){
            //create a random 16x16 bitmap
            fillRandomBits(H * STRIDE, (char*) &bits);

            //use passed function pointer to handle it
            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")); )