2013-02-04 14:57:28 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2013-02-04 14:57:28 +00:00
|
|
|
#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.
|
|
|
|
//
|
2014-06-19 19:32:29 +00:00
|
|
|
class StrokeRRectBench : public Benchmark {
|
2013-02-04 14:57:28 +00:00
|
|
|
SkString fName;
|
|
|
|
SkPaint::Join fJoin;
|
|
|
|
RRectRec fRec;
|
|
|
|
DrawProc fProc;
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
StrokeRRectBench(SkPaint::Join j, DrawProc proc) {
|
2013-02-04 14:57:28 +00:00
|
|
|
static const char* gJoinName[] = {
|
|
|
|
"miter", "round", "bevel"
|
|
|
|
};
|
|
|
|
|
|
|
|
fJoin = j;
|
|
|
|
fProc = proc;
|
|
|
|
fName.printf("draw_stroke_%s_%s", proc(NULL, 0), gJoinName[j]);
|
2013-02-05 07:02:01 +00:00
|
|
|
|
2013-02-04 14:57:28 +00:00
|
|
|
SkRect r = { 20, 20, 40, 40 };
|
|
|
|
SkScalar rad = 4;
|
|
|
|
fRec.fRRect.setRectXY(r, rad, rad);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void onDraw(const int loops, SkCanvas* canvas) {
|
2013-02-04 14:57:28 +00:00
|
|
|
fRec.fCanvas = canvas;
|
|
|
|
this->setupPaint(&fRec.fPaint);
|
|
|
|
fRec.fPaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
fRec.fPaint.setStrokeJoin(fJoin);
|
|
|
|
fRec.fPaint.setStrokeWidth(5);
|
2013-12-03 18:17:16 +00:00
|
|
|
fProc(&fRec, loops);
|
2013-02-04 14:57:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-02-04 14:57:28 +00:00
|
|
|
};
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new StrokeRRectBench(SkPaint::kRound_Join, draw_rect); )
|
|
|
|
DEF_BENCH( return new StrokeRRectBench(SkPaint::kBevel_Join, draw_rect); )
|
|
|
|
DEF_BENCH( return new StrokeRRectBench(SkPaint::kMiter_Join, draw_rect); )
|
2013-02-04 14:57:28 +00:00
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new StrokeRRectBench(SkPaint::kRound_Join, draw_rrect); )
|
|
|
|
DEF_BENCH( return new StrokeRRectBench(SkPaint::kBevel_Join, draw_rrect); )
|
|
|
|
DEF_BENCH( return new StrokeRRectBench(SkPaint::kMiter_Join, draw_rrect); )
|
2013-02-04 14:57:28 +00:00
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new StrokeRRectBench(SkPaint::kRound_Join, draw_oval); )
|
|
|
|
DEF_BENCH( return new StrokeRRectBench(SkPaint::kBevel_Join, draw_oval); )
|
|
|
|
DEF_BENCH( return new StrokeRRectBench(SkPaint::kMiter_Join, draw_oval); )
|