| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "Benchmark.h" | 8 #include "Benchmark.h" |
| 9 #include "SkBlurMask.h" | 9 #include "SkBlurMask.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 this->setupPaint(&paint); | 56 this->setupPaint(&paint); |
| 57 | 57 |
| 58 paint.setAntiAlias(true); | 58 paint.setAntiAlias(true); |
| 59 | 59 |
| 60 SkScalar pad = fRadius*3/2 + SK_Scalar1; | 60 SkScalar pad = fRadius*3/2 + SK_Scalar1; |
| 61 SkRect r = SkRect::MakeWH(2 * pad + SK_Scalar1, 2 * pad + SK_Scalar1); | 61 SkRect r = SkRect::MakeWH(2 * pad + SK_Scalar1, 2 * pad + SK_Scalar1); |
| 62 | 62 |
| 63 preBenchSetup(r); | 63 preBenchSetup(r); |
| 64 | 64 |
| 65 for (int i = 0; i < loops; i++) { | 65 for (int i = 0; i < loops; i++) { |
| 66 makeBlurryRect(r); | 66 this->makeBlurryRect(r); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 virtual void makeBlurryRect(const SkRect&) = 0; | 70 virtual void makeBlurryRect(const SkRect&) = 0; |
| 71 virtual void preBenchSetup(const SkRect&) {} | 71 virtual void preBenchSetup(const SkRect&) {} |
| 72 private: | 72 private: |
| 73 typedef Benchmark INHERITED; | 73 typedef Benchmark INHERITED; |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 | 76 |
| 77 class BlurRectDirectBench: public BlurRectBench { | 77 class BlurRectDirectBench: public BlurRectBench { |
| 78 public: | 78 public: |
| 79 BlurRectDirectBench(SkScalar rad) : INHERITED(rad) { | 79 BlurRectDirectBench(SkScalar rad) : INHERITED(rad) { |
| 80 SkString name; | 80 SkString name; |
| 81 | 81 |
| 82 if (SkScalarFraction(rad) != 0) { | 82 if (SkScalarFraction(rad) != 0) { |
| 83 name.printf("blurrect_direct_%.2f", SkScalarToFloat(rad)); | 83 name.printf("blurrect_direct_%.2f", SkScalarToFloat(rad)); |
| 84 } else { | 84 } else { |
| 85 name.printf("blurrect_direct_%d", SkScalarRoundToInt(rad)); | 85 name.printf("blurrect_direct_%d", SkScalarRoundToInt(rad)); |
| 86 } | 86 } |
| 87 | 87 |
| 88 this->setName(name); | 88 this->setName(name); |
| 89 } | 89 } |
| 90 protected: | 90 protected: |
| 91 void makeBlurryRect(const SkRect& r) override { | 91 void makeBlurryRect(const SkRect& r) override { |
| 92 SkMask mask; | 92 SkMask mask; |
| 93 SkBlurMask::BlurRect(SkBlurMask::ConvertRadiusToSigma(this->radius()), | 93 if (!SkBlurMask::BlurRect(SkBlurMask::ConvertRadiusToSigma(this->radius(
)), |
| 94 &mask, r, kNormal_SkBlurStyle); | 94 &mask, r, kNormal_SkBlurStyle)) { |
| 95 return; |
| 96 } |
| 95 SkMask::FreeImage(mask.fImage); | 97 SkMask::FreeImage(mask.fImage); |
| 96 } | 98 } |
| 97 private: | 99 private: |
| 98 typedef BlurRectBench INHERITED; | 100 typedef BlurRectBench INHERITED; |
| 99 }; | 101 }; |
| 100 | 102 |
| 101 class BlurRectSeparableBench: public BlurRectBench { | 103 class BlurRectSeparableBench: public BlurRectBench { |
| 102 | 104 |
| 103 public: | 105 public: |
| 104 BlurRectSeparableBench(SkScalar rad) : INHERITED(rad) { | 106 BlurRectSeparableBench(SkScalar rad) : INHERITED(rad) { } |
| 105 fSrcMask.fImage = nullptr; | |
| 106 } | |
| 107 | 107 |
| 108 ~BlurRectSeparableBench() { | 108 ~BlurRectSeparableBench() { |
| 109 SkMask::FreeImage(fSrcMask.fImage); | 109 SkMask::FreeImage(fSrcMask.fImage); |
| 110 } | 110 } |
| 111 | 111 |
| 112 protected: | 112 protected: |
| 113 void preBenchSetup(const SkRect& r) override { | 113 void preBenchSetup(const SkRect& r) override { |
| 114 SkMask::FreeImage(fSrcMask.fImage); | 114 SkMask::FreeImage(fSrcMask.fImage); |
| 115 | 115 |
| 116 r.roundOut(&fSrcMask.fBounds); | 116 r.roundOut(&fSrcMask.fBounds); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 137 name.printf("blurrect_boxfilter_%d", SkScalarRoundToInt(rad)); | 137 name.printf("blurrect_boxfilter_%d", SkScalarRoundToInt(rad)); |
| 138 } | 138 } |
| 139 | 139 |
| 140 this->setName(name); | 140 this->setName(name); |
| 141 } | 141 } |
| 142 | 142 |
| 143 protected: | 143 protected: |
| 144 | 144 |
| 145 void makeBlurryRect(const SkRect&) override { | 145 void makeBlurryRect(const SkRect&) override { |
| 146 SkMask mask; | 146 SkMask mask; |
| 147 mask.fImage = nullptr; | 147 if (!SkBlurMask::BoxBlur(&mask, fSrcMask, SkBlurMask::ConvertRadiusToSig
ma(this->radius()), |
| 148 SkBlurMask::BoxBlur(&mask, fSrcMask, SkBlurMask::ConvertRadiusToSigma(th
is->radius()), | 148 kNormal_SkBlurStyle, kHigh_SkBlurQuality)) { |
| 149 kNormal_SkBlurStyle, kHigh_SkBlurQuality); | 149 return; |
| 150 } |
| 150 SkMask::FreeImage(mask.fImage); | 151 SkMask::FreeImage(mask.fImage); |
| 151 } | 152 } |
| 152 private: | 153 private: |
| 153 typedef BlurRectSeparableBench INHERITED; | 154 typedef BlurRectSeparableBench INHERITED; |
| 154 }; | 155 }; |
| 155 | 156 |
| 156 class BlurRectGaussianBench: public BlurRectSeparableBench { | 157 class BlurRectGaussianBench: public BlurRectSeparableBench { |
| 157 public: | 158 public: |
| 158 BlurRectGaussianBench(SkScalar rad) : INHERITED(rad) { | 159 BlurRectGaussianBench(SkScalar rad) : INHERITED(rad) { |
| 159 SkString name; | 160 SkString name; |
| 160 | 161 |
| 161 if (SkScalarFraction(rad) != 0) { | 162 if (SkScalarFraction(rad) != 0) { |
| 162 name.printf("blurrect_gaussian_%.2f", SkScalarToFloat(rad)); | 163 name.printf("blurrect_gaussian_%.2f", SkScalarToFloat(rad)); |
| 163 } else { | 164 } else { |
| 164 name.printf("blurrect_gaussian_%d", SkScalarRoundToInt(rad)); | 165 name.printf("blurrect_gaussian_%d", SkScalarRoundToInt(rad)); |
| 165 } | 166 } |
| 166 | 167 |
| 167 this->setName(name); | 168 this->setName(name); |
| 168 } | 169 } |
| 169 | 170 |
| 170 protected: | 171 protected: |
| 171 | 172 |
| 172 void makeBlurryRect(const SkRect&) override { | 173 void makeBlurryRect(const SkRect&) override { |
| 173 SkMask mask; | 174 SkMask mask; |
| 174 mask.fImage = nullptr; | 175 if (!SkBlurMask::BlurGroundTruth(SkBlurMask::ConvertRadiusToSigma(this->
radius()), |
| 175 SkBlurMask::BlurGroundTruth(SkBlurMask::ConvertRadiusToSigma(this->radiu
s()), | 176 &mask, fSrcMask, kNormal_SkBlurStyle))
{ |
| 176 &mask, fSrcMask, kNormal_SkBlurStyle); | 177 return; |
| 178 } |
| 177 SkMask::FreeImage(mask.fImage); | 179 SkMask::FreeImage(mask.fImage); |
| 178 } | 180 } |
| 179 private: | 181 private: |
| 180 typedef BlurRectSeparableBench INHERITED; | 182 typedef BlurRectSeparableBench INHERITED; |
| 181 }; | 183 }; |
| 182 | 184 |
| 183 DEF_BENCH(return new BlurRectBoxFilterBench(SMALL);) | 185 DEF_BENCH(return new BlurRectBoxFilterBench(SMALL);) |
| 184 DEF_BENCH(return new BlurRectBoxFilterBench(BIG);) | 186 DEF_BENCH(return new BlurRectBoxFilterBench(BIG);) |
| 185 DEF_BENCH(return new BlurRectBoxFilterBench(REALBIG);) | 187 DEF_BENCH(return new BlurRectBoxFilterBench(REALBIG);) |
| 186 DEF_BENCH(return new BlurRectBoxFilterBench(REAL);) | 188 DEF_BENCH(return new BlurRectBoxFilterBench(REAL);) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(12));) | 221 DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(12));) |
| 220 DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(13));) | 222 DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(13));) |
| 221 DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(14));) | 223 DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(14));) |
| 222 DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(15));) | 224 DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(15));) |
| 223 DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(16));) | 225 DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(16));) |
| 224 DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(17));) | 226 DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(17));) |
| 225 DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(18));) | 227 DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(18));) |
| 226 DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(19));) | 228 DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(19));) |
| 227 DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(20));) | 229 DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(20));) |
| 228 #endif | 230 #endif |
| OLD | NEW |