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 #if defined(SK_GRAPHITE) modifyGraphiteContextOptions(skgpu::graphite::ContextOptions * options)26 void modifyGraphiteContextOptions(skgpu::graphite::ContextOptions* options) override { 27 fGM->modifyGraphiteContextOptions(options); 28 } 29 #endif 30 31 protected: 32 const char* onGetName() override; 33 bool isSuitableFor(Backend backend) override; 34 void onPerCanvasPreDraw(SkCanvas*) override; 35 void onPerCanvasPostDraw(SkCanvas*) override; 36 void onDraw(int loops, SkCanvas*) override; 37 SkISize onGetSize() override; 38 39 private: 40 std::unique_ptr<skiagm::GM> fGM; 41 SkString fName; 42 bool fGpuSetupFailed = false; 43 44 using INHERITED = Benchmark; 45 }; 46 47 #endif 48