msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
| 8 | #include "Benchmark.h" |
| 9 | #include "SkCanvas.h" |
| 10 | #include "SkRandom.h" |
| 11 | |
| 12 | class QuickRejectBench : public Benchmark { |
| 13 | enum { N = 1000000 }; |
| 14 | float fFloats[N]; |
| 15 | int fInts [N]; |
| 16 | |
| 17 | const char* onGetName() override { return "quick_reject"; } |
| 18 | bool isSuitableFor(Backend backend) override { return backend != kNonRendering_Backend; } |
| 19 | |
| 20 | void onDelayedSetup() override { |
| 21 | SkRandom rand; |
| 22 | for (int i = 0; i < N; ++i) { |
| 23 | fFloats[i] = 300.0f * (rand.nextSScalar1() + 0.5f); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | void onDraw(int loops, SkCanvas* canvas) override { |
| 28 | while (loops --> 0) { |
| 29 | for (int i = 0; i < N - 4; i++) { |
| 30 | if (canvas->quickReject(*(SkRect*)(fFloats+i))) { |
| 31 | fInts[i] = 11; |
| 32 | } else { |
| 33 | fInts[i] = 24; |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | }; |
| 39 | DEF_BENCH( return new QuickRejectBench; ) |
| 40 | |
| 41 | class ConcatBench : public Benchmark { |
| 42 | SkMatrix fMatrix; |
| 43 | |
| 44 | const char* onGetName() override { return "concat"; } |
| 45 | bool isSuitableFor(Backend backend) override { return backend != kNonRendering_Backend; } |
| 46 | |
| 47 | void onDelayedSetup() override { |
| 48 | SkRandom r; |
| 49 | fMatrix.setScale(5.0f, 5.0f); |
| 50 | fMatrix.setTranslateX(10.0f); |
| 51 | fMatrix.setTranslateY(10.0f); |
| 52 | } |
| 53 | |
| 54 | void onDraw(int loops, SkCanvas* canvas) override { |
| 55 | while (loops --> 0) { |
| 56 | canvas->setMatrix(SkMatrix::MakeScale(3.0f)); |
| 57 | canvas->concat(fMatrix); |
| 58 | } |
| 59 | } |
| 60 | }; |
| 61 | DEF_BENCH( return new ConcatBench; ) |