1 /*
2  * Copyright 2014 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 #ifndef GMBench_DEFINED
8 #define GMBench_DEFINED
9 
10 #include "bench/Benchmark.h"
11 #include "gm/gm.h"
12 #include "include/core/SkCanvas.h"
13 
14 /**
15  * Runs a GM as a benchmark by repeatedly drawing the GM.
16  */
17 class GMBench : public Benchmark {
18 public:
19     GMBench(std::unique_ptr<skiagm::GM> gm);
20 
modifyGrContextOptions(GrContextOptions * options)21     void modifyGrContextOptions(GrContextOptions* options) override {
22         return fGM->modifyGrContextOptions(options);
23     }
24 
25 protected:
26     const char* onGetName() override;
27     bool isSuitableFor(Backend backend) override;
28     void onPerCanvasPreDraw(SkCanvas*) override;
29     void onPerCanvasPostDraw(SkCanvas*) override;
30     void onDraw(int loops, SkCanvas*) override;
31     SkIPoint onGetSize() override;
32 
33 private:
34     std::unique_ptr<skiagm::GM> fGM;
35     SkString                    fName;
36     bool                        fGpuSetupFailed = false;
37 
38     using INHERITED = Benchmark;
39 };
40 
41 #endif
42