Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(618)

Side by Side Diff: bench/PathUtilsBench.cpp

Issue 16829003: Adding my Bitmap2Path sample for 1on1 meeting. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fixed more trybot errors. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | gyp/SampleApp.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7 #include "SkBenchmark.h"
8 #include "SkCanvas.h"
9 #include "SkPathUtils.h"
10 #include "SkRandom.h"
11 #include "SkTime.h"
12 #include "SkString.h"
13
14 #define H 16
15 #define W 16
16 #define STRIDE 2
17
18 //this function is redefined for sample, test, and bench. is there anywhere
19 // I can put it to avoid code duplcation?
20 static void fillRandomBits( int chars, char* bits ){
21 SkTime time;
22 SkMWCRandom rand = SkMWCRandom( time.GetMSecs() );
23
24 for (int i = 0; i < chars; ++i){
25 bits[i] = rand.nextU();
26 }
27 }
28
29 static void path_proc(char* bits, SkPath* path) {
30 SkPathUtils::BitsToPath_Path(path, bits, H, W, STRIDE);
31 }
32
33 static void region_proc(char* bits, SkPath* path) {
34 SkPathUtils::BitsToPath_Region(path, bits, H, W, STRIDE);
35 }
36
37 /// Emulates the mix of rects blitted by gmail during scrolling
38 class PathUtilsBench : public SkBenchmark {
39 typedef void (*Proc)(char*, SkPath*);
40
41 Proc fProc;
42 int fH, fW, fStride;
43 SkString fName;
44 char* bits[H * STRIDE];
45
46 enum { N = SkBENCHLOOP(20) };
47
48 public:
49 PathUtilsBench(void* param, Proc proc, const char name[]) : INHERITED(param) {
50 fProc = proc;
51 fName.printf("pathUtils_%s", name);
52
53
54 }
55
56 protected:
57 virtual const char* onGetName() { return fName.c_str(); }
58
59 virtual void onDraw(SkCanvas* canvas) {
60
61 for (int i = 0; i < N; ++i){
62 //create a random 16x16 bitmap
63 fillRandomBits(H * STRIDE, (char*) &bits);
64
65 //use passed function pointer to handle it
66 SkPath path;
67 fProc( (char*) &bits, &path);
68 }
69 }
70
71 private:
72 typedef SkBenchmark INHERITED;
73 };
74
75 static SkBenchmark* PU_path(void* p) { return SkNEW_ARGS(PathUtilsBench, (p, pat h_proc, "path")); }
76 static SkBenchmark* PU_region(void* p) { return SkNEW_ARGS(PathUtilsBench, (p, r egion_proc, "region")); }
77
78 static BenchRegistry PU_Path(PU_path);
79 static BenchRegistry PU_Region(PU_region);
OLDNEW
« no previous file with comments | « no previous file | gyp/SampleApp.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698