Debian Codegraph @

tools/viewer/StatsLayer.h

raw
1 /*
2 * Copyright 2017 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 #ifndef StatsLayer_DEFINED
9 #define StatsLayer_DEFINED
10
11 #include "include/core/SkColor.h"
12 #include "include/core/SkString.h"
13 #include "include/private/base/SkTArray.h"
14 #include "tools/sk_app/Window.h"
15
16 class SkSurface;
17
18 class StatsLayer : public sk_app::Window::Layer {
19 public:
20 StatsLayer();
21 void resetMeasurements();
22
23 typedef int Timer;
24
25 Timer addTimer(const char* label, SkColor color, SkColor labelColor = 0);
26 void beginTiming(Timer);
27 void endTiming(Timer);
28
29 void enableGpuTimer(SkColor color);
30 void disableGpuTimer();
31 bool isGpuTimerEnabled() const { return fGpuTimerEnabled; }
32 std::function<void(uint64_t ns)> issueGpuTimer();
33
34 void onPrePaint() override;
35 void onPaint(SkSurface*) override;
36
37 void setDisplayScale(float scale) { fDisplayScale = scale; }
38
39 private:
40 static const int kMeasurementCount = 1 << 6; // should be power of 2 for fast mod
41 struct TimerData {
42 double fTimes[kMeasurementCount];
43 SkString fLabel;
44 SkColor fColor;
45 SkColor fLabelColor;
46 };
47 skia_private::TArray<TimerData> fTimers;
48 double fTotalTimes[kMeasurementCount];
49
50 TimerData fGpuTimer;
51 bool fGpuTimerEnabled = false;
52
53 int fCurrentMeasurement;
54 double fLastTotalBegin;
55 double fCumulativeMeasurementTime;
56 int fCumulativeMeasurementCount;
57 float fDisplayScale;
58 };
59
60 #endif