sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 7 | #include "Benchmark.h" |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 8 | #include "SkBitmapSource.h" |
| 9 | #include "SkCanvas.h" |
| 10 | #include "SkDevice.h" |
| 11 | #include "SkLightingImageFilter.h" |
| 12 | |
| 13 | #define FILTER_WIDTH_SMALL SkIntToScalar(32) |
| 14 | #define FILTER_HEIGHT_SMALL SkIntToScalar(32) |
| 15 | #define FILTER_WIDTH_LARGE SkIntToScalar(256) |
| 16 | #define FILTER_HEIGHT_LARGE SkIntToScalar(256) |
| 17 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 18 | class LightingBaseBench : public Benchmark { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 19 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 20 | LightingBaseBench(bool small) : fIsSmall(small) { } |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 21 | |
| 22 | protected: |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 23 | void draw(const int loops, SkCanvas* canvas, SkImageFilter* imageFilter) const { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 24 | SkRect r = fIsSmall ? SkRect::MakeWH(FILTER_WIDTH_SMALL, FILTER_HEIGHT_SMALL) : |
| 25 | SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_LARGE); |
| 26 | SkPaint paint; |
| 27 | paint.setImageFilter(imageFilter)->unref(); |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 28 | for (int i = 0; i < loops; i++) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 29 | canvas->drawRect(r, paint); |
| 30 | } |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | static SkPoint3 getPointLocation() { |
| 34 | static SkPoint3 pointLocation(0, 0, SkIntToScalar(10)); |
| 35 | return pointLocation; |
| 36 | } |
| 37 | |
| 38 | static SkPoint3 getDistantDirection() { |
| 39 | static SkScalar azimuthRad = SkDegreesToRadians(SkIntToScalar(225)); |
| 40 | static SkScalar elevationRad = SkDegreesToRadians(SkIntToScalar(5)); |
| 41 | static SkPoint3 distantDirection(SkScalarMul(SkScalarCos(azimuthRad), |
| 42 | SkScalarCos(elevationRad)), |
| 43 | SkScalarMul(SkScalarSin(azimuthRad), |
| 44 | SkScalarCos(elevationRad)), |
| 45 | SkScalarSin(elevationRad)); |
| 46 | return distantDirection; |
| 47 | } |
| 48 | |
| 49 | static SkPoint3 getSpotLocation() { |
| 50 | static SkPoint3 spotLocation(SkIntToScalar(-10), SkIntToScalar(-10), SkIntToScalar(20)); |
| 51 | return spotLocation; |
| 52 | } |
| 53 | |
| 54 | static SkPoint3 getSpotTarget() { |
| 55 | static SkPoint3 spotTarget(SkIntToScalar(40), SkIntToScalar(40), 0); |
| 56 | return spotTarget; |
| 57 | } |
| 58 | |
| 59 | static SkScalar getSpotExponent() { |
| 60 | static SkScalar spotExponent = SK_Scalar1; |
| 61 | return spotExponent; |
| 62 | } |
| 63 | |
| 64 | static SkScalar getCutoffAngle() { |
| 65 | static SkScalar cutoffAngle = SkIntToScalar(15); |
| 66 | return cutoffAngle; |
| 67 | } |
| 68 | |
| 69 | static SkScalar getKd() { |
| 70 | static SkScalar kd = SkIntToScalar(2); |
| 71 | return kd; |
| 72 | } |
| 73 | |
| 74 | static SkScalar getKs() { |
| 75 | static SkScalar ks = SkIntToScalar(1); |
| 76 | return ks; |
| 77 | } |
| 78 | |
| 79 | static SkScalar getShininess() { |
| 80 | static SkScalar shininess = SkIntToScalar(8); |
| 81 | return shininess; |
| 82 | } |
| 83 | |
| 84 | static SkScalar getSurfaceScale() { |
| 85 | static SkScalar surfaceScale = SkIntToScalar(1); |
| 86 | return surfaceScale; |
| 87 | } |
| 88 | |
| 89 | static SkColor getWhite() { |
| 90 | static SkColor white(0xFFFFFFFF); |
| 91 | return white; |
| 92 | } |
| 93 | |
| 94 | bool fIsSmall; |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 95 | typedef Benchmark INHERITED; |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | class LightingPointLitDiffuseBench : public LightingBaseBench { |
| 99 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 100 | LightingPointLitDiffuseBench(bool small) : INHERITED(small) { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | protected: |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 104 | const char* onGetName() SK_OVERRIDE { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 105 | return fIsSmall ? "lightingpointlitdiffuse_small" : "lightingpointlitdiffuse_large"; |
| 106 | } |
| 107 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 108 | void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 109 | draw(loops, canvas, SkLightingImageFilter::CreatePointLitDiffuse(getPointLocation(), |
| 110 | getWhite(), |
| 111 | getSurfaceScale(), |
| 112 | getKd())); |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | private: |
| 116 | typedef LightingBaseBench INHERITED; |
| 117 | }; |
| 118 | |
| 119 | class LightingDistantLitDiffuseBench : public LightingBaseBench { |
| 120 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 121 | LightingDistantLitDiffuseBench(bool small) : INHERITED(small) { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | protected: |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 125 | const char* onGetName() SK_OVERRIDE { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 126 | return fIsSmall ? "lightingdistantlitdiffuse_small" : "lightingdistantlitdiffuse_large"; |
| 127 | } |
| 128 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 129 | void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 130 | draw(loops, canvas, SkLightingImageFilter::CreateDistantLitDiffuse(getDistantDirection(), |
| 131 | getWhite(), |
| 132 | getSurfaceScale(), |
| 133 | getKd())); |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | private: |
| 137 | typedef LightingBaseBench INHERITED; |
| 138 | }; |
| 139 | |
| 140 | class LightingSpotLitDiffuseBench : public LightingBaseBench { |
| 141 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 142 | LightingSpotLitDiffuseBench(bool small) : INHERITED(small) { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | protected: |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 146 | const char* onGetName() SK_OVERRIDE { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 147 | return fIsSmall ? "lightingspotlitdiffuse_small" : "lightingspotlitdiffuse_large"; |
| 148 | } |
| 149 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 150 | void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 151 | draw(loops, canvas, SkLightingImageFilter::CreateSpotLitDiffuse(getSpotLocation(), |
| 152 | getSpotTarget(), |
| 153 | getSpotExponent(), |
| 154 | getCutoffAngle(), |
| 155 | getWhite(), |
| 156 | getSurfaceScale(), |
| 157 | getKd())); |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | private: |
| 161 | typedef LightingBaseBench INHERITED; |
| 162 | }; |
| 163 | |
| 164 | class LightingPointLitSpecularBench : public LightingBaseBench { |
| 165 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 166 | LightingPointLitSpecularBench(bool small) : INHERITED(small) { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | protected: |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 170 | const char* onGetName() SK_OVERRIDE { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 171 | return fIsSmall ? "lightingpointlitspecular_small" : "lightingpointlitspecular_large"; |
| 172 | } |
| 173 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 174 | void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 175 | draw(loops, canvas, SkLightingImageFilter::CreatePointLitSpecular(getPointLocation(), |
| 176 | getWhite(), |
| 177 | getSurfaceScale(), |
| 178 | getKs(), |
| 179 | getShininess())); |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | private: |
| 183 | typedef LightingBaseBench INHERITED; |
| 184 | }; |
| 185 | |
| 186 | class LightingDistantLitSpecularBench : public LightingBaseBench { |
| 187 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 188 | LightingDistantLitSpecularBench(bool small) : INHERITED(small) { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | protected: |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 192 | const char* onGetName() SK_OVERRIDE { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 193 | return fIsSmall ? "lightingdistantlitspecular_small" : "lightingdistantlitspecular_large"; |
| 194 | } |
| 195 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 196 | void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 197 | draw(loops, canvas, SkLightingImageFilter::CreateDistantLitSpecular(getDistantDirection(), |
| 198 | getWhite(), |
| 199 | getSurfaceScale(), |
| 200 | getKs(), |
| 201 | getShininess())); |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | private: |
| 205 | typedef LightingBaseBench INHERITED; |
| 206 | }; |
| 207 | |
| 208 | class LightingSpotLitSpecularBench : public LightingBaseBench { |
| 209 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 210 | LightingSpotLitSpecularBench(bool small) : INHERITED(small) { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | protected: |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 214 | const char* onGetName() SK_OVERRIDE { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 215 | return fIsSmall ? "lightingspotlitspecular_small" : "lightingspotlitspecular_large"; |
| 216 | } |
| 217 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 218 | void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 219 | draw(loops, canvas, SkLightingImageFilter::CreateSpotLitSpecular(getSpotLocation(), |
| 220 | getSpotTarget(), |
| 221 | getSpotExponent(), |
| 222 | getCutoffAngle(), |
| 223 | getWhite(), |
| 224 | getSurfaceScale(), |
| 225 | getKs(), |
| 226 | getShininess())); |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | private: |
| 230 | typedef LightingBaseBench INHERITED; |
| 231 | }; |
| 232 | |
| 233 | /////////////////////////////////////////////////////////////////////////////// |
| 234 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 235 | DEF_BENCH( return new LightingPointLitDiffuseBench(true); ) |
| 236 | DEF_BENCH( return new LightingPointLitDiffuseBench(false); ) |
| 237 | DEF_BENCH( return new LightingDistantLitDiffuseBench(true); ) |
| 238 | DEF_BENCH( return new LightingDistantLitDiffuseBench(false); ) |
| 239 | DEF_BENCH( return new LightingSpotLitDiffuseBench(true); ) |
| 240 | DEF_BENCH( return new LightingSpotLitDiffuseBench(false); ) |
| 241 | DEF_BENCH( return new LightingPointLitSpecularBench(true); ) |
| 242 | DEF_BENCH( return new LightingPointLitSpecularBench(false); ) |
| 243 | DEF_BENCH( return new LightingDistantLitSpecularBench(true); ) |
| 244 | DEF_BENCH( return new LightingDistantLitSpecularBench(false); ) |
| 245 | DEF_BENCH( return new LightingSpotLitSpecularBench(true); ) |
| 246 | DEF_BENCH( return new LightingSpotLitSpecularBench(false); ) |