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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/*
* Copyright 2013 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 "SkPaint.h"
#include "SkRRect.h"
#include "SkString.h"
struct RRectRec {
SkCanvas* fCanvas;
SkRRect fRRect;
SkPaint fPaint;
};
typedef const char* (*DrawProc)(const RRectRec*, int);
static const char* draw_rect(const RRectRec* rec, int count) {
if (rec) {
const SkRect& r = rec->fRRect.getBounds();
for (int i = 0; i < count; ++i) {
rec->fCanvas->drawRect(r, rec->fPaint);
}
}
return "rect";
}
static const char* draw_rrect(const RRectRec* rec, int count) {
if (rec) {
for (int i = 0; i < count; ++i) {
rec->fCanvas->drawRRect(rec->fRRect, rec->fPaint);
}
}
return "rrect";
}
static const char* draw_oval(const RRectRec* rec, int count) {
if (rec) {
const SkRect& r = rec->fRRect.getBounds();
for (int i = 0; i < count; ++i) {
rec->fCanvas->drawOval(r, rec->fPaint);
}
}
return "oval";
}
// Handles rect, rrect, and oval
//
// Test drawing a small stroked version to see the effect of special-casing
// our stroke code for these convex single-contour shapes.
//
class StrokeRRectBench : public SkBenchmark {
SkString fName;
SkPaint::Join fJoin;
RRectRec fRec;
DrawProc fProc;
public:
StrokeRRectBench(void* param, SkPaint::Join j, DrawProc proc) : SkBenchmark(param) {
static const char* gJoinName[] = {
"miter", "round", "bevel"
};
fJoin = j;
fProc = proc;
fName.printf("draw_stroke_%s_%s", proc(NULL, 0), gJoinName[j]);
SkRect r = { 20, 20, 40, 40 };
SkScalar rad = 4;
fRec.fRRect.setRectXY(r, rad, rad);
}
protected:
virtual const char* onGetName() {
return fName.c_str();
}
virtual void onDraw(SkCanvas* canvas) {
fRec.fCanvas = canvas;
this->setupPaint(&fRec.fPaint);
fRec.fPaint.setStyle(SkPaint::kStroke_Style);
fRec.fPaint.setStrokeJoin(fJoin);
fRec.fPaint.setStrokeWidth(5);
fProc(&fRec, this->getLoops());
}
private:
typedef SkBenchmark INHERITED;
};
DEF_BENCH( return new StrokeRRectBench(p, SkPaint::kRound_Join, draw_rect); )
DEF_BENCH( return new StrokeRRectBench(p, SkPaint::kBevel_Join, draw_rect); )
DEF_BENCH( return new StrokeRRectBench(p, SkPaint::kMiter_Join, draw_rect); )
DEF_BENCH( return new StrokeRRectBench(p, SkPaint::kRound_Join, draw_rrect); )
DEF_BENCH( return new StrokeRRectBench(p, SkPaint::kBevel_Join, draw_rrect); )
DEF_BENCH( return new StrokeRRectBench(p, SkPaint::kMiter_Join, draw_rrect); )
DEF_BENCH( return new StrokeRRectBench(p, SkPaint::kRound_Join, draw_oval); )
DEF_BENCH( return new StrokeRRectBench(p, SkPaint::kBevel_Join, draw_oval); )
DEF_BENCH( return new StrokeRRectBench(p, SkPaint::kMiter_Join, draw_oval); )
|