Debian Codegraph @

bench/MSKPBench.cpp

raw
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"
9 #include "include/core/SkCanvas.h"
10 #include "include/gpu/ganesh/GrDirectContext.h"
11 #include "include/gpu/ganesh/GrRecordingContext.h"
12 #include "tools/MSKPPlayer.h"
13
14 #if defined(SK_GRAPHITE)
15 #include "include/gpu/graphite/Context.h"
16 #include "include/gpu/graphite/Recorder.h"
17 #include "src/gpu/graphite/RecorderPriv.h"
18 #endif
19
20 MSKPBench::MSKPBench(SkString name, std::unique_ptr<MSKPPlayer> player)
21 : fName(name), fPlayer(std::move(player)) {}
22
23 MSKPBench::~MSKPBench() = default;
24
25 void MSKPBench::onDrawFrame(int loops, SkCanvas* canvas, std::function<void()> submitFrame) {
26 for (int i = 0; i < loops; ++i) {
27 for (int f = 0; f < fPlayer->numFrames(); ++f) {
28 canvas->save();
29 canvas->clipIRect(SkIRect::MakeSize(fPlayer->frameDimensions(f)));
30 fPlayer->playFrame(canvas, f);
31 canvas->restore();
32 if (submitFrame) {
33 submitFrame();
34 }
35 }
36 // Ensure each loop replays all offscreen layer draws from scratch.
37 fPlayer->rewindLayers();
38 }
39 }
40
41 const char* MSKPBench::onGetName() { return fName.c_str(); }
42
43 SkISize MSKPBench::onGetSize() {
44 auto dims = fPlayer->maxDimensions();
45 return {dims.width(), dims.height()};
46 }
47
48 void MSKPBench::onPreDraw(SkCanvas* canvas) {
49 // We don't benchmark creation of the backing stores for layers so ensure they're all created.
50 fPlayer->allocateLayers(canvas);
51 }
52
53 void MSKPBench::onPostDraw(SkCanvas*) {
54 // nanobench can tear down the 3D API context/device before destroying the benchmarks.
55 fPlayer->resetLayers();
56 }