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(void* param, bool small) : INHERITED(param), fIsSmall(smal
l) { | 20 LightingBaseBench(bool small) : fIsSmall(small) { } |
21 } | |
22 | 21 |
23 protected: | 22 protected: |
24 void draw(SkCanvas* canvas, SkImageFilter* imageFilter) const { | 23 void draw(SkCanvas* canvas, SkImageFilter* imageFilter) const { |
25 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) : |
26 SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_L
ARGE); | 25 SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_L
ARGE); |
27 SkPaint paint; | 26 SkPaint paint; |
28 paint.setImageFilter(imageFilter)->unref(); | 27 paint.setImageFilter(imageFilter)->unref(); |
29 for (int i = 0; i < this->getLoops(); i++) { | 28 for (int i = 0; i < this->getLoops(); i++) { |
30 canvas->drawRect(r, paint); | 29 canvas->drawRect(r, paint); |
31 } | 30 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 static SkColor white(0xFFFFFFFF); | 90 static SkColor white(0xFFFFFFFF); |
92 return white; | 91 return white; |
93 } | 92 } |
94 | 93 |
95 bool fIsSmall; | 94 bool fIsSmall; |
96 typedef SkBenchmark INHERITED; | 95 typedef SkBenchmark INHERITED; |
97 }; | 96 }; |
98 | 97 |
99 class LightingPointLitDiffuseBench : public LightingBaseBench { | 98 class LightingPointLitDiffuseBench : public LightingBaseBench { |
100 public: | 99 public: |
101 LightingPointLitDiffuseBench(void* param, bool small) : INHERITED(param, sma
ll) { | 100 LightingPointLitDiffuseBench(bool small) : INHERITED(small) { |
102 } | 101 } |
103 | 102 |
104 protected: | 103 protected: |
105 virtual const char* onGetName() SK_OVERRIDE { | 104 virtual const char* onGetName() SK_OVERRIDE { |
106 return fIsSmall ? "lightingpointlitdiffuse_small" : "lightingpointlitdif
fuse_large"; | 105 return fIsSmall ? "lightingpointlitdiffuse_small" : "lightingpointlitdif
fuse_large"; |
107 } | 106 } |
108 | 107 |
109 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 108 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
110 draw(canvas, SkLightingImageFilter::CreatePointLitDiffuse(getPointLocati
on(), getWhite(), | 109 draw(canvas, SkLightingImageFilter::CreatePointLitDiffuse(getPointLocati
on(), getWhite(), |
111 getSurfaceScale(), getKd())); | 110 getSurfaceScale(), getKd())); |
112 } | 111 } |
113 | 112 |
114 private: | 113 private: |
115 typedef LightingBaseBench INHERITED; | 114 typedef LightingBaseBench INHERITED; |
116 }; | 115 }; |
117 | 116 |
118 class LightingDistantLitDiffuseBench : public LightingBaseBench { | 117 class LightingDistantLitDiffuseBench : public LightingBaseBench { |
119 public: | 118 public: |
120 LightingDistantLitDiffuseBench(void* param, bool small) : INHERITED(param, s
mall) { | 119 LightingDistantLitDiffuseBench(bool small) : INHERITED(small) { |
121 } | 120 } |
122 | 121 |
123 protected: | 122 protected: |
124 virtual const char* onGetName() SK_OVERRIDE { | 123 virtual const char* onGetName() SK_OVERRIDE { |
125 return fIsSmall ? "lightingdistantlitdiffuse_small" : "lightingdistantli
tdiffuse_large"; | 124 return fIsSmall ? "lightingdistantlitdiffuse_small" : "lightingdistantli
tdiffuse_large"; |
126 } | 125 } |
127 | 126 |
128 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 127 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
129 draw(canvas, SkLightingImageFilter::CreateDistantLitDiffuse(getDistantDi
rection(), | 128 draw(canvas, SkLightingImageFilter::CreateDistantLitDiffuse(getDistantDi
rection(), |
130 getWhite(), getSurfaceScale(), getKd())); | 129 getWhite(), getSurfaceScale(), getKd())); |
131 } | 130 } |
132 | 131 |
133 private: | 132 private: |
134 typedef LightingBaseBench INHERITED; | 133 typedef LightingBaseBench INHERITED; |
135 }; | 134 }; |
136 | 135 |
137 class LightingSpotLitDiffuseBench : public LightingBaseBench { | 136 class LightingSpotLitDiffuseBench : public LightingBaseBench { |
138 public: | 137 public: |
139 LightingSpotLitDiffuseBench(void* param, bool small) : INHERITED(param, smal
l) { | 138 LightingSpotLitDiffuseBench(bool small) : INHERITED(small) { |
140 } | 139 } |
141 | 140 |
142 protected: | 141 protected: |
143 virtual const char* onGetName() SK_OVERRIDE { | 142 virtual const char* onGetName() SK_OVERRIDE { |
144 return fIsSmall ? "lightingspotlitdiffuse_small" : "lightingspotlitdiffu
se_large"; | 143 return fIsSmall ? "lightingspotlitdiffuse_small" : "lightingspotlitdiffu
se_large"; |
145 } | 144 } |
146 | 145 |
147 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 146 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
148 draw(canvas, SkLightingImageFilter::CreateSpotLitDiffuse(getSpotLocation
(), | 147 draw(canvas, SkLightingImageFilter::CreateSpotLitDiffuse(getSpotLocation
(), |
149 getSpotTarget(), getSpotExponent(), getCutoffAngle(), getWhite(), ge
tSurfaceScale(), | 148 getSpotTarget(), getSpotExponent(), getCutoffAngle(), getWhite(), ge
tSurfaceScale(), |
150 getKd())); | 149 getKd())); |
151 } | 150 } |
152 | 151 |
153 private: | 152 private: |
154 typedef LightingBaseBench INHERITED; | 153 typedef LightingBaseBench INHERITED; |
155 }; | 154 }; |
156 | 155 |
157 class LightingPointLitSpecularBench : public LightingBaseBench { | 156 class LightingPointLitSpecularBench : public LightingBaseBench { |
158 public: | 157 public: |
159 LightingPointLitSpecularBench(void* param, bool small) : INHERITED(param, sm
all) { | 158 LightingPointLitSpecularBench(bool small) : INHERITED(small) { |
160 } | 159 } |
161 | 160 |
162 protected: | 161 protected: |
163 virtual const char* onGetName() SK_OVERRIDE { | 162 virtual const char* onGetName() SK_OVERRIDE { |
164 return fIsSmall ? "lightingpointlitspecular_small" : "lightingpointlitsp
ecular_large"; | 163 return fIsSmall ? "lightingpointlitspecular_small" : "lightingpointlitsp
ecular_large"; |
165 } | 164 } |
166 | 165 |
167 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 166 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
168 draw(canvas, SkLightingImageFilter::CreatePointLitSpecular(getPointLocat
ion(), getWhite(), | 167 draw(canvas, SkLightingImageFilter::CreatePointLitSpecular(getPointLocat
ion(), getWhite(), |
169 getSurfaceScale(), getKs(), getShininess())); | 168 getSurfaceScale(), getKs(), getShininess())); |
170 } | 169 } |
171 | 170 |
172 private: | 171 private: |
173 typedef LightingBaseBench INHERITED; | 172 typedef LightingBaseBench INHERITED; |
174 }; | 173 }; |
175 | 174 |
176 class LightingDistantLitSpecularBench : public LightingBaseBench { | 175 class LightingDistantLitSpecularBench : public LightingBaseBench { |
177 public: | 176 public: |
178 LightingDistantLitSpecularBench(void* param, bool small) : INHERITED(param,
small) { | 177 LightingDistantLitSpecularBench(bool small) : INHERITED(small) { |
179 } | 178 } |
180 | 179 |
181 protected: | 180 protected: |
182 virtual const char* onGetName() SK_OVERRIDE { | 181 virtual const char* onGetName() SK_OVERRIDE { |
183 return fIsSmall ? "lightingdistantlitspecular_small" : "lightingdistantl
itspecular_large"; | 182 return fIsSmall ? "lightingdistantlitspecular_small" : "lightingdistantl
itspecular_large"; |
184 } | 183 } |
185 | 184 |
186 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 185 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
187 draw(canvas, SkLightingImageFilter::CreateDistantLitSpecular(getDistantD
irection(), | 186 draw(canvas, SkLightingImageFilter::CreateDistantLitSpecular(getDistantD
irection(), |
188 getWhite(), getSurfaceScale(), getKs(), getShininess())); | 187 getWhite(), getSurfaceScale(), getKs(), getShininess())); |
189 } | 188 } |
190 | 189 |
191 private: | 190 private: |
192 typedef LightingBaseBench INHERITED; | 191 typedef LightingBaseBench INHERITED; |
193 }; | 192 }; |
194 | 193 |
195 class LightingSpotLitSpecularBench : public LightingBaseBench { | 194 class LightingSpotLitSpecularBench : public LightingBaseBench { |
196 public: | 195 public: |
197 LightingSpotLitSpecularBench(void* param, bool small) : INHERITED(param, sma
ll) { | 196 LightingSpotLitSpecularBench(bool small) : INHERITED(small) { |
198 } | 197 } |
199 | 198 |
200 protected: | 199 protected: |
201 virtual const char* onGetName() SK_OVERRIDE { | 200 virtual const char* onGetName() SK_OVERRIDE { |
202 return fIsSmall ? "lightingspotlitspecular_small" : "lightingspotlitspec
ular_large"; | 201 return fIsSmall ? "lightingspotlitspecular_small" : "lightingspotlitspec
ular_large"; |
203 } | 202 } |
204 | 203 |
205 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 204 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
206 draw(canvas, SkLightingImageFilter::CreateSpotLitSpecular(getSpotLocatio
n(), | 205 draw(canvas, SkLightingImageFilter::CreateSpotLitSpecular(getSpotLocatio
n(), |
207 getSpotTarget(), getSpotExponent(), getCutoffAngle(), getWhite(), ge
tSurfaceScale(), | 206 getSpotTarget(), getSpotExponent(), getCutoffAngle(), getWhite(), ge
tSurfaceScale(), |
208 getKs(), getShininess())); | 207 getKs(), getShininess())); |
209 } | 208 } |
210 | 209 |
211 private: | 210 private: |
212 typedef LightingBaseBench INHERITED; | 211 typedef LightingBaseBench INHERITED; |
213 }; | 212 }; |
214 | 213 |
215 /////////////////////////////////////////////////////////////////////////////// | 214 /////////////////////////////////////////////////////////////////////////////// |
216 | 215 |
217 DEF_BENCH( return new LightingPointLitDiffuseBench(p, true); ) | 216 DEF_BENCH( return new LightingPointLitDiffuseBench(true); ) |
218 DEF_BENCH( return new LightingPointLitDiffuseBench(p, false); ) | 217 DEF_BENCH( return new LightingPointLitDiffuseBench(false); ) |
219 DEF_BENCH( return new LightingDistantLitDiffuseBench(p, true); ) | 218 DEF_BENCH( return new LightingDistantLitDiffuseBench(true); ) |
220 DEF_BENCH( return new LightingDistantLitDiffuseBench(p, false); ) | 219 DEF_BENCH( return new LightingDistantLitDiffuseBench(false); ) |
221 DEF_BENCH( return new LightingSpotLitDiffuseBench(p, true); ) | 220 DEF_BENCH( return new LightingSpotLitDiffuseBench(true); ) |
222 DEF_BENCH( return new LightingSpotLitDiffuseBench(p, false); ) | 221 DEF_BENCH( return new LightingSpotLitDiffuseBench(false); ) |
223 DEF_BENCH( return new LightingPointLitSpecularBench(p, true); ) | 222 DEF_BENCH( return new LightingPointLitSpecularBench(true); ) |
224 DEF_BENCH( return new LightingPointLitSpecularBench(p, false); ) | 223 DEF_BENCH( return new LightingPointLitSpecularBench(false); ) |
225 DEF_BENCH( return new LightingDistantLitSpecularBench(p, true); ) | 224 DEF_BENCH( return new LightingDistantLitSpecularBench(true); ) |
226 DEF_BENCH( return new LightingDistantLitSpecularBench(p, false); ) | 225 DEF_BENCH( return new LightingDistantLitSpecularBench(false); ) |
227 DEF_BENCH( return new LightingSpotLitSpecularBench(p, true); ) | 226 DEF_BENCH( return new LightingSpotLitSpecularBench(true); ) |
228 DEF_BENCH( return new LightingSpotLitSpecularBench(p, false); ) | 227 DEF_BENCH( return new LightingSpotLitSpecularBench(false); ) |
OLD | NEW |