Flutter Engine
The Flutter Engine
BenchmarkTarget.cpp
Go to the documentation of this file.
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"
11
13DECLARE_int(maxLoops);
14
16
17double 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
29 double elapsed = nowMs() - start;
30 fBenchmark->postDraw(canvas);
31 return elapsed;
32}
33
35
37 if (!fSurfaceManager || !fSurfaceManager->getSurface()) {
38 return nullptr; // The NonRenderingBenchmarkTarget has a null SurfaceManager.
39 }
40 return fSurfaceManager->getSurface()->getCanvas();
41}
42
44
45std::map<std::string, std::string> BenchmarkTarget::getKeyValuePairs(std::string cpuName,
46 std::string gpuName) const {
48 return fSurfaceManager->getPerfKeyValuePairs(cpuName, gpuName);
49}
50
53 return fSurfaceManager->isCpuOrGpuBound();
54}
55
56double BenchmarkTarget::nowMs() const { return SkTime::GetNSecs() * 1e-6; }
DECLARE_int(loops)
#define SkASSERT_RELEASE(cond)
Definition: SkAssert.h:100
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
virtual void setup() const
std::unique_ptr< SurfaceManager > fSurfaceManager
virtual std::map< std::string, std::string > getKeyValuePairs(std::string cpuName, std::string gpuName) const
virtual SurfaceManager::CpuOrGpu isCpuOrGpuBound() const
Benchmark * fBenchmark
double nowMs() const
virtual void onAfterDraw() const
Benchmark * getBenchmark() const
virtual SkCanvas * onBeforeDraw(SkCanvas *canvas) const
double time(int loops) const
void tearDown() const
SkCanvas * getCanvas() const
void draw(int loops, SkCanvas *)
Definition: Benchmark.cpp:50
void postDraw(SkCanvas *)
Definition: Benchmark.cpp:42
void perCanvasPreDraw(SkCanvas *)
Definition: Benchmark.cpp:34
void perCanvasPostDraw(SkCanvas *)
Definition: Benchmark.cpp:46
void preDraw(SkCanvas *)
Definition: Benchmark.cpp:38
void clear(SkColor color)
Definition: SkCanvas.h:1199
double GetNSecs()
Definition: SkTime.cpp:17