1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2015 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 "include/core/SkBitmap.h" 10cb93a386Sopenharmony_ci#include "src/core/SkMipmap.h" 11cb93a386Sopenharmony_ci 12cb93a386Sopenharmony_ciclass MipmapBench: public Benchmark { 13cb93a386Sopenharmony_ci SkBitmap fBitmap; 14cb93a386Sopenharmony_ci SkString fName; 15cb93a386Sopenharmony_ci const int fW, fH; 16cb93a386Sopenharmony_ci bool fHalfFoat; 17cb93a386Sopenharmony_ci 18cb93a386Sopenharmony_cipublic: 19cb93a386Sopenharmony_ci MipmapBench(int w, int h, bool halfFloat = false) 20cb93a386Sopenharmony_ci : fW(w), fH(h), fHalfFoat(halfFloat) 21cb93a386Sopenharmony_ci { 22cb93a386Sopenharmony_ci fName.printf("mipmap_build_%dx%d", w, h); 23cb93a386Sopenharmony_ci if (halfFloat) { 24cb93a386Sopenharmony_ci fName.append("_f16"); 25cb93a386Sopenharmony_ci } 26cb93a386Sopenharmony_ci } 27cb93a386Sopenharmony_ci 28cb93a386Sopenharmony_ciprotected: 29cb93a386Sopenharmony_ci bool isSuitableFor(Backend backend) override { 30cb93a386Sopenharmony_ci return kNonRendering_Backend == backend; 31cb93a386Sopenharmony_ci } 32cb93a386Sopenharmony_ci 33cb93a386Sopenharmony_ci const char* onGetName() override { return fName.c_str(); } 34cb93a386Sopenharmony_ci 35cb93a386Sopenharmony_ci void onDelayedSetup() override { 36cb93a386Sopenharmony_ci SkColorType ct = fHalfFoat ? kRGBA_F16_SkColorType : kN32_SkColorType; 37cb93a386Sopenharmony_ci SkImageInfo info = SkImageInfo::Make(fW, fH, ct, kPremul_SkAlphaType, 38cb93a386Sopenharmony_ci SkColorSpace::MakeSRGB()); 39cb93a386Sopenharmony_ci fBitmap.allocPixels(info); 40cb93a386Sopenharmony_ci fBitmap.eraseColor(SK_ColorWHITE); // so we don't read uninitialized memory 41cb93a386Sopenharmony_ci } 42cb93a386Sopenharmony_ci 43cb93a386Sopenharmony_ci void onDraw(int loops, SkCanvas*) override { 44cb93a386Sopenharmony_ci for (int i = 0; i < loops * 4; i++) { 45cb93a386Sopenharmony_ci SkMipmap::Build(fBitmap, nullptr)->unref(); 46cb93a386Sopenharmony_ci } 47cb93a386Sopenharmony_ci } 48cb93a386Sopenharmony_ci 49cb93a386Sopenharmony_ciprivate: 50cb93a386Sopenharmony_ci using INHERITED = Benchmark; 51cb93a386Sopenharmony_ci}; 52cb93a386Sopenharmony_ci 53cb93a386Sopenharmony_ci// Build variants that exercise the width and heights being even or odd at each level, as the 54cb93a386Sopenharmony_ci// impl specializes on each of these. 55cb93a386Sopenharmony_ci// 56cb93a386Sopenharmony_ciDEF_BENCH( return new MipmapBench(511, 511); ) 57cb93a386Sopenharmony_ciDEF_BENCH( return new MipmapBench(512, 511); ) 58cb93a386Sopenharmony_ciDEF_BENCH( return new MipmapBench(511, 512); ) 59cb93a386Sopenharmony_ciDEF_BENCH( return new MipmapBench(512, 512); ) 60cb93a386Sopenharmony_ci 61cb93a386Sopenharmony_ciDEF_BENCH( return new MipmapBench(512, 512, true); ) 62cb93a386Sopenharmony_ciDEF_BENCH( return new MipmapBench(511, 511, true); ) 63cb93a386Sopenharmony_ci 64cb93a386Sopenharmony_ciDEF_BENCH( return new MipmapBench(2048, 2048); ) 65cb93a386Sopenharmony_ciDEF_BENCH( return new MipmapBench(2047, 2047); ) 66cb93a386Sopenharmony_ciDEF_BENCH( return new MipmapBench(2048, 2047); ) 67cb93a386Sopenharmony_ciDEF_BENCH( return new MipmapBench(2047, 2048); ) 68