blob: b5635c5ad88673b032738a49d895d330435b8f7b [file] [log] [blame]
robertphillips276d3282016-08-04 09:03:19 -07001/*
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"
robertphillips276d3282016-08-04 09:03:19 -07009#include "SkCanvas.h"
Mike Reed1be1f8d2018-03-14 13:01:17 -040010#include "SkMaskFilter.h"
robertphillips276d3282016-08-04 09:03:19 -070011#include "SkPaint.h"
12#include "SkRRect.h"
13#include "SkRect.h"
14#include "sk_tool_utils.h"
15
16class BlurOccludedRRectBench : public Benchmark {
17public:
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) {
robertphillips276d3282016-08-04 09:03:19 -070030 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);
robertphillips27cdd942016-08-10 16:25:25 -070036 SkRect occRect = sk_tool_utils::compute_central_occluder(rr);
robertphillips276d3282016-08-04 09:03:19 -070037
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 Reed1be1f8d2018-03-14 13:01:17 -040051 firstBlur.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle,
robertphillips27cdd942016-08-10 16:25:25 -070052 2.5f,
53 occRect));
robertphillips276d3282016-08-04 09:03:19 -070054
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 Reed1be1f8d2018-03-14 13:01:17 -040063 secondBlur.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle,
robertphillips27cdd942016-08-10 16:25:25 -070064 6.0f,
65 occRect));
robertphillips276d3282016-08-04 09:03:19 -070066
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
81private:
82 typedef Benchmark INHERITED;
83};
84
85DEF_BENCH(return new BlurOccludedRRectBench();)