• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "bench/GMBench.h"
9 
10 #include "include/gpu/GrRecordingContext.h"
11 #include "src/gpu/ganesh/GrRecordingContextPriv.h"
12 
GMBench(std::unique_ptr<skiagm::GM> gm)13 GMBench::GMBench(std::unique_ptr<skiagm::GM> gm) : fGM(std::move(gm)) {
14     fGM->setMode(skiagm::GM::kBench_Mode);
15 
16     fName.printf("GM_%s", fGM->getName());
17 }
18 
onGetName()19 const char* GMBench::onGetName() {
20     return fName.c_str();
21 }
22 
isSuitableFor(Backend backend)23 bool GMBench::isSuitableFor(Backend backend) {
24     return kNonRendering_Backend != backend;
25 }
26 
onPerCanvasPreDraw(SkCanvas * canvas)27 void GMBench::onPerCanvasPreDraw(SkCanvas* canvas) {
28     if (fGM->gpuSetup(canvas) != skiagm::DrawResult::kOk) {
29         fGpuSetupFailed = true;
30     }
31 
32     fGM->onceBeforeDraw();
33 }
34 
onPerCanvasPostDraw(SkCanvas *)35 void GMBench::onPerCanvasPostDraw(SkCanvas*) {
36     fGM->gpuTeardown();
37 
38     // The same GM will be reused with multiple GrContexts. Let the next GrContext start
39     // afresh.
40     fGpuSetupFailed = false;
41 }
42 
onDraw(int loops,SkCanvas * canvas)43 void GMBench::onDraw(int loops, SkCanvas* canvas) {
44     if (fGpuSetupFailed) {
45         return;
46     }
47 
48     fGM->drawBackground(canvas);
49     for (int i = 0; i < loops; ++i) {
50         fGM->drawContent(canvas);
51     }
52 }
53 
onGetSize()54 SkIPoint GMBench::onGetSize() {
55     SkISize size = fGM->getISize();
56     return SkIPoint::Make(size.fWidth, size.fHeight);
57 }
58