Make blurcircles2 run as a benchmark.
In bench mode it does not draw the comparison paths (or line separators). It also randomly perturbs the blur and circle radii to avoid trivially hitting the same cache entries and each repetition.
BUG=skia:5224
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1985713002
Review-Url: https://codereview.chromium.org/1985713002
diff --git a/gm/blurcircles2.cpp b/gm/blurcircles2.cpp
index 284c1ab..ad0c37d 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 @@
}
protected:
+ bool runAsBench() const override { return true; }
+
SkString onShortName() override { return SkString("blurcircles2"); }
SkISize onISize() override {
@@ -69,43 +74,58 @@
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 @@
SkScalar fAnimRadius;
SkScalar fAnimBlurRadius;
+ SkRandom fRandom;
+
typedef skiagm::GM INHERITED;
};