Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(616)

Side by Side Diff: bench/HardStopGradientBench_ScaleNumHardStops.cpp

Issue 2178913003: Add HardStopGradientBench_ScaleNumHardStops.cpp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 "Benchmark.h"
9
10 #include "SkCanvas.h"
11 #include "SkShader.h"
12 #include "SkGradientShader.h"
13 #include "SkString.h"
14 #include "SkColor.h"
15 #include "SkPaint.h"
16
17 class HardStopGradientBench_ScaleNumHardStops : public Benchmark {
18 public:
19 HardStopGradientBench_ScaleNumHardStops(int colorCount, int hardStopCount) {
20 SkASSERT(hardStopCount <= colorCount);
21
22 fName.printf("hardstop_scale_num_hard_stops_%03d_colors_%03d_hard_stops" ,
23 colorCount, hardStopCount);
24
25 fColorCount = colorCount;
26 fHardStopCount = hardStopCount;
27 }
28
29 const char* onGetName() override {
30 return fName.c_str();
31 }
32
33 SkIPoint onGetSize() override {
34 return SkIPoint::Make(kSize, kSize);
35 }
36
37 void onPreDraw(SkCanvas* canvas) override {
38 // Left to right
39 SkPoint points[2] = {
40 SkPoint::Make(0, kSize/2),
41 SkPoint::Make(kSize-1, kSize/2),
42 };
43
44 // "Evenly spaced" colors
45 SkAutoTArray<SkColor> colors(fColorCount);
46 for (int i = 0; i < fColorCount; i++) {
47 colors[i] = i * (0xffffffff / fColorCount);
48 }
49
50 // Create requisite number of hard stops, and evenly
51 // space positions after that
52 SkAutoTArray<SkScalar> positions(fColorCount);
53 int k = 0;
54 for (int i = 0; i < fHardStopCount; i++) {
55 positions[k++] = 0.0f;
tomhudson 2016/07/26 13:25:14 This is not right; it looks like you're creating o
56 }
57 for (int i = k; i < fColorCount; i++) {
58 positions[i] = i / (fColorCount - 1.0f);
59 }
60
61 fPaint.setShader(SkGradientShader::MakeLinear(points,
62 colors.get(),
63 positions.get(),
64 fColorCount,
65 SkShader::TileMode::kClamp _TileMode,
66 0,
67 nullptr));
68 }
69
70 /*
71 * Draw simple linear gradient from left to right
72 */
73 void onDraw(int loops, SkCanvas* canvas) override {
74 for (int i = 0; i < loops; i++) {
75 canvas->drawPaint(fPaint);
76 }
77 }
78
79 private:
80 static const int kSize = 500;
81
82 SkString fName;
83 int fColorCount;
84 int fHardStopCount;
85 SkPaint fPaint;
86
87 typedef Benchmark INHERITED;
88 };
89
90 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(10, 1);)
91 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(10, 2);)
92 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(10, 5);)
93
94 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(20, 1);)
95 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(20, 5);)
96 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(20, 10);)
97
98 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(50, 1);)
99 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(50, 10);)
100 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(50, 25);)
101
102 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(100, 1);)
103 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(100, 25);)
104 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(100, 50);)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698