Flutter Engine
The Flutter Engine
HardStopGradientBench_SpecialHardStops.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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
16
17enum class Kind {
18 k001,
19 k011,
21};
22
23const char* kindstr(Kind k) {
24 switch (k) {
25 case Kind::k001:
26 return "001";
27 case Kind::k011:
28 return "011";
29 case Kind::kCentered:
30 return "centered";
31 default:
32 return "Invalid kind";
33 }
34}
35
37public:
39 fW = w;
40 fH = h;
41 fKind = kind;
42
43 fName.printf("hardstop_special_%03dx%03d_%s", fW, fH, kindstr(fKind));
44 }
45
46 const char* onGetName() override {
47 return fName.c_str();
48 }
49
50 SkISize onGetSize() override {
51 return SkISize::Make(fW, fH);
52 }
53
54 void onPreDraw(SkCanvas* canvas) override {
55 SkPoint points[2] = {
56 SkPoint::Make( 0.0f, fH/2.0f),
57 SkPoint::Make(fW+2.0f, fH/2.0f),
58 };
59
60 SkColor colors[4] = {
65 };
66
67 SkScalar pos_001[3] = {
68 0.0f,
69 0.0f,
70 1.0f,
71 };
72
73 SkScalar pos_011[3] = {
74 0.0f,
75 1.0f,
76 1.0f,
77 };
78
79 SkScalar pos_centered[4] = {
80 0.0f,
81 0.5f,
82 0.5f,
83 1.0f,
84 };
85
86 SkScalar* positions = fKind == Kind::k001 ? pos_001 :
87 fKind == Kind::k011 ? pos_011 :
88 pos_centered;
89
90 int count = fKind == Kind::kCentered ? 4 : 3;
91
93 colors,
94 positions,
95 count,
97 0,
98 nullptr));
99 }
100
101 void onDraw(int loops, SkCanvas* canvas) override {
102 for (int i = 0; i < loops; i++) {
103 canvas->drawPaint(fPaint);
104 }
105 }
106
107private:
108 SkString fName;
109 int fW;
110 int fH;
111 Kind fKind;
112 SkPaint fPaint;
113};
114
120
126
int count
Definition: FontMgrTest.cpp:50
static const int points[]
const char * kindstr(Kind k)
DEF_BENCH(return new HardStopGradientBench_SpecialHardStops(100, 100, Kind::k001);)
@ kCentered
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
void drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
void setShader(sk_sp< SkShader > shader)
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
const char * c_str() const
Definition: SkString.h:133
float SkScalar
Definition: extension.cpp:12
PODArray< SkColor > colors
Definition: SkRecords.h:276
SkScalar w
SkScalar h
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173