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

Side by Side Diff: bench/HardStopGradientBench.cpp

Issue 2140603003: Revert of Add HardStopGradientBench.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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 static const char* get_tilemode_name(SkShader::TileMode tilemode) {
18 switch (tilemode) {
19 case SkShader::kClamp_TileMode:
20 return "clamp";
21 case SkShader::kRepeat_TileMode:
22 return "repeat";
23 case SkShader::kMirror_TileMode:
24 return "mirror";
25 default:
26 SkDEBUGFAIL("Unknown tilemode");
27 return "error";
28 }
29 }
30
31 class HardStopGradientBench : public Benchmark {
32 public:
33 HardStopGradientBench(SkShader::TileMode tilemode, int count) {
34 fName.printf("hardstop_%s_%03d_colors", get_tilemode_name(tilemode), cou nt);
35
36 fTileMode = tilemode;
37 fColorCount = count;
38 }
39
40 const char* onGetName() override {
41 return fName.c_str();
42 }
43
44 SkIPoint onGetSize() override {
45 return SkIPoint::Make(kSize, kSize);
46 }
47
48 void onPreDraw(SkCanvas* canvas) override {
49 // Left to right
50 SkPoint points[2] = {
51 SkPoint::Make(0, kSize/2),
52 SkPoint::Make(kSize-1, kSize/2),
53 };
54
55 // "Evenly spaced" colors
56 SkColor colors[50];
57 for (int i = 0; i < fColorCount; i++) {
58 colors[i] = i * (0xffffffff / fColorCount);
59 }
60
61 // Create a hard stop
62 SkScalar positions[50];
63 positions[0] = 0.0f;
64 positions[1] = 0.0f;
65 for (int i = 2; i < fColorCount; i++) {
66 // Evenly spaced afterwards
67 positions[i] = i / (fColorCount - 1.0f);
68 }
69
70 fPaint.setShader(SkGradientShader::MakeLinear(points,
71 colors,
72 positions,
73 fColorCount,
74 fTileMode,
75 0,
76 nullptr));
77 }
78
79 /*
80 * Draw simple linear gradient from left to right
81 */
82 void onDraw(int loops, SkCanvas* canvas) override {
83 for (int i = 0; i < loops; i++) {
84 canvas->drawPaint(fPaint);
85 }
86 }
87
88 private:
89 static const int kSize = 500;
90
91 SkShader::TileMode fTileMode;
92 SkString fName;
93 int fColorCount;
94 SkPaint fPaint;
95
96 typedef Benchmark INHERITED;
97 };
98
99 // Clamp
100 DEF_BENCH(return new HardStopGradientBench(SkShader::kClamp_TileMode, 5);)
101 DEF_BENCH(return new HardStopGradientBench(SkShader::kClamp_TileMode, 10);)
102 DEF_BENCH(return new HardStopGradientBench(SkShader::kClamp_TileMode, 25);)
103 DEF_BENCH(return new HardStopGradientBench(SkShader::kClamp_TileMode, 50);)
104 DEF_BENCH(return new HardStopGradientBench(SkShader::kClamp_TileMode, 100);)
105
106 // Repeat
107 DEF_BENCH(return new HardStopGradientBench(SkShader::kRepeat_TileMode, 5);)
108 DEF_BENCH(return new HardStopGradientBench(SkShader::kRepeat_TileMode, 10);)
109 DEF_BENCH(return new HardStopGradientBench(SkShader::kRepeat_TileMode, 25);)
110 DEF_BENCH(return new HardStopGradientBench(SkShader::kRepeat_TileMode, 50);)
111 DEF_BENCH(return new HardStopGradientBench(SkShader::kRepeat_TileMode, 100);)
112
113 // Mirror
114 DEF_BENCH(return new HardStopGradientBench(SkShader::kMirror_TileMode, 5);)
115 DEF_BENCH(return new HardStopGradientBench(SkShader::kMirror_TileMode, 10);)
116 DEF_BENCH(return new HardStopGradientBench(SkShader::kMirror_TileMode, 25);)
117 DEF_BENCH(return new HardStopGradientBench(SkShader::kMirror_TileMode, 50);)
118 DEF_BENCH(return new HardStopGradientBench(SkShader::kMirror_TileMode, 100);)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698