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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/blurcircles2.cpp
diff --git a/gm/blurcircles2.cpp b/gm/blurcircles2.cpp
index 284c1ab24e1a4399b3cb5852d45bc8f8cae716c7..ad0c37dc4b994b60e2c6f105864f236add5dedcc 100644
--- a/gm/blurcircles2.cpp
+++ b/gm/blurcircles2.cpp
@@ -20,6 +20,9 @@
*
* In Sample mode this draws a single circle and almost-circle with animating radius and blur
* radius.
+ *
+ * Bench mode draws the same as GM mode but without the comparison almost-circle paths. It also
+ * slightly perturbs the blur and circle radii to stress caching of blurred profiles in GPU mode.
*/
class BlurCircles2GM : public skiagm::GM {
public:
@@ -32,6 +35,8 @@ public:
}
protected:
+ bool runAsBench() const override { return true; }
+
SkString onShortName() override { return SkString("blurcircles2"); }
SkISize onISize() override {
@@ -69,43 +74,58 @@ protected:
canvas->drawPath(almostCircle, paint);
canvas->restore();
} else {
+ bool benchMode = this->getMode() == kBench_Mode;
canvas->save();
static constexpr SkScalar kPad = 5;
static constexpr SkScalar kRadiusSteps = 5;
static constexpr SkScalar kBlurRadiusSteps = 5;
canvas->translate(kPad + kMinRadius + kMaxBlurRadius,
kPad + kMinRadius + kMaxBlurRadius);
+ static constexpr SkScalar kDeltaRadius = (kMaxRadius - kMinRadius) / kRadiusSteps;
+ static constexpr SkScalar kDeltaBlurRadius = (kMaxBlurRadius - kMinBlurRadius) /
+ kBlurRadiusSteps;
SkScalar lineWidth = 0;
- for (int r = 0; r < kRadiusSteps - 1; ++r) {
- const SkScalar radius = r * (kMaxRadius - kMinRadius) / kBlurRadiusSteps +
- kMinRadius;
- lineWidth += 2 * (radius + kMaxBlurRadius) + kPad;
+ if (!benchMode) {
+ for (int r = 0; r < kRadiusSteps - 1; ++r) {
+ const SkScalar radius = r * kDeltaRadius + kMinRadius;
+ lineWidth += 2 * (radius + kMaxBlurRadius) + kPad;
+ }
}
for (int br = 0; br < kBlurRadiusSteps; ++br) {
- const SkScalar blurRadius = br * (kMaxBlurRadius - kMinBlurRadius) /
- kBlurRadiusSteps + kMinBlurRadius;
+ SkScalar blurRadius = br * kDeltaBlurRadius + kMinBlurRadius;
+ if (benchMode) {
+ blurRadius += fRandom.nextSScalar1() * kDeltaBlurRadius;
+ }
const SkScalar maxRowR = blurRadius + kMaxRadius;
paint.setMaskFilter(blurMaker(blurRadius));
canvas->save();
for (int r = 0; r < kRadiusSteps; ++r) {
- const SkScalar radius = r * (kMaxRadius - kMinRadius) / kBlurRadiusSteps +
- kMinRadius;
+ SkScalar radius = r * kDeltaRadius + kMinRadius;
+ if (benchMode) {
+ radius += fRandom.nextSScalar1() * kDeltaRadius;
+ }
SkPath almostCircle;
- almostCircleMaker(radius, &almostCircle);
+ if (!benchMode) {
+ almostCircleMaker(radius, &almostCircle);
+ }
canvas->save();
canvas->drawCircle(0, 0, radius, paint);
canvas->translate(0, 2 * maxRowR + kPad);
+ if (!benchMode) {
canvas->drawPath(almostCircle, paint);
+ }
canvas->restore();
const SkScalar maxColR = radius + kMaxBlurRadius;
canvas->translate(maxColR * 2 + kPad, 0);
}
canvas->restore();
- SkPaint blackPaint;
- blackPaint.setColor(SK_ColorBLACK);
- const SkScalar lineY = 3 * maxRowR + 1.5f * kPad;
- if (br != kBlurRadiusSteps - 1) {
- canvas->drawLine(0, lineY, lineWidth, lineY, blackPaint);
+ if (!benchMode) {
+ SkPaint blackPaint;
+ blackPaint.setColor(SK_ColorBLACK);
+ const SkScalar lineY = 3 * maxRowR + 1.5f * kPad;
+ if (br != kBlurRadiusSteps - 1) {
+ canvas->drawLine(0, lineY, lineWidth, lineY, blackPaint);
+ }
}
canvas->translate(0, maxRowR * 4 + 2 * kPad);
}
@@ -135,6 +155,8 @@ private:
SkScalar fAnimRadius;
SkScalar fAnimBlurRadius;
+ SkRandom fRandom;
+
typedef skiagm::GM INHERITED;
};
« 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