OLD | NEW |
(Empty) | |
| 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 */ |
| 7 #include "SkBenchmark.h" |
| 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 |
| 18 class LightingBaseBench : public SkBenchmark { |
| 19 public: |
| 20 LightingBaseBench(void* param, bool small) : INHERITED(param), fIsSmall(smal
l) { |
| 21 } |
| 22 |
| 23 protected: |
| 24 void draw(SkCanvas* canvas, SkImageFilter* imageFilter) const { |
| 25 SkRect r = fIsSmall ? SkRect::MakeWH(FILTER_WIDTH_SMALL, FILTER_HEIGHT_S
MALL) : |
| 26 SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_L
ARGE); |
| 27 SkPaint paint; |
| 28 paint.setImageFilter(imageFilter)->unref(); |
| 29 canvas->drawRect(r, paint); |
| 30 } |
| 31 |
| 32 static SkPoint3 getPointLocation() { |
| 33 static SkPoint3 pointLocation(0, 0, SkIntToScalar(10)); |
| 34 return pointLocation; |
| 35 } |
| 36 |
| 37 static SkPoint3 getDistantDirection() { |
| 38 static SkScalar azimuthRad = SkDegreesToRadians(SkIntToScalar(225)); |
| 39 static SkScalar elevationRad = SkDegreesToRadians(SkIntToScalar(5)); |
| 40 static SkPoint3 distantDirection(SkScalarMul(SkScalarCos(azimuthRad), |
| 41 SkScalarCos(elevationRad)), |
| 42 SkScalarMul(SkScalarSin(azimuthRad), |
| 43 SkScalarCos(elevationRad)), |
| 44 SkScalarSin(elevationRad)); |
| 45 return distantDirection; |
| 46 } |
| 47 |
| 48 static SkPoint3 getSpotLocation() { |
| 49 static SkPoint3 spotLocation(SkIntToScalar(-10), SkIntToScalar(-10), SkI
ntToScalar(20)); |
| 50 return spotLocation; |
| 51 } |
| 52 |
| 53 static SkPoint3 getSpotTarget() { |
| 54 static SkPoint3 spotTarget(SkIntToScalar(40), SkIntToScalar(40), 0); |
| 55 return spotTarget; |
| 56 } |
| 57 |
| 58 static SkScalar getSpotExponent() { |
| 59 static SkScalar spotExponent = SK_Scalar1; |
| 60 return spotExponent; |
| 61 } |
| 62 |
| 63 static SkScalar getCutoffAngle() { |
| 64 static SkScalar cutoffAngle = SkIntToScalar(15); |
| 65 return cutoffAngle; |
| 66 } |
| 67 |
| 68 static SkScalar getKd() { |
| 69 static SkScalar kd = SkIntToScalar(2); |
| 70 return kd; |
| 71 } |
| 72 |
| 73 static SkScalar getKs() { |
| 74 static SkScalar ks = SkIntToScalar(1); |
| 75 return ks; |
| 76 } |
| 77 |
| 78 static SkScalar getShininess() { |
| 79 static SkScalar shininess = SkIntToScalar(8); |
| 80 return shininess; |
| 81 } |
| 82 |
| 83 static SkScalar getSurfaceScale() { |
| 84 static SkScalar surfaceScale = SkIntToScalar(1); |
| 85 return surfaceScale; |
| 86 } |
| 87 |
| 88 static SkColor getWhite() { |
| 89 static SkColor white(0xFFFFFFFF); |
| 90 return white; |
| 91 } |
| 92 |
| 93 bool fIsSmall; |
| 94 typedef SkBenchmark INHERITED; |
| 95 }; |
| 96 |
| 97 class LightingPointLitDiffuseBench : public LightingBaseBench { |
| 98 public: |
| 99 LightingPointLitDiffuseBench(void* param, bool small) : INHERITED(param, sma
ll) { |
| 100 } |
| 101 |
| 102 protected: |
| 103 virtual const char* onGetName() SK_OVERRIDE { |
| 104 return fIsSmall ? "lightingpointlitdiffuse_small" : "lightingpointlitdif
fuse_large"; |
| 105 } |
| 106 |
| 107 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 108 draw(canvas, SkLightingImageFilter::CreatePointLitDiffuse(getPointLocati
on(), getWhite(), |
| 109 getSurfaceScale(), getKd())); |
| 110 } |
| 111 |
| 112 private: |
| 113 typedef LightingBaseBench INHERITED; |
| 114 }; |
| 115 |
| 116 class LightingDistantLitDiffuseBench : public LightingBaseBench { |
| 117 public: |
| 118 LightingDistantLitDiffuseBench(void* param, bool small) : INHERITED(param, s
mall) { |
| 119 } |
| 120 |
| 121 protected: |
| 122 virtual const char* onGetName() SK_OVERRIDE { |
| 123 return fIsSmall ? "lightingdistantlitdiffuse_small" : "lightingdistantli
tdiffuse_large"; |
| 124 } |
| 125 |
| 126 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 127 draw(canvas, SkLightingImageFilter::CreateDistantLitDiffuse(getDistantDi
rection(), |
| 128 getWhite(), getSurfaceScale(), getKd())); |
| 129 } |
| 130 |
| 131 private: |
| 132 typedef LightingBaseBench INHERITED; |
| 133 }; |
| 134 |
| 135 class LightingSpotLitDiffuseBench : public LightingBaseBench { |
| 136 public: |
| 137 LightingSpotLitDiffuseBench(void* param, bool small) : INHERITED(param, smal
l) { |
| 138 } |
| 139 |
| 140 protected: |
| 141 virtual const char* onGetName() SK_OVERRIDE { |
| 142 return fIsSmall ? "lightingspotlitdiffuse_small" : "lightingspotlitdiffu
se_large"; |
| 143 } |
| 144 |
| 145 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 146 draw(canvas, SkLightingImageFilter::CreateSpotLitDiffuse(getSpotLocation
(), |
| 147 getSpotTarget(), getSpotExponent(), getCutoffAngle(), getWhite(), ge
tSurfaceScale(), |
| 148 getKd())); |
| 149 } |
| 150 |
| 151 private: |
| 152 typedef LightingBaseBench INHERITED; |
| 153 }; |
| 154 |
| 155 class LightingPointLitSpecularBench : public LightingBaseBench { |
| 156 public: |
| 157 LightingPointLitSpecularBench(void* param, bool small) : INHERITED(param, sm
all) { |
| 158 } |
| 159 |
| 160 protected: |
| 161 virtual const char* onGetName() SK_OVERRIDE { |
| 162 return fIsSmall ? "lightingpointlitspecular_small" : "lightingpointlitsp
ecular_large"; |
| 163 } |
| 164 |
| 165 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 166 draw(canvas, SkLightingImageFilter::CreatePointLitSpecular(getPointLocat
ion(), getWhite(), |
| 167 getSurfaceScale(), getKs(), getShininess())); |
| 168 } |
| 169 |
| 170 private: |
| 171 typedef LightingBaseBench INHERITED; |
| 172 }; |
| 173 |
| 174 class LightingDistantLitSpecularBench : public LightingBaseBench { |
| 175 public: |
| 176 LightingDistantLitSpecularBench(void* param, bool small) : INHERITED(param,
small) { |
| 177 } |
| 178 |
| 179 protected: |
| 180 virtual const char* onGetName() SK_OVERRIDE { |
| 181 return fIsSmall ? "lightingdistantlitspecular_small" : "lightingdistantl
itspecular_large"; |
| 182 } |
| 183 |
| 184 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 185 draw(canvas, SkLightingImageFilter::CreateDistantLitSpecular(getDistantD
irection(), |
| 186 getWhite(), getSurfaceScale(), getKs(), getShininess())); |
| 187 } |
| 188 |
| 189 private: |
| 190 typedef LightingBaseBench INHERITED; |
| 191 }; |
| 192 |
| 193 class LightingSpotLitSpecularBench : public LightingBaseBench { |
| 194 public: |
| 195 LightingSpotLitSpecularBench(void* param, bool small) : INHERITED(param, sma
ll) { |
| 196 } |
| 197 |
| 198 protected: |
| 199 virtual const char* onGetName() SK_OVERRIDE { |
| 200 return fIsSmall ? "lightingspotlitspecular_small" : "lightingspotlitspec
ular_large"; |
| 201 } |
| 202 |
| 203 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 204 draw(canvas, SkLightingImageFilter::CreateSpotLitSpecular(getSpotLocatio
n(), |
| 205 getSpotTarget(), getSpotExponent(), getCutoffAngle(), getWhite(), ge
tSurfaceScale(), |
| 206 getKs(), getShininess())); |
| 207 } |
| 208 |
| 209 private: |
| 210 typedef LightingBaseBench INHERITED; |
| 211 }; |
| 212 |
| 213 /////////////////////////////////////////////////////////////////////////////// |
| 214 |
| 215 DEF_BENCH( return new LightingPointLitDiffuseBench(p, true); ) |
| 216 DEF_BENCH( return new LightingPointLitDiffuseBench(p, false); ) |
| 217 DEF_BENCH( return new LightingDistantLitDiffuseBench(p, true); ) |
| 218 DEF_BENCH( return new LightingDistantLitDiffuseBench(p, false); ) |
| 219 DEF_BENCH( return new LightingSpotLitDiffuseBench(p, true); ) |
| 220 DEF_BENCH( return new LightingSpotLitDiffuseBench(p, false); ) |
| 221 DEF_BENCH( return new LightingPointLitSpecularBench(p, true); ) |
| 222 DEF_BENCH( return new LightingPointLitSpecularBench(p, false); ) |
| 223 DEF_BENCH( return new LightingDistantLitSpecularBench(p, true); ) |
| 224 DEF_BENCH( return new LightingDistantLitSpecularBench(p, false); ) |
| 225 DEF_BENCH( return new LightingSpotLitSpecularBench(p, true); ) |
| 226 DEF_BENCH( return new LightingSpotLitSpecularBench(p, false); ) |
| 227 |
OLD | NEW |