StatsLayer.h 1.2 KB

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