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 | */ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 7 | #include "bench/Benchmark.h" |
| 8 | #include "include/core/SkCanvas.h" |
| 9 | #include "include/core/SkPoint3.h" |
Michael Ludwig | 2300318 | 2019-08-05 11:25:23 -0400 | [diff] [blame] | 10 | #include "include/effects/SkImageFilters.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; |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 95 | using INHERITED = Benchmark; |
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 { |
Michael Ludwig | 2300318 | 2019-08-05 11:25:23 -0400 | [diff] [blame] | 108 | draw(loops, canvas, SkImageFilters::PointLitDiffuse( |
| 109 | GetPointLocation(), GetWhite(), GetSurfaceScale(), GetKd(), nullptr)); |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 113 | using INHERITED = LightingBaseBench; |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | class LightingDistantLitDiffuseBench : public LightingBaseBench { |
| 117 | public: |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 118 | LightingDistantLitDiffuseBench(bool small) : INHERITED(small) { } |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 119 | |
| 120 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 121 | const char* onGetName() override { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 122 | return fIsSmall ? "lightingdistantlitdiffuse_small" : "lightingdistantlitdiffuse_large"; |
| 123 | } |
| 124 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 125 | void onDraw(int loops, SkCanvas* canvas) override { |
Michael Ludwig | 2300318 | 2019-08-05 11:25:23 -0400 | [diff] [blame] | 126 | draw(loops, canvas, SkImageFilters::DistantLitDiffuse( |
| 127 | GetDistantDirection(), GetWhite(), GetSurfaceScale(), GetKd(), nullptr)); |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 131 | using INHERITED = LightingBaseBench; |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | class LightingSpotLitDiffuseBench : public LightingBaseBench { |
| 135 | public: |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 136 | LightingSpotLitDiffuseBench(bool small) : INHERITED(small) { } |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 137 | |
| 138 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 139 | const char* onGetName() override { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 140 | return fIsSmall ? "lightingspotlitdiffuse_small" : "lightingspotlitdiffuse_large"; |
| 141 | } |
| 142 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 143 | void onDraw(int loops, SkCanvas* canvas) override { |
Michael Ludwig | 2300318 | 2019-08-05 11:25:23 -0400 | [diff] [blame] | 144 | draw(loops, canvas, SkImageFilters::SpotLitDiffuse( |
| 145 | GetSpotLocation(), GetSpotTarget(), GetSpotExponent(), GetCutoffAngle(), |
| 146 | GetWhite(), GetSurfaceScale(), GetKd(), nullptr)); |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 150 | using INHERITED = LightingBaseBench; |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | class LightingPointLitSpecularBench : public LightingBaseBench { |
| 154 | public: |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 155 | LightingPointLitSpecularBench(bool small) : INHERITED(small) { } |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 156 | |
| 157 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 158 | const char* onGetName() override { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 159 | return fIsSmall ? "lightingpointlitspecular_small" : "lightingpointlitspecular_large"; |
| 160 | } |
| 161 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 162 | void onDraw(int loops, SkCanvas* canvas) override { |
Michael Ludwig | 2300318 | 2019-08-05 11:25:23 -0400 | [diff] [blame] | 163 | draw(loops, canvas, SkImageFilters::PointLitSpecular( |
| 164 | GetPointLocation(), GetWhite(), GetSurfaceScale(), GetKs(), GetShininess(), |
| 165 | nullptr)); |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 169 | using INHERITED = LightingBaseBench; |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | class LightingDistantLitSpecularBench : public LightingBaseBench { |
| 173 | public: |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 174 | LightingDistantLitSpecularBench(bool small) : INHERITED(small) { } |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 175 | |
| 176 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 177 | const char* onGetName() override { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 178 | return fIsSmall ? "lightingdistantlitspecular_small" : "lightingdistantlitspecular_large"; |
| 179 | } |
| 180 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 181 | void onDraw(int loops, SkCanvas* canvas) override { |
Michael Ludwig | 2300318 | 2019-08-05 11:25:23 -0400 | [diff] [blame] | 182 | draw(loops, canvas, SkImageFilters::DistantLitSpecular( |
| 183 | GetDistantDirection(), GetWhite(), GetSurfaceScale(), GetKs(), GetShininess(), |
| 184 | nullptr)); |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 188 | using INHERITED = LightingBaseBench; |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 189 | }; |
| 190 | |
| 191 | class LightingSpotLitSpecularBench : public LightingBaseBench { |
| 192 | public: |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 193 | LightingSpotLitSpecularBench(bool small) : INHERITED(small) { } |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 194 | |
| 195 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 196 | const char* onGetName() override { |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 197 | return fIsSmall ? "lightingspotlitspecular_small" : "lightingspotlitspecular_large"; |
| 198 | } |
| 199 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 200 | void onDraw(int loops, SkCanvas* canvas) override { |
Michael Ludwig | 2300318 | 2019-08-05 11:25:23 -0400 | [diff] [blame] | 201 | draw(loops, canvas, SkImageFilters::SpotLitSpecular( |
| 202 | GetSpotLocation(), GetSpotTarget(), GetSpotExponent(), GetCutoffAngle(), |
| 203 | GetWhite(), GetSurfaceScale(), GetKs(), GetShininess(), nullptr)); |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 207 | using INHERITED = LightingBaseBench; |
sugoi@google.com | 5d71adf | 2013-04-24 19:36:44 +0000 | [diff] [blame] | 208 | }; |
| 209 | |
| 210 | /////////////////////////////////////////////////////////////////////////////// |
| 211 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 212 | DEF_BENCH( return new LightingPointLitDiffuseBench(true); ) |
| 213 | DEF_BENCH( return new LightingPointLitDiffuseBench(false); ) |
| 214 | DEF_BENCH( return new LightingDistantLitDiffuseBench(true); ) |
| 215 | DEF_BENCH( return new LightingDistantLitDiffuseBench(false); ) |
| 216 | DEF_BENCH( return new LightingSpotLitDiffuseBench(true); ) |
| 217 | DEF_BENCH( return new LightingSpotLitDiffuseBench(false); ) |
| 218 | DEF_BENCH( return new LightingPointLitSpecularBench(true); ) |
| 219 | DEF_BENCH( return new LightingPointLitSpecularBench(false); ) |
| 220 | DEF_BENCH( return new LightingDistantLitSpecularBench(true); ) |
| 221 | DEF_BENCH( return new LightingDistantLitSpecularBench(false); ) |
| 222 | DEF_BENCH( return new LightingSpotLitSpecularBench(true); ) |
| 223 | DEF_BENCH( return new LightingSpotLitSpecularBench(false); ) |