blob: c634547a6b54cd89e9095ce604acdead289e602c [file] [log] [blame]
mtklein55c86ab2016-01-08 06:32:52 -08001/*
2 * Copyright 2016 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
8#include "Benchmark.h"
9#include "SkOpts.h"
10
11class SwizzleBench : public Benchmark {
12public:
Mike Klein6e78ae52018-09-19 13:37:16 -040013
14 SwizzleBench(const char* name, SkOpts::Swizzle_8888_u32 fn) : fName(name), fFn_u32(fn) {}
15 SwizzleBench(const char* name, SkOpts::Swizzle_8888_u8 fn) : fName(name), fFn_u8 (fn) {}
mtklein55c86ab2016-01-08 06:32:52 -080016
17 bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
18 const char* onGetName() override { return fName; }
19 void onDraw(int loops, SkCanvas*) override {
20 static const int K = 1023; // Arbitrary, but nice to be a non-power-of-two to trip up SIMD.
21 uint32_t dst[K], src[K];
22 while (loops --> 0) {
Mike Klein6e78ae52018-09-19 13:37:16 -040023 if (fFn_u32) { fFn_u32(dst, src, K); }
24 if (fFn_u8) { fFn_u8 (dst, (const uint8_t*)src, K); }
mtklein55c86ab2016-01-08 06:32:52 -080025 }
26 }
27private:
28 const char* fName;
Mike Klein6e78ae52018-09-19 13:37:16 -040029 SkOpts::Swizzle_8888_u32 fFn_u32 = nullptr;
30 SkOpts::Swizzle_8888_u8 fFn_u8 = nullptr;
mtklein55c86ab2016-01-08 06:32:52 -080031};
32
33
mtklein8bf7b792016-01-22 07:42:53 -080034DEF_BENCH(return new SwizzleBench("SkOpts::RGBA_to_rgbA", SkOpts::RGBA_to_rgbA));
35DEF_BENCH(return new SwizzleBench("SkOpts::RGBA_to_bgrA", SkOpts::RGBA_to_bgrA));
36DEF_BENCH(return new SwizzleBench("SkOpts::RGBA_to_BGRA", SkOpts::RGBA_to_BGRA));
msarettf1b8b6a2016-01-22 09:54:21 -080037DEF_BENCH(return new SwizzleBench("SkOpts::RGB_to_RGB1", SkOpts::RGB_to_RGB1));
38DEF_BENCH(return new SwizzleBench("SkOpts::RGB_to_BGR1", SkOpts::RGB_to_BGR1));
msarett2eff71c2016-02-02 12:59:45 -080039DEF_BENCH(return new SwizzleBench("SkOpts::gray_to_RGB1", SkOpts::gray_to_RGB1));
msarett09574242016-02-03 15:28:35 -080040DEF_BENCH(return new SwizzleBench("SkOpts::grayA_to_RGBA", SkOpts::grayA_to_RGBA));
41DEF_BENCH(return new SwizzleBench("SkOpts::grayA_to_rgbA", SkOpts::grayA_to_rgbA));
msarettc5c322d2016-02-08 13:26:25 -080042DEF_BENCH(return new SwizzleBench("SkOpts::inverted_CMYK_to_RGB1", SkOpts::inverted_CMYK_to_RGB1));
43DEF_BENCH(return new SwizzleBench("SkOpts::inverted_CMYK_to_BGR1", SkOpts::inverted_CMYK_to_BGR1));