Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 95b099f

Browse files
committed
typedefs
1 parent cac1a8e commit 95b099f

10 files changed

+61
-59
lines changed

ci/licenses_golden/licenses_flutter

+2
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,7 @@ ORIGIN: ../../../flutter/impeller/base/thread.cc + ../../../flutter/LICENSE
11461146
ORIGIN: ../../../flutter/impeller/base/thread.h + ../../../flutter/LICENSE
11471147
ORIGIN: ../../../flutter/impeller/base/thread_safety.cc + ../../../flutter/LICENSE
11481148
ORIGIN: ../../../flutter/impeller/base/thread_safety.h + ../../../flutter/LICENSE
1149+
ORIGIN: ../../../flutter/impeller/base/timing.h + ../../../flutter/LICENSE
11491150
ORIGIN: ../../../flutter/impeller/base/validation.cc + ../../../flutter/LICENSE
11501151
ORIGIN: ../../../flutter/impeller/base/validation.h + ../../../flutter/LICENSE
11511152
ORIGIN: ../../../flutter/impeller/base/version.cc + ../../../flutter/LICENSE
@@ -3614,6 +3615,7 @@ FILE: ../../../flutter/impeller/base/thread.cc
36143615
FILE: ../../../flutter/impeller/base/thread.h
36153616
FILE: ../../../flutter/impeller/base/thread_safety.cc
36163617
FILE: ../../../flutter/impeller/base/thread_safety.h
3618+
FILE: ../../../flutter/impeller/base/timing.h
36173619
FILE: ../../../flutter/impeller/base/validation.cc
36183620
FILE: ../../../flutter/impeller/base/validation.h
36193621
FILE: ../../../flutter/impeller/base/version.cc

impeller/base/timing.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#pragma once
6+
7+
#include <chrono>
8+
9+
namespace impeller {
10+
11+
using SecondsF = std::chrono::duration<float>;
12+
using Clock = std::chrono::high_resolution_clock;
13+
using TimePoint = std::chrono::time_point<std::chrono::high_resolution_clock>;
14+
15+
} // namespace impeller

impeller/scene/animation/animation.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const std::vector<Animation::Channel>& Animation::GetChannels() const {
117117
return channels_;
118118
}
119119

