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 "tools/sk_app/Window.h" 14 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); 25 26 void onPrePaint() override; 27 void onPaint(SkSurface*) override; 28 29 void setDisplayScale(float scale) { fDisplayScale = scale; } 30 31private: 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 double fTotalTimes[kMeasurementCount]; 41 int fCurrentMeasurement; 42 double fLastTotalBegin; 43 double fCumulativeMeasurementTime; 44 int fCumulativeMeasurementCount; 45 float fDisplayScale; 46}; 47 48#endif 49