Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_layers_VelocityTracker_h
8
#define mozilla_layers_VelocityTracker_h
9
10
#include <utility>
11
#include <cstdint>
12
13
#include "Axis.h"
14
#include "mozilla/Attributes.h"
15
#include "nsTArray.h"
16
17
namespace mozilla {
18
namespace layers {
19
20
class SimpleVelocityTracker : public VelocityTracker {
21
public:
22
explicit SimpleVelocityTracker(Axis* aAxis);
23
void StartTracking(ParentLayerCoord aPos, uint32_t aTimestamp) override;
24
Maybe<float> AddPosition(ParentLayerCoord aPos,
25
uint32_t aTimestampMs) override;
26
float HandleDynamicToolbarMovement(uint32_t aStartTimestampMs,
27
uint32_t aEndTimestampMs,
28
ParentLayerCoord aDelta) override;
29
Maybe<float> ComputeVelocity(uint32_t aTimestampMs) override;
30
void Clear() override;
31
32
private:
33
void AddVelocityToQueue(uint32_t aTimestampMs, float aVelocity);
34
float ApplyFlingCurveToVelocity(float aVelocity) const;
35
36
// The Axis that uses this velocity tracker.
37
// This is a raw pointer because the Axis owns the velocity tracker
38
// by UniquePtr, so the velocity tracker cannot outlive the Axis.
39
Axis* MOZ_NON_OWNING_REF mAxis;
40
41
// A queue of (timestamp, velocity) pairs; these are the historical
42
// velocities at the given timestamps. Timestamps are in milliseconds,
43
// velocities are in screen pixels per ms. This member can only be
44
// accessed on the controller/UI thread.
45
nsTArray<std::pair<uint32_t, float>> mVelocityQueue;
46
47
// mVelocitySampleTimeMs and mVelocitySamplePos are the time and position
48
// used in the last velocity sampling. They get updated when a new sample is
49
// taken (which may not happen on every input event, if the time delta is too
50
// small).
51
uint32_t mVelocitySampleTimeMs;
52
ParentLayerCoord mVelocitySamplePos;
53
};
54
55
} // namespace layers
56
} // namespace mozilla
57
58
#endif