Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
HardStopGradientBench_ScaleNumColors.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
17#include "tools/ToolUtils.h"
18
20public:
22 fName.printf("hardstop_scale_num_colors_%s_%03d_colors",
24
25 fTileMode = tilemode;
26 fColorCount = count;
27 }
28
29 const char* onGetName() override {
30 return fName.c_str();
31 }
32
33 SkISize onGetSize() override {
34 return SkISize::Make(kSize, kSize);
35 }
36
37 /*
38 * Set up a linear gradient from left to right with
39 * fColorCount colors alternating between four
40 * different colors. The positions are evenly spaced,
41 * with the exception of the first two; these create a
42 * hard stop in order to trigger the hard stop code.
43 */
44 void onPreDraw(SkCanvas* canvas) override {
45 // Left to right
46 SkPoint points[2] = {
47 SkPoint::Make(0, kSize/2),
48 SkPoint::Make(kSize-1, kSize/2),
49 };
50
51 constexpr int kNumColorChoices = 4;
52 SkColor color_choices[kNumColorChoices] = {
57 };
58
59 // Alternate between different choices
60 SkColor colors[100];
61 for (int i = 0; i < fColorCount; i++) {
62 colors[i] = color_choices[i % kNumColorChoices];
63 }
64
65 // Create a hard stop
66 SkScalar positions[100];
67 positions[0] = 0.0f;
68 positions[1] = 0.0f;
69 for (int i = 2; i < fColorCount; i++) {
70 // Evenly spaced afterwards
71 positions[i] = i / (fColorCount - 1.0f);
72 }
73
75 colors,
76 positions,
77 fColorCount,
78 fTileMode,
79 0,
80 nullptr));
81 }
82
83 /*
84 * Draw simple linear gradient from left to right
85 */
86 void onDraw(int loops, SkCanvas* canvas) override {
87 for (int i = 0; i < loops; i++) {
88 canvas->drawPaint(fPaint);
89 }
90 }
91
92private:
93 static const int kSize = 500;
94
95 SkTileMode fTileMode;
96 SkString fName;
97 int fColorCount;
98 SkPaint fPaint;
99
100 using INHERITED = Benchmark;
101};
102
103// Clamp
111
112// Repeat
120
121// Mirror
#define DEF_BENCH(code)
Definition Benchmark.h:20
int count
static const int points[]
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
SkTileMode
Definition SkTileMode.h:13
HardStopGradientBench_ScaleNumColors(SkTileMode tilemode, int count)
void onDraw(int loops, SkCanvas *canvas) override
void drawPaint(const SkPaint &paint)
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
const char * tilemode_name(SkTileMode mode)
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
static constexpr SkPoint Make(float x, float y)