1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2018 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#include "bench/Benchmark.h"
9cb93a386Sopenharmony_ci#include "include/core/SkCubicMap.h"
10cb93a386Sopenharmony_ci
11cb93a386Sopenharmony_ciclass CubicMapBench : public Benchmark {
12cb93a386Sopenharmony_cipublic:
13cb93a386Sopenharmony_ci    CubicMapBench(SkPoint p1, SkPoint p2) : fCMap(p1, p2) {
14cb93a386Sopenharmony_ci        fName.printf("cubicmap_%g_%g_%g_%g", p1.fX, p1.fY, p2.fX, p2.fY);
15cb93a386Sopenharmony_ci    }
16cb93a386Sopenharmony_ci
17cb93a386Sopenharmony_ci    bool isSuitableFor(Backend backend) override {
18cb93a386Sopenharmony_ci        return backend == kNonRendering_Backend;
19cb93a386Sopenharmony_ci    }
20cb93a386Sopenharmony_ci
21cb93a386Sopenharmony_ci    const char* onGetName() override {
22cb93a386Sopenharmony_ci        return fName.c_str();
23cb93a386Sopenharmony_ci    }
24cb93a386Sopenharmony_ci
25cb93a386Sopenharmony_ci    void onDraw(int loops, SkCanvas*) override {
26cb93a386Sopenharmony_ci        for (int outer = 0; outer < 100; ++outer) {
27cb93a386Sopenharmony_ci            for (int i = 0; i < loops; ++i) {
28cb93a386Sopenharmony_ci                for (SkScalar x = 0; x <= 1; x += 1.0f / 512) {
29cb93a386Sopenharmony_ci                    fCMap.computeYFromX(x);
30cb93a386Sopenharmony_ci                }
31cb93a386Sopenharmony_ci            }
32cb93a386Sopenharmony_ci        }
33cb93a386Sopenharmony_ci    }
34cb93a386Sopenharmony_ci
35cb93a386Sopenharmony_ciprivate:
36cb93a386Sopenharmony_ci    SkCubicMap  fCMap;
37cb93a386Sopenharmony_ci    SkString    fName;
38cb93a386Sopenharmony_ci
39cb93a386Sopenharmony_ci    using INHERITED = Benchmark;
40cb93a386Sopenharmony_ci};
41cb93a386Sopenharmony_ci
42cb93a386Sopenharmony_ciDEF_BENCH( return new CubicMapBench({1, 0}, {0,0}); )
43cb93a386Sopenharmony_ciDEF_BENCH( return new CubicMapBench({1, 0}, {0,1}); )
44cb93a386Sopenharmony_ciDEF_BENCH( return new CubicMapBench({1, 0}, {1,0}); )
45cb93a386Sopenharmony_ciDEF_BENCH( return new CubicMapBench({1, 0}, {1,1}); )
46cb93a386Sopenharmony_ci
47cb93a386Sopenharmony_ciDEF_BENCH( return new CubicMapBench({0, 1}, {0,0}); )
48cb93a386Sopenharmony_ciDEF_BENCH( return new CubicMapBench({0, 1}, {0,1}); )
49cb93a386Sopenharmony_ciDEF_BENCH( return new CubicMapBench({0, 1}, {1,0}); )
50cb93a386Sopenharmony_ciDEF_BENCH( return new CubicMapBench({0, 1}, {1,1}); )
51cb93a386Sopenharmony_ci
52cb93a386Sopenharmony_ciDEF_BENCH( return new CubicMapBench({0, 0}, {1,1}); )
53cb93a386Sopenharmony_ciDEF_BENCH( return new CubicMapBench({1, 1}, {0,0}); )
54