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"
|
2019-08-05 15:25:23 +00:00
|
|
|
#include "include/effects/SkImageFilters.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;
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Benchmark;
|
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 {
|
2019-08-05 15:25:23 +00:00
|
|
|
draw(loops, canvas, SkImageFilters::PointLitDiffuse(
|
|
|
|
GetPointLocation(), GetWhite(), GetSurfaceScale(), GetKd(), nullptr));
|
2013-04-24 19:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = LightingBaseBench;
|
2013-04-24 19:36:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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 {
|
2019-08-05 15:25:23 +00:00
|
|
|
draw(loops, canvas, SkImageFilters::DistantLitDiffuse(
|
|
|
|
GetDistantDirection(), GetWhite(), GetSurfaceScale(), GetKd(), nullptr));
|
2013-04-24 19:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = LightingBaseBench;
|
2013-04-24 19:36:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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 {
|
2019-08-05 15:25:23 +00:00
|
|
|
draw(loops, canvas, SkImageFilters::SpotLitDiffuse(
|
|
|
|
GetSpotLocation(), GetSpotTarget(), GetSpotExponent(), GetCutoffAngle(),
|
|
|
|
GetWhite(), GetSurfaceScale(), GetKd(), nullptr));
|
2013-04-24 19:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = LightingBaseBench;
|
2013-04-24 19:36:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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 {
|
2019-08-05 15:25:23 +00:00
|
|
|
draw(loops, canvas, SkImageFilters::PointLitSpecular(
|
|
|
|
GetPointLocation(), GetWhite(), GetSurfaceScale(), GetKs(), GetShininess(),
|
|
|
|
nullptr));
|
2013-04-24 19:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = LightingBaseBench;
|
2013-04-24 19:36:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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 {
|
2019-08-05 15:25:23 +00:00
|
|
|
draw(loops, canvas, SkImageFilters::DistantLitSpecular(
|
|
|
|
GetDistantDirection(), GetWhite(), GetSurfaceScale(), GetKs(), GetShininess(),
|
|
|
|
nullptr));
|
2013-04-24 19:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = LightingBaseBench;
|
2013-04-24 19:36:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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 {
|
2019-08-05 15:25:23 +00:00
|
|
|
draw(loops, canvas, SkImageFilters::SpotLitSpecular(
|
|
|
|
GetSpotLocation(), GetSpotTarget(), GetSpotExponent(), GetCutoffAngle(),
|
|
|
|
GetWhite(), GetSurfaceScale(), GetKs(), GetShininess(), nullptr));
|
2013-04-24 19:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = LightingBaseBench;
|
2013-04-24 19:36:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
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); )
|