| 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 #include "Benchmark.h" | 7 #include "Benchmark.h" |
| 8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkDevice.h" | 9 #include "SkDevice.h" |
| 10 #include "SkLightingImageFilter.h" | 10 #include "SkLightingImageFilter.h" |
| 11 #include "SkPoint3.h" | 11 #include "SkPoint3.h" |
| 12 | 12 |
| 13 #define FILTER_WIDTH_SMALL SkIntToScalar(32) | 13 #define FILTER_WIDTH_SMALL SkIntToScalar(32) |
| 14 #define FILTER_HEIGHT_SMALL SkIntToScalar(32) | 14 #define FILTER_HEIGHT_SMALL SkIntToScalar(32) |
| 15 #define FILTER_WIDTH_LARGE SkIntToScalar(256) | 15 #define FILTER_WIDTH_LARGE SkIntToScalar(256) |
| 16 #define FILTER_HEIGHT_LARGE SkIntToScalar(256) | 16 #define FILTER_HEIGHT_LARGE SkIntToScalar(256) |
| 17 | 17 |
| 18 class LightingBaseBench : public Benchmark { | 18 class LightingBaseBench : public Benchmark { |
| 19 public: | 19 public: |
| 20 LightingBaseBench(bool small) : fIsSmall(small) { } | 20 LightingBaseBench(bool small) : fIsSmall(small) { } |
| 21 | 21 |
| 22 protected: | 22 protected: |
| 23 void draw(int loops, SkCanvas* canvas, SkImageFilter* imageFilter) const { | 23 void draw(int loops, SkCanvas* canvas, sk_sp<SkImageFilter> imageFilter) con
st { |
| 24 SkRect r = fIsSmall ? SkRect::MakeWH(FILTER_WIDTH_SMALL, FILTER_HEIGHT_S
MALL) : | 24 SkRect r = fIsSmall ? SkRect::MakeWH(FILTER_WIDTH_SMALL, FILTER_HEIGHT_S
MALL) : |
| 25 SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_L
ARGE); | 25 SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_L
ARGE); |
| 26 SkPaint paint; | 26 SkPaint paint; |
| 27 paint.setImageFilter(imageFilter)->unref(); | 27 paint.setImageFilter(std::move(imageFilter)); |
| 28 for (int i = 0; i < loops; i++) { | 28 for (int i = 0; i < loops; i++) { |
| 29 canvas->drawRect(r, paint); | 29 canvas->drawRect(r, paint); |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 | 32 |
| 33 static SkPoint3 GetPointLocation() { | 33 static SkPoint3 GetPointLocation() { |
| 34 static SkPoint3 pointLocation = SkPoint3::Make(0, 0, SkIntToScalar(10)); | 34 static SkPoint3 pointLocation = SkPoint3::Make(0, 0, SkIntToScalar(10)); |
| 35 return pointLocation; | 35 return pointLocation; |
| 36 } | 36 } |
| 37 | 37 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 static SkColor white(0xFFFFFFFF); | 92 static SkColor white(0xFFFFFFFF); |
| 93 return white; | 93 return white; |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool fIsSmall; | 96 bool fIsSmall; |
| 97 typedef Benchmark INHERITED; | 97 typedef Benchmark INHERITED; |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 class LightingPointLitDiffuseBench : public LightingBaseBench { | 100 class LightingPointLitDiffuseBench : public LightingBaseBench { |
| 101 public: | 101 public: |
| 102 LightingPointLitDiffuseBench(bool small) : INHERITED(small) { | 102 LightingPointLitDiffuseBench(bool small) : INHERITED(small) { } |
| 103 } | |
| 104 | 103 |
| 105 protected: | 104 protected: |
| 106 const char* onGetName() override { | 105 const char* onGetName() override { |
| 107 return fIsSmall ? "lightingpointlitdiffuse_small" : "lightingpointlitdif
fuse_large"; | 106 return fIsSmall ? "lightingpointlitdiffuse_small" : "lightingpointlitdif
fuse_large"; |
| 108 } | 107 } |
| 109 | 108 |
| 110 void onDraw(int loops, SkCanvas* canvas) override { | 109 void onDraw(int loops, SkCanvas* canvas) override { |
| 111 draw(loops, canvas, SkLightingImageFilter::CreatePointLitDiffuse(GetPoin
tLocation(), | 110 draw(loops, canvas, SkLightingImageFilter::MakePointLitDiffuse(GetPointL
ocation(), |
| 112 GetWhit
e(), | 111 GetWhite(
), |
| 113 GetSurf
aceScale(), | 112 GetSurfac
eScale(), |
| 114 GetKd()
)); | 113 GetKd(), |
| 114 nullptr))
; |
| 115 } | 115 } |
| 116 | 116 |
| 117 private: | 117 private: |
| 118 typedef LightingBaseBench INHERITED; | 118 typedef LightingBaseBench INHERITED; |
| 119 }; | 119 }; |
| 120 | 120 |
| 121 class LightingDistantLitDiffuseBench : public LightingBaseBench { | 121 class LightingDistantLitDiffuseBench : public LightingBaseBench { |
| 122 public: | 122 public: |
| 123 LightingDistantLitDiffuseBench(bool small) : INHERITED(small) { | 123 LightingDistantLitDiffuseBench(bool small) : INHERITED(small) { } |
| 124 } | |
| 125 | 124 |
| 126 protected: | 125 protected: |
| 127 const char* onGetName() override { | 126 const char* onGetName() override { |
| 128 return fIsSmall ? "lightingdistantlitdiffuse_small" : "lightingdistantli
tdiffuse_large"; | 127 return fIsSmall ? "lightingdistantlitdiffuse_small" : "lightingdistantli
tdiffuse_large"; |
| 129 } | 128 } |
| 130 | 129 |
| 131 void onDraw(int loops, SkCanvas* canvas) override { | 130 void onDraw(int loops, SkCanvas* canvas) override { |
| 132 draw(loops, canvas, SkLightingImageFilter::CreateDistantLitDiffuse(GetDi
stantDirection(), | 131 draw(loops, canvas, SkLightingImageFilter::MakeDistantLitDiffuse(GetDist
antDirection(), |
| 133 GetWh
ite(), | 132 GetWhit
e(), |
| 134 GetSu
rfaceScale(), | 133 GetSurf
aceScale(), |
| 135 GetKd
())); | 134 GetKd()
, |
| 135 nullptr
)); |
| 136 } | 136 } |
| 137 | 137 |
| 138 private: | 138 private: |
| 139 typedef LightingBaseBench INHERITED; | 139 typedef LightingBaseBench INHERITED; |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 class LightingSpotLitDiffuseBench : public LightingBaseBench { | 142 class LightingSpotLitDiffuseBench : public LightingBaseBench { |
| 143 public: | 143 public: |
| 144 LightingSpotLitDiffuseBench(bool small) : INHERITED(small) { | 144 LightingSpotLitDiffuseBench(bool small) : INHERITED(small) { } |
| 145 } | |
| 146 | 145 |
| 147 protected: | 146 protected: |
| 148 const char* onGetName() override { | 147 const char* onGetName() override { |
| 149 return fIsSmall ? "lightingspotlitdiffuse_small" : "lightingspotlitdiffu
se_large"; | 148 return fIsSmall ? "lightingspotlitdiffuse_small" : "lightingspotlitdiffu
se_large"; |
| 150 } | 149 } |
| 151 | 150 |
| 152 void onDraw(int loops, SkCanvas* canvas) override { | 151 void onDraw(int loops, SkCanvas* canvas) override { |
| 153 draw(loops, canvas, SkLightingImageFilter::CreateSpotLitDiffuse(GetSpotL
ocation(), | 152 draw(loops, canvas, SkLightingImageFilter::MakeSpotLitDiffuse(GetSpotLoc
ation(), |
| 154 GetSpotT
arget(), | 153 GetSpotTa
rget(), |
| 155 GetSpotE
xponent(), | 154 GetSpotEx
ponent(), |
| 156 GetCutof
fAngle(), | 155 GetCutoff
Angle(), |
| 157 GetWhite
(), | 156 GetWhite(
), |
| 158 GetSurfa
ceScale(), | 157 GetSurfac
eScale(), |
| 159 GetKd())
); | 158 GetKd(), |
| 159 nullptr))
; |
| 160 } | 160 } |
| 161 | 161 |
| 162 private: | 162 private: |
| 163 typedef LightingBaseBench INHERITED; | 163 typedef LightingBaseBench INHERITED; |
| 164 }; | 164 }; |
| 165 | 165 |
| 166 class LightingPointLitSpecularBench : public LightingBaseBench { | 166 class LightingPointLitSpecularBench : public LightingBaseBench { |
| 167 public: | 167 public: |
| 168 LightingPointLitSpecularBench(bool small) : INHERITED(small) { | 168 LightingPointLitSpecularBench(bool small) : INHERITED(small) { } |
| 169 } | |
| 170 | 169 |
| 171 protected: | 170 protected: |
| 172 const char* onGetName() override { | 171 const char* onGetName() override { |
| 173 return fIsSmall ? "lightingpointlitspecular_small" : "lightingpointlitsp
ecular_large"; | 172 return fIsSmall ? "lightingpointlitspecular_small" : "lightingpointlitsp
ecular_large"; |
| 174 } | 173 } |
| 175 | 174 |
| 176 void onDraw(int loops, SkCanvas* canvas) override { | 175 void onDraw(int loops, SkCanvas* canvas) override { |
| 177 draw(loops, canvas, SkLightingImageFilter::CreatePointLitSpecular(GetPoi
ntLocation(), | 176 draw(loops, canvas, SkLightingImageFilter::MakePointLitSpecular(GetPoint
Location(), |
| 178 GetWhi
te(), | 177 GetWhite
(), |
| 179 GetSur
faceScale(), | 178 GetSurfa
ceScale(), |
| 180 GetKs(
), | 179 GetKs(), |
| 181 GetShi
niness())); | 180 GetShini
ness(), |
| 181 nullptr)
); |
| 182 } | 182 } |
| 183 | 183 |
| 184 private: | 184 private: |
| 185 typedef LightingBaseBench INHERITED; | 185 typedef LightingBaseBench INHERITED; |
| 186 }; | 186 }; |
| 187 | 187 |
| 188 class LightingDistantLitSpecularBench : public LightingBaseBench { | 188 class LightingDistantLitSpecularBench : public LightingBaseBench { |
| 189 public: | 189 public: |
| 190 LightingDistantLitSpecularBench(bool small) : INHERITED(small) { | 190 LightingDistantLitSpecularBench(bool small) : INHERITED(small) { } |
| 191 } | |
| 192 | 191 |
| 193 protected: | 192 protected: |
| 194 const char* onGetName() override { | 193 const char* onGetName() override { |
| 195 return fIsSmall ? "lightingdistantlitspecular_small" : "lightingdistantl
itspecular_large"; | 194 return fIsSmall ? "lightingdistantlitspecular_small" : "lightingdistantl
itspecular_large"; |
| 196 } | 195 } |
| 197 | 196 |
| 198 void onDraw(int loops, SkCanvas* canvas) override { | 197 void onDraw(int loops, SkCanvas* canvas) override { |
| 199 draw(loops, canvas, SkLightingImageFilter::CreateDistantLitSpecular(GetD
istantDirection(), | 198 draw(loops, canvas, SkLightingImageFilter::MakeDistantLitSpecular(GetDis
tantDirection(), |
| 200 GetW
hite(), | 199 GetWhi
te(), |
| 201 GetS
urfaceScale(), | 200 GetSur
faceScale(), |
| 202 GetK
s(), | 201 GetKs(
), |
| 203 GetS
hininess())); | 202 GetShi
niness(), |
| 203 nullpt
r)); |
| 204 } | 204 } |
| 205 | 205 |
| 206 private: | 206 private: |
| 207 typedef LightingBaseBench INHERITED; | 207 typedef LightingBaseBench INHERITED; |
| 208 }; | 208 }; |
| 209 | 209 |
| 210 class LightingSpotLitSpecularBench : public LightingBaseBench { | 210 class LightingSpotLitSpecularBench : public LightingBaseBench { |
| 211 public: | 211 public: |
| 212 LightingSpotLitSpecularBench(bool small) : INHERITED(small) { | 212 LightingSpotLitSpecularBench(bool small) : INHERITED(small) { } |
| 213 } | |
| 214 | 213 |
| 215 protected: | 214 protected: |
| 216 const char* onGetName() override { | 215 const char* onGetName() override { |
| 217 return fIsSmall ? "lightingspotlitspecular_small" : "lightingspotlitspec
ular_large"; | 216 return fIsSmall ? "lightingspotlitspecular_small" : "lightingspotlitspec
ular_large"; |
| 218 } | 217 } |
| 219 | 218 |
| 220 void onDraw(int loops, SkCanvas* canvas) override { | 219 void onDraw(int loops, SkCanvas* canvas) override { |
| 221 draw(loops, canvas, SkLightingImageFilter::CreateSpotLitSpecular(GetSpot
Location(), | 220 draw(loops, canvas, SkLightingImageFilter::MakeSpotLitSpecular(GetSpotLo
cation(), |
| 222 GetSpot
Target(), | 221 GetSpotTa
rget(), |
| 223 GetSpot
Exponent(), | 222 GetSpotEx
ponent(), |
| 224 GetCuto
ffAngle(), | 223 GetCutoff
Angle(), |
| 225 GetWhit
e(), | 224 GetWhite(
), |
| 226 GetSurf
aceScale(), | 225 GetSurfac
eScale(), |
| 227 GetKs()
, | 226 GetKs(), |
| 228 GetShin
iness())); | 227 GetShinin
ess(), |
| 228 nullptr))
; |
| 229 } | 229 } |
| 230 | 230 |
| 231 private: | 231 private: |
| 232 typedef LightingBaseBench INHERITED; | 232 typedef LightingBaseBench INHERITED; |
| 233 }; | 233 }; |
| 234 | 234 |
| 235 /////////////////////////////////////////////////////////////////////////////// | 235 /////////////////////////////////////////////////////////////////////////////// |
| 236 | 236 |
| 237 DEF_BENCH( return new LightingPointLitDiffuseBench(true); ) | 237 DEF_BENCH( return new LightingPointLitDiffuseBench(true); ) |
| 238 DEF_BENCH( return new LightingPointLitDiffuseBench(false); ) | 238 DEF_BENCH( return new LightingPointLitDiffuseBench(false); ) |
| 239 DEF_BENCH( return new LightingDistantLitDiffuseBench(true); ) | 239 DEF_BENCH( return new LightingDistantLitDiffuseBench(true); ) |
| 240 DEF_BENCH( return new LightingDistantLitDiffuseBench(false); ) | 240 DEF_BENCH( return new LightingDistantLitDiffuseBench(false); ) |
| 241 DEF_BENCH( return new LightingSpotLitDiffuseBench(true); ) | 241 DEF_BENCH( return new LightingSpotLitDiffuseBench(true); ) |
| 242 DEF_BENCH( return new LightingSpotLitDiffuseBench(false); ) | 242 DEF_BENCH( return new LightingSpotLitDiffuseBench(false); ) |
| 243 DEF_BENCH( return new LightingPointLitSpecularBench(true); ) | 243 DEF_BENCH( return new LightingPointLitSpecularBench(true); ) |
| 244 DEF_BENCH( return new LightingPointLitSpecularBench(false); ) | 244 DEF_BENCH( return new LightingPointLitSpecularBench(false); ) |
| 245 DEF_BENCH( return new LightingDistantLitSpecularBench(true); ) | 245 DEF_BENCH( return new LightingDistantLitSpecularBench(true); ) |
| 246 DEF_BENCH( return new LightingDistantLitSpecularBench(false); ) | 246 DEF_BENCH( return new LightingDistantLitSpecularBench(false); ) |
| 247 DEF_BENCH( return new LightingSpotLitSpecularBench(true); ) | 247 DEF_BENCH( return new LightingSpotLitSpecularBench(true); ) |
| 248 DEF_BENCH( return new LightingSpotLitSpecularBench(false); ) | 248 DEF_BENCH( return new LightingSpotLitSpecularBench(false); ) |
| OLD | NEW |