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)); |
Mike Reed | df85c38 | 2017-02-14 10:59:19 -0500 | [diff] [blame] | 40 | static SkPoint3 distantDirection = SkPoint3::Make( |
| 41 | SkScalarCos(azimuthRad) * SkScalarCos(elevationRad), |
| 42 | SkScalarSin(azimuthRad) * SkScalarCos(elevationRad), |
| 43 | SkScalarSin(elevationRad)); |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 44 | return distantDirection; |
| 45 | } |
| 46 | |
robertphillips | 3d32d76 | 2015-07-13 13:16:44 -0700 | [diff] [blame] | 47 | static SkPoint3 GetSpotLocation() { |
| 48 | static SkPoint3 spotLocation = SkPoint3::Make(SkIntToScalar(-10), |
| 49 | SkIntToScalar(-10), |
| 50 | SkIntToScalar(20)); |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 51 | return spotLocation; |
| 52 | } |
| 53 | |
robertphillips | 3d32d76 | 2015-07-13 13:16:44 -0700 | [diff] [blame] | 54 | static SkPoint3 GetSpotTarget() { |
| 55 | static SkPoint3 spotTarget = SkPoint3::Make(SkIntToScalar(40), SkIntToScalar(40), 0); |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 56 | return spotTarget; |
| 57 | } |
| 58 | |
robertphillips | 3d32d76 | 2015-07-13 13:16:44 -0700 | [diff] [blame] | 59 | static SkScalar GetSpotExponent() { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 60 | static SkScalar spotExponent = SK_Scalar1; |
| 61 | return spotExponent; |
| 62 | } |
| 63 | |
robertphillips | 3d32d76 | 2015-07-13 13:16:44 -0700 | [diff] [blame] | 64 | static SkScalar GetCutoffAngle() { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 65 | static SkScalar cutoffAngle = SkIntToScalar(15); |
| 66 | return cutoffAngle; |
| 67 | } |
| 68 | |
robertphillips | 3d32d76 | 2015-07-13 13:16:44 -0700 | [diff] [blame] | 69 | static SkScalar GetKd() { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 70 | static SkScalar kd = SkIntToScalar(2); |
| 71 | return kd; |
| 72 | } |
| 73 | |
robertphillips | 3d32d76 | 2015-07-13 13:16:44 -0700 | [diff] [blame] | 74 | static SkScalar GetKs() { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 75 | static SkScalar ks = SkIntToScalar(1); |
| 76 | return ks; |
| 77 | } |
| 78 | |
robertphillips | 3d32d76 | 2015-07-13 13:16:44 -0700 | [diff] [blame] | 79 | static SkScalar GetShininess() { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 80 | static SkScalar shininess = SkIntToScalar(8); |
| 81 | return shininess; |
| 82 | } |
| 83 | |
robertphillips | 3d32d76 | 2015-07-13 13:16:44 -0700 | [diff] [blame] | 84 | static SkScalar GetSurfaceScale() { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 85 | static SkScalar surfaceScale = SkIntToScalar(1); |
| 86 | return surfaceScale; |
| 87 | } |
| 88 | |
robertphillips | 3d32d76 | 2015-07-13 13:16:44 -0700 | [diff] [blame] | 89 | static SkColor GetWhite() { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 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: |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 100 | LightingPointLitDiffuseBench(bool small) : INHERITED(small) { } |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 101 | |
| 102 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 103 | const char* onGetName() override { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 104 | return fIsSmall ? "lightingpointlitdiffuse_small" : "lightingpointlitdiffuse_large"; |
| 105 | } |
| 106 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 107 | void onDraw(int loops, SkCanvas* canvas) override { |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 108 | draw(loops, canvas, SkLightingImageFilter::MakePointLitDiffuse(GetPointLocation(), |
| 109 | GetWhite(), |
| 110 | GetSurfaceScale(), |
| 111 | GetKd(), |
| 112 | nullptr)); |
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: |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 121 | LightingDistantLitDiffuseBench(bool small) : INHERITED(small) { } |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 122 | |
| 123 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 124 | const char* onGetName() override { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 125 | return fIsSmall ? "lightingdistantlitdiffuse_small" : "lightingdistantlitdiffuse_large"; |
| 126 | } |
| 127 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 128 | void onDraw(int loops, SkCanvas* canvas) override { |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 129 | draw(loops, canvas, SkLightingImageFilter::MakeDistantLitDiffuse(GetDistantDirection(), |
| 130 | GetWhite(), |
| 131 | GetSurfaceScale(), |
| 132 | GetKd(), |
| 133 | nullptr)); |
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: |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 142 | LightingSpotLitDiffuseBench(bool small) : INHERITED(small) { } |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 143 | |
| 144 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 145 | const char* onGetName() override { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 146 | return fIsSmall ? "lightingspotlitdiffuse_small" : "lightingspotlitdiffuse_large"; |
| 147 | } |
| 148 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 149 | void onDraw(int loops, SkCanvas* canvas) override { |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 150 | draw(loops, canvas, SkLightingImageFilter::MakeSpotLitDiffuse(GetSpotLocation(), |
| 151 | GetSpotTarget(), |
| 152 | GetSpotExponent(), |
| 153 | GetCutoffAngle(), |
| 154 | GetWhite(), |
| 155 | GetSurfaceScale(), |
| 156 | GetKd(), |
| 157 | nullptr)); |
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: |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 166 | LightingPointLitSpecularBench(bool small) : INHERITED(small) { } |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 167 | |
| 168 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 169 | const char* onGetName() override { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 170 | return fIsSmall ? "lightingpointlitspecular_small" : "lightingpointlitspecular_large"; |
| 171 | } |
| 172 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 173 | void onDraw(int loops, SkCanvas* canvas) override { |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 174 | draw(loops, canvas, SkLightingImageFilter::MakePointLitSpecular(GetPointLocation(), |
| 175 | GetWhite(), |
| 176 | GetSurfaceScale(), |
| 177 | GetKs(), |
| 178 | GetShininess(), |
| 179 | nullptr)); |
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: |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 188 | LightingDistantLitSpecularBench(bool small) : INHERITED(small) { } |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 189 | |
| 190 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 191 | const char* onGetName() override { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 192 | return fIsSmall ? "lightingdistantlitspecular_small" : "lightingdistantlitspecular_large"; |
| 193 | } |
| 194 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 195 | void onDraw(int loops, SkCanvas* canvas) override { |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 196 | draw(loops, canvas, SkLightingImageFilter::MakeDistantLitSpecular(GetDistantDirection(), |
| 197 | GetWhite(), |
| 198 | GetSurfaceScale(), |
| 199 | GetKs(), |
| 200 | GetShininess(), |
| 201 | nullptr)); |
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: |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 210 | LightingSpotLitSpecularBench(bool small) : INHERITED(small) { } |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 211 | |
| 212 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 213 | const char* onGetName() override { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 214 | return fIsSmall ? "lightingspotlitspecular_small" : "lightingspotlitspecular_large"; |
| 215 | } |
| 216 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 217 | void onDraw(int loops, SkCanvas* canvas) override { |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 218 | draw(loops, canvas, SkLightingImageFilter::MakeSpotLitSpecular(GetSpotLocation(), |
| 219 | GetSpotTarget(), |
| 220 | GetSpotExponent(), |
| 221 | GetCutoffAngle(), |
| 222 | GetWhite(), |
| 223 | GetSurfaceScale(), |
| 224 | GetKs(), |
| 225 | GetShininess(), |
| 226 | nullptr)); |
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); ) |