OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkAnimTimer.h" | 9 #include "SkAnimTimer.h" |
10 #include "SkBlurMask.h" | 10 #include "SkBlurMask.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 protected: | 37 protected: |
38 bool runAsBench() const override { return true; } | 38 bool runAsBench() const override { return true; } |
39 | 39 |
40 SkString onShortName() override { return SkString("blurcircles2"); } | 40 SkString onShortName() override { return SkString("blurcircles2"); } |
41 | 41 |
42 SkISize onISize() override { | 42 SkISize onISize() override { |
43 return SkISize::Make(730, 1350); | 43 return SkISize::Make(730, 1350); |
44 } | 44 } |
45 | 45 |
46 void onDraw(SkCanvas* canvas) override { | 46 void onDraw(SkCanvas* canvas) override { |
47 static constexpr SkScalar kMaxR = kMaxRadius + kMaxBlurRadius; | 47 constexpr SkScalar kMaxR = kMaxRadius + kMaxBlurRadius; |
48 | 48 |
49 auto almostCircleMaker = [] (SkScalar radius, SkPath* dst) { | 49 auto almostCircleMaker = [] (SkScalar radius, SkPath* dst) { |
50 dst->reset(); | 50 dst->reset(); |
51 dst->addArc(SkRect::MakeXYWH(-radius, -radius, 2 * radius, 2 * radiu
s), 0, 355); | 51 dst->addArc(SkRect::MakeXYWH(-radius, -radius, 2 * radius, 2 * radiu
s), 0, 355); |
52 dst->setIsVolatile(true); | 52 dst->setIsVolatile(true); |
53 dst->close(); | 53 dst->close(); |
54 }; | 54 }; |
55 | 55 |
56 auto blurMaker = [] (SkScalar radius) ->sk_sp<SkMaskFilter> { | 56 auto blurMaker = [] (SkScalar radius) ->sk_sp<SkMaskFilter> { |
57 return SkBlurMaskFilter::Make(kNormal_SkBlurStyle, | 57 return SkBlurMaskFilter::Make(kNormal_SkBlurStyle, |
(...skipping 11 matching lines...) Expand all Loading... |
69 almostCircleMaker(fAnimRadius, &almostCircle); | 69 almostCircleMaker(fAnimRadius, &almostCircle); |
70 canvas->save(); | 70 canvas->save(); |
71 canvas->translate(size.fWidth / 2.f, size.fHeight / 4.f); | 71 canvas->translate(size.fWidth / 2.f, size.fHeight / 4.f); |
72 canvas->drawCircle(0, 0, fAnimRadius, paint); | 72 canvas->drawCircle(0, 0, fAnimRadius, paint); |
73 canvas->translate(0, 2 * kMaxR); | 73 canvas->translate(0, 2 * kMaxR); |
74 canvas->drawPath(almostCircle, paint); | 74 canvas->drawPath(almostCircle, paint); |
75 canvas->restore(); | 75 canvas->restore(); |
76 } else { | 76 } else { |
77 bool benchMode = this->getMode() == kBench_Mode; | 77 bool benchMode = this->getMode() == kBench_Mode; |
78 canvas->save(); | 78 canvas->save(); |
79 static constexpr SkScalar kPad = 5; | 79 constexpr SkScalar kPad = 5; |
80 static constexpr SkScalar kRadiusSteps = 5; | 80 constexpr SkScalar kRadiusSteps = 5; |
81 static constexpr SkScalar kBlurRadiusSteps = 5; | 81 constexpr SkScalar kBlurRadiusSteps = 5; |
82 canvas->translate(kPad + kMinRadius + kMaxBlurRadius, | 82 canvas->translate(kPad + kMinRadius + kMaxBlurRadius, |
83 kPad + kMinRadius + kMaxBlurRadius); | 83 kPad + kMinRadius + kMaxBlurRadius); |
84 static constexpr SkScalar kDeltaRadius = (kMaxRadius - kMinRadius) /
kRadiusSteps; | 84 constexpr SkScalar kDeltaRadius = (kMaxRadius - kMinRadius) / kRadiu
sSteps; |
85 static constexpr SkScalar kDeltaBlurRadius = (kMaxBlurRadius - kMinB
lurRadius) / | 85 constexpr SkScalar kDeltaBlurRadius = (kMaxBlurRadius - kMinBlurRadi
us) / |
86 kBlurRadiusSteps; | 86 kBlurRadiusSteps; |
87 SkScalar lineWidth = 0; | 87 SkScalar lineWidth = 0; |
88 if (!benchMode) { | 88 if (!benchMode) { |
89 for (int r = 0; r < kRadiusSteps - 1; ++r) { | 89 for (int r = 0; r < kRadiusSteps - 1; ++r) { |
90 const SkScalar radius = r * kDeltaRadius + kMinRadius; | 90 const SkScalar radius = r * kDeltaRadius + kMinRadius; |
91 lineWidth += 2 * (radius + kMaxBlurRadius) + kPad; | 91 lineWidth += 2 * (radius + kMaxBlurRadius) + kPad; |
92 } | 92 } |
93 } | 93 } |
94 for (int br = 0; br < kBlurRadiusSteps; ++br) { | 94 for (int br = 0; br < kBlurRadiusSteps; ++br) { |
95 SkScalar blurRadius = br * kDeltaBlurRadius + kMinBlurRadius; | 95 SkScalar blurRadius = br * kDeltaBlurRadius + kMinBlurRadius; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 154 |
155 SkScalar fAnimRadius; | 155 SkScalar fAnimRadius; |
156 SkScalar fAnimBlurRadius; | 156 SkScalar fAnimBlurRadius; |
157 | 157 |
158 SkRandom fRandom; | 158 SkRandom fRandom; |
159 | 159 |
160 typedef skiagm::GM INHERITED; | 160 typedef skiagm::GM INHERITED; |
161 }; | 161 }; |
162 | 162 |
163 DEF_GM(return new BlurCircles2GM();) | 163 DEF_GM(return new BlurCircles2GM();) |
OLD | NEW |