Add high resolution WallTimer to SampleApp
Gives better than 1 ms results when timing framerate.
Review URL: https://codereview.chromium.org/1288473002
diff --git a/gyp/SampleApp.gyp b/gyp/SampleApp.gyp
index 67692b7..f2301db 100644
--- a/gyp/SampleApp.gyp
+++ b/gyp/SampleApp.gyp
@@ -22,6 +22,7 @@
'../samplecode', # To pull SampleApp.h and SampleCode.h
'../src/pipe/utils', # For TiledPipeController
'../src/utils/debugger',
+ '../tools',
],
'includes': [
'gmslides.gypi',
@@ -154,6 +155,7 @@
'skia_lib.gyp:skia_lib',
'tools.gyp:resources',
'tools.gyp:sk_tool_utils',
+ 'tools.gyp:timer',
'views.gyp:views',
'views_animated.gyp:views_animated',
'xml.gyp:xml',
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 486feed..5bb223a 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -1313,8 +1313,9 @@
}
// Do this after presentGL and other finishing, rather than in afterChild
- if (fMeasureFPS && fMeasureFPS_StartTime) {
- fMeasureFPS_Time += SkTime::GetMSecs() - fMeasureFPS_StartTime;
+ if (fMeasureFPS) {
+ fTimer.end();
+ fMeasureFPS_Time += fTimer.fWall;
}
}
@@ -1351,9 +1352,8 @@
}
if (fMeasureFPS) {
- if (SampleView::SetRepeatDraw(child, FPS_REPEAT_COUNT)) {
- fMeasureFPS_StartTime = SkTime::GetMSecs();
- }
+ (void)SampleView::SetRepeatDraw(child, FPS_REPEAT_COUNT);
+ fTimer.start();
} else {
(void)SampleView::SetRepeatDraw(child, 1);
}
@@ -1935,7 +1935,7 @@
}
if (fMeasureFPS) {
- title.appendf(" %8.3f ms", fMeasureFPS_Time / (float)FPS_REPEAT_COUNT);
+ title.appendf(" %8.4f ms", fMeasureFPS_Time / (float)FPS_REPEAT_COUNT);
}
SkView* view = curr_view(this);
diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h
index 97854fc..c0f845d 100644
--- a/samplecode/SampleApp.h
+++ b/samplecode/SampleApp.h
@@ -16,6 +16,7 @@
#include "SkTDArray.h"
#include "SkTouchGesture.h"
#include "SkWindow.h"
+#include "timer/Timer.h"
class GrContext;
class GrRenderTarget;
@@ -183,8 +184,8 @@
bool fPerspAnim;
bool fRequestGrabImage;
bool fMeasureFPS;
- SkMSec fMeasureFPS_Time;
- SkMSec fMeasureFPS_StartTime;
+ WallTimer fTimer;
+ double fMeasureFPS_Time;
bool fMagnify;
int fTilingMode;