blob: 79f4a780f096fcc1045bff6e6d4a3604abfc14c8 [file] [log] [blame]
Brian Osman56a24812017-12-19 11:15:16 -05001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkColor.h"
12#include "include/core/SkString.h"
13#include "tools/sk_app/Window.h"
Brian Osman56a24812017-12-19 11:15:16 -050014
15class StatsLayer : public sk_app::Window::Layer {
16public:
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);
Brian Osman56a24812017-12-19 11:15:16 -050025
Greg Daniel655002b2019-03-21 14:43:00 -040026 void onPrePaint() override;
Robert Phillips9882dae2019-03-04 11:00:10 -050027 void onPaint(SkSurface*) override;
Brian Osman56a24812017-12-19 11:15:16 -050028
Brian Osmanb63f6002018-07-24 18:01:53 -040029 void setDisplayScale(float scale) { fDisplayScale = scale; }
30
Brian Osman56a24812017-12-19 11:15:16 -050031private:
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;
Greg Daniel655002b2019-03-21 14:43:00 -040040 double fTotalTimes[kMeasurementCount];
Brian Osman56a24812017-12-19 11:15:16 -050041 int fCurrentMeasurement;
Greg Daniel655002b2019-03-21 14:43:00 -040042 double fLastTotalBegin;
Brian Osman56a24812017-12-19 11:15:16 -050043 double fCumulativeMeasurementTime;
44 int fCumulativeMeasurementCount;
Brian Osmanb63f6002018-07-24 18:01:53 -040045 float fDisplayScale;
Brian Osman56a24812017-12-19 11:15:16 -050046};
47
48#endif