• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 onPrePaint() override;
30     void onPaint(SkSurface*) override;
31 
setDisplayScale(float scale)32     void setDisplayScale(float scale) { fDisplayScale = scale; }
33 
34 private:
35     static const int kMeasurementCount = 1 << 6;  // should be power of 2 for fast mod
36     struct TimerData {
37         double fTimes[kMeasurementCount];
38         SkString fLabel;
39         SkColor fColor;
40         SkColor fLabelColor;
41     };
42     skia_private::TArray<TimerData> fTimers;
43     double fTotalTimes[kMeasurementCount];
44     int fCurrentMeasurement;
45     double fLastTotalBegin;
46     double fCumulativeMeasurementTime;
47     int fCumulativeMeasurementCount;
48     float fDisplayScale;
49 };
50 
51 #endif
52