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

Side by Side Diff: gm/SkAnimTimer.h

Issue 1974353003: Add blurcircles2 GM (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: more warning fixes Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | gm/blurcircles2.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkTime.h" 8 #include "SkTime.h"
9 9
10 #ifndef SkAnimTimer_DEFINED 10 #ifndef SkAnimTimer_DEFINED
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 * Returns 0 if the timer is stopped. 97 * Returns 0 if the timer is stopped.
98 */ 98 */
99 SkScalar scaled(SkScalar speed, SkScalar period = 0) const { 99 SkScalar scaled(SkScalar speed, SkScalar period = 0) const {
100 double value = this->secs() * speed; 100 double value = this->secs() * speed;
101 if (period) { 101 if (period) {
102 value = ::fmod(value, SkScalarToDouble(period)); 102 value = ::fmod(value, SkScalarToDouble(period));
103 } 103 }
104 return SkDoubleToScalar(value); 104 return SkDoubleToScalar(value);
105 } 105 }
106 106
107 /**
108 * Transitions from ends->mid->ends linearly over period seconds. The phase specifies a phase
109 * shift in seconds.
110 */
111 SkScalar pingPong(SkScalar period, SkScalar phase, SkScalar ends, SkScalar m id) const {
112 return PingPong(this->secs(), period, phase, ends, mid);
113 }
114
115 /** Helper for computing a ping-pong value without a SkAnimTimer object. */
116 static SkScalar PingPong(double t, SkScalar period, SkScalar phase, SkScalar ends,
117 SkScalar mid) {
118 double value = ::fmod(t + phase, period);
119 double half = period / 2.0;
120 double diff = ::fabs(value - half);
121 return SkDoubleToScalar(ends + (1.0 - diff / half) * (mid - ends));
122 }
123
107 private: 124 private:
108 double fBaseTimeNanos; 125 double fBaseTimeNanos;
109 double fCurrTimeNanos; 126 double fCurrTimeNanos;
110 State fState; 127 State fState;
111 128
112 void setState(State newState) { 129 void setState(State newState) {
113 switch (newState) { 130 switch (newState) {
114 case kStopped_State: 131 case kStopped_State:
115 fBaseTimeNanos = fCurrTimeNanos = 0; 132 fBaseTimeNanos = fCurrTimeNanos = 0;
116 fState = kStopped_State; 133 fState = kStopped_State;
(...skipping 16 matching lines...) Expand all
133 case kRunning_State: 150 case kRunning_State:
134 break; 151 break;
135 } 152 }
136 fState = kRunning_State; 153 fState = kRunning_State;
137 break; 154 break;
138 } 155 }
139 } 156 }
140 }; 157 };
141 158
142 #endif 159 #endif
OLDNEW
« no previous file with comments | « no previous file | gm/blurcircles2.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698