| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 * | 6 * |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #ifndef VisualBench_DEFINED | 9 #ifndef VisualLightweightBenchModule_DEFINED |
| 10 #define VisualBench_DEFINED | 10 #define VisualLightweightBenchModule_DEFINED |
| 11 | 11 |
| 12 #include "SkWindow.h" | 12 #include "VisualModule.h" |
| 13 | 13 |
| 14 #include "ResultsWriter.h" | 14 #include "ResultsWriter.h" |
| 15 #include "SkPicture.h" | 15 #include "SkPicture.h" |
| 16 #include "SkString.h" | |
| 17 #include "SkSurface.h" | |
| 18 #include "Timer.h" | 16 #include "Timer.h" |
| 17 #include "VisualBench.h" |
| 19 #include "VisualBenchmarkStream.h" | 18 #include "VisualBenchmarkStream.h" |
| 20 #include "gl/SkGLContext.h" | |
| 21 | 19 |
| 22 class GrContext; | |
| 23 struct GrGLInterface; | |
| 24 class GrRenderTarget; | |
| 25 class SkCanvas; | 20 class SkCanvas; |
| 26 | 21 |
| 27 /* | 22 /* |
| 28 * A Visual benchmarking tool for gpu benchmarking | 23 * This module is designed to be a minimal overhead timing module for VisualBenc
h |
| 29 */ | 24 */ |
| 30 class VisualBench : public SkOSWindow { | 25 class VisualLightweightBenchModule : public VisualModule { |
| 31 public: | 26 public: |
| 32 VisualBench(void* hwnd, int argc, char** argv); | 27 // TODO get rid of backpointer |
| 33 ~VisualBench() override; | 28 VisualLightweightBenchModule(VisualBench* owner); |
| 34 | |
| 35 protected: | |
| 36 SkSurface* createSurface() override; | |
| 37 | 29 |
| 38 void draw(SkCanvas* canvas) override; | 30 void draw(SkCanvas* canvas) override; |
| 39 | 31 |
| 40 void onSizeChange() override; | |
| 41 | |
| 42 private: | 32 private: |
| 43 /* | 33 /* |
| 44 * The heart of visual bench is an event driven timing loop. | 34 * The heart of visual bench is an event driven timing loop. |
| 45 * kPreWarmLoopsPerCanvasPreDraw_State: Before we begin timing, Benchmarks
have a hook to | 35 * kPreWarmLoopsPerCanvasPreDraw_State: Before we begin timing, Benchmarks
have a hook to |
| 46 * access the canvas. Then we prewarm
before the autotune | 36 * access the canvas. Then we prewarm
before the autotune |
| 47 * loops step. | 37 * loops step. |
| 48 * kPreWarmLoops_State: We prewarm the gpu before auto tuni
ng to enter a steady | 38 * kPreWarmLoops_State: We prewarm the gpu before auto tuni
ng to enter a steady |
| 49 * work state | 39 * work state |
| 50 * kTuneLoops_State: Then we tune the loops of the bench
mark to ensure we | 40 * kTuneLoops_State: Then we tune the loops of the bench
mark to ensure we |
| 51 * are doing a measurable amount of wo
rk | 41 * are doing a measurable amount of wo
rk |
| (...skipping 11 matching lines...) Expand all Loading... |
| 63 enum State { | 53 enum State { |
| 64 kPreWarmLoopsPerCanvasPreDraw_State, | 54 kPreWarmLoopsPerCanvasPreDraw_State, |
| 65 kPreWarmLoops_State, | 55 kPreWarmLoops_State, |
| 66 kTuneLoops_State, | 56 kTuneLoops_State, |
| 67 kPreWarmTimingPerCanvasPreDraw_State, | 57 kPreWarmTimingPerCanvasPreDraw_State, |
| 68 kPreWarmTiming_State, | 58 kPreWarmTiming_State, |
| 69 kTiming_State, | 59 kTiming_State, |
| 70 }; | 60 }; |
| 71 void setTitle(); | 61 void setTitle(); |
| 72 bool setupBackend(); | 62 bool setupBackend(); |
| 73 void resetContext(); | |
| 74 void setupRenderTarget(); | 63 void setupRenderTarget(); |
| 75 bool onHandleChar(SkUnichar unichar) override; | |
| 76 void printStats(); | 64 void printStats(); |
| 77 bool advanceRecordIfNecessary(SkCanvas*); | 65 bool advanceRecordIfNecessary(SkCanvas*); |
| 78 inline void renderFrame(SkCanvas*); | 66 inline void renderFrame(SkCanvas*); |
| 79 inline void nextState(State); | 67 inline void nextState(State); |
| 80 void perCanvasPreDraw(SkCanvas*, State); | 68 void perCanvasPreDraw(SkCanvas*, State); |
| 81 void preWarm(State nextState); | 69 void preWarm(State nextState); |
| 82 void scaleLoops(double elapsedMs); | 70 void scaleLoops(double elapsedMs); |
| 83 inline void tuneLoops(); | 71 inline void tuneLoops(); |
| 84 inline void timing(SkCanvas*); | 72 inline void timing(SkCanvas*); |
| 85 inline double elapsed(); | 73 inline double elapsed(); |
| 86 void resetTimingState(); | 74 void resetTimingState(); |
| 87 void postDraw(SkCanvas*); | 75 void postDraw(SkCanvas*); |
| 88 void recordMeasurement(); | 76 void recordMeasurement(); |
| 89 | 77 |
| 90 struct Record { | 78 struct Record { |
| 91 SkTArray<double> fMeasurements; | 79 SkTArray<double> fMeasurements; |
| 92 }; | 80 }; |
| 93 | 81 |
| 94 int fCurrentSample; | 82 int fCurrentSample; |
| 95 int fCurrentFrame; | 83 int fCurrentFrame; |
| 96 int fLoops; | 84 int fLoops; |
| 97 SkTArray<Record> fRecords; | 85 SkTArray<Record> fRecords; |
| 98 WallTimer fTimer; | 86 WallTimer fTimer; |
| 99 State fState; | 87 State fState; |
| 100 SkAutoTDelete<VisualBenchmarkStream> fBenchmarkStream; | 88 SkAutoTDelete<VisualBenchmarkStream> fBenchmarkStream; |
| 101 SkAutoTUnref<Benchmark> fBenchmark; | 89 SkAutoTUnref<Benchmark> fBenchmark; |
| 102 | 90 |
| 103 // support framework | 91 // support framework |
| 104 SkAutoTUnref<SkSurface> fSurface; | 92 SkAutoTUnref<VisualBench> fOwner; |
| 105 SkAutoTUnref<GrContext> fContext; | |
| 106 SkAutoTUnref<GrRenderTarget> fRenderTarget; | |
| 107 AttachmentInfo fAttachmentInfo; | |
| 108 SkAutoTUnref<const GrGLInterface> fInterface; | |
| 109 SkAutoTDelete<ResultsWriter> fResults; | 93 SkAutoTDelete<ResultsWriter> fResults; |
| 110 | 94 |
| 111 typedef SkOSWindow INHERITED; | 95 typedef VisualModule INHERITED; |
| 112 }; | 96 }; |
| 113 | 97 |
| 114 #endif | 98 #endif |
| OLD | NEW |