2018-08-06 21:03:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../src/jumper/SkJumper.h"
|
|
|
|
#include "Benchmark.h"
|
|
|
|
#include "SkColor.h"
|
2018-08-07 17:21:21 +00:00
|
|
|
#include "SkColorSpaceXformer.h"
|
2018-08-06 21:03:33 +00:00
|
|
|
#include "SkColorSpaceXformSteps.h"
|
|
|
|
#include "SkMakeUnique.h"
|
2018-09-28 14:51:13 +00:00
|
|
|
#include "SkPM4f.h"
|
2018-08-06 21:03:33 +00:00
|
|
|
#include "SkRandom.h"
|
|
|
|
|
2018-10-18 14:11:00 +00:00
|
|
|
enum class Mode { steps, xformer };
|
2018-08-06 21:03:33 +00:00
|
|
|
|
|
|
|
struct ColorSpaceXformBench : public Benchmark {
|
|
|
|
ColorSpaceXformBench(Mode mode) : fMode(mode) {}
|
|
|
|
|
|
|
|
const Mode fMode;
|
|
|
|
|
2018-10-18 14:11:00 +00:00
|
|
|
std::unique_ptr<SkColorSpaceXformSteps> fSteps;
|
|
|
|
std::unique_ptr<SkColorSpaceXformer> fXformer;
|
2018-08-07 17:21:21 +00:00
|
|
|
|
2018-08-06 21:03:33 +00:00
|
|
|
const char* onGetName() override {
|
|
|
|
switch (fMode) {
|
2018-08-07 17:21:21 +00:00
|
|
|
case Mode::steps : return "ColorSpaceXformBench_steps";
|
|
|
|
case Mode::xformer: return "ColorSpaceXformBench_xformer";
|
2018-08-06 21:03:33 +00:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSuitableFor(Backend backend) override { return kNonRendering_Backend == backend; }
|
|
|
|
|
|
|
|
void onDelayedSetup() override {
|
|
|
|
sk_sp<SkColorSpace> src = SkColorSpace::MakeSRGB(),
|
|
|
|
dst = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
|
|
|
|
SkColorSpace::kDCIP3_D65_Gamut);
|
|
|
|
|
2018-08-14 14:28:05 +00:00
|
|
|
fSteps = skstd::make_unique<SkColorSpaceXformSteps>(src.get(), kOpaque_SkAlphaType,
|
|
|
|
dst.get(), kPremul_SkAlphaType);
|
2018-08-07 17:21:21 +00:00
|
|
|
fXformer = SkColorSpaceXformer::Make(dst); // src is implicitly sRGB, what we want anyway
|
2018-08-06 21:03:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(int n, SkCanvas* canvas) override {
|
|
|
|
volatile SkColor junk = 0;
|
|
|
|
SkRandom rand;
|
|
|
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
SkColor src = rand.nextU(),
|
|
|
|
dst;
|
|
|
|
switch (fMode) {
|
|
|
|
case Mode::steps: {
|
|
|
|
float rgba[4];
|
|
|
|
swizzle_rb(Sk4f_fromL32(src)).store(rgba);
|
|
|
|
fSteps->apply(rgba);
|
|
|
|
dst = Sk4f_toL32(swizzle_rb(Sk4f::Load(rgba)));
|
|
|
|
} break;
|
|
|
|
|
2018-08-07 17:21:21 +00:00
|
|
|
case Mode::xformer: {
|
|
|
|
dst = fXformer->apply(src);
|
|
|
|
} break;
|
2018-08-06 21:03:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (false && i == 0) {
|
|
|
|
SkDebugf("%x ~~> %x\n", src, dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
junk ^= dst;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-07 17:21:21 +00:00
|
|
|
DEF_BENCH(return new ColorSpaceXformBench{Mode::steps };)
|
|
|
|
DEF_BENCH(return new ColorSpaceXformBench{Mode::xformer};)
|