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(const int loops, SkCanvas* canvas, SkImageFilter* imageFilter) con
st { | 23 void draw(int loops, SkCanvas* canvas, SkImageFilter* imageFilter) const { |
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 < 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() { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } | 103 } |
104 | 104 |
105 protected: | 105 protected: |
106 const char* onGetName() override { | 106 const char* onGetName() override { |
107 return fIsSmall ? "lightingpointlitdiffuse_small" : "lightingpointlitdif
fuse_large"; | 107 return fIsSmall ? "lightingpointlitdiffuse_small" : "lightingpointlitdif
fuse_large"; |
108 } | 108 } |
109 | 109 |
110 void onDraw(const int loops, SkCanvas* canvas) override { | 110 void onDraw(int loops, SkCanvas* canvas) override { |
111 draw(loops, canvas, SkLightingImageFilter::CreatePointLitDiffuse(GetPoin
tLocation(), | 111 draw(loops, canvas, SkLightingImageFilter::CreatePointLitDiffuse(GetPoin
tLocation(), |
112 GetWhit
e(), | 112 GetWhit
e(), |
113 GetSurf
aceScale(), | 113 GetSurf
aceScale(), |
114 GetKd()
)); | 114 GetKd()
)); |
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 } | 124 } |
125 | 125 |
126 protected: | 126 protected: |
127 const char* onGetName() override { | 127 const char* onGetName() override { |
128 return fIsSmall ? "lightingdistantlitdiffuse_small" : "lightingdistantli
tdiffuse_large"; | 128 return fIsSmall ? "lightingdistantlitdiffuse_small" : "lightingdistantli
tdiffuse_large"; |
129 } | 129 } |
130 | 130 |
131 void onDraw(const int loops, SkCanvas* canvas) override { | 131 void onDraw(int loops, SkCanvas* canvas) override { |
132 draw(loops, canvas, SkLightingImageFilter::CreateDistantLitDiffuse(GetDi
stantDirection(), | 132 draw(loops, canvas, SkLightingImageFilter::CreateDistantLitDiffuse(GetDi
stantDirection(), |
133 GetWh
ite(), | 133 GetWh
ite(), |
134 GetSu
rfaceScale(), | 134 GetSu
rfaceScale(), |
135 GetKd
())); | 135 GetKd
())); |
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 } | 145 } |
146 | 146 |
147 protected: | 147 protected: |
148 const char* onGetName() override { | 148 const char* onGetName() override { |
149 return fIsSmall ? "lightingspotlitdiffuse_small" : "lightingspotlitdiffu
se_large"; | 149 return fIsSmall ? "lightingspotlitdiffuse_small" : "lightingspotlitdiffu
se_large"; |
150 } | 150 } |
151 | 151 |
152 void onDraw(const int loops, SkCanvas* canvas) override { | 152 void onDraw(int loops, SkCanvas* canvas) override { |
153 draw(loops, canvas, SkLightingImageFilter::CreateSpotLitDiffuse(GetSpotL
ocation(), | 153 draw(loops, canvas, SkLightingImageFilter::CreateSpotLitDiffuse(GetSpotL
ocation(), |
154 GetSpotT
arget(), | 154 GetSpotT
arget(), |
155 GetSpotE
xponent(), | 155 GetSpotE
xponent(), |
156 GetCutof
fAngle(), | 156 GetCutof
fAngle(), |
157 GetWhite
(), | 157 GetWhite
(), |
158 GetSurfa
ceScale(), | 158 GetSurfa
ceScale(), |
159 GetKd())
); | 159 GetKd())
); |
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 } | 169 } |
170 | 170 |
171 protected: | 171 protected: |
172 const char* onGetName() override { | 172 const char* onGetName() override { |
173 return fIsSmall ? "lightingpointlitspecular_small" : "lightingpointlitsp
ecular_large"; | 173 return fIsSmall ? "lightingpointlitspecular_small" : "lightingpointlitsp
ecular_large"; |
174 } | 174 } |
175 | 175 |
176 void onDraw(const int loops, SkCanvas* canvas) override { | 176 void onDraw(int loops, SkCanvas* canvas) override { |
177 draw(loops, canvas, SkLightingImageFilter::CreatePointLitSpecular(GetPoi
ntLocation(), | 177 draw(loops, canvas, SkLightingImageFilter::CreatePointLitSpecular(GetPoi
ntLocation(), |
178 GetWhi
te(), | 178 GetWhi
te(), |
179 GetSur
faceScale(), | 179 GetSur
faceScale(), |
180 GetKs(
), | 180 GetKs(
), |
181 GetShi
niness())); | 181 GetShi
niness())); |
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 } | 191 } |
192 | 192 |
193 protected: | 193 protected: |
194 const char* onGetName() override { | 194 const char* onGetName() override { |
195 return fIsSmall ? "lightingdistantlitspecular_small" : "lightingdistantl
itspecular_large"; | 195 return fIsSmall ? "lightingdistantlitspecular_small" : "lightingdistantl
itspecular_large"; |
196 } | 196 } |
197 | 197 |
198 void onDraw(const int loops, SkCanvas* canvas) override { | 198 void onDraw(int loops, SkCanvas* canvas) override { |
199 draw(loops, canvas, SkLightingImageFilter::CreateDistantLitSpecular(GetD
istantDirection(), | 199 draw(loops, canvas, SkLightingImageFilter::CreateDistantLitSpecular(GetD
istantDirection(), |
200 GetW
hite(), | 200 GetW
hite(), |
201 GetS
urfaceScale(), | 201 GetS
urfaceScale(), |
202 GetK
s(), | 202 GetK
s(), |
203 GetS
hininess())); | 203 GetS
hininess())); |
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 } | 213 } |
214 | 214 |
215 protected: | 215 protected: |
216 const char* onGetName() override { | 216 const char* onGetName() override { |
217 return fIsSmall ? "lightingspotlitspecular_small" : "lightingspotlitspec
ular_large"; | 217 return fIsSmall ? "lightingspotlitspecular_small" : "lightingspotlitspec
ular_large"; |
218 } | 218 } |
219 | 219 |
220 void onDraw(const int loops, SkCanvas* canvas) override { | 220 void onDraw(int loops, SkCanvas* canvas) override { |
221 draw(loops, canvas, SkLightingImageFilter::CreateSpotLitSpecular(GetSpot
Location(), | 221 draw(loops, canvas, SkLightingImageFilter::CreateSpotLitSpecular(GetSpot
Location(), |
222 GetSpot
Target(), | 222 GetSpot
Target(), |
223 GetSpot
Exponent(), | 223 GetSpot
Exponent(), |
224 GetCuto
ffAngle(), | 224 GetCuto
ffAngle(), |
225 GetWhit
e(), | 225 GetWhit
e(), |
226 GetSurf
aceScale(), | 226 GetSurf
aceScale(), |
227 GetKs()
, | 227 GetKs()
, |
228 GetShin
iness())); | 228 GetShin
iness())); |
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 |