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