1 /* 2 * Copyright 2023 Google LLC 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 "src/base/SkTime.h" 9 #include "tools/flags/CommandLineFlags.h" 10 #include "tools/testrunners/benchmark/target/BenchmarkTarget.h" 11 12 DECLARE_int(loops); 13 DECLARE_int(maxLoops); 14 setup() const15void BenchmarkTarget::setup() const { fBenchmark->perCanvasPreDraw(getCanvas()); } 16 time(int loops) const17double BenchmarkTarget::time(int loops) const { 18 SkCanvas* canvas = getCanvas(); 19 if (canvas) { 20 canvas->clear(SK_ColorWHITE); 21 } 22 fBenchmark->preDraw(canvas); 23 double start = nowMs(); 24 canvas = onBeforeDraw(canvas); 25 26 fBenchmark->draw(loops, canvas); 27 28 onAfterDraw(); 29 double elapsed = nowMs() - start; 30 fBenchmark->postDraw(canvas); 31 return elapsed; 32 } 33 tearDown() const34void BenchmarkTarget::tearDown() const { fBenchmark->perCanvasPostDraw(getCanvas()); } 35 getCanvas() const36SkCanvas* BenchmarkTarget::getCanvas() const { 37 if (!fSurfaceManager || !fSurfaceManager->getSurface()) { 38 return nullptr; // The NonRenderingBenchmarkTarget has a null SurfaceManager. 39 } 40 return fSurfaceManager->getSurface()->getCanvas(); 41 } 42 getBenchmark() const43Benchmark* BenchmarkTarget::getBenchmark() const { return fBenchmark; } 44 getKeyValuePairs(std::string cpuName,std::string gpuName) const45std::map<std::string, std::string> BenchmarkTarget::getKeyValuePairs(std::string cpuName, 46 std::string gpuName) const { 47 SkASSERT_RELEASE(fSurfaceManager); 48 return fSurfaceManager->getPerfKeyValuePairs(cpuName, gpuName); 49 } 50 isCpuOrGpuBound() const51SurfaceManager::CpuOrGpu BenchmarkTarget::isCpuOrGpuBound() const { 52 SkASSERT_RELEASE(fSurfaceManager); 53 return fSurfaceManager->isCpuOrGpuBound(); 54 } 55 nowMs() const56double BenchmarkTarget::nowMs() const { return SkTime::GetNSecs() * 1e-6; } 57