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

Side by Side Diff: gm/blurcircles2.cpp

Issue 1985713002: Make blurcircles2 run as a benchmark (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Address comment Created 4 years, 7 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
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkAnimTimer.h" 9 #include "SkAnimTimer.h"
10 #include "SkBlurMask.h" 10 #include "SkBlurMask.h"
11 #include "SkBlurMaskFilter.h" 11 #include "SkBlurMaskFilter.h"
12 #include "SkCanvas.h" 12 #include "SkCanvas.h"
13 #include "SkPaint.h" 13 #include "SkPaint.h"
14 #include "SkPath.h" 14 #include "SkPath.h"
15 #include "SkString.h" 15 #include "SkString.h"
16 16
17 /** 17 /**
18 * In GM mode this draws an array of circles with different radii and different blur radii. Below 18 * In GM mode this draws an array of circles with different radii and different blur radii. Below
19 * each circle an almost-circle path is drawn with the same blur filter for comp arison. 19 * each circle an almost-circle path is drawn with the same blur filter for comp arison.
20 * 20 *
21 * In Sample mode this draws a single circle and almost-circle with animating ra dius and blur 21 * In Sample mode this draws a single circle and almost-circle with animating ra dius and blur
22 * radius. 22 * radius.
23 *
24 * Bench mode draws the same as GM mode but without the comparison almost-circle paths. It also
25 * slightly perturbs the blur and circle radii to stress caching of blurred prof iles in GPU mode.
23 */ 26 */
24 class BlurCircles2GM : public skiagm::GM { 27 class BlurCircles2GM : public skiagm::GM {
25 public: 28 public:
26 BlurCircles2GM() { 29 BlurCircles2GM() {
27 fAnimRadius = SkAnimTimer::PingPong(0, kRadiusPingPoingPeriod, kRadiusPi ngPoingShift, 30 fAnimRadius = SkAnimTimer::PingPong(0, kRadiusPingPoingPeriod, kRadiusPi ngPoingShift,
28 kMinRadius, kMaxRadius); 31 kMinRadius, kMaxRadius);
29 fAnimBlurRadius = SkAnimTimer::PingPong(0, kBlurRadiusPingPoingPeriod, 32 fAnimBlurRadius = SkAnimTimer::PingPong(0, kBlurRadiusPingPoingPeriod,
30 kBlurRadiusPingPoingShift, kMinB lurRadius, 33 kBlurRadiusPingPoingShift, kMinB lurRadius,
31 kMaxBlurRadius); 34 kMaxBlurRadius);
32 } 35 }
33 36
34 protected: 37 protected:
38 bool runAsBench() const override { return true; }
39
35 SkString onShortName() override { return SkString("blurcircles2"); } 40 SkString onShortName() override { return SkString("blurcircles2"); }
36 41
37 SkISize onISize() override { 42 SkISize onISize() override {
38 return SkISize::Make(730, 1350); 43 return SkISize::Make(730, 1350);
39 } 44 }
40 45
41 void onDraw(SkCanvas* canvas) override { 46 void onDraw(SkCanvas* canvas) override {
42 static constexpr SkScalar kMaxR = kMaxRadius + kMaxBlurRadius; 47 static constexpr SkScalar kMaxR = kMaxRadius + kMaxBlurRadius;
43 48
44 auto almostCircleMaker = [] (SkScalar radius, SkPath* dst) { 49 auto almostCircleMaker = [] (SkScalar radius, SkPath* dst) {
(...skipping 17 matching lines...) Expand all
62 SkISize size = canvas->getBaseLayerSize(); 67 SkISize size = canvas->getBaseLayerSize();
63 SkPath almostCircle; 68 SkPath almostCircle;
64 almostCircleMaker(fAnimRadius, &almostCircle); 69 almostCircleMaker(fAnimRadius, &almostCircle);
65 canvas->save(); 70 canvas->save();
66 canvas->translate(size.fWidth / 2.f, size.fHeight / 4.f); 71 canvas->translate(size.fWidth / 2.f, size.fHeight / 4.f);
67 canvas->drawCircle(0, 0, fAnimRadius, paint); 72 canvas->drawCircle(0, 0, fAnimRadius, paint);
68 canvas->translate(0, 2 * kMaxR); 73 canvas->translate(0, 2 * kMaxR);
69 canvas->drawPath(almostCircle, paint); 74 canvas->drawPath(almostCircle, paint);
70 canvas->restore(); 75 canvas->restore();
71 } else { 76 } else {
77 bool benchMode = this->getMode() == kBench_Mode;
72 canvas->save(); 78 canvas->save();
73 static constexpr SkScalar kPad = 5; 79 static constexpr SkScalar kPad = 5;
74 static constexpr SkScalar kRadiusSteps = 5; 80 static constexpr SkScalar kRadiusSteps = 5;
75 static constexpr SkScalar kBlurRadiusSteps = 5; 81 static constexpr SkScalar kBlurRadiusSteps = 5;
76 canvas->translate(kPad + kMinRadius + kMaxBlurRadius, 82 canvas->translate(kPad + kMinRadius + kMaxBlurRadius,
77 kPad + kMinRadius + kMaxBlurRadius); 83 kPad + kMinRadius + kMaxBlurRadius);
84 static constexpr SkScalar kDeltaRadius = (kMaxRadius - kMinRadius) / kRadiusSteps;
85 static constexpr SkScalar kDeltaBlurRadius = (kMaxBlurRadius - kMinB lurRadius) /
86 kBlurRadiusSteps;
78 SkScalar lineWidth = 0; 87 SkScalar lineWidth = 0;
79 for (int r = 0; r < kRadiusSteps - 1; ++r) { 88 if (!benchMode) {
80 const SkScalar radius = r * (kMaxRadius - kMinRadius) / kBlurRad iusSteps + 89 for (int r = 0; r < kRadiusSteps - 1; ++r) {
81 kMinRadius; 90 const SkScalar radius = r * kDeltaRadius + kMinRadius;
82 lineWidth += 2 * (radius + kMaxBlurRadius) + kPad; 91 lineWidth += 2 * (radius + kMaxBlurRadius) + kPad;
92 }
83 } 93 }
84 for (int br = 0; br < kBlurRadiusSteps; ++br) { 94 for (int br = 0; br < kBlurRadiusSteps; ++br) {
85 const SkScalar blurRadius = br * (kMaxBlurRadius - kMinBlurRadiu s) / 95 SkScalar blurRadius = br * kDeltaBlurRadius + kMinBlurRadius;
86 kBlurRadiusSteps + kMinBlurRadius; 96 if (benchMode) {
97 blurRadius += fRandom.nextSScalar1() * kDeltaBlurRadius;
98 }
87 const SkScalar maxRowR = blurRadius + kMaxRadius; 99 const SkScalar maxRowR = blurRadius + kMaxRadius;
88 paint.setMaskFilter(blurMaker(blurRadius)); 100 paint.setMaskFilter(blurMaker(blurRadius));
89 canvas->save(); 101 canvas->save();
90 for (int r = 0; r < kRadiusSteps; ++r) { 102 for (int r = 0; r < kRadiusSteps; ++r) {
91 const SkScalar radius = r * (kMaxRadius - kMinRadius) / kBlu rRadiusSteps + 103 SkScalar radius = r * kDeltaRadius + kMinRadius;
92 kMinRadius; 104 if (benchMode) {
105 radius += fRandom.nextSScalar1() * kDeltaRadius;
106 }
93 SkPath almostCircle; 107 SkPath almostCircle;
94 almostCircleMaker(radius, &almostCircle); 108 if (!benchMode) {
109 almostCircleMaker(radius, &almostCircle);
110 }
95 canvas->save(); 111 canvas->save();
96 canvas->drawCircle(0, 0, radius, paint); 112 canvas->drawCircle(0, 0, radius, paint);
97 canvas->translate(0, 2 * maxRowR + kPad); 113 canvas->translate(0, 2 * maxRowR + kPad);
114 if (!benchMode) {
98 canvas->drawPath(almostCircle, paint); 115 canvas->drawPath(almostCircle, paint);
116 }
99 canvas->restore(); 117 canvas->restore();
100 const SkScalar maxColR = radius + kMaxBlurRadius; 118 const SkScalar maxColR = radius + kMaxBlurRadius;
101 canvas->translate(maxColR * 2 + kPad, 0); 119 canvas->translate(maxColR * 2 + kPad, 0);
102 } 120 }
103 canvas->restore(); 121 canvas->restore();
104 SkPaint blackPaint; 122 if (!benchMode) {
105 blackPaint.setColor(SK_ColorBLACK); 123 SkPaint blackPaint;
106 const SkScalar lineY = 3 * maxRowR + 1.5f * kPad; 124 blackPaint.setColor(SK_ColorBLACK);
107 if (br != kBlurRadiusSteps - 1) { 125 const SkScalar lineY = 3 * maxRowR + 1.5f * kPad;
108 canvas->drawLine(0, lineY, lineWidth, lineY, blackPaint); 126 if (br != kBlurRadiusSteps - 1) {
127 canvas->drawLine(0, lineY, lineWidth, lineY, blackPaint) ;
128 }
109 } 129 }
110 canvas->translate(0, maxRowR * 4 + 2 * kPad); 130 canvas->translate(0, maxRowR * 4 + 2 * kPad);
111 } 131 }
112 canvas->restore(); 132 canvas->restore();
113 } 133 }
114 } 134 }
115 135
116 bool onAnimate(const SkAnimTimer& timer) override { 136 bool onAnimate(const SkAnimTimer& timer) override {
117 fAnimRadius = timer.pingPong(kRadiusPingPoingPeriod, kRadiusPingPoingShi ft, kMinRadius, 137 fAnimRadius = timer.pingPong(kRadiusPingPoingPeriod, kRadiusPingPoingShi ft, kMinRadius,
118 kMaxRadius); 138 kMaxRadius);
119 fAnimBlurRadius = timer.pingPong(kBlurRadiusPingPoingPeriod, kBlurRadius PingPoingShift, 139 fAnimBlurRadius = timer.pingPong(kBlurRadiusPingPoingPeriod, kBlurRadius PingPoingShift,
120 kMinBlurRadius, kMaxBlurRadius); 140 kMinBlurRadius, kMaxBlurRadius);
121 return true; 141 return true;
122 } 142 }
123 143
124 private: 144 private:
125 static constexpr SkScalar kMinRadius = 15; 145 static constexpr SkScalar kMinRadius = 15;
126 static constexpr SkScalar kMaxRadius = 45; 146 static constexpr SkScalar kMaxRadius = 45;
127 static constexpr SkScalar kRadiusPingPoingPeriod = 8; 147 static constexpr SkScalar kRadiusPingPoingPeriod = 8;
128 static constexpr SkScalar kRadiusPingPoingShift = 3; 148 static constexpr SkScalar kRadiusPingPoingShift = 3;
129 149
130 static constexpr SkScalar kMinBlurRadius = 5; 150 static constexpr SkScalar kMinBlurRadius = 5;
131 static constexpr SkScalar kMaxBlurRadius = 45; 151 static constexpr SkScalar kMaxBlurRadius = 45;
132 static constexpr SkScalar kBlurRadiusPingPoingPeriod = 3; 152 static constexpr SkScalar kBlurRadiusPingPoingPeriod = 3;
133 static constexpr SkScalar kBlurRadiusPingPoingShift = 1.5; 153 static constexpr SkScalar kBlurRadiusPingPoingShift = 1.5;
134 154
135 SkScalar fAnimRadius; 155 SkScalar fAnimRadius;
136 SkScalar fAnimBlurRadius; 156 SkScalar fAnimBlurRadius;
137 157
158 SkRandom fRandom;
159
138 typedef skiagm::GM INHERITED; 160 typedef skiagm::GM INHERITED;
139 }; 161 };
140 162
141 DEF_GM(return new BlurCircles2GM();) 163 DEF_GM(return new BlurCircles2GM();)
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