30 : fCurrentMeasurement(-1)
32 , fCumulativeMeasurementTime(0)
33 , fCumulativeMeasurementCount(0)
34 , fDisplayScale(1.0f) {
35 memset(fTotalTimes, 0,
sizeof(fTotalTimes));
39 for (
int i = 0;
i < fTimers.
size(); ++
i) {
40 memset(fTimers[
i].fTimes, 0,
sizeof(fTimers[
i].fTimes));
42 memset(fTotalTimes, 0,
sizeof(fTotalTimes));
43 fCurrentMeasurement = -1;
45 fCumulativeMeasurementTime = 0;
46 fCumulativeMeasurementCount = 0;
52 memset(newData.fTimes, 0,
sizeof(newData.fTimes));
53 newData.fLabel = label;
54 newData.fColor =
color;
55 newData.fLabelColor = labelColor ? labelColor :
color;
60 if (fCurrentMeasurement >= 0) {
66 if (fCurrentMeasurement >= 0) {
72 if (fCurrentMeasurement >= 0) {
74 fCumulativeMeasurementTime += fTotalTimes[fCurrentMeasurement];
75 fCumulativeMeasurementCount++;
77 fCurrentMeasurement = (fCurrentMeasurement + 1) & (kMeasurementCount - 1);
78 SkASSERT(fCurrentMeasurement >= 0 && fCurrentMeasurement < kMeasurementCount);
83 int nextMeasurement = (fCurrentMeasurement + 1) & (kMeasurementCount - 1);
84 for (
int i = 0;
i < fTimers.
size(); ++
i) {
85 fTimers[
i].fTimes[nextMeasurement] = 0;
88#ifdef SK_BUILD_FOR_ANDROID
96 static const float kPixelPerMS = 2.0f;
97 static const int kDisplayWidth = 192;
98 static const int kGraphHeight = 100;
100 static const int kDisplayHeight = kGraphHeight +
kTextHeight;
101 static const int kDisplayPadding = 10;
102 static const int kGraphPadding = 3;
103 static const SkScalar kBaseMS = 1000.f / 60.f;
105 auto canvas =
surface->getCanvas();
106 SkISize canvasSize = canvas->getBaseLayerSize();
124 canvas->drawLine(
rect.fLeft,
rect.fBottom - kBaseMS*kPixelPerMS,
133 int i = nextMeasurement;
136 memset(sumTimes.
begin(), 0, sumTimes.
size() *
sizeof(
double));
138 double totalTime = 0;
143 for (
int timer = 0; timer < fTimers.
size(); ++timer) {
144 int height = (
int)(fTimers[timer].fTimes[
i] * kPixelPerMS + 0.5);
146 paint.setColor(fTimers[timer].fColor);
150 inc += fTimers[timer].fTimes[
i];
151 sumTimes[timer] += fTimers[timer].fTimes[
i];
154 int height = (
int)(fTotalTimes[
i] * kPixelPerMS + 0.5);
160 totalTime += fTotalTimes[
i];
161 if (fTotalTimes[
i] > 0) {
170 i &= (kMeasurementCount - 1);
172 }
while (
i != nextMeasurement);
177 double measure = fCumulativeMeasurementTime /
std::max(1, fCumulativeMeasurementCount);
181 for (
int timer = 0; timer < fTimers.
size(); ++timer) {
182 paint.setColor(fTimers[timer].fLabelColor);
183 canvas->drawString(
SkStringPrintf(
"%s: %4.3f ms", fTimers[timer].fLabel.c_str(),
constexpr SkColor SK_ColorLTGRAY
constexpr SkColor SK_ColorRED
constexpr SkColor SK_ColorBLACK
constexpr SkColor SK_ColorWHITE
#define SkScalarTruncToInt(x)
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
static SkMatrix RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
@ kStroke_Style
set to stroke geometry
@ kFill_Style
set to fill geometry
Timer addTimer(const char *label, SkColor color, SkColor labelColor=0)
void onPrePaint() override
void onPaint(SkSurface *) override
constexpr SkScalar kTextHeight
static float max(float r, float g, float b)
sk_sp< SkBlender > blender SkRect rect
font
Font Metadata and Metrics.
static double time(int loops, Benchmark *bench, Target *target)
constexpr int32_t width() const
constexpr int32_t height() const
static SkRect Make(const SkISize &size)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)