| 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 "SkBenchmark.h" | 7 #include "SkBenchmark.h" |
| 8 #include "SkBitmapSource.h" | 8 #include "SkBitmapSource.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkDevice.h" | 10 #include "SkDevice.h" |
| 11 #include "SkLightingImageFilter.h" | 11 #include "SkLightingImageFilter.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 SkBenchmark { | 18 class LightingBaseBench : public SkBenchmark { |
| 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(SkCanvas* canvas, SkImageFilter* imageFilter) const { | 23 void draw(const int loops, SkCanvas* canvas, 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(imageFilter)->unref(); |
| 28 for (int i = 0; i < this->getLoops(); 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(0, 0, SkIntToScalar(10)); | 34 static SkPoint3 pointLocation(0, 0, SkIntToScalar(10)); |
| 35 return pointLocation; | 35 return pointLocation; |
| 36 } | 36 } |
| 37 | 37 |
| 38 static SkPoint3 getDistantDirection() { | 38 static SkPoint3 getDistantDirection() { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 class LightingPointLitDiffuseBench : public LightingBaseBench { | 98 class LightingPointLitDiffuseBench : public LightingBaseBench { |
| 99 public: | 99 public: |
| 100 LightingPointLitDiffuseBench(bool small) : INHERITED(small) { | 100 LightingPointLitDiffuseBench(bool small) : INHERITED(small) { |
| 101 } | 101 } |
| 102 | 102 |
| 103 protected: | 103 protected: |
| 104 virtual const char* onGetName() SK_OVERRIDE { | 104 virtual const char* onGetName() SK_OVERRIDE { |
| 105 return fIsSmall ? "lightingpointlitdiffuse_small" : "lightingpointlitdif
fuse_large"; | 105 return fIsSmall ? "lightingpointlitdiffuse_small" : "lightingpointlitdif
fuse_large"; |
| 106 } | 106 } |
| 107 | 107 |
| 108 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 108 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 109 draw(canvas, SkLightingImageFilter::CreatePointLitDiffuse(getPointLocati
on(), getWhite(), | 109 draw(loops, canvas, SkLightingImageFilter::CreatePointLitDiffuse(getPoin
tLocation(), |
| 110 getSurfaceScale(), getKd())); | 110 getWhit
e(), |
| 111 getSurf
aceScale(), |
| 112 getKd()
)); |
| 111 } | 113 } |
| 112 | 114 |
| 113 private: | 115 private: |
| 114 typedef LightingBaseBench INHERITED; | 116 typedef LightingBaseBench INHERITED; |
| 115 }; | 117 }; |
| 116 | 118 |
| 117 class LightingDistantLitDiffuseBench : public LightingBaseBench { | 119 class LightingDistantLitDiffuseBench : public LightingBaseBench { |
| 118 public: | 120 public: |
| 119 LightingDistantLitDiffuseBench(bool small) : INHERITED(small) { | 121 LightingDistantLitDiffuseBench(bool small) : INHERITED(small) { |
| 120 } | 122 } |
| 121 | 123 |
| 122 protected: | 124 protected: |
| 123 virtual const char* onGetName() SK_OVERRIDE { | 125 virtual const char* onGetName() SK_OVERRIDE { |
| 124 return fIsSmall ? "lightingdistantlitdiffuse_small" : "lightingdistantli
tdiffuse_large"; | 126 return fIsSmall ? "lightingdistantlitdiffuse_small" : "lightingdistantli
tdiffuse_large"; |
| 125 } | 127 } |
| 126 | 128 |
| 127 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 129 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 128 draw(canvas, SkLightingImageFilter::CreateDistantLitDiffuse(getDistantDi
rection(), | 130 draw(loops, canvas, SkLightingImageFilter::CreateDistantLitDiffuse(getDi
stantDirection(), |
| 129 getWhite(), getSurfaceScale(), getKd())); | 131 getWh
ite(), |
| 132 getSu
rfaceScale(), |
| 133 getKd
())); |
| 130 } | 134 } |
| 131 | 135 |
| 132 private: | 136 private: |
| 133 typedef LightingBaseBench INHERITED; | 137 typedef LightingBaseBench INHERITED; |
| 134 }; | 138 }; |
| 135 | 139 |
| 136 class LightingSpotLitDiffuseBench : public LightingBaseBench { | 140 class LightingSpotLitDiffuseBench : public LightingBaseBench { |
| 137 public: | 141 public: |
| 138 LightingSpotLitDiffuseBench(bool small) : INHERITED(small) { | 142 LightingSpotLitDiffuseBench(bool small) : INHERITED(small) { |
| 139 } | 143 } |
| 140 | 144 |
| 141 protected: | 145 protected: |
| 142 virtual const char* onGetName() SK_OVERRIDE { | 146 virtual const char* onGetName() SK_OVERRIDE { |
| 143 return fIsSmall ? "lightingspotlitdiffuse_small" : "lightingspotlitdiffu
se_large"; | 147 return fIsSmall ? "lightingspotlitdiffuse_small" : "lightingspotlitdiffu
se_large"; |
| 144 } | 148 } |
| 145 | 149 |
| 146 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 150 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 147 draw(canvas, SkLightingImageFilter::CreateSpotLitDiffuse(getSpotLocation
(), | 151 draw(loops, canvas, SkLightingImageFilter::CreateSpotLitDiffuse(getSpotL
ocation(), |
| 148 getSpotTarget(), getSpotExponent(), getCutoffAngle(), getWhite(), ge
tSurfaceScale(), | 152 getSpotT
arget(), |
| 149 getKd())); | 153 getSpotE
xponent(), |
| 154 getCutof
fAngle(), |
| 155 getWhite
(), |
| 156 getSurfa
ceScale(), |
| 157 getKd())
); |
| 150 } | 158 } |
| 151 | 159 |
| 152 private: | 160 private: |
| 153 typedef LightingBaseBench INHERITED; | 161 typedef LightingBaseBench INHERITED; |
| 154 }; | 162 }; |
| 155 | 163 |
| 156 class LightingPointLitSpecularBench : public LightingBaseBench { | 164 class LightingPointLitSpecularBench : public LightingBaseBench { |
| 157 public: | 165 public: |
| 158 LightingPointLitSpecularBench(bool small) : INHERITED(small) { | 166 LightingPointLitSpecularBench(bool small) : INHERITED(small) { |
| 159 } | 167 } |
| 160 | 168 |
| 161 protected: | 169 protected: |
| 162 virtual const char* onGetName() SK_OVERRIDE { | 170 virtual const char* onGetName() SK_OVERRIDE { |
| 163 return fIsSmall ? "lightingpointlitspecular_small" : "lightingpointlitsp
ecular_large"; | 171 return fIsSmall ? "lightingpointlitspecular_small" : "lightingpointlitsp
ecular_large"; |
| 164 } | 172 } |
| 165 | 173 |
| 166 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 174 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 167 draw(canvas, SkLightingImageFilter::CreatePointLitSpecular(getPointLocat
ion(), getWhite(), | 175 draw(loops, canvas, SkLightingImageFilter::CreatePointLitSpecular(getPoi
ntLocation(), |
| 168 getSurfaceScale(), getKs(), getShininess())); | 176 getWhi
te(), |
| 177 getSur
faceScale(), |
| 178 getKs(
), |
| 179 getShi
niness())); |
| 169 } | 180 } |
| 170 | 181 |
| 171 private: | 182 private: |
| 172 typedef LightingBaseBench INHERITED; | 183 typedef LightingBaseBench INHERITED; |
| 173 }; | 184 }; |
| 174 | 185 |
| 175 class LightingDistantLitSpecularBench : public LightingBaseBench { | 186 class LightingDistantLitSpecularBench : public LightingBaseBench { |
| 176 public: | 187 public: |
| 177 LightingDistantLitSpecularBench(bool small) : INHERITED(small) { | 188 LightingDistantLitSpecularBench(bool small) : INHERITED(small) { |
| 178 } | 189 } |
| 179 | 190 |
| 180 protected: | 191 protected: |
| 181 virtual const char* onGetName() SK_OVERRIDE { | 192 virtual const char* onGetName() SK_OVERRIDE { |
| 182 return fIsSmall ? "lightingdistantlitspecular_small" : "lightingdistantl
itspecular_large"; | 193 return fIsSmall ? "lightingdistantlitspecular_small" : "lightingdistantl
itspecular_large"; |
| 183 } | 194 } |
| 184 | 195 |
| 185 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 196 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 186 draw(canvas, SkLightingImageFilter::CreateDistantLitSpecular(getDistantD
irection(), | 197 draw(loops, canvas, SkLightingImageFilter::CreateDistantLitSpecular(getD
istantDirection(), |
| 187 getWhite(), getSurfaceScale(), getKs(), getShininess())); | 198 getW
hite(), |
| 199 getS
urfaceScale(), |
| 200 getK
s(), |
| 201 getS
hininess())); |
| 188 } | 202 } |
| 189 | 203 |
| 190 private: | 204 private: |
| 191 typedef LightingBaseBench INHERITED; | 205 typedef LightingBaseBench INHERITED; |
| 192 }; | 206 }; |
| 193 | 207 |
| 194 class LightingSpotLitSpecularBench : public LightingBaseBench { | 208 class LightingSpotLitSpecularBench : public LightingBaseBench { |
| 195 public: | 209 public: |
| 196 LightingSpotLitSpecularBench(bool small) : INHERITED(small) { | 210 LightingSpotLitSpecularBench(bool small) : INHERITED(small) { |
| 197 } | 211 } |
| 198 | 212 |
| 199 protected: | 213 protected: |
| 200 virtual const char* onGetName() SK_OVERRIDE { | 214 virtual const char* onGetName() SK_OVERRIDE { |
| 201 return fIsSmall ? "lightingspotlitspecular_small" : "lightingspotlitspec
ular_large"; | 215 return fIsSmall ? "lightingspotlitspecular_small" : "lightingspotlitspec
ular_large"; |
| 202 } | 216 } |
| 203 | 217 |
| 204 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 218 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 205 draw(canvas, SkLightingImageFilter::CreateSpotLitSpecular(getSpotLocatio
n(), | 219 draw(loops, canvas, SkLightingImageFilter::CreateSpotLitSpecular(getSpot
Location(), |
| 206 getSpotTarget(), getSpotExponent(), getCutoffAngle(), getWhite(), ge
tSurfaceScale(), | 220 getSpot
Target(), |
| 207 getKs(), getShininess())); | 221 getSpot
Exponent(), |
| 222 getCuto
ffAngle(), |
| 223 getWhit
e(), |
| 224 getSurf
aceScale(), |
| 225 getKs()
, |
| 226 getShin
iness())); |
| 208 } | 227 } |
| 209 | 228 |
| 210 private: | 229 private: |
| 211 typedef LightingBaseBench INHERITED; | 230 typedef LightingBaseBench INHERITED; |
| 212 }; | 231 }; |
| 213 | 232 |
| 214 /////////////////////////////////////////////////////////////////////////////// | 233 /////////////////////////////////////////////////////////////////////////////// |
| 215 | 234 |
| 216 DEF_BENCH( return new LightingPointLitDiffuseBench(true); ) | 235 DEF_BENCH( return new LightingPointLitDiffuseBench(true); ) |
| 217 DEF_BENCH( return new LightingPointLitDiffuseBench(false); ) | 236 DEF_BENCH( return new LightingPointLitDiffuseBench(false); ) |
| 218 DEF_BENCH( return new LightingDistantLitDiffuseBench(true); ) | 237 DEF_BENCH( return new LightingDistantLitDiffuseBench(true); ) |
| 219 DEF_BENCH( return new LightingDistantLitDiffuseBench(false); ) | 238 DEF_BENCH( return new LightingDistantLitDiffuseBench(false); ) |
| 220 DEF_BENCH( return new LightingSpotLitDiffuseBench(true); ) | 239 DEF_BENCH( return new LightingSpotLitDiffuseBench(true); ) |
| 221 DEF_BENCH( return new LightingSpotLitDiffuseBench(false); ) | 240 DEF_BENCH( return new LightingSpotLitDiffuseBench(false); ) |
| 222 DEF_BENCH( return new LightingPointLitSpecularBench(true); ) | 241 DEF_BENCH( return new LightingPointLitSpecularBench(true); ) |
| 223 DEF_BENCH( return new LightingPointLitSpecularBench(false); ) | 242 DEF_BENCH( return new LightingPointLitSpecularBench(false); ) |
| 224 DEF_BENCH( return new LightingDistantLitSpecularBench(true); ) | 243 DEF_BENCH( return new LightingDistantLitSpecularBench(true); ) |
| 225 DEF_BENCH( return new LightingDistantLitSpecularBench(false); ) | 244 DEF_BENCH( return new LightingDistantLitSpecularBench(false); ) |
| 226 DEF_BENCH( return new LightingSpotLitSpecularBench(true); ) | 245 DEF_BENCH( return new LightingSpotLitSpecularBench(true); ) |
| 227 DEF_BENCH( return new LightingSpotLitSpecularBench(false); ) | 246 DEF_BENCH( return new LightingSpotLitSpecularBench(false); ) |
| OLD | NEW |