Flutter Engine
The Flutter Engine
BigPathBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 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
8#include "bench/Benchmark.h"
9#include "bench/BigPath.h"
11#include "include/core/SkPath.h"
12#include "tools/ToolUtils.h"
13
14enum Align {
18};
19
20const char* gAlignName[] = { "left", "middle", "right" };
21
22// Inspired by crbug.com/455429
23class BigPathBench : public Benchmark {
24 SkPath fPath;
25 SkString fName;
26 Align fAlign;
27 bool fRound;
28
29public:
30 BigPathBench(Align align, bool round) : fAlign(align), fRound(round) {
31 fName.printf("bigpath_%s", gAlignName[fAlign]);
32 if (round) {
33 fName.append("_round");
34 }
35 }
36
37protected:
38 const char* onGetName() override {
39 return fName.c_str();
40 }
41
42 SkISize onGetSize() override {
43 return SkISize::Make(640, 100);
44 }
45
47
48 void onDraw(int loops, SkCanvas* canvas) override {
50 paint.setAntiAlias(true);
52 paint.setStrokeWidth(2);
53 if (fRound) {
54 paint.setStrokeJoin(SkPaint::kRound_Join);
55 }
56 this->setupPaint(&paint);
57
58 const SkRect r = fPath.getBounds();
59 switch (fAlign) {
60 case kLeft_Align:
61 canvas->translate(-r.left(), 0);
62 break;
63 case kMiddle_Align:
64 break;
65 case kRight_Align:
66 canvas->translate(640 - r.right(), 0);
67 break;
68 }
69
70 for (int i = 0; i < loops; i++) {
71 canvas->drawPath(fPath, paint);
72 }
73 }
74
75private:
76 using INHERITED = Benchmark;
77};
78
79DEF_BENCH( return new BigPathBench(kLeft_Align, false); )
80DEF_BENCH( return new BigPathBench(kMiddle_Align, false); )
81DEF_BENCH( return new BigPathBench(kRight_Align, false); )
82
83DEF_BENCH( return new BigPathBench(kLeft_Align, true); )
84DEF_BENCH( return new BigPathBench(kMiddle_Align, true); )
85DEF_BENCH( return new BigPathBench(kRight_Align, true); )
SkPath fPath
#define DEF_BENCH(code)
Definition: Benchmark.h:20
Align
@ kMiddle_Align
@ kRight_Align
@ kLeft_Align
const char * gAlignName[]
const char * fName
static void round(SkPoint *p)
virtual void setupPaint(SkPaint *paint)
Definition: Benchmark.cpp:55
BigPathBench(Align align, bool round)
void onDelayedSetup() override
SkISize onGetSize() override
void onDraw(int loops, SkCanvas *canvas) override
const char * onGetName() override
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kRound_Join
adds circle
Definition: SkPaint.h:360
Definition: SkPath.h:59
const SkRect & getBounds() const
Definition: SkPath.cpp:430
const Paint & paint
Definition: color_source.cc:38
SkPath make_big_path()
Definition: BigPath.cpp:19
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
constexpr float left() const
Definition: SkRect.h:734
constexpr float right() const
Definition: SkRect.h:748