1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2016 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#include "bench/Benchmark.h" 9cb93a386Sopenharmony_ci#include "src/core/SkOpts.h" 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ciclass SwizzleBench : public Benchmark { 12cb93a386Sopenharmony_cipublic: 13cb93a386Sopenharmony_ci 14cb93a386Sopenharmony_ci SwizzleBench(const char* name, SkOpts::Swizzle_8888_u32 fn) : fName(name), fFn_u32(fn) {} 15cb93a386Sopenharmony_ci SwizzleBench(const char* name, SkOpts::Swizzle_8888_u8 fn) : fName(name), fFn_u8 (fn) {} 16cb93a386Sopenharmony_ci 17cb93a386Sopenharmony_ci bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; } 18cb93a386Sopenharmony_ci const char* onGetName() override { return fName; } 19cb93a386Sopenharmony_ci void onDraw(int loops, SkCanvas*) override { 20cb93a386Sopenharmony_ci static const int K = 1023; // Arbitrary, but nice to be a non-power-of-two to trip up SIMD. 21cb93a386Sopenharmony_ci uint32_t dst[K], src[K]; 22cb93a386Sopenharmony_ci while (loops --> 0) { 23cb93a386Sopenharmony_ci if (fFn_u32) { fFn_u32(dst, src, K); } 24cb93a386Sopenharmony_ci if (fFn_u8) { fFn_u8 (dst, (const uint8_t*)src, K); } 25cb93a386Sopenharmony_ci } 26cb93a386Sopenharmony_ci } 27cb93a386Sopenharmony_ciprivate: 28cb93a386Sopenharmony_ci const char* fName; 29cb93a386Sopenharmony_ci SkOpts::Swizzle_8888_u32 fFn_u32 = nullptr; 30cb93a386Sopenharmony_ci SkOpts::Swizzle_8888_u8 fFn_u8 = nullptr; 31cb93a386Sopenharmony_ci}; 32cb93a386Sopenharmony_ci 33cb93a386Sopenharmony_ci 34cb93a386Sopenharmony_ciDEF_BENCH(return new SwizzleBench("SkOpts::RGBA_to_rgbA", SkOpts::RGBA_to_rgbA)); 35cb93a386Sopenharmony_ciDEF_BENCH(return new SwizzleBench("SkOpts::RGBA_to_bgrA", SkOpts::RGBA_to_bgrA)); 36cb93a386Sopenharmony_ciDEF_BENCH(return new SwizzleBench("SkOpts::RGBA_to_BGRA", SkOpts::RGBA_to_BGRA)); 37cb93a386Sopenharmony_ciDEF_BENCH(return new SwizzleBench("SkOpts::RGB_to_RGB1", SkOpts::RGB_to_RGB1)); 38cb93a386Sopenharmony_ciDEF_BENCH(return new SwizzleBench("SkOpts::RGB_to_BGR1", SkOpts::RGB_to_BGR1)); 39cb93a386Sopenharmony_ciDEF_BENCH(return new SwizzleBench("SkOpts::gray_to_RGB1", SkOpts::gray_to_RGB1)); 40cb93a386Sopenharmony_ciDEF_BENCH(return new SwizzleBench("SkOpts::grayA_to_RGBA", SkOpts::grayA_to_RGBA)); 41cb93a386Sopenharmony_ciDEF_BENCH(return new SwizzleBench("SkOpts::grayA_to_rgbA", SkOpts::grayA_to_rgbA)); 42cb93a386Sopenharmony_ciDEF_BENCH(return new SwizzleBench("SkOpts::inverted_CMYK_to_RGB1", SkOpts::inverted_CMYK_to_RGB1)); 43cb93a386Sopenharmony_ciDEF_BENCH(return new SwizzleBench("SkOpts::inverted_CMYK_to_BGR1", SkOpts::inverted_CMYK_to_BGR1)); 44