Flutter Engine
The Flutter Engine
MSKPBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google Inc.
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 "bench/MSKPBench.h"
12#include "tools/MSKPPlayer.h"
13
14MSKPBench::MSKPBench(SkString name, std::unique_ptr<MSKPPlayer> player)
15 : fName(name), fPlayer(std::move(player)) {}
16
17MSKPBench::~MSKPBench() = default;
18
19void MSKPBench::onDraw(int loops, SkCanvas* canvas) {
20 for (int i = 0; i < loops; ++i) {
21 for (int f = 0; f < fPlayer->numFrames(); ++f) {
22 canvas->save();
23 canvas->clipIRect(SkIRect::MakeSize(fPlayer->frameDimensions(f)));
24 fPlayer->playFrame(canvas, f);
25 canvas->restore();
26 if (auto dContext = GrAsDirectContext(canvas->recordingContext())) {
27 dContext->flushAndSubmit();
28 }
29 }
30 // Ensure each loop replays all offscreen layer draws from scratch.
31 fPlayer->rewindLayers();
32 }
33}
34
35const char* MSKPBench::onGetName() { return fName.c_str(); }
36
38 auto dims = fPlayer->maxDimensions();
39 return {dims.width(), dims.height()};
40}
41
43 // We don't benchmark creation of the backing stores for layers so ensure they're all created.
44 fPlayer->allocateLayers(canvas);
45}
46
48 // nanobench can tear down the 3D API context/device before destroying the benchmarks.
49 fPlayer->resetLayers();
50}
const char * fName
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
void onPostDraw(SkCanvas *) override
Definition: MSKPBench.cpp:47
void onPreDraw(SkCanvas *) override
Definition: MSKPBench.cpp:42
~MSKPBench() override
const char * onGetName() override
Definition: MSKPBench.cpp:35
MSKPBench(SkString name, std::unique_ptr< MSKPPlayer > player)
Definition: MSKPBench.cpp:14
SkISize onGetSize() override
Definition: MSKPBench.cpp:37
void onDraw(int loops, SkCanvas *) override
Definition: MSKPBench.cpp:19
void restore()
Definition: SkCanvas.cpp:461
void clipIRect(const SkIRect &irect, SkClipOp op=SkClipOp::kIntersect)
Definition: SkCanvas.h:991
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
int save()
Definition: SkCanvas.cpp:447
const char * c_str() const
Definition: SkString.h:133
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
Definition: ref_ptr.h:256
static constexpr SkIRect MakeSize(const SkISize &size)
Definition: SkRect.h:66
Definition: SkSize.h:16