Flutter Engine
The Flutter Engine
PerlinNoiseBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7#include "bench/Benchmark.h"
11
13 SkISize fSize;
14
15public:
17 fSize = SkISize::Make(80, 80);
18 }
19
20protected:
21 const char* onGetName() override {
22 return "perlinnoise";
23 }
24
25 void onDraw(int loops, SkCanvas* canvas) override {
26 this->test(loops, canvas, 0, 0, 0.1f, 0.1f, 3, 0, false);
27 }
28
29private:
30 void drawClippedRect(SkCanvas* canvas, int x, int y, const SkPaint& paint) {
31 canvas->save();
33 SkIntToScalar(fSize.width()), SkIntToScalar(fSize.height())));
35 SkIntToScalar(fSize.width()),
36 SkIntToScalar(fSize.height()));
37 canvas->drawRect(r, paint);
38 canvas->restore();
39 }
40
41 void test(int loops, SkCanvas* canvas, int x, int y,
42 float baseFrequencyX, float baseFrequencyY, int numOctaves, float seed,
43 bool stitchTiles) {
46 baseFrequencyX, baseFrequencyY, numOctaves, seed, stitchTiles ? &fSize : nullptr));
47 for (int i = 0; i < loops; i++) {
48 this->drawClippedRect(canvas, x, y, paint);
49 }
50 }
51
52 using INHERITED = Benchmark;
53};
54
55///////////////////////////////////////////////////////////////////////////////
56
57DEF_BENCH( return new PerlinNoiseBench(); )
#define DEF_BENCH(code)
Definition: Benchmark.h:20
#define SkIntToScalar(x)
Definition: SkScalar.h:57
const char * onGetName() override
void onDraw(int loops, SkCanvas *canvas) override
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
int save()
Definition: SkCanvas.cpp:447
const Paint & paint
Definition: color_source.cc:38
double y
double x
SK_API sk_sp< SkShader > MakeFractalNoise(SkScalar baseFrequencyX, SkScalar baseFrequencyY, int numOctaves, SkScalar seed, const SkISize *tileSize=nullptr)
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659