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