2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "SkPerlinNoiseShader.h"
11 class PerlinNoiseBench : public Benchmark {
16 fSize = SkISize::Make(80, 80);
20 const char* onGetName() SK_OVERRIDE {
24 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
25 this->test(loops, canvas, 0, 0, SkPerlinNoiseShader::kFractalNoise_Type,
26 0.1f, 0.1f, 3, 0, false);
30 void drawClippedRect(SkCanvas* canvas, int x, int y, const SkPaint& paint) {
32 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
33 SkIntToScalar(fSize.width()), SkIntToScalar(fSize.height())));
34 SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
35 SkIntToScalar(fSize.width()),
36 SkIntToScalar(fSize.height()));
37 canvas->drawRect(r, paint);
41 void test(const int loops, SkCanvas* canvas, int x, int y, SkPerlinNoiseShader::Type type,
42 float baseFrequencyX, float baseFrequencyY, int numOctaves, float seed,
44 SkShader* shader = (type == SkPerlinNoiseShader::kFractalNoise_Type) ?
45 SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequencyY, numOctaves,
46 seed, stitchTiles ? &fSize : NULL) :
47 SkPerlinNoiseShader::CreateTurbulence(baseFrequencyX, baseFrequencyY, numOctaves,
48 seed, stitchTiles ? &fSize : NULL);
50 paint.setShader(shader)->unref();
52 for (int i = 0; i < loops; i++) {
53 this->drawClippedRect(canvas, x, y, paint);
57 typedef Benchmark INHERITED;
60 ///////////////////////////////////////////////////////////////////////////////
62 DEF_BENCH( return new PerlinNoiseBench(); )