Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Attributes | Friends | List of all members
flutter::VolatilePathTracker Class Reference

#include <volatile_path_tracker.h>

Classes

struct  TrackedPath
 The fields of this struct must only accessed on the UI task runner. More...
 

Public Member Functions

 VolatilePathTracker (fml::RefPtr< fml::TaskRunner > ui_task_runner, bool enabled)
 
void Track (const std::shared_ptr< TrackedPath > &path)
 
void OnFrame ()
 
bool enabled () const
 

Static Public Attributes

static constexpr int kFramesOfVolatility = 2
 

Friends

class testing::ShellTest
 

Detailed Description

A cache for paths drawn from dart:ui.

Whenever a flutter::CanvasPath is created, it must Insert an entry into this cache. Whenever a frame is drawn, the shell must call OnFrame. The cache will flip the volatility bit on the SkPath and remove it from the cache. If the Dart object is released, Erase must be called to avoid tracking a path that is no longer referenced in Dart code.

Enabling this cache may cause difficult to predict minor pixel differences when paths are rendered. If deterministic rendering is needed, e.g. for a screen diffing test, this class will not cache any paths and will automatically set the volatility of the path to false.

Definition at line 36 of file volatile_path_tracker.h.

Constructor & Destructor Documentation

◆ VolatilePathTracker()

flutter::VolatilePathTracker::VolatilePathTracker ( fml::RefPtr< fml::TaskRunner ui_task_runner,
bool  enabled 
)

Definition at line 11 of file volatile_path_tracker.cc.

14 : ui_task_runner_(std::move(ui_task_runner)), enabled_(enabled) {}

Member Function Documentation

◆ enabled()

bool flutter::VolatilePathTracker::enabled ( ) const
inline

Definition at line 65 of file volatile_path_tracker.h.

65{ return enabled_; }

◆ OnFrame()

void flutter::VolatilePathTracker::OnFrame ( )

Definition at line 27 of file volatile_path_tracker.cc.

27 {
28 FML_DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
29 if (!enabled_) {
30 return;
31 }
32
33 paths_.erase(std::remove_if(paths_.begin(), paths_.end(),
34 [](const std::weak_ptr<TrackedPath>& weak_path) {
35 auto path = weak_path.lock();
36 if (!path) {
37 return true;
38 }
39 path->frame_count++;
40 if (path->frame_count >= kFramesOfVolatility) {
41 path->path.setIsVolatile(false);
42 path->tracking_volatility = false;
43 return true;
44 }
45 return false;
46 }),
47 paths_.end());
48}
static constexpr int kFramesOfVolatility
virtual bool RunsTasksOnCurrentThread()
Definition: task_runner.cc:43
if(end==-1)
#define FML_DCHECK(condition)
Definition: logging.h:103
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ Track()

void flutter::VolatilePathTracker::Track ( const std::shared_ptr< TrackedPath > &  path)

Definition at line 16 of file volatile_path_tracker.cc.

16 {
17 FML_DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
19 FML_DCHECK(path->path.isVolatile());
20 if (!enabled_) {
21 path->path.setIsVolatile(false);
22 return;
23 }
24 paths_.push_back(path);
25}

Friends And Related Function Documentation

◆ testing::ShellTest

friend class testing::ShellTest
friend

Definition at line 72 of file volatile_path_tracker.h.

Member Data Documentation

◆ kFramesOfVolatility

constexpr int flutter::VolatilePathTracker::kFramesOfVolatility = 2
staticconstexpr

Definition at line 48 of file volatile_path_tracker.h.


The documentation for this class was generated from the following files: