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 "SkBlurMaskFilter.h"
10 #include "SkCanvas.h"
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) {
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);
36             SkRect occRect = sk_tool_utils::compute_central_occluder(rr);
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);
51                         firstBlur.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
52                                                                        2.5f,
53                                                                        occRect));
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);
63                             secondBlur.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
64                                                                             6.0f,
65                                                                             occRect));
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();)
86