Flutter Engine
The Flutter Engine
LightingBench.cpp
Go to the documentation of this file.
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 "bench/Benchmark.h"
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
18public:
19 LightingBaseBench(bool small) : fIsSmall(small) { }
20
21protected:
22 void draw(int loops, SkCanvas* canvas, sk_sp<SkImageFilter> imageFilter) const {
26 paint.setImageFilter(std::move(imageFilter));
27 for (int i = 0; i < loops; i++) {
28 canvas->drawRect(r, paint);
29 }
30 }
31
33 static SkPoint3 pointLocation = SkPoint3::Make(0, 0, SkIntToScalar(10));
34 return pointLocation;
35 }
36
38 static SkScalar azimuthRad = SkDegreesToRadians(SkIntToScalar(225));
39 static SkScalar elevationRad = SkDegreesToRadians(SkIntToScalar(5));
40 static SkPoint3 distantDirection = SkPoint3::Make(
41 SkScalarCos(azimuthRad) * SkScalarCos(elevationRad),
42 SkScalarSin(azimuthRad) * SkScalarCos(elevationRad),
43 SkScalarSin(elevationRad));
44 return distantDirection;
45 }
46
48 static SkPoint3 spotLocation = SkPoint3::Make(SkIntToScalar(-10),
49 SkIntToScalar(-10),
50 SkIntToScalar(20));
51 return spotLocation;
52 }
53
55 static SkPoint3 spotTarget = SkPoint3::Make(SkIntToScalar(40), SkIntToScalar(40), 0);
56 return spotTarget;
57 }
58
60 static SkScalar spotExponent = SK_Scalar1;
61 return spotExponent;
62 }
63
65 static SkScalar cutoffAngle = SkIntToScalar(15);
66 return cutoffAngle;
67 }
68
69 static SkScalar GetKd() {
70 static SkScalar kd = SkIntToScalar(2);
71 return kd;
72 }
73
74 static SkScalar GetKs() {
75 static SkScalar ks = SkIntToScalar(1);
76 return ks;
77 }
78
80 static SkScalar shininess = SkIntToScalar(8);
81 return shininess;
82 }
83
85 static SkScalar surfaceScale = SkIntToScalar(1);
86 return surfaceScale;
87 }
88
89 static SkColor GetWhite() {
90 static SkColor white(0xFFFFFFFF);
91 return white;
92 }
93
96};
97
99public:
101
102protected:
103 const char* onGetName() override {
104 return fIsSmall ? "lightingpointlitdiffuse_small" : "lightingpointlitdiffuse_large";
105 }
106
107 void onDraw(int loops, SkCanvas* canvas) override {
109 GetPointLocation(), GetWhite(), GetSurfaceScale(), GetKd(), nullptr));
110 }
111
112private:
113 using INHERITED = LightingBaseBench;
114};
115
117public:
119
120protected:
121 const char* onGetName() override {
122 return fIsSmall ? "lightingdistantlitdiffuse_small" : "lightingdistantlitdiffuse_large";
123 }
124
125 void onDraw(int loops, SkCanvas* canvas) override {
128 }
129
130private:
131 using INHERITED = LightingBaseBench;
132};
133
135public:
136 LightingSpotLitDiffuseBench(bool small) : INHERITED(small) { }
137
138protected:
139 const char* onGetName() override {
140 return fIsSmall ? "lightingspotlitdiffuse_small" : "lightingspotlitdiffuse_large";
141 }
142
143 void onDraw(int loops, SkCanvas* canvas) override {
146 GetWhite(), GetSurfaceScale(), GetKd(), nullptr));
147 }
148
149private:
150 using INHERITED = LightingBaseBench;
151};
152
154public:
156
157protected:
158 const char* onGetName() override {
159 return fIsSmall ? "lightingpointlitspecular_small" : "lightingpointlitspecular_large";
160 }
161
162 void onDraw(int loops, SkCanvas* canvas) override {
165 nullptr));
166 }
167
168private:
169 using INHERITED = LightingBaseBench;
170};
171
173public:
175
176protected:
177 const char* onGetName() override {
178 return fIsSmall ? "lightingdistantlitspecular_small" : "lightingdistantlitspecular_large";
179 }
180
181 void onDraw(int loops, SkCanvas* canvas) override {
184 nullptr));
185 }
186
187private:
188 using INHERITED = LightingBaseBench;
189};
190
192public:
194
195protected:
196 const char* onGetName() override {
197 return fIsSmall ? "lightingspotlitspecular_small" : "lightingspotlitspecular_large";
198 }
199
200 void onDraw(int loops, SkCanvas* canvas) override {
203 GetWhite(), GetSurfaceScale(), GetKs(), GetShininess(), nullptr));
204 }
205
206private:
207 using INHERITED = LightingBaseBench;
208};
209
210///////////////////////////////////////////////////////////////////////////////
211
212DEF_BENCH( return new LightingPointLitDiffuseBench(true); )
213DEF_BENCH( return new LightingPointLitDiffuseBench(false); )
214DEF_BENCH( return new LightingDistantLitDiffuseBench(true); )
215DEF_BENCH( return new LightingDistantLitDiffuseBench(false); )
216DEF_BENCH( return new LightingSpotLitDiffuseBench(true); )
217DEF_BENCH( return new LightingSpotLitDiffuseBench(false); )
218DEF_BENCH( return new LightingPointLitSpecularBench(true); )
219DEF_BENCH( return new LightingPointLitSpecularBench(false); )
221DEF_BENCH( return new LightingDistantLitSpecularBench(false); )
222DEF_BENCH( return new LightingSpotLitSpecularBench(true); )
223DEF_BENCH( return new LightingSpotLitSpecularBench(false); )
#define DEF_BENCH(code)
Definition: Benchmark.h:20
#define FILTER_WIDTH_SMALL
#define FILTER_WIDTH_LARGE
#define FILTER_HEIGHT_SMALL
#define FILTER_HEIGHT_LARGE
uint32_t SkColor
Definition: SkColor.h:37
#define SkDegreesToRadians(degrees)
Definition: SkScalar.h:77
#define SkScalarSin(radians)
Definition: SkScalar.h:45
#define SK_Scalar1
Definition: SkScalar.h:18
#define SkIntToScalar(x)
Definition: SkScalar.h:57
#define SkScalarCos(radians)
Definition: SkScalar.h:46
static SkColor GetWhite()
static SkScalar GetShininess()
static SkScalar GetSurfaceScale()
static SkPoint3 GetSpotTarget()
static SkPoint3 GetSpotLocation()
void draw(int loops, SkCanvas *canvas, sk_sp< SkImageFilter > imageFilter) const
static SkScalar GetCutoffAngle()
static SkScalar GetKd()
LightingBaseBench(bool small)
static SkScalar GetSpotExponent()
static SkPoint3 GetDistantDirection()
static SkScalar GetKs()
static SkPoint3 GetPointLocation()
void onDraw(int loops, SkCanvas *canvas) override
const char * onGetName() override
const char * onGetName() override
void onDraw(int loops, SkCanvas *canvas) override
void onDraw(int loops, SkCanvas *canvas) override
const char * onGetName() override
void onDraw(int loops, SkCanvas *canvas) override
const char * onGetName() override
const char * onGetName() override
void onDraw(int loops, SkCanvas *canvas) override
const char * onGetName() override
void onDraw(int loops, SkCanvas *canvas) override
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
static sk_sp< SkImageFilter > PointLitDiffuse(const SkPoint3 &location, SkColor lightColor, SkScalar surfaceScale, SkScalar kd, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > DistantLitSpecular(const SkPoint3 &direction, SkColor lightColor, SkScalar surfaceScale, SkScalar ks, SkScalar shininess, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > DistantLitDiffuse(const SkPoint3 &direction, SkColor lightColor, SkScalar surfaceScale, SkScalar kd, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > PointLitSpecular(const SkPoint3 &location, SkColor lightColor, SkScalar surfaceScale, SkScalar ks, SkScalar shininess, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > SpotLitDiffuse(const SkPoint3 &location, const SkPoint3 &target, SkScalar falloffExponent, SkScalar cutoffAngle, SkColor lightColor, SkScalar surfaceScale, SkScalar kd, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > SpotLitSpecular(const SkPoint3 &location, const SkPoint3 &target, SkScalar falloffExponent, SkScalar cutoffAngle, SkColor lightColor, SkScalar surfaceScale, SkScalar ks, SkScalar shininess, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
static SkPoint3 Make(SkScalar x, SkScalar y, SkScalar z)
Definition: SkPoint3.h:18
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609