Flutter Engine
The Flutter Engine
HardStopGradientBench_ScaleNumHardStops.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
17
18using namespace skia_private;
19
21public:
22 HardStopGradientBench_ScaleNumHardStops(int colorCount, int hardStopCount) {
23 SkASSERT(hardStopCount <= colorCount/2);
24
25 fName.printf("hardstop_scale_num_hard_stops_%03d_colors_%03d_hard_stops",
26 colorCount, hardStopCount);
27
28 fColorCount = colorCount;
29 fHardStopCount = hardStopCount;
30 }
31
32 const char* onGetName() override {
33 return fName.c_str();
34 }
35
36 SkISize onGetSize() override {
37 return SkISize::Make(kSize, kSize);
38 }
39
40 void onPreDraw(SkCanvas* canvas) override {
41 // Left to right
42 SkPoint points[2] = {
43 SkPoint::Make(0, kSize/2),
44 SkPoint::Make(kSize-1, kSize/2),
45 };
46
47 constexpr int kNumColorChoices = 4;
48 SkColor color_choices[kNumColorChoices] = {
53 };
54
55 // Alternate between different choices
56 AutoTArray<SkColor> colors(fColorCount);
57 for (int i = 0; i < fColorCount; i++) {
58 colors[i] = color_choices[i % kNumColorChoices];
59 }
60
61 // Create requisite number of hard stops, and evenly
62 // space positions after that
63 AutoTArray<SkScalar> positions(fColorCount);
64 int k = 0;
65 for (int i = 0; i < fHardStopCount; i++) {
66 float val = k/2.0f;
67 positions[k++] = val / fColorCount;
68 positions[k++] = val / fColorCount;
69 }
70 for (int i = k; i < fColorCount; i++) {
71 positions[i] = i / (fColorCount - 1.0f);
72 }
73
75 colors.get(),
76 positions.get(),
77 fColorCount,
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 SkString fName;
96 int fColorCount;
97 int fHardStopCount;
98 SkPaint fPaint;
99
100 using INHERITED = Benchmark;
101};
102
106
110
114
#define DEF_BENCH(code)
Definition: Benchmark.h:20
static const int points[]
#define SkASSERT(cond)
Definition: SkAssert.h:116
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
HardStopGradientBench_ScaleNumHardStops(int colorCount, int hardStopCount)
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
PODArray< SkColor > colors
Definition: SkRecords.h:276
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