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#include "bench/Benchmark.h" 8cb93a386Sopenharmony_ci#include "include/core/SkCanvas.h" 9cb93a386Sopenharmony_ci#include "include/core/SkImage.h" 10cb93a386Sopenharmony_ci#include "include/core/SkMatrix.h" 11cb93a386Sopenharmony_ci#include "include/core/SkPaint.h" 12cb93a386Sopenharmony_ci#include "include/core/SkString.h" 13cb93a386Sopenharmony_ci#include "include/core/SkSurface.h" 14cb93a386Sopenharmony_ci 15cb93a386Sopenharmony_ci/** 16cb93a386Sopenharmony_ci * This bench measures the rendering time of SkCanvas::drawBitmap with different anti-aliasing / 17cb93a386Sopenharmony_ci * matrix combinations. 18cb93a386Sopenharmony_ci */ 19cb93a386Sopenharmony_ci 20cb93a386Sopenharmony_ciclass DrawBitmapAABench : public Benchmark { 21cb93a386Sopenharmony_cipublic: 22cb93a386Sopenharmony_ci DrawBitmapAABench(bool doAA, const SkMatrix& matrix, const char name[]) 23cb93a386Sopenharmony_ci : fMatrix(matrix) 24cb93a386Sopenharmony_ci , fName("draw_bitmap_") { 25cb93a386Sopenharmony_ci 26cb93a386Sopenharmony_ci fPaint.setAntiAlias(doAA); 27cb93a386Sopenharmony_ci fName.appendf("%s_%s", doAA ? "aa" : "noaa", name); 28cb93a386Sopenharmony_ci } 29cb93a386Sopenharmony_ci 30cb93a386Sopenharmony_ciprotected: 31cb93a386Sopenharmony_ci const char* onGetName() override { 32cb93a386Sopenharmony_ci return fName.c_str(); 33cb93a386Sopenharmony_ci } 34cb93a386Sopenharmony_ci 35cb93a386Sopenharmony_ci void onDelayedSetup() override { 36cb93a386Sopenharmony_ci auto surf = SkSurface::MakeRasterN32Premul(200, 200); 37cb93a386Sopenharmony_ci surf->getCanvas()->clear(0xFF00FF00); 38cb93a386Sopenharmony_ci fImage = surf->makeImageSnapshot(); 39cb93a386Sopenharmony_ci } 40cb93a386Sopenharmony_ci 41cb93a386Sopenharmony_ci void onDraw(int loops, SkCanvas* canvas) override { 42cb93a386Sopenharmony_ci SkSamplingOptions sampling(SkFilterMode::kLinear); 43cb93a386Sopenharmony_ci canvas->concat(fMatrix); 44cb93a386Sopenharmony_ci for (int i = 0; i < loops; i++) { 45cb93a386Sopenharmony_ci canvas->drawImage(fImage.get(), 0, 0, sampling, &fPaint); 46cb93a386Sopenharmony_ci } 47cb93a386Sopenharmony_ci } 48cb93a386Sopenharmony_ci 49cb93a386Sopenharmony_ciprivate: 50cb93a386Sopenharmony_ci SkPaint fPaint; 51cb93a386Sopenharmony_ci SkMatrix fMatrix; 52cb93a386Sopenharmony_ci SkString fName; 53cb93a386Sopenharmony_ci sk_sp<SkImage> fImage; 54cb93a386Sopenharmony_ci 55cb93a386Sopenharmony_ci using INHERITED = Benchmark; 56cb93a386Sopenharmony_ci}; 57cb93a386Sopenharmony_ci 58cb93a386Sopenharmony_ciDEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::I(), "ident"); ) 59cb93a386Sopenharmony_ci 60cb93a386Sopenharmony_ciDEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::Scale(1.17f, 1.17f), "scale"); ) 61cb93a386Sopenharmony_ci 62cb93a386Sopenharmony_ciDEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::Translate(17.5f, 17.5f), "translate"); ) 63cb93a386Sopenharmony_ci 64cb93a386Sopenharmony_ciDEF_BENCH( 65cb93a386Sopenharmony_ci SkMatrix m; 66cb93a386Sopenharmony_ci m.reset(); 67cb93a386Sopenharmony_ci m.preRotate(15); 68cb93a386Sopenharmony_ci return new DrawBitmapAABench(false, m, "rotate"); 69cb93a386Sopenharmony_ci) 70cb93a386Sopenharmony_ci 71cb93a386Sopenharmony_ciDEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::I(), "ident"); ) 72cb93a386Sopenharmony_ci 73cb93a386Sopenharmony_ciDEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::Scale(1.17f, 1.17f), "scale"); ) 74cb93a386Sopenharmony_ci 75cb93a386Sopenharmony_ciDEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::Translate(17.5f, 17.5f), "translate"); ) 76cb93a386Sopenharmony_ci 77cb93a386Sopenharmony_ciDEF_BENCH( 78cb93a386Sopenharmony_ci SkMatrix m; 79cb93a386Sopenharmony_ci m.reset(); 80cb93a386Sopenharmony_ci m.preRotate(15); 81cb93a386Sopenharmony_ci return new DrawBitmapAABench(true, m, "rotate"); 82cb93a386Sopenharmony_ci) 83