Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: bench/BlurOccludedRRectBench.cpp

Issue 2203153002: Add new bench for occluded blurmaskfilter draws (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Clean up Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
15 // compute the intersection point between the diagonal and the ellipse in the
16 // lower right corner
17 static SkPoint intersection(SkScalar w, SkScalar h) {
18 SkASSERT(w > 0.0f || h > 0.0f);
19
20 return SkPoint::Make(w / SK_ScalarSqrt2, h / SK_ScalarSqrt2);
21 }
22
23 // Use the intersection of the corners' diagonals with their ellipses to shrink
24 // the bounding rect
25 static SkRect compute_central_occluder(const SkRRect& rr) {
reed1 2016/08/03 20:16:18 This could be checked in centrally (but perhaps st
robertphillips 2016/08/04 14:49:58 Done.
26 const SkRect r = rr.getBounds();
27
28 SkScalar newL = r.fLeft, newT = r.fTop, newR = r.fRight, newB = r.fBottom;
29
30 SkVector radii = rr.radii(SkRRect::kUpperLeft_Corner);
31 if (!radii.isZero()) {
32 SkPoint p = intersection(radii.fX, radii.fY);
33
34 newL = SkTMax(newL, r.fLeft + radii.fX - p.fX);
35 newT = SkTMax(newT, r.fTop + radii.fY - p.fY);
36 }
37
38 radii = rr.radii(SkRRect::kUpperRight_Corner);
39 if (!radii.isZero()) {
40 SkPoint p = intersection(radii.fX, radii.fY);
41
42 newR = SkTMin(newR, r.fRight + p.fX - radii.fX);
43 newT = SkTMax(newT, r.fTop + radii.fY - p.fY);
44 }
45
46 radii = rr.radii(SkRRect::kLowerRight_Corner);
47 if (!radii.isZero()) {
48 SkPoint p = intersection(radii.fX, radii.fY);
49
50 newR = SkTMin(newR, r.fRight + p.fX - radii.fX);
51 newB = SkTMin(newB, r.fBottom - radii.fY + p.fY);
52 }
53
54 radii = rr.radii(SkRRect::kLowerLeft_Corner);
55 if (!radii.isZero()) {
56 SkPoint p = intersection(radii.fX, radii.fY);
57
58 newL = SkTMax(newL, r.fLeft + radii.fX - p.fX);
59 newB = SkTMin(newB, r.fBottom - radii.fY + p.fY);
60 }
61
62 return SkRect::MakeLTRB(newL, newT, newR, newB);
63 }
64
65 class BlurOccludedRRectBench : public Benchmark {
66 public:
67 BlurOccludedRRectBench() {}
68
69 const char* onGetName() override {
70 return "bluroccludedrrect";
71 }
72
73 SkIPoint onGetSize() override {
74 return SkIPoint::Make(1024, 2048);
75 }
76
77 void onDraw(int loops, SkCanvas* canvas) override {
78 for (int l = 0; l < loops; ++l) {
79 canvas->clear(0xFFFAFAFA);
80
81 SkPaint opaque;
82 opaque.setAntiAlias(true);
83 opaque.setColor(SK_ColorWHITE);
84
85 const SkRect r = SkRect::MakeWH(480, 230);
86 const SkRRect rr = SkRRect::MakeRectXY(r, 8, 8);
87 SkRect occRect = compute_central_occluder(rr);
88
89 for (int i = 0; i < 2; ++i) {
90 canvas->save();
91
92 canvas->translate(i*502.0f+20, 10.0f);
93
94 for (int j = 0; j < 8; ++j) {
95 canvas->save();
96
97 canvas->translate(0.0f, j*256.0f);
98
99 SkPaint firstBlur;
100 firstBlur.setAntiAlias(true);
101 firstBlur.setColor(0x09000000);
102 firstBlur.setMaskFilter(SkBlurMaskFilter::Make(kNormal_S kBlurStyle,
103 2.5f));
104 //, occRe ct));
105
106 canvas->drawRRect(rr, firstBlur);
107
108 canvas->save();
109 canvas->translate(1.5f, 1.5f);
110
111 SkPaint secondBlur;
112 secondBlur.setAntiAlias(true);
113 secondBlur.setColor(0x30000000);
114 secondBlur.setMaskFilter(SkBlurMaskFilter::Make(kNor mal_SkBlurStyle,
115 6.0f ));
116 //, occRect));
117
118 canvas->drawRRect(rr, secondBlur);
119
120 canvas->restore();
121
122 canvas->drawRRect(rr, opaque);
123
124 canvas->restore();
125 }
126
127 canvas->restore();
128 }
129 }
130 }
131
132 private:
133 typedef Benchmark INHERITED;
134 };
135
136 DEF_BENCH(return new BlurOccludedRRectBench();)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698