2013-04-24 19:36:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPoint3.h"
|
|
|
|
#include "include/effects/SkLightingImageFilter.h"
|
2013-04-24 19:36:44 +00:00
|
|
|
|
|
|
|
#define FILTER_WIDTH_SMALL SkIntToScalar(32)
|
|
|
|
#define FILTER_HEIGHT_SMALL SkIntToScalar(32)
|
|
|
|
#define FILTER_WIDTH_LARGE SkIntToScalar(256)
|
|
|
|
#define FILTER_HEIGHT_LARGE SkIntToScalar(256)
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class LightingBaseBench : public Benchmark {
|
2013-04-24 19:36:44 +00:00
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
LightingBaseBench(bool small) : fIsSmall(small) { }
|
2013-04-24 19:36:44 +00:00
|
|
|
|
|
|
|
protected:
|
2016-04-08 23:28:09 +00:00
|
|
|
void draw(int loops, SkCanvas* canvas, sk_sp<SkImageFilter> imageFilter) const {
|
2013-04-24 19:36:44 +00:00
|
|
|
SkRect r = fIsSmall ? SkRect::MakeWH(FILTER_WIDTH_SMALL, FILTER_HEIGHT_SMALL) :
|
|
|
|
SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_LARGE);
|
|
|
|
SkPaint paint;
|
2016-04-08 23:28:09 +00:00
|
|
|
paint.setImageFilter(std::move(imageFilter));
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2013-09-10 19:23:38 +00:00
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
}
|
2013-04-24 19:36:44 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 20:16:44 +00:00
|
|
|
static SkPoint3 GetPointLocation() {
|
|
|
|
static SkPoint3 pointLocation = SkPoint3::Make(0, 0, SkIntToScalar(10));
|
2013-04-24 19:36:44 +00:00
|
|
|
return pointLocation;
|
|
|
|
}
|
|
|
|
|
2015-07-13 20:16:44 +00:00
|
|
|
static SkPoint3 GetDistantDirection() {
|
2013-04-24 19:36:44 +00:00
|
|
|
static SkScalar azimuthRad = SkDegreesToRadians(SkIntToScalar(225));
|
|
|
|
static SkScalar elevationRad = SkDegreesToRadians(SkIntToScalar(5));
|
2017-02-14 15:59:19 +00:00
|
|
|
static SkPoint3 distantDirection = SkPoint3::Make(
|
|
|
|
SkScalarCos(azimuthRad) * SkScalarCos(elevationRad),
|
|
|
|
SkScalarSin(azimuthRad) * SkScalarCos(elevationRad),
|
|
|
|
SkScalarSin(elevationRad));
|
2013-04-24 19:36:44 +00:00
|
|
|
return distantDirection;
|
|
|
|
}
|
|
|
|
|
2015-07-13 20:16:44 +00:00
|
|
|
static SkPoint3 GetSpotLocation() {
|
|
|
|
static SkPoint3 spotLocation = SkPoint3::Make(SkIntToScalar(-10),
|
|
|
|
SkIntToScalar(-10),
|
|
|
|
SkIntToScalar(20));
|
2013-04-24 19:36:44 +00:00
|
|
|
return spotLocation;
|
|
|
|
}
|
|
|
|
|
2015-07-13 20:16:44 +00:00
|
|
|
static SkPoint3 GetSpotTarget() {
|
|
|
|
static SkPoint3 spotTarget = SkPoint3::Make(SkIntToScalar(40), SkIntToScalar(40), 0);
|
2013-04-24 19:36:44 +00:00
|
|
|
return spotTarget;
|
|
|
|
}
|
|
|
|
|
2015-07-13 20:16:44 +00:00
|
|
|
static SkScalar GetSpotExponent() {
|
2013-04-24 19:36:44 +00:00
|
|
|
static SkScalar spotExponent = SK_Scalar1;
|
|
|
|
return spotExponent;
|
|
|
|
}
|
|
|
|
|
2015-07-13 20:16:44 +00:00
|
|
|
static SkScalar GetCutoffAngle() {
|
2013-04-24 19:36:44 +00:00
|
|
|
static SkScalar cutoffAngle = SkIntToScalar(15);
|
|
|
|
return cutoffAngle;
|
|
|
|
}
|
|
|
|
|
2015-07-13 20:16:44 +00:00
|
|
|
static SkScalar GetKd() {
|
2013-04-24 19:36:44 +00:00
|
|
|
static SkScalar kd = SkIntToScalar(2);
|
|
|
|
return kd;
|
|
|
|
}
|
|
|
|
|
2015-07-13 20:16:44 +00:00
|
|
|
static SkScalar GetKs() {
|
2013-04-24 19:36:44 +00:00
|
|
|
static SkScalar ks = SkIntToScalar(1);
|
|
|
|
return ks;
|
|
|
|
}
|
|
|
|
|
2015-07-13 20:16:44 +00:00
|
|
|
static SkScalar GetShininess() {
|
2013-04-24 19:36:44 +00:00
|
|
|
static SkScalar shininess = SkIntToScalar(8);
|
|
|
|
return shininess;
|
|
|
|
}
|
|
|
|
|
2015-07-13 20:16:44 +00:00
|
|
|
static SkScalar GetSurfaceScale() {
|
2013-04-24 19:36:44 +00:00
|
|
|
static SkScalar surfaceScale = SkIntToScalar(1);
|
|
|
|
return surfaceScale;
|
|
|
|
}
|
|
|
|
|
2015-07-13 20:16:44 +00:00
|
|
|
static SkColor GetWhite() {
|
2013-04-24 19:36:44 +00:00
|
|
|
static SkColor white(0xFFFFFFFF);
|
|
|
|
return white;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool fIsSmall;
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-04-24 19:36:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class LightingPointLitDiffuseBench : public LightingBaseBench {
|
|
|
|
public:
|
2016-04-08 23:28:09 +00:00
|
|
|
LightingPointLitDiffuseBench(bool small) : INHERITED(small) { }
|
2013-04-24 19:36:44 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2013-04-24 19:36:44 +00:00
|
|
|
return fIsSmall ? "lightingpointlitdiffuse_small" : "lightingpointlitdiffuse_large";
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2016-04-08 23:28:09 +00:00
|
|
|
draw(loops, canvas, SkLightingImageFilter::MakePointLitDiffuse(GetPointLocation(),
|
|
|
|
GetWhite(),
|
|
|
|
GetSurfaceScale(),
|
|
|
|
GetKd(),
|
|
|
|
nullptr));
|
2013-04-24 19:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef LightingBaseBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LightingDistantLitDiffuseBench : public LightingBaseBench {
|
|
|
|
public:
|
2016-04-08 23:28:09 +00:00
|
|
|
LightingDistantLitDiffuseBench(bool small) : INHERITED(small) { }
|
2013-04-24 19:36:44 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2013-04-24 19:36:44 +00:00
|
|
|
return fIsSmall ? "lightingdistantlitdiffuse_small" : "lightingdistantlitdiffuse_large";
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2016-04-08 23:28:09 +00:00
|
|
|
draw(loops, canvas, SkLightingImageFilter::MakeDistantLitDiffuse(GetDistantDirection(),
|
|
|
|
GetWhite(),
|
|
|
|
GetSurfaceScale(),
|
|
|
|
GetKd(),
|
|
|
|
nullptr));
|
2013-04-24 19:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef LightingBaseBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LightingSpotLitDiffuseBench : public LightingBaseBench {
|
|
|
|
public:
|
2016-04-08 23:28:09 +00:00
|
|
|
LightingSpotLitDiffuseBench(bool small) : INHERITED(small) { }
|
2013-04-24 19:36:44 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2013-04-24 19:36:44 +00:00
|
|
|
return fIsSmall ? "lightingspotlitdiffuse_small" : "lightingspotlitdiffuse_large";
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2016-04-08 23:28:09 +00:00
|
|
|
draw(loops, canvas, SkLightingImageFilter::MakeSpotLitDiffuse(GetSpotLocation(),
|
|
|
|
GetSpotTarget(),
|
|
|
|
GetSpotExponent(),
|
|
|
|
GetCutoffAngle(),
|
|
|
|
GetWhite(),
|
|
|
|
GetSurfaceScale(),
|
|
|
|
GetKd(),
|
|
|
|
nullptr));
|
2013-04-24 19:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef LightingBaseBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LightingPointLitSpecularBench : public LightingBaseBench {
|
|
|
|
public:
|
2016-04-08 23:28:09 +00:00
|
|
|
LightingPointLitSpecularBench(bool small) : INHERITED(small) { }
|
2013-04-24 19:36:44 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2013-04-24 19:36:44 +00:00
|
|
|
return fIsSmall ? "lightingpointlitspecular_small" : "lightingpointlitspecular_large";
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2016-04-08 23:28:09 +00:00
|
|
|
draw(loops, canvas, SkLightingImageFilter::MakePointLitSpecular(GetPointLocation(),
|
|
|
|
GetWhite(),
|
|
|
|
GetSurfaceScale(),
|
|
|
|
GetKs(),
|
|
|
|
GetShininess(),
|
|
|
|
nullptr));
|
2013-04-24 19:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef LightingBaseBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LightingDistantLitSpecularBench : public LightingBaseBench {
|
|
|
|
public:
|
2016-04-08 23:28:09 +00:00
|
|
|
LightingDistantLitSpecularBench(bool small) : INHERITED(small) { }
|
2013-04-24 19:36:44 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2013-04-24 19:36:44 +00:00
|
|
|
return fIsSmall ? "lightingdistantlitspecular_small" : "lightingdistantlitspecular_large";
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2016-04-08 23:28:09 +00:00
|
|
|
draw(loops, canvas, SkLightingImageFilter::MakeDistantLitSpecular(GetDistantDirection(),
|
|
|
|
GetWhite(),
|
|
|
|
GetSurfaceScale(),
|
|
|
|
GetKs(),
|
|
|
|
GetShininess(),
|
|
|
|
nullptr));
|
2013-04-24 19:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef LightingBaseBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LightingSpotLitSpecularBench : public LightingBaseBench {
|
|
|
|
public:
|
2016-04-08 23:28:09 +00:00
|
|
|
LightingSpotLitSpecularBench(bool small) : INHERITED(small) { }
|
2013-04-24 19:36:44 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2013-04-24 19:36:44 +00:00
|
|
|
return fIsSmall ? "lightingspotlitspecular_small" : "lightingspotlitspecular_large";
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2016-04-08 23:28:09 +00:00
|
|
|
draw(loops, canvas, SkLightingImageFilter::MakeSpotLitSpecular(GetSpotLocation(),
|
|
|
|
GetSpotTarget(),
|
|
|
|
GetSpotExponent(),
|
|
|
|
GetCutoffAngle(),
|
|
|
|
GetWhite(),
|
|
|
|
GetSurfaceScale(),
|
|
|
|
GetKs(),
|
|
|
|
GetShininess(),
|
|
|
|
nullptr));
|
2013-04-24 19:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef LightingBaseBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new LightingPointLitDiffuseBench(true); )
|
|
|
|
DEF_BENCH( return new LightingPointLitDiffuseBench(false); )
|
|
|
|
DEF_BENCH( return new LightingDistantLitDiffuseBench(true); )
|
|
|
|
DEF_BENCH( return new LightingDistantLitDiffuseBench(false); )
|
|
|
|
DEF_BENCH( return new LightingSpotLitDiffuseBench(true); )
|
|
|
|
DEF_BENCH( return new LightingSpotLitDiffuseBench(false); )
|
|
|
|
DEF_BENCH( return new LightingPointLitSpecularBench(true); )
|
|
|
|
DEF_BENCH( return new LightingPointLitSpecularBench(false); )
|
|
|
|
DEF_BENCH( return new LightingDistantLitSpecularBench(true); )
|
|
|
|
DEF_BENCH( return new LightingDistantLitSpecularBench(false); )
|
|
|
|
DEF_BENCH( return new LightingSpotLitSpecularBench(true); )
|
|
|
|
DEF_BENCH( return new LightingSpotLitSpecularBench(false); )
|