Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Unified Diff: gm/SkAnimTimer.h

Issue 1811613004: Change SkTime::GetMSecs to double; ensure values stored in SkMSec do not overflow. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Rebase. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dm/DM.cpp ('k') | include/animator/SkAnimator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/SkAnimTimer.h
diff --git a/gm/SkAnimTimer.h b/gm/SkAnimTimer.h
index 725171a8fe55034ab223565f8653016571cf22c2..2c8a723e5bb970d0799e1a802536ad5e6715b95a 100644
--- a/gm/SkAnimTimer.h
+++ b/gm/SkAnimTimer.h
@@ -29,7 +29,7 @@ public:
/**
* Class begins in the "stopped" state.
*/
- SkAnimTimer() : fBaseTime(0), fCurrTime(0), fState(kStopped_State) {}
+ SkAnimTimer() : fBaseTimeNanos(0), fCurrTimeNanos(0), fState(kStopped_State) {}
bool isStopped() const { return kStopped_State == fState; }
bool isRunning() const { return kRunning_State == fState; }
@@ -70,23 +70,26 @@ public:
*/
void updateTime() {
if (kRunning_State == fState) {
- fCurrTime = SkTime::GetMSecs();
+ fCurrTimeNanos = SkTime::GetNSecs();
}
}
/**
* Return the time in milliseconds the timer has been in the running state.
- * Returns 0 if the timer is stopped.
+ * Returns 0 if the timer is stopped. Behavior is undefined if the timer
+ * has been running longer than SK_MSecMax.
*/
- SkMSec msec() const { return fCurrTime - fBaseTime; }
+ SkMSec msec() const {
+ const double msec = (fCurrTimeNanos - fBaseTimeNanos) * 1e-6;
+ SkASSERT(SK_MSecMax >= msec);
+ return static_cast<SkMSec>(msec);
+ }
/**
* Return the time in seconds the timer has been in the running state.
* Returns 0 if the timer is stopped.
*/
- double secs() const {
- return this->msec() * 0.001;
- }
+ double secs() const { return (fCurrTimeNanos - fBaseTimeNanos) * 1e-9; }
/**
* Return the time in seconds the timer has been in the running state,
@@ -102,14 +105,14 @@ public:
}
private:
- SkMSec fBaseTime;
- SkMSec fCurrTime;
+ double fBaseTimeNanos;
+ double fCurrTimeNanos;
State fState;
void setState(State newState) {
switch (newState) {
case kStopped_State:
- fBaseTime = fCurrTime = 0;
+ fBaseTimeNanos = fCurrTimeNanos = 0;
fState = kStopped_State;
break;
case kPaused_State:
@@ -120,12 +123,12 @@ private:
case kRunning_State:
switch (fState) {
case kStopped_State:
- fBaseTime = fCurrTime = SkTime::GetMSecs();
+ fBaseTimeNanos = fCurrTimeNanos = SkTime::GetNSecs();
break;
case kPaused_State: {// they want "resume"
- SkMSec now = SkTime::GetMSecs();
- fBaseTime += now - fCurrTime;
- fCurrTime = now;
+ double now = SkTime::GetNSecs();
+ fBaseTimeNanos += now - fCurrTimeNanos;
+ fCurrTimeNanos = now;
} break;
case kRunning_State:
break;
« no previous file with comments | « dm/DM.cpp ('k') | include/animator/SkAnimator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698