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

Unified Diff: bench/HardStopGradientBench_ScaleNumHardStops.cpp

Issue 2178913003: Add HardStopGradientBench_ScaleNumHardStops.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 side-by-side diff with in-line comments
Download patch
Index: bench/HardStopGradientBench_ScaleNumHardStops.cpp
diff --git a/bench/HardStopGradientBench_ScaleNumHardStops.cpp b/bench/HardStopGradientBench_ScaleNumHardStops.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..fabb3b0121ea33d79aa87e408b89cd7488bdbf33
--- /dev/null
+++ b/bench/HardStopGradientBench_ScaleNumHardStops.cpp
@@ -0,0 +1,104 @@
+/*
+ * 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);
+
+ 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),
+ };
+
+ // "Evenly spaced" colors
+ SkAutoTArray<SkColor> colors(fColorCount);
+ for (int i = 0; i < fColorCount; i++) {
+ colors[i] = i * (0xffffffff / fColorCount);
+ }
+
+ // 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++) {
+ positions[k++] = 0.0f;
tomhudson 2016/07/26 13:25:14 This is not right; it looks like you're creating o
+ }
+ for (int i = k; i < fColorCount; i++) {
+ positions[i] = i / (fColorCount - 1.0f);
+ }
+
+ fPaint.setShader(SkGradientShader::MakeLinear(points,
+ colors.get(),
+ positions.get(),
+ fColorCount,
+ SkShader::TileMode::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);)

Powered by Google App Engine
This is Rietveld 408576698