joshualitt | da7b843 | 2015-05-27 09:19:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
| 9 | #ifndef VisualBench_DEFINED |
| 10 | #define VisualBench_DEFINED |
| 11 | |
| 12 | #include "SkWindow.h" |
| 13 | |
| 14 | #include "SkPicture.h" |
bsalomon | 45171e2 | 2015-06-16 13:52:18 -0700 | [diff] [blame] | 15 | #include "SkString.h" |
joshualitt | da7b843 | 2015-05-27 09:19:03 -0700 | [diff] [blame] | 16 | #include "SkSurface.h" |
joshualitt | 7fe8ee4 | 2015-06-01 10:03:54 -0700 | [diff] [blame] | 17 | #include "Timer.h" |
joshualitt | 962cc98 | 2015-06-30 07:43:14 -0700 | [diff] [blame^] | 18 | #include "VisualBenchmarkStream.h" |
joshualitt | da7b843 | 2015-05-27 09:19:03 -0700 | [diff] [blame] | 19 | #include "gl/SkGLContext.h" |
| 20 | |
| 21 | class GrContext; |
| 22 | struct GrGLInterface; |
| 23 | class GrRenderTarget; |
| 24 | class SkCanvas; |
| 25 | |
| 26 | /* |
| 27 | * A Visual benchmarking tool for gpu benchmarking |
| 28 | */ |
| 29 | class VisualBench : public SkOSWindow { |
| 30 | public: |
| 31 | VisualBench(void* hwnd, int argc, char** argv); |
| 32 | ~VisualBench() override; |
| 33 | |
| 34 | protected: |
| 35 | SkSurface* createSurface() override; |
| 36 | |
| 37 | void draw(SkCanvas* canvas) override; |
| 38 | |
| 39 | void onSizeChange() override; |
| 40 | |
| 41 | private: |
| 42 | void setTitle(); |
| 43 | bool setupBackend(); |
joshualitt | 7fe8ee4 | 2015-06-01 10:03:54 -0700 | [diff] [blame] | 44 | void resetContext(); |
joshualitt | da7b843 | 2015-05-27 09:19:03 -0700 | [diff] [blame] | 45 | void setupRenderTarget(); |
| 46 | bool onHandleChar(SkUnichar unichar) override; |
joshualitt | 7fe8ee4 | 2015-06-01 10:03:54 -0700 | [diff] [blame] | 47 | void printStats(); |
joshualitt | 962cc98 | 2015-06-30 07:43:14 -0700 | [diff] [blame^] | 48 | bool advanceRecordIfNecessary(SkCanvas*); |
joshualitt | 7fe8ee4 | 2015-06-01 10:03:54 -0700 | [diff] [blame] | 49 | inline void renderFrame(SkCanvas*); |
joshualitt | da7b843 | 2015-05-27 09:19:03 -0700 | [diff] [blame] | 50 | |
bsalomon | 45171e2 | 2015-06-16 13:52:18 -0700 | [diff] [blame] | 51 | struct Record { |
joshualitt | 7fe8ee4 | 2015-06-01 10:03:54 -0700 | [diff] [blame] | 52 | SkTArray<double> fMeasurements; |
| 53 | }; |
| 54 | |
| 55 | enum State { |
joshualitt | 6205af0 | 2015-06-23 07:10:59 -0700 | [diff] [blame] | 56 | kPreWarmLoops_State, |
| 57 | kTuneLoops_State, |
| 58 | kPreWarmTiming_State, |
joshualitt | 7fe8ee4 | 2015-06-01 10:03:54 -0700 | [diff] [blame] | 59 | kTiming_State, |
| 60 | }; |
joshualitt | 6205af0 | 2015-06-23 07:10:59 -0700 | [diff] [blame] | 61 | void preWarm(State nextState); |
joshualitt | 7fe8ee4 | 2015-06-01 10:03:54 -0700 | [diff] [blame] | 62 | |
joshualitt | 7fe8ee4 | 2015-06-01 10:03:54 -0700 | [diff] [blame] | 63 | int fCurrentSample; |
joshualitt | 6205af0 | 2015-06-23 07:10:59 -0700 | [diff] [blame] | 64 | int fCurrentFrame; |
| 65 | int fFlushes; |
| 66 | int fLoops; |
bsalomon | 45171e2 | 2015-06-16 13:52:18 -0700 | [diff] [blame] | 67 | SkTArray<Record> fRecords; |
joshualitt | 7fe8ee4 | 2015-06-01 10:03:54 -0700 | [diff] [blame] | 68 | WallTimer fTimer; |
| 69 | State fState; |
joshualitt | 962cc98 | 2015-06-30 07:43:14 -0700 | [diff] [blame^] | 70 | SkAutoTDelete<VisualBenchmarkStream> fBenchmarkStream; |
| 71 | Benchmark* fBenchmark; |
joshualitt | da7b843 | 2015-05-27 09:19:03 -0700 | [diff] [blame] | 72 | |
| 73 | // support framework |
| 74 | SkAutoTUnref<SkSurface> fSurface; |
| 75 | SkAutoTUnref<GrContext> fContext; |
| 76 | SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 77 | AttachmentInfo fAttachmentInfo; |
| 78 | SkAutoTUnref<const GrGLInterface> fInterface; |
| 79 | |
| 80 | typedef SkOSWindow INHERITED; |
| 81 | }; |
| 82 | |
| 83 | #endif |