skia2/bench/SwizzleBench.cpp
Mike Klein 6e78ae5525 Reland "have SkConvertPixels use SkColorSpaceXformSteps"
This is a reland of 6d0e566e94

On second thought, it's probably better to correct the
types of the swizzle functions to express their required alignment.
This is a more involved CL, but I think leaves things better off.

Original change's description:
> have SkConvertPixels use SkColorSpaceXformSteps
>
> This ought to allow the fast paths in more cases, e.g. memcpy() when
> both src and dst are the same format.  Today if we tag a dst color space
> at all, we'll think we need to fall back to the general case pipeline.
>
> Some refactoring too, but no big functional change beyond using steps.
>
> Change-Id: I8fa01025229e3b9418e7f43241a2f03628a97288
> Reviewed-on: https://skia-review.googlesource.com/155640
> Reviewed-by: Brian Osman <brianosman@google.com>
> Commit-Queue: Mike Klein <mtklein@google.com>

Change-Id: Ia17d93acfe88a36c4c36d29e3a0b243f91178b61
Reviewed-on: https://skia-review.googlesource.com/156241
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2018-09-21 16:18:06 +00:00

44 lines
1.9 KiB
C++

/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "Benchmark.h"
#include "SkOpts.h"
class SwizzleBench : public Benchmark {
public:
SwizzleBench(const char* name, SkOpts::Swizzle_8888_u32 fn) : fName(name), fFn_u32(fn) {}
SwizzleBench(const char* name, SkOpts::Swizzle_8888_u8 fn) : fName(name), fFn_u8 (fn) {}
bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
const char* onGetName() override { return fName; }
void onDraw(int loops, SkCanvas*) override {
static const int K = 1023; // Arbitrary, but nice to be a non-power-of-two to trip up SIMD.
uint32_t dst[K], src[K];
while (loops --> 0) {
if (fFn_u32) { fFn_u32(dst, src, K); }
if (fFn_u8) { fFn_u8 (dst, (const uint8_t*)src, K); }
}
}
private:
const char* fName;
SkOpts::Swizzle_8888_u32 fFn_u32 = nullptr;
SkOpts::Swizzle_8888_u8 fFn_u8 = nullptr;
};
DEF_BENCH(return new SwizzleBench("SkOpts::RGBA_to_rgbA", SkOpts::RGBA_to_rgbA));
DEF_BENCH(return new SwizzleBench("SkOpts::RGBA_to_bgrA", SkOpts::RGBA_to_bgrA));
DEF_BENCH(return new SwizzleBench("SkOpts::RGBA_to_BGRA", SkOpts::RGBA_to_BGRA));
DEF_BENCH(return new SwizzleBench("SkOpts::RGB_to_RGB1", SkOpts::RGB_to_RGB1));
DEF_BENCH(return new SwizzleBench("SkOpts::RGB_to_BGR1", SkOpts::RGB_to_BGR1));
DEF_BENCH(return new SwizzleBench("SkOpts::gray_to_RGB1", SkOpts::gray_to_RGB1));
DEF_BENCH(return new SwizzleBench("SkOpts::grayA_to_RGBA", SkOpts::grayA_to_RGBA));
DEF_BENCH(return new SwizzleBench("SkOpts::grayA_to_rgbA", SkOpts::grayA_to_rgbA));
DEF_BENCH(return new SwizzleBench("SkOpts::inverted_CMYK_to_RGB1", SkOpts::inverted_CMYK_to_RGB1));
DEF_BENCH(return new SwizzleBench("SkOpts::inverted_CMYK_to_BGR1", SkOpts::inverted_CMYK_to_BGR1));