• 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/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     auto direct = GrAsDirectContext(canvas->recordingContext());
29 
30     if (fGM->gpuSetup(direct, canvas) != skiagm::DrawResult::kOk) {
31         fGpuSetupFailed = true;
32     }
33 
34     fGM->onceBeforeDraw();
35 }
36 
onPerCanvasPostDraw(SkCanvas *)37 void GMBench::onPerCanvasPostDraw(SkCanvas*) {
38     fGM->gpuTeardown();
39 
40     // The same GM will be reused with multiple GrContexts. Let the next GrContext start
41     // afresh.
42     fGpuSetupFailed = false;
43 }
44 
onDraw(int loops,SkCanvas * canvas)45 void GMBench::onDraw(int loops, SkCanvas* canvas) {
46     if (fGpuSetupFailed) {
47         return;
48     }
49 
50     fGM->drawBackground(canvas);
51     for (int i = 0; i < loops; ++i) {
52         fGM->drawContent(canvas);
53     }
54 }
55 
onGetSize()56 SkIPoint GMBench::onGetSize() {
57     SkISize size = fGM->getISize();
58     return SkIPoint::Make(size.fWidth, size.fHeight);
59 }
60