aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench
diff options
context:
space:
mode:
authorGravatar fmenozzi <fmenozzi@google.com>2016-07-28 10:59:49 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-07-28 10:59:49 -0700
commit17e829794db9621879baf2e90856a72b17eaf7dc (patch)
tree97019401e38fcbd65ca4bd379a673674e12ec996 /bench
parentf49d9d77bbaf9b075426046173c976a15bde8ee5 (diff)
Add HardStopGradientBench_ScaleNumHardStops.cpp
Rename HardStopGradientBench.cpp to HardStopGradientBench_ScaleNumColors.cpp BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2178913003 Review-Url: https://codereview.chromium.org/2178913003
Diffstat (limited to 'bench')
-rw-r--r--bench/HardStopGradientBench.cpp124
-rw-r--r--bench/HardStopGradientBench_ScaleNumColors.cpp139
-rw-r--r--bench/HardStopGradientBench_ScaleNumHardStops.cpp114
3 files changed, 253 insertions, 124 deletions
diff --git a/bench/HardStopGradientBench.cpp b/bench/HardStopGradientBench.cpp
deleted file mode 100644
index 3a323fec6f..0000000000
--- a/bench/HardStopGradientBench.cpp
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright 2016 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "Benchmark.h"
-
-#include "SkCanvas.h"
-#include "SkShader.h"
-#include "SkGradientShader.h"
-#include "SkString.h"
-#include "SkColor.h"
-#include "SkPaint.h"
-
-static const char* get_tilemode_name(SkShader::TileMode tilemode) {
- switch (tilemode) {
- case SkShader::kClamp_TileMode:
- return "clamp";
- case SkShader::kRepeat_TileMode:
- return "repeat";
- case SkShader::kMirror_TileMode:
- return "mirror";
- default:
- SkDEBUGFAIL("Unknown tilemode");
- return "error";
- }
-}
-
-class HardStopGradientBench : public Benchmark {
-public:
- HardStopGradientBench(SkShader::TileMode tilemode, int count) {
- fName.printf("hardstop_%s_%03d_colors", get_tilemode_name(tilemode), count);
-
- fTileMode = tilemode;
- fColorCount = count;
- }
-
- const char* onGetName() override {
- return fName.c_str();
- }
-
- SkIPoint onGetSize() override {
- return SkIPoint::Make(kSize, kSize);
- }
-
- void onPreDraw(SkCanvas* canvas) override {
- // Left to right
- SkPoint points[2] = {
- SkPoint::Make(0, kSize/2),
- SkPoint::Make(kSize-1, kSize/2),
- };
-
- // "Evenly spaced" colors
- SkColor colors[100];
- for (int i = 0; i < fColorCount; i++) {
- colors[i] = i * (0xffffffff / fColorCount);
- }
-
- // Create a hard stop
- SkScalar positions[100];
- positions[0] = 0.0f;
- positions[1] = 0.0f;
- for (int i = 2; i < fColorCount; i++) {
- // Evenly spaced afterwards
- positions[i] = i / (fColorCount - 1.0f);
- }
-
- fPaint.setShader(SkGradientShader::MakeLinear(points,
- colors,
- positions,
- fColorCount,
- fTileMode,
- 0,
- nullptr));
- }
-
- /*
- * Draw simple linear gradient from left to right
- */
- void onDraw(int loops, SkCanvas* canvas) override {
- for (int i = 0; i < loops; i++) {
- canvas->drawPaint(fPaint);
- }
- }
-
-private:
- static const int kSize = 500;
-
- SkShader::TileMode fTileMode;
- SkString fName;
- int fColorCount;
- SkPaint fPaint;
-
- typedef Benchmark INHERITED;
-};
-
-// Clamp
-DEF_BENCH(return new HardStopGradientBench(SkShader::kClamp_TileMode, 3);)
-DEF_BENCH(return new HardStopGradientBench(SkShader::kClamp_TileMode, 4);)
-DEF_BENCH(return new HardStopGradientBench(SkShader::kClamp_TileMode, 5);)
-DEF_BENCH(return new HardStopGradientBench(SkShader::kClamp_TileMode, 10);)
-DEF_BENCH(return new HardStopGradientBench(SkShader::kClamp_TileMode, 25);)
-DEF_BENCH(return new HardStopGradientBench(SkShader::kClamp_TileMode, 50);)
-DEF_BENCH(return new HardStopGradientBench(SkShader::kClamp_TileMode, 100);)
-
-// Repeat
-DEF_BENCH(return new HardStopGradientBench(SkShader::kRepeat_TileMode, 3);)
-DEF_BENCH(return new HardStopGradientBench(SkShader::kRepeat_TileMode, 4);)
-DEF_BENCH(return new HardStopGradientBench(SkShader::kRepeat_TileMode, 5);)
-DEF_BENCH(return new HardStopGradientBench(SkShader::kRepeat_TileMode, 10);)
-DEF_BENCH(return new HardStopGradientBench(SkShader::kRepeat_TileMode, 25);)
-DEF_BENCH(return new HardStopGradientBench(SkShader::kRepeat_TileMode, 50);)
-DEF_BENCH(return new HardStopGradientBench(SkShader::kRepeat_TileMode, 100);)
-
-// Mirror
-DEF_BENCH(return new HardStopGradientBench(SkShader::kMirror_TileMode, 3);)
-DEF_BENCH(return new HardStopGradientBench(SkShader::kMirror_TileMode, 4);)
-DEF_BENCH(return new HardStopGradientBench(SkShader::kMirror_TileMode, 5);)
-DEF_BENCH(return new HardStopGradientBench(SkShader::kMirror_TileMode, 10);)
-DEF_BENCH(return new HardStopGradientBench(SkShader::kMirror_TileMode, 25);)
-DEF_BENCH(return new HardStopGradientBench(SkShader::kMirror_TileMode, 50);)
-DEF_BENCH(return new HardStopGradientBench(SkShader::kMirror_TileMode, 100);)
diff --git a/bench/HardStopGradientBench_ScaleNumColors.cpp b/bench/HardStopGradientBench_ScaleNumColors.cpp
new file mode 100644
index 0000000000..108803c496
--- /dev/null
+++ b/bench/HardStopGradientBench_ScaleNumColors.cpp
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Benchmark.h"
+
+#include "SkCanvas.h"
+#include "SkShader.h"
+#include "SkGradientShader.h"
+#include "SkString.h"
+#include "SkColor.h"
+#include "SkPaint.h"
+
+static const char* get_tilemode_name(SkShader::TileMode tilemode) {
+ switch (tilemode) {
+ case SkShader::kClamp_TileMode:
+ return "clamp";
+ case SkShader::kRepeat_TileMode:
+ return "repeat";
+ case SkShader::kMirror_TileMode:
+ return "mirror";
+ default:
+ SkDEBUGFAIL("Unknown tilemode");
+ return "error";
+ }
+}
+
+class HardStopGradientBench_ScaleNumColors : public Benchmark {
+public:
+ HardStopGradientBench_ScaleNumColors(SkShader::TileMode tilemode, int count) {
+ fName.printf("hardstop_scale_num_colors_%s_%03d_colors", get_tilemode_name(tilemode), count);
+
+ fTileMode = tilemode;
+ fColorCount = count;
+ }
+
+ const char* onGetName() override {
+ return fName.c_str();
+ }
+
+ SkIPoint onGetSize() override {
+ return SkIPoint::Make(kSize, kSize);
+ }
+
+ /*
+ * Set up a linear gradient from left to right with
+ * fColorCount colors alternating between four
+ * different colors. The positions are evenly spaced,
+ * with the exception of the first two; these create a
+ * hard stop in order to trigger the hard stop code.
+ */
+ void onPreDraw(SkCanvas* canvas) override {
+ // Left to right
+ SkPoint points[2] = {
+ SkPoint::Make(0, kSize/2),
+ SkPoint::Make(kSize-1, kSize/2),
+ };
+
+ constexpr int kNumColorChoices = 4;
+ SkColor color_choices[kNumColorChoices] = {
+ SK_ColorRED,
+ SK_ColorGREEN,
+ SK_ColorBLUE,
+ SK_ColorYELLOW,
+ };
+
+ // Alternate between different choices
+ SkColor colors[100];
+ for (int i = 0; i < fColorCount; i++) {
+ colors[i] = color_choices[i % kNumColorChoices];
+ }
+
+ // Create a hard stop
+ SkScalar positions[100];
+ positions[0] = 0.0f;
+ positions[1] = 0.0f;
+ for (int i = 2; i < fColorCount; i++) {
+ // Evenly spaced afterwards
+ positions[i] = i / (fColorCount - 1.0f);
+ }
+
+ fPaint.setShader(SkGradientShader::MakeLinear(points,
+ colors,
+ positions,
+ fColorCount,
+ fTileMode,
+ 0,
+ nullptr));
+ }
+
+ /*
+ * Draw simple linear gradient from left to right
+ */
+ void onDraw(int loops, SkCanvas* canvas) override {
+ for (int i = 0; i < loops; i++) {
+ canvas->drawPaint(fPaint);
+ }
+ }
+
+private:
+ static const int kSize = 500;
+
+ SkShader::TileMode fTileMode;
+ SkString fName;
+ int fColorCount;
+ SkPaint fPaint;
+
+ typedef Benchmark INHERITED;
+};
+
+// Clamp
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kClamp_TileMode, 3);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kClamp_TileMode, 4);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kClamp_TileMode, 5);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kClamp_TileMode, 10);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kClamp_TileMode, 25);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kClamp_TileMode, 50);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kClamp_TileMode, 100);)
+
+// Repeat
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kRepeat_TileMode, 3);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kRepeat_TileMode, 4);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kRepeat_TileMode, 5);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kRepeat_TileMode, 10);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kRepeat_TileMode, 25);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kRepeat_TileMode, 50);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kRepeat_TileMode, 100);)
+
+// Mirror
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kMirror_TileMode, 3);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kMirror_TileMode, 4);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kMirror_TileMode, 5);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kMirror_TileMode, 10);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kMirror_TileMode, 25);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kMirror_TileMode, 50);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumColors(SkShader::kMirror_TileMode, 100);)
diff --git a/bench/HardStopGradientBench_ScaleNumHardStops.cpp b/bench/HardStopGradientBench_ScaleNumHardStops.cpp
new file mode 100644
index 0000000000..2b8b55e67a
--- /dev/null
+++ b/bench/HardStopGradientBench_ScaleNumHardStops.cpp
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Benchmark.h"
+
+#include "SkCanvas.h"
+#include "SkShader.h"
+#include "SkGradientShader.h"
+#include "SkString.h"
+#include "SkColor.h"
+#include "SkPaint.h"
+
+class HardStopGradientBench_ScaleNumHardStops : public Benchmark {
+public:
+ HardStopGradientBench_ScaleNumHardStops(int colorCount, int hardStopCount) {
+ SkASSERT(hardStopCount <= colorCount/2);
+
+ fName.printf("hardstop_scale_num_hard_stops_%03d_colors_%03d_hard_stops",
+ colorCount, hardStopCount);
+
+ fColorCount = colorCount;
+ fHardStopCount = hardStopCount;
+ }
+
+ const char* onGetName() override {
+ return fName.c_str();
+ }
+
+ SkIPoint onGetSize() override {
+ return SkIPoint::Make(kSize, kSize);
+ }
+
+ void onPreDraw(SkCanvas* canvas) override {
+ // Left to right
+ SkPoint points[2] = {
+ SkPoint::Make(0, kSize/2),
+ SkPoint::Make(kSize-1, kSize/2),
+ };
+
+ constexpr int kNumColorChoices = 4;
+ SkColor color_choices[kNumColorChoices] = {
+ SK_ColorRED,
+ SK_ColorGREEN,
+ SK_ColorBLUE,
+ SK_ColorYELLOW,
+ };
+
+ // Alternate between different choices
+ SkAutoTArray<SkColor> colors(fColorCount);
+ for (int i = 0; i < fColorCount; i++) {
+ colors[i] = color_choices[i % kNumColorChoices];
+ }
+
+ // Create requisite number of hard stops, and evenly
+ // space positions after that
+ SkAutoTArray<SkScalar> positions(fColorCount);
+ int k = 0;
+ for (int i = 0; i < fHardStopCount; i++) {
+ float val = k/2.0f;
+ positions[k++] = val / fColorCount;
+ positions[k++] = val / fColorCount;
+ }
+ for (int i = k; i < fColorCount; i++) {
+ positions[i] = i / (fColorCount - 1.0f);
+ }
+
+ fPaint.setShader(SkGradientShader::MakeLinear(points,
+ colors.get(),
+ positions.get(),
+ fColorCount,
+ SkShader::kClamp_TileMode,
+ 0,
+ nullptr));
+ }
+
+ /*
+ * Draw simple linear gradient from left to right
+ */
+ void onDraw(int loops, SkCanvas* canvas) override {
+ for (int i = 0; i < loops; i++) {
+ canvas->drawPaint(fPaint);
+ }
+ }
+
+private:
+ static const int kSize = 500;
+
+ SkString fName;
+ int fColorCount;
+ int fHardStopCount;
+ SkPaint fPaint;
+
+ typedef Benchmark INHERITED;
+};
+
+DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(10, 1);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(10, 2);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(10, 5);)
+
+DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(20, 1);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(20, 5);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(20, 10);)
+
+DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(50, 1);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(50, 10);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(50, 25);)
+
+DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(100, 1);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(100, 25);)
+DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(100, 50);)