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 VisualBench_DEFINED |
10 #define VisualBench_DEFINED | 10 #define VisualBench_DEFINED |
(...skipping 21 matching lines...) Expand all Loading... |
32 ~VisualBench() override; | 32 ~VisualBench() override; |
33 | 33 |
34 protected: | 34 protected: |
35 SkSurface* createSurface() override; | 35 SkSurface* createSurface() override; |
36 | 36 |
37 void draw(SkCanvas* canvas) override; | 37 void draw(SkCanvas* canvas) override; |
38 | 38 |
39 void onSizeChange() override; | 39 void onSizeChange() override; |
40 | 40 |
41 private: | 41 private: |
| 42 /* |
| 43 * The heart of visual bench is an event driven timing loop. |
| 44 * kPreWarmLoopsPerCanvasPreDraw_State: Before we begin timing, Benchmarks
have a hook to |
| 45 * access the canvas. Then we prewarm
before the autotune |
| 46 * loops step. |
| 47 * kPreWarmLoops_State: We prewarm the gpu before auto tuni
ng to enter a steady |
| 48 * work state |
| 49 * kTuneLoops_State: Then we tune the loops of the bench
mark to ensure we |
| 50 * are doing a measurable amount of wo
rk |
| 51 * kPreWarmTimingPerCanvasPreDraw_State: Because reset the context after tun
ing loops to ensure |
| 52 * coherent state, we need to give the
benchmark |
| 53 * another hook |
| 54 * kPreWarmTiming_State: We prewarm the gpu again to enter a
steady state |
| 55 * kTiming_State: Finally we time the benchmark. Whe
n finished timing |
| 56 * if we have enough samples then we'l
l start the next |
| 57 * benchmark in the kPreWarmLoopsPerCa
nvasPreDraw_State. |
| 58 * otherwise, we enter the |
| 59 * kPreWarmTimingPerCanvasPreDraw_Stat
e for another sample |
| 60 * In either case we reset the context
. |
| 61 */ |
| 62 enum State { |
| 63 kPreWarmLoopsPerCanvasPreDraw_State, |
| 64 kPreWarmLoops_State, |
| 65 kTuneLoops_State, |
| 66 kPreWarmTimingPerCanvasPreDraw_State, |
| 67 kPreWarmTiming_State, |
| 68 kTiming_State, |
| 69 }; |
42 void setTitle(); | 70 void setTitle(); |
43 bool setupBackend(); | 71 bool setupBackend(); |
44 void resetContext(); | 72 void resetContext(); |
45 void setupRenderTarget(); | 73 void setupRenderTarget(); |
46 bool onHandleChar(SkUnichar unichar) override; | 74 bool onHandleChar(SkUnichar unichar) override; |
47 void printStats(); | 75 void printStats(); |
48 bool advanceRecordIfNecessary(SkCanvas*); | 76 bool advanceRecordIfNecessary(SkCanvas*); |
49 inline void renderFrame(SkCanvas*); | 77 inline void renderFrame(SkCanvas*); |
| 78 inline void nextState(State); |
| 79 void perCanvasPreDraw(SkCanvas*, State); |
| 80 void preWarm(State nextState); |
| 81 void scaleLoops(double elapsedMs); |
| 82 inline void tuneLoops(); |
| 83 inline void timing(SkCanvas*); |
| 84 inline double elapsed(); |
| 85 void resetTimingState(); |
| 86 void postDraw(SkCanvas*); |
| 87 void recordMeasurement(); |
50 | 88 |
51 struct Record { | 89 struct Record { |
52 SkTArray<double> fMeasurements; | 90 SkTArray<double> fMeasurements; |
53 }; | 91 }; |
54 | 92 |
55 enum State { | |
56 kPreWarmLoops_State, | |
57 kTuneLoops_State, | |
58 kPreWarmTiming_State, | |
59 kTiming_State, | |
60 }; | |
61 void preWarm(State nextState); | |
62 | |
63 int fCurrentSample; | 93 int fCurrentSample; |
64 int fCurrentFrame; | 94 int fCurrentFrame; |
65 int fFlushes; | 95 int fFlushes; |
66 int fLoops; | 96 int fLoops; |
67 SkTArray<Record> fRecords; | 97 SkTArray<Record> fRecords; |
68 WallTimer fTimer; | 98 WallTimer fTimer; |
69 State fState; | 99 State fState; |
70 SkAutoTDelete<VisualBenchmarkStream> fBenchmarkStream; | 100 SkAutoTDelete<VisualBenchmarkStream> fBenchmarkStream; |
71 SkAutoTUnref<Benchmark> fBenchmark; | 101 SkAutoTUnref<Benchmark> fBenchmark; |
72 | 102 |
73 // support framework | 103 // support framework |
74 SkAutoTUnref<SkSurface> fSurface; | 104 SkAutoTUnref<SkSurface> fSurface; |
75 SkAutoTUnref<GrContext> fContext; | 105 SkAutoTUnref<GrContext> fContext; |
76 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 106 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
77 AttachmentInfo fAttachmentInfo; | 107 AttachmentInfo fAttachmentInfo; |
78 SkAutoTUnref<const GrGLInterface> fInterface; | 108 SkAutoTUnref<const GrGLInterface> fInterface; |
79 | 109 |
80 typedef SkOSWindow INHERITED; | 110 typedef SkOSWindow INHERITED; |
81 }; | 111 }; |
82 | 112 |
83 #endif | 113 #endif |
OLD | NEW |