robertphillips | 276d328 | 2016-08-04 09:03:19 -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" |
robertphillips | 276d328 | 2016-08-04 09:03:19 -0700 | [diff] [blame] | 9 | #include "SkCanvas.h" |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 10 | #include "SkMaskFilter.h" |
robertphillips | 276d328 | 2016-08-04 09:03:19 -0700 | [diff] [blame] | 11 | #include "SkPaint.h" |
| 12 | #include "SkRRect.h" |
| 13 | #include "SkRect.h" |
| 14 | #include "sk_tool_utils.h" |
| 15 | |
| 16 | class BlurOccludedRRectBench : public Benchmark { |
| 17 | public: |
| 18 | BlurOccludedRRectBench() {} |
| 19 | |
| 20 | const char* onGetName() override { |
| 21 | return "bluroccludedrrect"; |
| 22 | } |
| 23 | |
| 24 | SkIPoint onGetSize() override { |
| 25 | return SkIPoint::Make(1024, 2048); |
| 26 | } |
| 27 | |
| 28 | void onDraw(int loops, SkCanvas* canvas) override { |
| 29 | for (int l = 0; l < loops; ++l) { |
robertphillips | 276d328 | 2016-08-04 09:03:19 -0700 | [diff] [blame] | 30 | SkPaint opaque; |
| 31 | opaque.setAntiAlias(true); |
| 32 | opaque.setColor(SK_ColorWHITE); |
| 33 | |
| 34 | const SkRect r = SkRect::MakeWH(480, 230); |
| 35 | const SkRRect rr = SkRRect::MakeRectXY(r, 8, 8); |
robertphillips | 27cdd94 | 2016-08-10 16:25:25 -0700 | [diff] [blame] | 36 | SkRect occRect = sk_tool_utils::compute_central_occluder(rr); |
robertphillips | 276d328 | 2016-08-04 09:03:19 -0700 | [diff] [blame] | 37 | |
| 38 | for (int i = 0; i < 2; ++i) { |
| 39 | canvas->save(); |
| 40 | |
| 41 | canvas->translate(i*502.0f+20, 10.0f); |
| 42 | |
| 43 | for (int j = 0; j < 8; ++j) { |
| 44 | canvas->save(); |
| 45 | |
| 46 | canvas->translate(0.0f, j*256.0f); |
| 47 | |
| 48 | SkPaint firstBlur; |
| 49 | firstBlur.setAntiAlias(true); |
| 50 | firstBlur.setColor(0x09000000); |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 51 | firstBlur.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, |
robertphillips | 27cdd94 | 2016-08-10 16:25:25 -0700 | [diff] [blame] | 52 | 2.5f, |
| 53 | occRect)); |
robertphillips | 276d328 | 2016-08-04 09:03:19 -0700 | [diff] [blame] | 54 | |
| 55 | canvas->drawRRect(rr, firstBlur); |
| 56 | |
| 57 | canvas->save(); |
| 58 | canvas->translate(1.5f, 1.5f); |
| 59 | |
| 60 | SkPaint secondBlur; |
| 61 | secondBlur.setAntiAlias(true); |
| 62 | secondBlur.setColor(0x30000000); |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 63 | secondBlur.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, |
robertphillips | 27cdd94 | 2016-08-10 16:25:25 -0700 | [diff] [blame] | 64 | 6.0f, |
| 65 | occRect)); |
robertphillips | 276d328 | 2016-08-04 09:03:19 -0700 | [diff] [blame] | 66 | |
| 67 | canvas->drawRRect(rr, secondBlur); |
| 68 | |
| 69 | canvas->restore(); |
| 70 | |
| 71 | canvas->drawRRect(rr, opaque); |
| 72 | |
| 73 | canvas->restore(); |
| 74 | } |
| 75 | |
| 76 | canvas->restore(); |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | private: |
| 82 | typedef Benchmark INHERITED; |
| 83 | }; |
| 84 | |
| 85 | DEF_BENCH(return new BlurOccludedRRectBench();) |