blob: a3c9e193ac81228baaa215ca1a7c217ac32937bb [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"
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
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) {
30 canvas->clear(0xFFFAFAFA);
31
32 SkPaint opaque;
33 opaque.setAntiAlias(true);
34 opaque.setColor(SK_ColorWHITE);
35
36 const SkRect r = SkRect::MakeWH(480, 230);
37 const SkRRect rr = SkRRect::MakeRectXY(r, 8, 8);
robertphillips27cdd942016-08-10 16:25:25 -070038 SkRect occRect = sk_tool_utils::compute_central_occluder(rr);
robertphillips276d3282016-08-04 09:03:19 -070039
40 for (int i = 0; i < 2; ++i) {
41 canvas->save();
42
43 canvas->translate(i*502.0f+20, 10.0f);
44
45 for (int j = 0; j < 8; ++j) {
46 canvas->save();
47
48 canvas->translate(0.0f, j*256.0f);
49
50 SkPaint firstBlur;
51 firstBlur.setAntiAlias(true);
52 firstBlur.setColor(0x09000000);
53 firstBlur.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
robertphillips27cdd942016-08-10 16:25:25 -070054 2.5f,
55 occRect));
robertphillips276d3282016-08-04 09:03:19 -070056
57 canvas->drawRRect(rr, firstBlur);
58
59 canvas->save();
60 canvas->translate(1.5f, 1.5f);
61
62 SkPaint secondBlur;
63 secondBlur.setAntiAlias(true);
64 secondBlur.setColor(0x30000000);
65 secondBlur.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
robertphillips27cdd942016-08-10 16:25:25 -070066 6.0f,
67 occRect));
robertphillips276d3282016-08-04 09:03:19 -070068
69 canvas->drawRRect(rr, secondBlur);
70
71 canvas->restore();
72
73 canvas->drawRRect(rr, opaque);
74
75 canvas->restore();
76 }
77
78 canvas->restore();
79 }
80 }
81 }
82
83private:
84 typedef Benchmark INHERITED;
85};
86
87DEF_BENCH(return new BlurOccludedRRectBench();)