120-
std::chrono::duration<Scalar> Animation::GetEndTime() const {
120+
SecondsF Animation::GetEndTime() const {
121121
return end_time_;
122122
}
123123

impeller/scene/animation/animation.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "flutter/fml/hash_combine.h"
1212
#include "flutter/fml/macros.h"
13+
#include "impeller/base/timing.h"
1314
#include "impeller/geometry/quaternion.h"
1415
#include "impeller/geometry/scalar.h"
1516
#include "impeller/geometry/vector.h"
@@ -60,14 +61,14 @@ class Animation final {
6061

6162
const std::vector<Channel>& GetChannels() const;
6263

63-
std::chrono::duration<Scalar> GetEndTime() const;
64+
SecondsF GetEndTime() const;
6465

6566
private:
6667
Animation();
6768

6869
std::string name_;
6970
std::vector<Channel> channels_;
70-
std::chrono::duration<Scalar> end_time_;
71+
SecondsF end_time_;
7172

7273
FML_DISALLOW_COPY_AND_ASSIGN(Animation);
7374
};

impeller/scene/animation/animation_clip.cc

+16-20
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "impeller/scene/animation/animation_clip.h"
66

77
#include <algorithm>
8-
#include <chrono>
98
#include <cmath>
109
#include <memory>
1110
#include <valarray>
@@ -44,7 +43,7 @@ void AnimationClip::Pause() {
4443

4544
void AnimationClip::Stop() {
4645
SetPlaying(false);
47-
Seek(std::chrono::duration<Scalar>::zero());
46+
Seek(SecondsF::zero());
4847
}
4948

5049
bool AnimationClip::GetLoop() const {
@@ -71,17 +70,16 @@ void AnimationClip::SetWeight(Scalar weight) {
7170
weight_ = weight;
7271
}
7372

74-
std::chrono::duration<Scalar> AnimationClip::GetPlaybackTime() const {
73+
SecondsF AnimationClip::GetPlaybackTime() const {
7574
return playback_time_;
7675
}
7776

78-
void AnimationClip::Seek(std::chrono::duration<Scalar> time) {
79-
playback_time_ = std::clamp(time, std::chrono::duration<Scalar>::zero(),
80-
animation_->GetEndTime());
77+
void AnimationClip::Seek(SecondsF time) {
78+
playback_time_ = std::clamp(time, SecondsF::zero(), animation_->GetEndTime());
8179
}
8280

83-
void AnimationClip::Advance(std::chrono::duration<Scalar> delta_time) {
84-
if (!playing_ || delta_time <= std::chrono::duration<Scalar>::zero()) {
81+
void AnimationClip::Advance(SecondsF delta_time) {
82+
if (!playing_ || delta_time <= SecondsF::zero()) {
8583
return;
8684
}
8785
delta_time *= playback_time_scale_;
@@ -90,27 +88,25 @@ void AnimationClip::Advance(std::chrono::duration<Scalar> delta_time) {
9088
/// Handle looping behavior.
9189

9290
auto end_time = animation_->GetEndTime();
93-
if (end_time == std::chrono::duration<Scalar>::zero()) {
94-
playback_time_ = std::chrono::duration<Scalar>::zero();
91+
if (end_time == SecondsF::zero()) {
92+
playback_time_ = SecondsF::zero();
9593
return;
9694
}
97-
if (!loop_ && (playback_time_ < std::chrono::duration<Scalar>::zero() ||
98-
playback_time_ > end_time)) {
95+
if (!loop_ &&
96+
(playback_time_ < SecondsF::zero() || playback_time_ > end_time)) {
9997
// If looping is disabled, clamp to the end (or beginning, if playing in
10098
// reverse) and pause.
10199
Pause();
102-
playback_time_ = std::clamp(
103-
playback_time_, std::chrono::duration<Scalar>::zero(), end_time);
100+
playback_time_ = std::clamp(playback_time_, SecondsF::zero(), end_time);
104101
} else if (/* loop && */ playback_time_ > end_time) {
105102
// If looping is enabled and we ran off the end, loop to the beginning.
106-
playback_time_ = std::chrono::duration<Scalar>(
107-
std::fmod(std::abs(playback_time_.count()), end_time.count()));
108-
} else if (/* loop && */ playback_time_ <
109-
std::chrono::duration<Scalar>::zero()) {
103+
playback_time_ =
104+
SecondsF(std::fmod(std::abs(playback_time_.count()), end_time.count()));
105+
} else if (/* loop && */ playback_time_ < SecondsF::zero()) {
110106
// If looping is enabled and we ran off the beginning, loop to the end.
111107
playback_time_ =
112-
end_time - std::chrono::duration<Scalar>(std::fmod(
113-
std::abs(playback_time_.count()), end_time.count()));
108+
end_time -
109+
SecondsF(std::fmod(std::abs(playback_time_.count()), end_time.count()));
114110
}
115111
}
116112

impeller/scene/animation/animation_clip.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ class AnimationClip final {
4949
void SetWeight(Scalar weight);
5050

5151
/// @brief Get the current playback time of the animation.
52-
std::chrono::duration<Scalar> GetPlaybackTime() const;
52+
SecondsF GetPlaybackTime() const;
5353

5454
/// @brief Move the animation to the specified time. The given `time` is
5555
/// clamped to the animation's playback range.
56-
void Seek(std::chrono::duration<Scalar> time);
56+
void Seek(SecondsF time);
5757

5858
/// @brief Advance the animation by `delta_time` seconds. Negative
5959
/// `delta_time` values do nothing.
60-
void Advance(std::chrono::duration<Scalar> delta_time);
60+
void Advance(SecondsF delta_time);
6161

6262
/// @brief Applies the animation to all binded properties in the scene.
6363
void ApplyToBindings() const;
@@ -73,7 +73,7 @@ class AnimationClip final {
7373
std::shared_ptr<Animation> animation_;
7474
std::vector<ChannelBinding> bindings_;
7575

76-
std::chrono::duration<Scalar> playback_time_;
76+
SecondsF playback_time_;
7777
Scalar playback_time_scale_ = 1; // Seconds multiplier, can be negative.
7878
Scalar weight_ = 1;
7979
bool playing_ = false;

impeller/scene/animation/animation_player.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
#include "impeller/scene/animation/animation_player.h"
66

7-
#include <chrono>
87
#include <memory>
98

109
#include "flutter/fml/time/time_point.h"
10+
#include "impeller/base/timing.h"
1111
#include "impeller/scene/node.h"
1212

1313
namespace impeller {
@@ -37,9 +37,9 @@ AnimationClip& AnimationPlayer::AddAnimation(
3737

3838
void AnimationPlayer::Update() {
3939
if (!previous_time_.has_value()) {
40-
previous_time_ = std::chrono::high_resolution_clock::now();
40+
previous_time_ = Clock::now();
4141
}
42-
auto new_time = std::chrono::high_resolution_clock::now();
42+
auto new_time = Clock::now();
4343
auto delta_time = new_time - previous_time_.value();
4444
previous_time_ = new_time;
4545

impeller/scene/animation/animation_player.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#pragma once
66

7-
#include <chrono>
87
#include <memory>
98
#include <optional>
109
#include <unordered_set>
@@ -13,6 +12,7 @@
1312
#include "flutter/fml/hash_combine.h"
1413
#include "flutter/fml/macros.h"
1514
#include "flutter/fml/time/time_delta.h"
15+
#include "impeller/base/timing.h"
1616
#include "impeller/geometry/matrix.h"
1717
#include "impeller/scene/animation/animation_clip.h"
1818

@@ -43,8 +43,7 @@ class AnimationPlayer final {
4343

4444
std::vector<AnimationClip> clips_;
4545

46-
std::optional<std::chrono::time_point<std::chrono::high_resolution_clock>>
47-
previous_time_;
46+
std::optional<TimePoint> previous_time_;
4847

4948
FML_DISALLOW_COPY_AND_ASSIGN(AnimationPlayer);
5049
};

impeller/scene/animation/property_resolver.cc

+7-10
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,14 @@ PropertyResolver::~PropertyResolver() = default;
5151

5252
TimelineResolver::~TimelineResolver() = default;
5353

54-
std::chrono::duration<Scalar> TimelineResolver::GetEndTime() {
54+
SecondsF TimelineResolver::GetEndTime() {
5555
if (times_.empty()) {
56-
return std::chrono::duration<Scalar>::zero();
56+
return SecondsF::zero();
5757
}
58-
return std::chrono::duration<Scalar>(times_.back());
58+
return SecondsF(times_.back());
5959
}
6060

61-
TimelineResolver::TimelineKey TimelineResolver::GetTimelineKey(
62-
std::chrono::duration<Scalar> time) {
61+
TimelineResolver::TimelineKey TimelineResolver::GetTimelineKey(SecondsF time) {
6362
if (times_.size() <= 1 || time.count() <= times_.front()) {
6463
return {.index = 0, .lerp = 1};
6564
}
@@ -80,7 +79,7 @@ TranslationTimelineResolver::TranslationTimelineResolver() = default;
8079
TranslationTimelineResolver::~TranslationTimelineResolver() = default;
8180

8281
void TranslationTimelineResolver::Apply(Node& target,
83-
std::chrono::duration<Scalar> time,
82+
SecondsF time,
8483
Scalar weight) {
8584
if (values_.empty()) {
8685
return;
@@ -99,7 +98,7 @@ RotationTimelineResolver::RotationTimelineResolver() = default;
9998
RotationTimelineResolver::~RotationTimelineResolver() = default;
10099

101100
void RotationTimelineResolver::Apply(Node& target,
102-
std::chrono::duration<Scalar> time,
101+
SecondsF time,
103102
Scalar weight) {
104103
if (values_.empty()) {
105104
return;
@@ -117,9 +116,7 @@ ScaleTimelineResolver::ScaleTimelineResolver() = default;
117116

118117
ScaleTimelineResolver::~ScaleTimelineResolver() = default;
119118

120-
void ScaleTimelineResolver::Apply(Node& target,
121-
std::chrono::duration<Scalar> time,
122-
Scalar weight) {
119+
void ScaleTimelineResolver::Apply(Node& target, SecondsF time, Scalar weight) {
123120
if (values_.empty()) {
124121
return;
125122
}

impeller/scene/animation/property_resolver.h

+8-16
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
#pragma once
66

7-
#include <chrono>
87
#include <memory>
98
#include <string>
109
#include <vector>
1110

1211
#include "flutter/fml/hash_combine.h"
1312
#include "flutter/fml/macros.h"
13+
#include "impeller/base/timing.h"
1414
#include "impeller/geometry/quaternion.h"
1515
#include "impeller/geometry/scalar.h"
1616
#include "impeller/geometry/vector.h"
@@ -39,24 +39,22 @@ class PropertyResolver {
3939

4040
virtual ~PropertyResolver();
4141

42-
virtual std::chrono::duration<Scalar> GetEndTime() = 0;
42+
virtual SecondsF GetEndTime() = 0;
4343

4444
/// @brief Resolve and apply the property value to a target node. This
4545
/// operation is additive; a given node property may be amended by
4646
/// many different PropertyResolvers prior to rendering. For example,
4747
/// an AnimationPlayer may blend multiple Animations together by
4848
/// applying several AnimationClips.
49-
virtual void Apply(Node& target,
50-
std::chrono::duration<Scalar> time,
51-
Scalar weight) = 0;
49+
virtual void Apply(Node& target, SecondsF time, Scalar weight) = 0;
5250
};
5351

5452
class TimelineResolver : public PropertyResolver {
5553
public:
5654
virtual ~TimelineResolver();
5755

5856
// |Resolver|
59-
std::chrono::duration<Scalar> GetEndTime();
57+
SecondsF GetEndTime();
6058

6159
protected:
6260
struct TimelineKey {
@@ -66,7 +64,7 @@ class TimelineResolver : public PropertyResolver {
6664
/// and `timeline_index`. The range of this value should always be `0>N>=1`.
6765
Scalar lerp = 1;
6866
};
69-
TimelineKey GetTimelineKey(std::chrono::duration<Scalar> time);
67+
TimelineKey GetTimelineKey(SecondsF time);
7068

7169
std::vector<Scalar> times_;
7270
};
@@ -76,9 +74,7 @@ class TranslationTimelineResolver final : public TimelineResolver {
7674
~TranslationTimelineResolver();
7775

7876
// |Resolver|
79-
void Apply(Node& target,
80-
std::chrono::duration<Scalar> time,
81-
Scalar weight) override;
77+
void Apply(Node& target, SecondsF time, Scalar weight) override;
8278

8379
private:
8480
TranslationTimelineResolver();
@@ -95,9 +91,7 @@ class RotationTimelineResolver final : public TimelineResolver {
9591
~RotationTimelineResolver();
9692

9793
// |Resolver|
98-
void Apply(Node& target,
99-
std::chrono::duration<Scalar> time,
100-
Scalar weight) override;
94+
void Apply(Node& target, SecondsF time, Scalar weight) override;
10195

10296
private:
10397
RotationTimelineResolver();
@@ -114,9 +108,7 @@ class ScaleTimelineResolver final : public TimelineResolver {
114108
~ScaleTimelineResolver();
115109

116110
// |Resolver|
117-
void Apply(Node& target,
118-
std::chrono::duration<Scalar> time,
119-
Scalar weight) override;
111+
void Apply(Node& target, SecondsF time, Scalar weight) override;
120112

121113
private:
122114
ScaleTimelineResolver();

0 commit comments

Comments
 (0)