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

Unified Diff: bench/PerlinNoiseBench.cpp

Issue 14087002: Perlin noise adjustments (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 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 | gm/perlinnoise.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/PerlinNoiseBench.cpp
===================================================================
--- bench/PerlinNoiseBench.cpp (revision 0)
+++ bench/PerlinNoiseBench.cpp (revision 0)
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkBenchmark.h"
+#include "SkCanvas.h"
+#include "SkPerlinNoiseShader.h"
+
+class PerlinNoiseBench : public SkBenchmark {
+ SkISize fSize;
+
+public:
+ PerlinNoiseBench(void* param) : INHERITED(param) {
+ fSize = SkISize::Make(80, 80);
+ }
+
+protected:
+ virtual const char* onGetName() SK_OVERRIDE {
+ return "perlinnoise";
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ this->test(canvas, 0, 0, SkPerlinNoiseShader::kFractalNoise_Type,
+ 0.1f, 0.1f, 3, 0, false);
+ }
+
+private:
+ void drawClippedRect(SkCanvas* canvas, int x, int y, const SkPaint& paint) {
+ canvas->save();
+ canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
+ SkIntToScalar(fSize.width()), SkIntToScalar(fSize.height())));
+ SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
+ SkIntToScalar(fSize.width()),
+ SkIntToScalar(fSize.height()));
+ canvas->drawRect(r, paint);
+ canvas->restore();
+ }
+
+ void test(SkCanvas* canvas, int x, int y, SkPerlinNoiseShader::Type type,
+ float baseFrequencyX, float baseFrequencyY, int numOctaves, float seed,
+ bool stitchTiles) {
+ SkShader* shader = (type == SkPerlinNoiseShader::kFractalNoise_Type) ?
+ SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequencyY, numOctaves,
+ seed, stitchTiles ? &fSize : NULL) :
+ SkPerlinNoiseShader::CreateTubulence(baseFrequencyX, baseFrequencyY, numOctaves,
+ seed, stitchTiles ? &fSize : NULL);
+ SkPaint paint;
+ paint.setShader(shader)->unref();
+ this->drawClippedRect(canvas, x, y, paint);
+ }
+
+ typedef SkBenchmark INHERITED;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+DEF_BENCH( return new PerlinNoiseBench(p); )
+
« no previous file with comments | « no previous file | gm/perlinnoise.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698