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 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 double getLastTime(Timer); 26 27 void onPaint(SkCanvas* canvas) override; 28 29private: 30 static const int kMeasurementCount = 1 << 6; // should be power of 2 for fast mod 31 struct TimerData { 32 double fTimes[kMeasurementCount]; 33 SkString fLabel; 34 SkColor fColor; 35 SkColor fLabelColor; 36 }; 37 SkTArray<TimerData> fTimers; 38 int fCurrentMeasurement; 39 double fCumulativeMeasurementTime; 40 int fCumulativeMeasurementCount; 41}; 42 43#endif 44