forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvolatile_path_tracker.cc
50 lines (42 loc) · 1.64 KB
/
volatile_path_tracker.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/lib/ui/volatile_path_tracker.h"
#include <utility>
namespace flutter {
VolatilePathTracker::VolatilePathTracker(
fml::RefPtr<fml::TaskRunner> ui_task_runner,
bool enabled)
: ui_task_runner_(std::move(ui_task_runner)), enabled_(enabled) {}
void VolatilePathTracker::Track(const std::shared_ptr<TrackedPath>& path) {
FML_DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
FML_DCHECK(path);
FML_DCHECK(path->path.isVolatile());
if (!enabled_) {
path->path.setIsVolatile(false);
return;
}
paths_.push_back(path);
}
void VolatilePathTracker::OnFrame() {
FML_DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
if (!enabled_) {
return;
}
paths_.erase(std::remove_if(paths_.begin(), paths_.end(),
[](const std::weak_ptr<TrackedPath>& weak_path) {
auto path = weak_path.lock();
if (!path) {
return true;
}
path->frame_count++;
if (path->frame_count >= kFramesOfVolatility) {
path->path.setIsVolatile(false);
path->tracking_volatility = false;
return true;
}
return false;
}),
paths_.end());
}
} // namespace flutter