• 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 "SkColor.h"
12 #include "SkString.h"
13 #include "sk_app/Window.h"
14 
15 class StatsLayer : public sk_app::Window::Layer {
16 public:
17     StatsLayer();
18     void resetMeasurements();
19 
20     typedef int Timer;
21 
22     Timer addTimer(const char* label, SkColor color, SkColor labelColor = 0);
23     void beginTiming(Timer);
24     void endTiming(Timer);
25     double getLastTime(Timer);
26 
27     void onPaint(SkCanvas* canvas) override;
28 
setDisplayScale(float scale)29     void setDisplayScale(float scale) { fDisplayScale = scale; }
30 
31 private:
32     static const int kMeasurementCount = 1 << 6;  // should be power of 2 for fast mod
33     struct TimerData {
34         double fTimes[kMeasurementCount];
35         SkString fLabel;
36         SkColor fColor;
37         SkColor fLabelColor;
38     };
39     SkTArray<TimerData> fTimers;
40     int fCurrentMeasurement;
41     double fCumulativeMeasurementTime;
42     int fCumulativeMeasurementCount;
43     float fDisplayScale;
44 };
45 
46 #endif
47