Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
fml Namespace Reference

Namespaces

namespace  benchmarking
 
namespace  icu
 
namespace  internal
 
namespace  jni
 
namespace  paths
 
namespace  scoped_policy
 
namespace  state
 
namespace  testing
 
namespace  tracing
 

Classes

class  AsciiTrie
 A trie for looking for ASCII prefixes. More...
 
class  AtomicObject
 
class  AutoResetWaitableEvent
 
class  BasicTaskRunner
 An interface over the ability to schedule tasks on a TaskRunner. More...
 
class  BitConverter
 
class  CFRef
 
class  ChronoTimestampProvider
 
class  CommandLine
 
class  ConcurrentMessageLoop
 
class  ConcurrentMessageLoopDarwin
 
class  ConcurrentTaskRunner
 
class  CountDownLatch
 
struct  CpuIndexAndSpeed
 
class  CPUSpeedTracker
 A class that computes the correct CPU indices for a requested CPU affinity. More...
 
class  DataMapping
 
struct  DebugTaskRunnerChecker
 
struct  DebugThreadChecker
 
class  DelayedTask
 
class  FileMapping
 
struct  IsByteSwappable
 
class  LogInterestListener
 
class  LogMessage
 
class  LogMessageVoidify
 
struct  LogSettings
 
class  LogState
 
class  MallocMapping
 A Mapping like NonOwnedMapping, but uses Free as its release proc. More...
 
class  ManualResetWaitableEvent
 
class  Mapping
 
class  MessageLoop
 
class  MessageLoopAndroid
 
class  MessageLoopDarwin
 
class  MessageLoopFuchsia
 
class  MessageLoopImpl
 
class  MessageLoopLinux
 
class  MessageLoopTaskQueues
 
class  MessageLoopWin
 
class  NativeLibrary
 
class  NonOwnedMapping
 
class  PlatformSemaphore
 
class  RasterThreadMerger
 
class  RefCountedThreadSafe
 
class  RefPtr
 
class  scoped_nsobject
 
class  scoped_nsobject< id >
 
class  scoped_nsprotocol
 
class  ScopedCleanupClosure
 Wraps a closure that is invoked in the destructor unless released by the caller. More...
 
class  ScopedNSAutoreleasePool
 
class  ScopedSetLogSettings
 
class  ScopedTemporaryDirectory
 
class  ScopedTypeRef
 
struct  ScopedTypeRefTraits
 
class  Semaphore
 A traditional counting semaphore. Waits decrement the counter and Signal increments it. More...
 
class  SharedLock
 
class  SharedMutex
 
class  SharedMutexPosix
 
class  SharedMutexStd
 
class  SharedThreadMerger
 
class  Status
 
class  StatusOr
 
class  SymbolMapping
 
class  SyncSwitch
 
class  TaskQueueEntry
 
class  TaskQueueId
 
class  TaskRunner
 
class  TaskRunnerAffineWeakPtr
 
class  TaskRunnerAffineWeakPtrFactory
 
class  TaskRunnerChecker
 
class  TaskSource
 
class  Thread
 
class  ThreadChecker
 
class  ThreadHandle
 
class  TimeDelta
 
class  TimePoint
 
class  TimestampProvider
 
class  UniqueLock
 
struct  UniqueLooperTraits
 
class  UniqueObject
 
class  Wakeable
 
class  WeakContainer
 
class  WeakNSObject
 
class  WeakNSObject< id >
 
class  WeakNSObjectFactory
 
class  WeakNSProtocol
 
class  WeakPtr
 
class  WeakPtrFactory
 

Typedefs

typedef AsciiTrie::TrieNode TrieNode
 
typedef AsciiTrie::TrieNodePtr TrieNodePtr
 
using Base32DecodeConverter = BitConverter< 5, 8, 16 >
 
using Base32EncodeConverter = BitConverter< 8, 5, 16 >
 
using closure = std::function< void()>
 
using DelayedTaskQueue = std::priority_queue< DelayedTask, std::deque< DelayedTask >, std::greater< DelayedTask > >
 
using FileVisitor = std::function< bool(const fml::UniqueFD &directory, const std::string &filename)>
 
typedef int LogSeverity
 
template<typename B >
using ScopedBlock = ScopedTypeRef< B, internal::ScopedBlockTraits< B > >
 
using WideStringConverter = std::wstring_convert< std::codecvt_utf8_utf16< wchar_t >, wchar_t >
 
typedef void * RasterThreadMergerId
 
using Utf16StringConverter = std::wstring_convert< std::codecvt_utf8_utf16< char16_t >, char16_t >
 
typedef std::function< void()> ThreadFunction
 
using Milliseconds = std::chrono::duration< double, std::milli >
 
using UniqueFD = UniqueObject< int, internal::os_unix::UniqueFDTraits >
 
using UniqueDir = UniqueObject< DIR *, internal::os_unix::UniqueDirTraits >
 

Enumerations

enum class  CpuAffinity { kPerformance , kEfficiency , kNotPerformance }
 
enum class  FilePermission { kRead , kWrite , kReadWrite }
 
enum class  FlushType { kSingle , kAll }
 
enum class  RasterThreadStatus { kRemainsMerged , kRemainsUnmerged , kUnmergedNow }
 
enum class  StatusCode {
  kOk , kCancelled , kUnknown , kInvalidArgument ,
  kDeadlineExceeded , kNotFound , kAlreadyExists , kPermissionDenied ,
  kResourceExhausted , kFailedPrecondition , kAborted , kOutOfRange ,
  kUnimplemented , kInternal , kUnavailable , kDataLoss ,
  kUnauthenticated
}
 
enum class  TaskSourceGrade { kUserInteraction , kDartEventLoop , kUnspecified }
 

Functions

static std::string GetSymbolName (void *symbol)
 
static int Backtrace (void **symbols, int size)
 
std::string BacktraceHere (size_t offset)
 
static std::string SignalNameToString (int signal)
 
static void ToggleSignalHandlers (bool set)
 
static void SignalHandler (int signal)
 
void InstallCrashHandler ()
 
bool IsCrashHandlingSupported ()
 
std::pair< bool, std::string > Base32Encode (std::string_view input)
 
std::pair< bool, std::string > Base32Decode (const std::string &input)
 
std::vector< std::string > CommandLineToArgv (const CommandLine &command_line)
 
template<typename InputIterator >
CommandLine CommandLineFromIteratorsFindFirstPositionalArg (InputIterator first, InputIterator last, InputIterator *first_positional_arg)
 
template<typename InputIterator >
CommandLine CommandLineFromIterators (InputIterator first, InputIterator last)
 
template<typename InputIterator >
CommandLine CommandLineFromIteratorsWithArgv0 (const std::string &argv0, InputIterator first, InputIterator last)
 
std::optional< CommandLineCommandLineFromPlatform ()
 
CommandLine CommandLineFromArgcArgv (int argc, const char *const *argv)
 
CommandLine CommandLineFromPlatformOrArgcArgv (int argc, const char *const *argv)
 
template<typename StringType >
CommandLine CommandLineFromInitializerList (std::initializer_list< StringType > argv)
 
template<class Collection = std::unordered_map<class Key, class Value, class Hash, class Equal>>
void erase_if (Collection &container, std::function< bool(typename Collection::iterator)> predicate)
 
std::optional< size_t > EfficiencyCoreCount ()
 Request count of efficiency cores.
 
bool RequestAffinity (CpuAffinity affinity)
 Request the given affinity for the current thread.
 
std::optional< int64_t > ReadIntFromFile (const std::string &path)
 
template<typename T , class = std::enable_if_t<kIsByteSwappableV<T>>>
constexpr T ByteSwap (T n)
 Flips the endianness of the given value. The given value must be an integral type of size 1, 2, 4, or 8.
 
template<typename T , class = std::enable_if_t<kIsByteSwappableV<T>>>
constexpr T BigEndianToArch (T n)
 Convert a known big endian value to match the endianness of the current architecture. This is effectively a cross platform ntohl/ntohs (as network byte order is always Big Endian). The given value must be an integral type of size 1, 2, 4, or 8.
 
template<typename T , class = std::enable_if_t<kIsByteSwappableV<T>>>
constexpr T LittleEndianToArch (T n)
 Convert a known little endian value to match the endianness of the current architecture. The given value must be an integral type of size 1, 2, 4, or 8.
 
static fml::UniqueFD CreateDirectory (const fml::UniqueFD &base_directory, const std::vector< std::string > &components, FilePermission permission, size_t index)
 
fml::UniqueFD CreateDirectory (const fml::UniqueFD &base_directory, const std::vector< std::string > &components, FilePermission permission)
 
bool VisitFilesRecursively (const fml::UniqueFD &directory, const FileVisitor &visitor)
 
fml::UniqueFD OpenFileReadOnly (const fml::UniqueFD &base_directory, const char *path)
 
fml::UniqueFD OpenDirectoryReadOnly (const fml::UniqueFD &base_directory, const char *path)
 
bool RemoveFilesInDirectory (const fml::UniqueFD &directory)
 
bool RemoveDirectoryRecursively (const fml::UniqueFD &parent, const char *directory_name)
 
std::string CreateTemporaryDirectory ()
 
fml::UniqueFD OpenFile (const char *path, bool create_if_necessary, FilePermission permission)
 This can open a directory on POSIX, but not on Windows.
 
fml::UniqueFD OpenFile (const fml::UniqueFD &base_directory, const char *path, bool create_if_necessary, FilePermission permission)
 This can open a directory on POSIX, but not on Windows.
 
fml::UniqueFD OpenDirectory (const char *path, bool create_if_necessary, FilePermission permission)
 
fml::UniqueFD OpenDirectory (const fml::UniqueFD &base_directory, const char *path, bool create_if_necessary, FilePermission permission)
 
fml::UniqueFD Duplicate (fml::UniqueFD::element_type descriptor)
 
bool IsDirectory (const fml::UniqueFD &directory)
 
bool IsDirectory (const fml::UniqueFD &base_directory, const char *path)
 
bool IsFile (const std::string &path)
 
bool TruncateFile (const fml::UniqueFD &file, size_t size)
 
bool FileExists (const fml::UniqueFD &base_directory, const char *path)
 
bool UnlinkDirectory (const char *path)
 
bool UnlinkDirectory (const fml::UniqueFD &base_directory, const char *path)
 
bool UnlinkFile (const char *path)
 
bool UnlinkFile (const fml::UniqueFD &base_directory, const char *path)
 
bool WriteAtomically (const fml::UniqueFD &base_directory, const char *file_name, const Mapping &mapping)
 
bool VisitFiles (const fml::UniqueFD &directory, const FileVisitor &visitor)
 
template<class Type >
constexpr void HashCombineSeed (std::size_t &seed, Type arg)
 
template<class Type , class... Rest>
constexpr void HashCombineSeed (std::size_t &seed, Type arg, Rest... other_args)
 
constexpr std::size_t HashCombine ()
 
template<class... Type>
constexpr std::size_t HashCombine (Type... args)
 
std::string HexEncode (std::string_view input)
 
void SetLogSettings (const LogSettings &settings)
 
LogSettings GetLogSettings ()
 
int GetMinLogLevel ()
 
int GetVlogVerbosity ()
 
bool ShouldCreateLogMessage (LogSeverity severity)
 
void KillProcess ()
 
template<typename T >
internal::CopyableLambda< TMakeCopyable (T lambda)
 
 TEST (MallocMapping, EmptyContructor)
 
 TEST (MallocMapping, NotEmptyContructor)
 
 TEST (MallocMapping, MoveConstructor)
 
 TEST (MallocMapping, Copy)
 
 TEST (MallocMapping, Release)
 
 TEST (MallocMapping, IsDontNeedSafe)
 
 TEST (MallocMapping, CopySizeZero)
 
template<typename T >
RefPtr< TAdoptRef (T *ptr)
 
template<typename T >
RefPtr< TRef (T *ptr)
 
template<typename T , typename... Args>
RefPtr< TMakeRefCounted (Args &&... args)
 
void InitCPUInfo (size_t cpu_count)
 
bool SetUpCPUTracker ()
 
std::optional< size_t > AndroidEfficiencyCoreCount ()
 Android specific implementation of EfficiencyCoreCount.
 
bool AndroidRequestAffinity (CpuAffinity affinity)
 Android specific implementation of RequestAffinity.
 
static ALooper * AcquireLooperForThread ()
 
bool IsPlatformVersionAtLeast (size_t major, size_t minor=0, size_t patch=0)
 
template<class C >
void swap (scoped_nsprotocol< C > &p1, scoped_nsprotocol< C > &p2)
 
template<class C >
bool operator== (C p1, const scoped_nsprotocol< C > &p2)
 
template<class C >
bool operator!= (C p1, const scoped_nsprotocol< C > &p2)
 
NSRange RangeForCharacterAtIndex (NSString *text, NSUInteger index)
 
NSRange RangeForCharactersInRange (NSString *text, NSRange range)
 
bool operator== (NST p1, const WeakNSProtocol< NST > &p2)
 
bool operator!= (NST p1, const WeakNSProtocol< NST > &p2)
 
void ExecuteAfterTaskObservers ()
 
void CurrentMessageLoopAddAfterTaskObserver (intptr_t key, fit::closure observer)
 
void CurrentMessageLoopRemoveAfterTaskObserver (intptr_t key)
 
bool TimerRearm (int fd, fml::TimePoint time_point)
 Rearms the timer to expire at the given time point.
 
bool TimerDrain (int fd)
 
static int ToPosixAccessFlags (FilePermission permission)
 
static int ToPosixCreateModeFlags (FilePermission permission)
 
static int ToPosixProtectionFlags (std::initializer_list< FileMapping::Protection > protection_flags)
 
static bool IsWritable (std::initializer_list< FileMapping::Protection > protection_flags)
 
char * strdup (const char *str1)
 
int GetCurrentProcId ()
 
std::string GetLastErrorMessage ()
 
static std::string GetFullHandlePath (const fml::UniqueFD &handle)
 
static bool IsAbsolutePath (const char *path)
 
static std::string GetAbsolutePath (const fml::UniqueFD &base_directory, const char *subpath)
 
static std::wstring GetTemporaryDirectoryPath ()
 
static DWORD GetDesiredAccessFlags (FilePermission permission)
 
static DWORD GetShareFlags (FilePermission permission)
 
static DWORD GetFileAttributesForUtf8Path (const char *absolute_path)
 
static DWORD GetFileAttributesForUtf8Path (const fml::UniqueFD &base_directory, const char *path)
 
static bool IsWritable (std::initializer_list< FileMapping::Protection > protection_flags)
 
static bool IsExecutable (std::initializer_list< FileMapping::Protection > protection_flags)
 
std::string WideStringToUtf8 (const std::wstring_view str)
 
std::wstring Utf8ToWideString (const std::string_view str)
 
std::u16string WideStringToUtf16 (const std::wstring_view str)
 
std::wstring Utf16ToWideString (const std::u16string_view str)
 
template<typename T , std::size_t N>
constexpr std::size_t size (T(&array)[N])
 
std::string Join (const std::vector< std::string > &vec, const char *delim)
 
std::string Utf16ToUtf8 (const std::u16string_view string)
 
std::u16string Utf8ToUtf16 (const std::string_view string)
 
 TEST (CountDownLatchTest, CanWaitOnZero)
 
 TEST (CountDownLatchTest, CanWait)
 
template<typename ConditionFn >
bool WaitWithTimeoutImpl (std::unique_lock< std::mutex > *locker, std::condition_variable *cv, ConditionFn condition, TimeDelta timeout)
 
void SetThreadName (const std::string &name)
 
fml::TimePoint ChronoTicksSinceEpoch ()
 
template<typename T >
Milliseconds RefreshRateToFrameBudget (T refresh_rate)
 
template<typename Clock , typename Duration >
static int64_t NanosSinceEpoch (std::chrono::time_point< Clock, Duration > time_point)
 
template<class T , class Traits >
void swap (const UniqueObject< T, Traits > &a, const UniqueObject< T, Traits > &b)
 
template<class T , class Traits >
bool operator== (const T &value, const UniqueObject< T, Traits > &object)
 
template<class T , class Traits >
bool operator!= (const T &value, const UniqueObject< T, Traits > &object)
 

Variables

static std::string kKUnknownFrameName = "Unknown"
 
static size_t kKnownSignalHandlers []
 
static std::string kKUnknownFrameName = "Unknown"
 
static constexpr char kEncoding [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
 
static constexpr signed char kDecodeMap []
 
static constexpr int kDecodeMapSize
 
template<typename T >
constexpr bool kIsByteSwappableV = IsByteSwappable<T>::value
 
static constexpr char kEncoding [] = "0123456789abcdef"
 
constexpr LogSeverity kLogInfo = 0
 
constexpr LogSeverity kLogWarning = 1
 
constexpr LogSeverity kLogError = 2
 
constexpr LogSeverity kLogImportant = 3
 
constexpr LogSeverity kLogFatal = 4
 
constexpr LogSeverity kLogNumSeverities = 5
 
constexpr LogSeverity LOG_INFO = kLogInfo
 
constexpr LogSeverity LOG_WARNING = kLogWarning
 
constexpr LogSeverity LOG_ERROR = kLogError
 
constexpr LogSeverity LOG_IMPORTANT = kLogImportant
 
constexpr LogSeverity LOG_FATAL = kLogFatal
 
const LogSeverity kLogDFatal = kLogFatal
 
const LogSeverity LOG_DFATAL = kLogDFatal
 
static thread_local std::unique_ptr< MessageLooptls_message_loop
 
static thread_local std::unique_ptr< TaskSourceGradeHolder > tls_task_source_grade
 
static const TaskQueueId kUnmerged = TaskQueueId(TaskQueueId::kUnmerged)
 
std::once_flag gCPUTrackerFlag
 
static CPUSpeedTrackergCPUTracker
 
static constexpr int kClockType = CLOCK_MONOTONIC
 
static constexpr CFTimeInterval kDistantFuture = 1.0e10
 
thread_local std::map< intptr_t, fit::closure > tTaskObservers
 
static constexpr int kClockType = CLOCK_MONOTONIC
 
constexpr Milliseconds kDefaultFrameBudget = Milliseconds(1s) / 60
 

Typedef Documentation

◆ Base32DecodeConverter

using fml::Base32DecodeConverter = typedef BitConverter<5, 8, 16>

Definition at line 49 of file base32.h.

◆ Base32EncodeConverter

using fml::Base32EncodeConverter = typedef BitConverter<8, 5, 16>

Definition at line 50 of file base32.h.

◆ closure

using fml::closure = typedef std::function<void()>

Definition at line 14 of file closure.h.

◆ DelayedTaskQueue

using fml::DelayedTaskQueue = typedef std::priority_queue<DelayedTask, std::deque<DelayedTask>, std::greater<DelayedTask> >

Definition at line 42 of file delayed_task.h.

◆ FileVisitor

using fml::FileVisitor = typedef std::function<bool(const fml::UniqueFD& directory, const std::string& filename)>

Signature of a callback on a file in directory with filename (relative to directory). The returned bool should be false if and only if further traversal should be stopped. For example, a file-search visitor may return false when the file is found so no more visiting is needed.

Definition at line 97 of file file.h.

◆ LogSeverity

Definition at line 11 of file log_level.h.

◆ Milliseconds

using fml::Milliseconds = typedef std::chrono::duration<double, std::milli>

Definition at line 18 of file time_delta.h.

◆ RasterThreadMergerId

Definition at line 19 of file shared_thread_merger.h.

◆ ScopedBlock

template<typename B >
using fml::ScopedBlock = typedef ScopedTypeRef<B, internal::ScopedBlockTraits<B> >

Definition at line 41 of file scoped_block.h.

◆ ThreadFunction

typedef std::function<void()> fml::ThreadFunction

Definition at line 27 of file thread.cc.

◆ TrieNode

Definition at line 10 of file ascii_trie.cc.

◆ TrieNodePtr

Definition at line 11 of file ascii_trie.cc.

◆ UniqueDir

Definition at line 101 of file unique_fd.h.

◆ UniqueFD

Definition at line 100 of file unique_fd.h.

◆ Utf16StringConverter

using fml::Utf16StringConverter = typedef std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>

Definition at line 23 of file string_conversion.cc.

◆ WideStringConverter

using fml::WideStringConverter = typedef std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>

Definition at line 13 of file wstring_conversion.cc.

Enumeration Type Documentation

◆ CpuAffinity

enum class fml::CpuAffinity
strong

The CPU Affinity provides a hint to the operating system on which cores a particular thread should be scheduled on. The operating system may or may not honor these requests.

Enumerator
kPerformance 

Request CPU affinity for the performance cores.

     Generally speaking, only the UI and Raster thread should
     use this option. 
kEfficiency 

Request CPU affinity for the efficiency cores.

kNotPerformance 

Request affinity for all non-performance cores.

Definition at line 17 of file cpu_affinity.h.

17 {
18 /// @brief Request CPU affinity for the performance cores.
19 ///
20 /// Generally speaking, only the UI and Raster thread should
21 /// use this option.
23
24 /// @brief Request CPU affinity for the efficiency cores.
26
27 /// @brief Request affinity for all non-performance cores.
29};
@ kPerformance
Request CPU affinity for the performance cores.
@ kEfficiency
Request CPU affinity for the efficiency cores.
@ kNotPerformance
Request affinity for all non-performance cores.

◆ FilePermission

enum class fml::FilePermission
strong
Enumerator
kRead 
kWrite 
kReadWrite 

Definition at line 24 of file file.h.

24 {
25 kRead,
26 kWrite,
28};

◆ FlushType

enum class fml::FlushType
strong
Enumerator
kSingle 
kAll 

Definition at line 55 of file message_loop_task_queues.h.

55 {
56 kSingle,
57 kAll,
58};

◆ RasterThreadStatus

enum class fml::RasterThreadStatus
strong
Enumerator
kRemainsMerged 
kRemainsUnmerged 
kUnmergedNow 

Definition at line 20 of file raster_thread_merger.h.

◆ StatusCode

enum class fml::StatusCode
strong
Enumerator
kOk 
kCancelled 
kUnknown 
kInvalidArgument 
kDeadlineExceeded 
kNotFound 
kAlreadyExists 
kPermissionDenied 
kResourceExhausted 
kFailedPrecondition 
kAborted 
kOutOfRange 
kUnimplemented 
kInternal 
kUnavailable 
kDataLoss 
kUnauthenticated 

Definition at line 12 of file status.h.

◆ TaskSourceGrade

enum class fml::TaskSourceGrade
strong

Categories of work dispatched to MessageLoopTaskQueues dispatcher. By specifying the TaskSourceGrade, you indicate the task's importance to the dispatcher.

Enumerator
kUserInteraction 

This TaskSourceGrade indicates that a task is critical to user interaction.

kDartEventLoop 

This TaskSourceGrade indicates that a task corresponds to servicing a dart event loop task. These aren't critical to user interaction.

kUnspecified 

The absence of a specialized TaskSourceGrade.

Definition at line 15 of file task_source_grade.h.

15 {
16 /// This `TaskSourceGrade` indicates that a task is critical to user
17 /// interaction.
19 /// This `TaskSourceGrade` indicates that a task corresponds to servicing a
20 /// dart event loop task. These aren't critical to user interaction.
22 /// The absence of a specialized `TaskSourceGrade`.
24};

Function Documentation

◆ AcquireLooperForThread()

static ALooper * fml::AcquireLooperForThread ( )
static

Definition at line 16 of file message_loop_android.cc.

16 {
17 ALooper* looper = ALooper_forThread();
18
19 if (looper == nullptr) {
20 // No looper has been configured for the current thread. Create one and
21 // return the same.
22 looper = ALooper_prepare(0);
23 }
24
25 // The thread already has a looper. Acquire a reference to the same and return
26 // it.
27 ALooper_acquire(looper);
28 return looper;
29}

◆ AdoptRef()

template<typename T >
RefPtr< T > fml::AdoptRef ( T ptr)
inline

Definition at line 222 of file ref_ptr.h.

222 {
223#ifndef NDEBUG
224 ptr->Adopt();
225#endif
226 return RefPtr<T>(ptr, RefPtr<T>::kAdopt);
227}

◆ AndroidEfficiencyCoreCount()

std::optional< size_t > fml::AndroidEfficiencyCoreCount ( )

Android specific implementation of EfficiencyCoreCount.

Definition at line 50 of file cpu_affinity.cc.

50 {
51 if (!SetUpCPUTracker()) {
52 return true;
53 }
54 auto result = gCPUTracker->GetIndices(CpuAffinity::kEfficiency).size();
55 FML_DCHECK(result > 0);
56 return result;
57}
const std::vector< size_t > & GetIndices(CpuAffinity affinity) const
Return the set of CPU indices for the requested CPU affinity.
GAsyncResult * result
#define FML_DCHECK(condition)
Definition logging.h:103
bool SetUpCPUTracker()

◆ AndroidRequestAffinity()

bool fml::AndroidRequestAffinity ( CpuAffinity  affinity)

Android specific implementation of RequestAffinity.

Definition at line 59 of file cpu_affinity.cc.

59 {
60 if (!SetUpCPUTracker()) {
61 return true;
62 }
63
64 cpu_set_t set;
65 CPU_ZERO(&set);
66 for (const auto index : gCPUTracker->GetIndices(affinity)) {
67 CPU_SET(index, &set);
68 }
69 return sched_setaffinity(gettid(), sizeof(set), &set) == 0;
70}

◆ Backtrace()

static int fml::Backtrace ( void **  symbols,
int  size 
)
static

Definition at line 35 of file backtrace.cc.

35 {
36#if FML_OS_WIN
37 return CaptureStackBackTrace(0, size, symbols, NULL);
38#else
39 return ::backtrace(symbols, size);
40#endif // FML_OS_WIN
41}

◆ BacktraceHere()

std::string fml::BacktraceHere ( size_t  offset = 0)

Definition at line 43 of file backtrace.cc.

43 {
44 constexpr size_t kMaxFrames = 256;
45 void* symbols[kMaxFrames];
46 const auto available_frames = Backtrace(symbols, kMaxFrames);
47 if (available_frames <= 0) {
48 return "";
49 }
50
51 // Exclude here.
52 offset += 2;
53
54 std::stringstream stream;
55 for (int i = offset; i < available_frames; ++i) {
56 stream << "Frame " << i - offset << ": " << symbols[i] << " "
57 << GetSymbolName(symbols[i]) << std::endl;
58 }
59 return stream.str();
60}
static int Backtrace(void **symbols, int size)
Definition backtrace.cc:35
Point offset

◆ Base32Decode()

std::pair< bool, std::string > fml::Base32Decode ( const std::string &  input)

Definition at line 55 of file base32.cc.

55 {
56 std::string result;
57 Base32DecodeConverter converter;
58 for (char c : input) {
59 int map_index = c - '2';
60 if (map_index < 0 || map_index >= kDecodeMapSize ||
61 kDecodeMap[map_index] == -1) {
62 return {false, result};
63 }
64 converter.Append(kDecodeMap[map_index]);
65 if (converter.CanExtract()) {
66 result.push_back(converter.Extract());
67 }
68 }
69 if (converter.Peek() != 0) {
70 // The padding should always be zero. Return false if not.
71 return {false, result};
72 }
73 return {true, result};
74}

◆ Base32Encode()

std::pair< bool, std::string > fml::Base32Encode ( std::string_view  input)

Definition at line 15 of file base32.cc.

15 {
16 if (input.empty()) {
17 return {true, ""};
18 }
19
20 if (input.size() > std::numeric_limits<size_t>::max() / 8) {
21 return {false, ""};
22 }
23
24 std::string output;
25 const size_t encoded_length = (input.size() * 8 + 4) / 5;
26 output.reserve(encoded_length);
27
29 converter.Append(static_cast<uint8_t>(input[0]));
30 size_t next_byte_index = 1;
31
32 while (converter.CanExtract()) {
33 output.push_back(kEncoding[converter.Extract()]);
34 if (converter.CanAppend() && next_byte_index < input.size()) {
35 converter.Append(static_cast<uint8_t>(input[next_byte_index++]));
36 }
37 }
38
39 if (converter.BitsAvailable() > 0) {
40 output.push_back(kEncoding[converter.Peek()]);
41 }
42
43 return {true, output};
44}
BitConverter< 8, 5, 16 > Base32EncodeConverter
Definition base32.h:50

◆ BigEndianToArch()

template<typename T , class = std::enable_if_t<kIsByteSwappableV<T>>>
constexpr T fml::BigEndianToArch ( T  n)
constexpr

Convert a known big endian value to match the endianness of the current architecture. This is effectively a cross platform ntohl/ntohs (as network byte order is always Big Endian). The given value must be an integral type of size 1, 2, 4, or 8.

Definition at line 59 of file endianness.h.

59 {
60#if FML_ARCH_CPU_LITTLE_ENDIAN
61 return ByteSwap<T>(n);
62#else
63 return n;
64#endif
65}

◆ ByteSwap()

template<typename T , class = std::enable_if_t<kIsByteSwappableV<T>>>
constexpr T fml::ByteSwap ( T  n)
constexpr

Flips the endianness of the given value. The given value must be an integral type of size 1, 2, 4, or 8.

Definition at line 40 of file endianness.h.

40 {
41 if constexpr (sizeof(T) == 1) {
42 return n;
43 } else if constexpr (sizeof(T) == 2) {
44 return (T)FML_BYTESWAP_16((uint16_t)n);
45 } else if constexpr (sizeof(T) == 4) {
46 return (T)FML_BYTESWAP_32((uint32_t)n);
47 } else if constexpr (sizeof(T) == 8) {
48 return (T)FML_BYTESWAP_64((uint64_t)n);
49 } else {
50 static_assert(!sizeof(T), "Unsupported size");
51 }
52}
#define FML_BYTESWAP_64(n)
Definition endianness.h:24
#define FML_BYTESWAP_16(n)
Definition endianness.h:22
#define FML_BYTESWAP_32(n)
Definition endianness.h:23
#define T

◆ ChronoTicksSinceEpoch()

fml::TimePoint fml::ChronoTicksSinceEpoch ( )

Definition at line 21 of file chrono_timestamp_provider.cc.

21 {
22 return ChronoTimestampProvider::Instance().Now();
23}

◆ CommandLineFromArgcArgv()

CommandLine fml::CommandLineFromArgcArgv ( int  argc,
const char *const *  argv 
)
inline

Definition at line 233 of file command_line.h.

233 {
234 return CommandLineFromIterators(argv, argv + argc);
235}
CommandLine CommandLineFromIterators(InputIterator first, InputIterator last)

◆ CommandLineFromInitializerList()

template<typename StringType >
CommandLine fml::CommandLineFromInitializerList ( std::initializer_list< StringType >  argv)
inline

Definition at line 254 of file command_line.h.

255 {
256 return CommandLineFromIterators(argv.begin(), argv.end());
257}
char ** argv
Definition library.h:9

◆ CommandLineFromIterators()

template<typename InputIterator >
CommandLine fml::CommandLineFromIterators ( InputIterator  first,
InputIterator  last 
)
inline

Definition at line 204 of file command_line.h.

205 {
206 return CommandLineFromIteratorsFindFirstPositionalArg<InputIterator>(
207 first, last, nullptr);
208}

◆ CommandLineFromIteratorsFindFirstPositionalArg()

template<typename InputIterator >
CommandLine fml::CommandLineFromIteratorsFindFirstPositionalArg ( InputIterator  first,
InputIterator  last,
InputIterator *  first_positional_arg 
)
inline

Definition at line 182 of file command_line.h.

185 {
186 if (first_positional_arg) {
187 *first_positional_arg = last;
188 }
189 internal::CommandLineBuilder builder;
190 for (auto it = first; it < last; ++it) {
191 if (builder.ProcessArg(*it)) {
192 if (first_positional_arg) {
193 *first_positional_arg = it;
194 }
195 }
196 }
197 return builder.Build();
198}

◆ CommandLineFromIteratorsWithArgv0()

template<typename InputIterator >
CommandLine fml::CommandLineFromIteratorsWithArgv0 ( const std::string &  argv0,
InputIterator  first,
InputIterator  last 
)
inline

Definition at line 214 of file command_line.h.

216 {
218 builder.ProcessArg(argv0);
219 for (auto it = first; it < last; ++it) {
220 builder.ProcessArg(*it);
221 }
222 return builder.Build();
223}

◆ CommandLineFromPlatform()

std::optional< CommandLine > fml::CommandLineFromPlatform ( )

Definition at line 9 of file command_line_posix.cc.

9 {
10 return std::nullopt;
11}

◆ CommandLineFromPlatformOrArgcArgv()

CommandLine fml::CommandLineFromPlatformOrArgcArgv ( int  argc,
const char *const *  argv 
)
inline

Definition at line 242 of file command_line.h.

243 {
244 auto command_line = CommandLineFromPlatform();
245 if (command_line.has_value()) {
246 return *command_line;
247 }
248 return CommandLineFromArgcArgv(argc, argv);
249}
std::optional< CommandLine > CommandLineFromPlatform()

◆ CommandLineToArgv()

std::vector< std::string > fml::CommandLineToArgv ( const CommandLine command_line)

Definition at line 141 of file command_line.cc.

141 {
142 if (!command_line.has_argv0()) {
143 return std::vector<std::string>();
144 }
145
146 std::vector<std::string> argv;
147 const std::vector<CommandLine::Option>& options = command_line.options();
148 const std::vector<std::string>& positional_args =
149 command_line.positional_args();
150 // Reserve space for argv[0], options, maybe a "--" (if needed), and the
151 // positional arguments.
152 argv.reserve(1u + options.size() + 1u + positional_args.size());
153
154 argv.push_back(command_line.argv0());
155 for (const auto& option : options) {
156 if (option.value.empty()) {
157 argv.push_back("--" + option.name);
158 } else {
159 argv.push_back("--" + option.name + "=" + option.value);
160 }
161 }
162
163 if (!positional_args.empty()) {
164 // Insert a "--" if necessary.
165 if (positional_args[0].size() >= 2u && positional_args[0][0] == '-' &&
166 positional_args[0][1] == '-') {
167 argv.push_back("--");
168 }
169
170 argv.insert(argv.end(), positional_args.begin(), positional_args.end());
171 }
172
173 return argv;
174}
const char * options
const std::string & argv0() const
const std::vector< Option > & options() const
const std::vector< std::string > & positional_args() const
bool has_argv0() const
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259

◆ CreateDirectory() [1/2]

fml::UniqueFD fml::CreateDirectory ( const fml::UniqueFD base_directory,
const std::vector< std::string > &  components,
FilePermission  permission 
)

Definition at line 33 of file file.cc.

35 {
36 if (!IsDirectory(base_directory)) {
37 return {};
38 }
39
40 if (components.empty()) {
41 return {};
42 }
43
44 return CreateDirectory(base_directory, components, permission, 0);
45}
bool IsDirectory(const fml::UniqueFD &directory)
#define CreateDirectory

◆ CreateDirectory() [2/2]

static fml::UniqueFD fml::CreateDirectory ( const fml::UniqueFD base_directory,
const std::vector< std::string > &  components,
FilePermission  permission,
size_t  index 
)
static

Definition at line 12 of file file.cc.

15 {
16 FML_DCHECK(index <= components.size());
17
18 const char* file_path = components[index].c_str();
19
20 auto directory = OpenDirectory(base_directory, file_path, true, permission);
21
22 if (!directory.is_valid()) {
23 return {};
24 }
25
26 if (index == components.size() - 1) {
27 return directory;
28 }
29
30 return CreateDirectory(directory, components, permission, index + 1);
31}
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
Definition file_posix.cc:97

◆ CreateTemporaryDirectory()

std::string fml::CreateTemporaryDirectory ( )

Definition at line 25 of file file_posix.cc.

25 {
26 char directory_name[] = "/tmp/flutter_XXXXXXXX";
27 auto* result = ::mkdtemp(directory_name);
28 if (result == nullptr) {
29 return "";
30 }
31 return {result};
32}

◆ CurrentMessageLoopAddAfterTaskObserver()

void fml::CurrentMessageLoopAddAfterTaskObserver ( intptr_t  key,
fit::closure  observer 
)

Definition at line 19 of file task_observers.cc.

20 {
21 if (observer) {
22 tTaskObservers[key] = std::move(observer);
23 }
24}
thread_local std::map< intptr_t, fit::closure > tTaskObservers

◆ CurrentMessageLoopRemoveAfterTaskObserver()

void fml::CurrentMessageLoopRemoveAfterTaskObserver ( intptr_t  key)

Definition at line 26 of file task_observers.cc.

26 {
27 tTaskObservers.erase(key);
28}

◆ Duplicate()

fml::UniqueFD fml::Duplicate ( fml::UniqueFD::element_type  descriptor)

Definition at line 123 of file file_posix.cc.

123 {
124 return fml::UniqueFD{FML_HANDLE_EINTR(::dup(descriptor))};
125}
#define FML_HANDLE_EINTR(x)

◆ EfficiencyCoreCount()

std::optional< size_t > fml::EfficiencyCoreCount ( )

Request count of efficiency cores.

   Efficiency cores are defined as those with the lowest reported
   cpu_max_freq. If the CPU speed could not be determined, or if all
   cores have the same reported speed then this returns std::nullopt.
   That is, the result will never be 0. 

Definition at line 18 of file cpu_affinity.cc.

18 {
19#ifdef FML_OS_ANDROID
21#else
22 return std::nullopt;
23#endif
24}
std::optional< size_t > AndroidEfficiencyCoreCount()
Android specific implementation of EfficiencyCoreCount.

◆ erase_if()

template<class Collection = std::unordered_map<class Key, class Value, class Hash, class Equal>>
void fml::erase_if ( Collection &  container,
std::function< bool(typename Collection::iterator)>  predicate 
)

Definition at line 16 of file container.h.

17 {
18 auto it = container.begin();
19 while (it != container.end()) {
20 if (predicate(it)) {
21 it = container.erase(it);
22 continue;
23 }
24 it++;
25 }
26}

◆ ExecuteAfterTaskObservers()

void fml::ExecuteAfterTaskObservers ( )

Definition at line 13 of file task_observers.cc.

13 {
14 for (const auto& callback : tTaskObservers) {
15 callback.second();
16 }
17}
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ FileExists()

bool fml::FileExists ( const fml::UniqueFD base_directory,
const char *  path 
)

Definition at line 183 of file file_posix.cc.

183 {
184 if (!base_directory.is_valid()) {
185 return false;
186 }
187
188 return ::faccessat(base_directory.get(), path, F_OK, 0) == 0;
189}
bool is_valid() const
const T & get() const

◆ GetAbsolutePath()

static std::string fml::GetAbsolutePath ( const fml::UniqueFD base_directory,
const char *  subpath 
)
static

Definition at line 50 of file file_win.cc.

51 {
52 std::string path;
53 if (IsAbsolutePath(subpath)) {
54 path = subpath;
55 } else {
56 std::stringstream stream;
57 stream << GetFullHandlePath(base_directory) << "\\" << subpath;
58 path = stream.str();
59 }
60 std::replace(path.begin(), path.end(), '/', '\\');
61 return path;
62}
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
static bool IsAbsolutePath(const char *path)
Definition file_win.cc:37

◆ GetCurrentProcId()

int fml::GetCurrentProcId ( )

Definition at line 9 of file process_posix.cc.

9 {
10 return static_cast<int>(getpid());
11}

◆ GetDesiredAccessFlags()

static DWORD fml::GetDesiredAccessFlags ( FilePermission  permission)
static

Definition at line 73 of file file_win.cc.

73 {
74 switch (permission) {
75 case FilePermission::kRead:
76 return GENERIC_READ;
77 case FilePermission::kWrite:
78 return GENERIC_WRITE;
79 case FilePermission::kReadWrite:
80 return GENERIC_READ | GENERIC_WRITE;
81 }
82 return GENERIC_READ;
83}

◆ GetFileAttributesForUtf8Path() [1/2]

static DWORD fml::GetFileAttributesForUtf8Path ( const char *  absolute_path)
static

Definition at line 97 of file file_win.cc.

97 {
98 return ::GetFileAttributes(Utf8ToWideString(absolute_path).c_str());
99}
std::wstring Utf8ToWideString(const std::string_view str)

◆ GetFileAttributesForUtf8Path() [2/2]

static DWORD fml::GetFileAttributesForUtf8Path ( const fml::UniqueFD base_directory,
const char *  path 
)
static

Definition at line 101 of file file_win.cc.

102 {
103 std::string full_path = GetAbsolutePath(base_directory, path);
104 return GetFileAttributesForUtf8Path(full_path.c_str());
105}
static std::string GetAbsolutePath(const fml::UniqueFD &base_directory, const char *subpath)
Definition file_win.cc:50
static DWORD GetFileAttributesForUtf8Path(const char *absolute_path)
Definition file_win.cc:97

◆ GetFullHandlePath()

static std::string fml::GetFullHandlePath ( const fml::UniqueFD handle)
static

Definition at line 27 of file file_win.cc.

27 {
28 wchar_t buffer[MAX_PATH] = {0};
29 const DWORD buffer_size = ::GetFinalPathNameByHandle(
30 handle.get(), buffer, MAX_PATH, FILE_NAME_NORMALIZED);
31 if (buffer_size == 0) {
32 return {};
33 }
35}
static uint32_t buffer_size(uint32_t offset, uint32_t maxAlignment)
static const uint8_t buffer[]
std::string WideStringToUtf8(const std::wstring_view str)
#define MAX_PATH
unsigned long DWORD

◆ GetLastErrorMessage()

std::string fml::GetLastErrorMessage ( )

Definition at line 15 of file errors_win.cc.

15 {
16 DWORD last_error = ::GetLastError();
17 if (last_error == 0) {
18 return {};
19 }
20
21 const DWORD flags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
22 FORMAT_MESSAGE_FROM_SYSTEM |
23 FORMAT_MESSAGE_IGNORE_INSERTS;
24
25 wchar_t* buffer = nullptr;
26 size_t size = ::FormatMessage(
27 flags, // dwFlags
28 NULL, // lpSource
29 last_error, // dwMessageId
30 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // dwLanguageId
31 (LPWSTR)&buffer, // lpBuffer
32 0, // nSize
33 NULL // Arguments
34 );
35
36 std::wstring message(buffer, size);
37
38 ::LocalFree(buffer);
39
40 std::wstringstream stream;
41 stream << message << " (" << last_error << ").";
42
43 return WideStringToUtf8(stream.str());
44}
FlutterSemanticsFlag flags
Win32Message message
WINBASEAPI _Check_return_ _Post_equals_last_error_ DWORD WINAPI GetLastError(VOID)

◆ GetLogSettings()

LogSettings fml::GetLogSettings ( )

Definition at line 32 of file log_settings.cc.

32 {
33 return state::g_log_settings;
34}

◆ GetMinLogLevel()

int fml::GetMinLogLevel ( )

Definition at line 36 of file log_settings.cc.

36 {
37 return std::min(state::g_log_settings.min_log_level, kLogFatal);
38}

◆ GetShareFlags()

static DWORD fml::GetShareFlags ( FilePermission  permission)
static

Definition at line 85 of file file_win.cc.

85 {
86 switch (permission) {
87 case FilePermission::kRead:
88 return FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
89 case FilePermission::kWrite:
90 return 0;
91 case FilePermission::kReadWrite:
92 return 0;
93 }
94 return FILE_SHARE_READ;
95}

◆ GetSymbolName()

static std::string fml::GetSymbolName ( void *  symbol)
static

Definition at line 27 of file backtrace.cc.

27 {
28 char name[1024];
29 if (!absl::Symbolize(symbol, name, sizeof(name))) {
30 return kKUnknownFrameName;
31 }
32 return name;
33}
const char * name
Definition fuchsia.cc:50
static std::string kKUnknownFrameName
Definition backtrace.cc:25

◆ GetTemporaryDirectoryPath()

static std::wstring fml::GetTemporaryDirectoryPath ( )
static

Definition at line 64 of file file_win.cc.

64 {
65 wchar_t wchar_path[MAX_PATH];
66 auto result_size = ::GetTempPath(MAX_PATH, wchar_path);
67 if (result_size > 0) {
68 return {wchar_path, result_size};
69 }
70 return {};
71}

◆ GetVlogVerbosity()

int fml::GetVlogVerbosity ( )

Definition at line 212 of file logging.cc.

212 {
213 return std::max(-1, kLogInfo - GetMinLogLevel());
214}
int GetMinLogLevel()

◆ HashCombine() [1/2]

constexpr std::size_t fml::HashCombine ( )
constexpr

Definition at line 25 of file hash_combine.h.

25 {
26 return 0xdabbad00;
27}

◆ HashCombine() [2/2]

template<class... Type>
constexpr std::size_t fml::HashCombine ( Type...  args)
constexpr

Definition at line 30 of file hash_combine.h.

30 {
31 std::size_t seed = HashCombine();
32 HashCombineSeed(seed, args...);
33 return seed;
34}
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
constexpr std::size_t HashCombine()
constexpr void HashCombineSeed(std::size_t &seed, Type arg)

◆ HashCombineSeed() [1/2]

template<class Type >
constexpr void fml::HashCombineSeed ( std::size_t &  seed,
Type  arg 
)
constexpr

Definition at line 13 of file hash_combine.h.

13 {
14 seed ^= std::hash<Type>{}(arg) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
15}

◆ HashCombineSeed() [2/2]

template<class Type , class... Rest>
constexpr void fml::HashCombineSeed ( std::size_t &  seed,
Type  arg,
Rest...  other_args 
)
constexpr

Definition at line 18 of file hash_combine.h.

20 {
21 HashCombineSeed(seed, arg);
22 HashCombineSeed(seed, other_args...);
23}

◆ HexEncode()

std::string fml::HexEncode ( std::string_view  input)

Definition at line 14 of file hex_codec.cc.

14 {
15 std::string result;
16 result.reserve(input.size() * 2);
17 for (char c : input) {
18 uint8_t b = static_cast<uint8_t>(c);
19 result.push_back(kEncoding[b >> 4]);
20 result.push_back(kEncoding[b & 0xF]);
21 }
22 return result;
23}
static bool b

◆ InitCPUInfo()

void fml::InitCPUInfo ( size_t  cpu_count)

Definition at line 26 of file cpu_affinity.cc.

26 {
27 std::vector<CpuIndexAndSpeed> cpu_speeds;
28
29 for (auto i = 0u; i < cpu_count; i++) {
30 auto path = "/sys/devices/system/cpu/cpu" + std::to_string(i) +
31 "/cpufreq/cpuinfo_max_freq";
32 auto speed = ReadIntFromFile(path);
33 if (speed.has_value()) {
34 cpu_speeds.push_back({.index = i, .speed = speed.value()});
35 }
36 }
37 gCPUTracker = new CPUSpeedTracker(cpu_speeds);
38}
std::optional< int64_t > ReadIntFromFile(const std::string &path)
static CPUSpeedTracker * gCPUTracker

◆ InstallCrashHandler()

void fml::InstallCrashHandler ( )

Definition at line 126 of file backtrace.cc.

126 {
127#if FML_OS_WIN
128 if (!IsDebuggerPresent()) {
129 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
130 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
131 }
132#endif
133 auto exe_path = fml::paths::GetExecutablePath();
134 if (exe_path.first) {
135 absl::InitializeSymbolizer(exe_path.second.c_str());
136 }
138}
std::pair< bool, std::string > GetExecutablePath()
static void ToggleSignalHandlers(bool set)
Definition backtrace.cc:115

◆ IsAbsolutePath()

static bool fml::IsAbsolutePath ( const char *  path)
static

Definition at line 37 of file file_win.cc.

37 {
38 if (path == nullptr || strlen(path) == 0) {
39 return false;
40 }
41
42 auto wpath = Utf8ToWideString({path});
43 if (wpath.empty()) {
44 return false;
45 }
46
47 return ::PathIsRelative(wpath.c_str()) == FALSE;
48}
return FALSE

◆ IsCrashHandlingSupported()

bool fml::IsCrashHandlingSupported ( )

Definition at line 140 of file backtrace.cc.

140 {
141 return true;
142}

◆ IsDirectory() [1/2]

bool fml::IsDirectory ( const fml::UniqueFD base_directory,
const char *  path 
)

Definition at line 141 of file file_posix.cc.

141 {
142 UniqueFD file = OpenFileReadOnly(base_directory, path);
143 return (file.is_valid() && IsDirectory(file));
144}
fml::UniqueFD OpenFileReadOnly(const fml::UniqueFD &base_directory, const char *path)
Definition file.cc:92

◆ IsDirectory() [2/2]

bool fml::IsDirectory ( const fml::UniqueFD directory)

Definition at line 127 of file file_posix.cc.

127 {
128 if (!directory.is_valid()) {
129 return false;
130 }
131
132 struct stat stat_result = {};
133
134 if (::fstat(directory.get(), &stat_result) != 0) {
135 return false;
136 }
137
138 return S_ISDIR(stat_result.st_mode);
139}

◆ IsExecutable()

static bool fml::IsExecutable ( std::initializer_list< FileMapping::Protection protection_flags)
static

Definition at line 33 of file mapping_win.cc.

34 {
35 for (auto protection : protection_flags) {
36 if (protection == FileMapping::Protection::kExecute) {
37 return true;
38 }
39 }
40 return false;
41}

◆ IsFile()

bool fml::IsFile ( const std::string &  path)

Definition at line 146 of file file_posix.cc.

146 {
147 struct stat buf;
148 if (stat(path.c_str(), &buf) != 0) {
149 return false;
150 }
151
152 return S_ISREG(buf.st_mode);
153}

◆ IsPlatformVersionAtLeast()

bool fml::IsPlatformVersionAtLeast ( size_t  major,
size_t  minor = 0,
size_t  patch = 0 
)

Definition at line 11 of file platform_version.mm.

11 {
12 const NSOperatingSystemVersion version = {
13 .majorVersion = static_cast<NSInteger>(major),
14 .minorVersion = static_cast<NSInteger>(minor),
15 .patchVersion = static_cast<NSInteger>(patch),
16 };
17 return [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:version];
18}

◆ IsWritable() [1/2]

static bool fml::IsWritable ( std::initializer_list< FileMapping::Protection protection_flags)
static

Definition at line 39 of file mapping_posix.cc.

40 {
41 for (auto protection : protection_flags) {
42 if (protection == FileMapping::Protection::kWrite) {
43 return true;
44 }
45 }
46 return false;
47}

◆ IsWritable() [2/2]

static bool fml::IsWritable ( std::initializer_list< FileMapping::Protection protection_flags)
static

Definition at line 23 of file mapping_win.cc.

24 {
25 for (auto protection : protection_flags) {
26 if (protection == FileMapping::Protection::kWrite) {
27 return true;
28 }
29 }
30 return false;
31}

◆ Join()

std::string fml::Join ( const std::vector< std::string > &  vec,
const char *  delim 
)

Definition at line 26 of file string_conversion.cc.

26 {
27 std::stringstream res;
28 for (size_t i = 0; i < vec.size(); ++i) {
29 res << vec[i];
30 if (i < vec.size() - 1) {
31 res << delim;
32 }
33 }
34 return res.str();
35}

◆ KillProcess()

void fml::KillProcess ( )

Definition at line 220 of file logging.cc.

220 {
221 abort();
222}

◆ LittleEndianToArch()

template<typename T , class = std::enable_if_t<kIsByteSwappableV<T>>>
constexpr T fml::LittleEndianToArch ( T  n)
constexpr

Convert a known little endian value to match the endianness of the current architecture. The given value must be an integral type of size 1, 2, 4, or 8.

Definition at line 71 of file endianness.h.

71 {
72#if !FML_ARCH_CPU_LITTLE_ENDIAN
73 return ByteSwap<T>(n);
74#else
75 return n;
76#endif
77}

◆ MakeCopyable()

template<typename T >
internal::CopyableLambda< T > fml::MakeCopyable ( T  lambda)

Definition at line 57 of file make_copyable.h.

57 {
58 return internal::CopyableLambda<T>(std::move(lambda));
59}

◆ MakeRefCounted()

template<typename T , typename... Args>
RefPtr< T > fml::MakeRefCounted ( Args &&...  args)

Definition at line 248 of file ref_ptr.h.

◆ NanosSinceEpoch()

template<typename Clock , typename Duration >
static int64_t fml::NanosSinceEpoch ( std::chrono::time_point< Clock, Duration >  time_point)
static

Definition at line 39 of file time_point.cc.

40 {
41 const auto elapsed = time_point.time_since_epoch();
42 return std::chrono::duration_cast<std::chrono::nanoseconds>(elapsed).count();
43}

◆ OpenDirectory() [1/2]

fml::UniqueFD fml::OpenDirectory ( const char *  path,
bool  create_if_necessary,
FilePermission  permission 
)

Definition at line 97 of file file_posix.cc.

99 {
100 return OpenDirectory(fml::UniqueFD{AT_FDCWD}, path, create_if_necessary,
101 permission);
102}

◆ OpenDirectory() [2/2]

fml::UniqueFD fml::OpenDirectory ( const fml::UniqueFD base_directory,
const char *  path,
bool  create_if_necessary,
FilePermission  permission 
)

Definition at line 104 of file file_posix.cc.

107 {
108 if (path == nullptr) {
109 return {};
110 }
111
112 if (create_if_necessary && !FileExists(base_directory, path)) {
113 if (::mkdirat(base_directory.get(), path,
114 ToPosixCreateModeFlags(permission) | S_IXUSR) != 0) {
115 return {};
116 }
117 }
118
120 ::openat(base_directory.get(), path, O_RDONLY | O_DIRECTORY))};
121}
static int ToPosixCreateModeFlags(FilePermission permission)
Definition file_posix.cc:50
bool FileExists(const fml::UniqueFD &base_directory, const char *path)

◆ OpenDirectoryReadOnly()

fml::UniqueFD fml::OpenDirectoryReadOnly ( const fml::UniqueFD base_directory,
const char *  path 
)

Helper method that calls OpenDirectory with create_if_necessary = false and permission = kRead.

Definition at line 97 of file file.cc.

98 {
99 return OpenDirectory(base_directory, path, false, FilePermission::kRead);
100}

◆ OpenFile() [1/2]

fml::UniqueFD fml::OpenFile ( const char *  path,
bool  create_if_necessary,
FilePermission  permission 
)

This can open a directory on POSIX, but not on Windows.

Definition at line 66 of file file_posix.cc.

68 {
69 return OpenFile(fml::UniqueFD{AT_FDCWD}, path, create_if_necessary,
70 permission);
71}
fml::UniqueFD OpenFile(const char *path, bool create_if_necessary, FilePermission permission)
This can open a directory on POSIX, but not on Windows.
Definition file_posix.cc:66

◆ OpenFile() [2/2]

fml::UniqueFD fml::OpenFile ( const fml::UniqueFD base_directory,
const char *  path,
bool  create_if_necessary,
FilePermission  permission 
)

This can open a directory on POSIX, but not on Windows.

Definition at line 73 of file file_posix.cc.

76 {
77 TRACE_EVENT0("flutter", "fml::OpenFile");
78 if (path == nullptr) {
79 return {};
80 }
81
82 int flags = 0;
83 int mode = 0;
84
85 if (create_if_necessary && !FileExists(base_directory, path)) {
86 flags = ToPosixAccessFlags(permission) | O_CREAT | O_TRUNC;
87 mode = ToPosixCreateModeFlags(permission);
88 } else {
89 flags = ToPosixAccessFlags(permission);
90 mode = 0; // Not creating since it already exists.
91 }
92
93 return fml::UniqueFD{
94 FML_HANDLE_EINTR(::openat(base_directory.get(), path, flags, mode))};
95}
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition switches.h:228
static int ToPosixAccessFlags(FilePermission permission)
Definition file_posix.cc:34
#define TRACE_EVENT0(category_group, name)

◆ OpenFileReadOnly()

fml::UniqueFD fml::OpenFileReadOnly ( const fml::UniqueFD base_directory,
const char *  path 
)

Helper method that calls OpenFile with create_if_necessary = false and permission = kRead.

This can open a directory on POSIX, but not on Windows.

Definition at line 92 of file file.cc.

93 {
94 return OpenFile(base_directory, path, false, FilePermission::kRead);
95}

◆ operator!=() [1/3]

template<class C >
bool fml::operator!= ( C  p1,
const scoped_nsprotocol< C > &  p2 
)

Definition at line 147 of file scoped_nsobject.h.

147 {
148 return p1 != p2.get();
149}
T get() const __attribute((ns_returns_not_retained))

◆ operator!=() [2/3]

template<class T , class Traits >
bool fml::operator!= ( const T value,
const UniqueObject< T, Traits > &  object 
)

Definition at line 131 of file unique_object.h.

131 {
132 return !(value == object.get());
133}
uint8_t value

◆ operator!=() [3/3]

bool fml::operator!= ( NST  p1,
const WeakNSProtocol< NST > &  p2 
)

Definition at line 188 of file weak_nsobject.h.

188 {
189 return p1 != p2.get();
190}

◆ operator==() [1/3]

template<class C >
bool fml::operator== ( C  p1,
const scoped_nsprotocol< C > &  p2 
)

Definition at line 142 of file scoped_nsobject.h.

142 {
143 return p1 == p2.get();
144}

◆ operator==() [2/3]

template<class T , class Traits >
bool fml::operator== ( const T value,
const UniqueObject< T, Traits > &  object 
)

Definition at line 126 of file unique_object.h.

126 {
127 return value == object.get();
128}

◆ operator==() [3/3]

bool fml::operator== ( NST  p1,
const WeakNSProtocol< NST > &  p2 
)

Definition at line 183 of file weak_nsobject.h.

183 {
184 return p1 == p2.get();
185}

◆ RangeForCharacterAtIndex()

NSRange fml::RangeForCharacterAtIndex ( NSString *  text,
NSUInteger  index 
)

Definition at line 9 of file string_range_sanitization.mm.

9 {
10 if (text == nil || index > text.length) {
11 return NSMakeRange(NSNotFound, 0);
12 }
13 if (index < text.length) {
14 return [text rangeOfComposedCharacterSequenceAtIndex:index];
15 }
16 return NSMakeRange(index, 0);
17}
std::u16string text

◆ RangeForCharactersInRange()

NSRange fml::RangeForCharactersInRange ( NSString *  text,
NSRange  range 
)

Definition at line 19 of file string_range_sanitization.mm.

19 {
20 if (text == nil || range.location + range.length > text.length) {
21 return NSMakeRange(NSNotFound, 0);
22 }
23 NSRange sanitizedRange = [text rangeOfComposedCharacterSequencesForRange:range];
24 // We don't want to override the length, we just want to make sure we don't
25 // select into the middle of a multi-byte character. Taking the
26 // `sanitizedRange`'s length will end up altering the actual selection.
27 return NSMakeRange(sanitizedRange.location, range.length);
28}

◆ ReadIntFromFile()

std::optional< int64_t > fml::ReadIntFromFile ( const std::string &  path)
Note
Visible for testing.

Definition at line 86 of file cpu_affinity.cc.

86 {
87 std::ifstream file;
88 file.open(path.c_str());
89
90 // Dont use stoi because if this data isnt a parseable number then it
91 // will abort, as we compile with exceptions disabled.
92 int64_t speed = 0;
93 file >> speed;
94 if (speed > 0) {
95 return speed;
96 }
97 return std::nullopt;
98}

◆ Ref()

template<typename T >
RefPtr< T > fml::Ref ( T ptr)
inline

Definition at line 237 of file ref_ptr.h.

237 {
238 return RefPtr<T>(ptr);
239}

◆ RefreshRateToFrameBudget()

template<typename T >
Milliseconds fml::RefreshRateToFrameBudget ( T  refresh_rate)

Definition at line 24 of file time_delta.h.

24 {
25 return Milliseconds(1s) / refresh_rate;
26}
struct MyStruct s
std::chrono::duration< double, std::milli > Milliseconds
Definition time_delta.h:18

◆ RemoveDirectoryRecursively()

bool fml::RemoveDirectoryRecursively ( const fml::UniqueFD parent,
const char *  directory_name 
)

Helper method to recursively remove files and subdirectories inside the directory. The directory itself will also be removed.

Return true if and only if all files have been successfully removed.

Definition at line 120 of file file.cc.

121 {
122 auto dir = fml::OpenDirectory(parent, directory_name, false,
124 return RemoveFilesInDirectory(dir) && UnlinkDirectory(parent, directory_name);
125}
bool RemoveFilesInDirectory(const fml::UniqueFD &directory)
Definition file.cc:102
bool UnlinkDirectory(const char *path)

◆ RemoveFilesInDirectory()

bool fml::RemoveFilesInDirectory ( const fml::UniqueFD directory)

Helper method to recursively remove files and subdirectories inside the directory. The directory itself will not be removed.

Return true if and only if all files have been successfully removed.

Definition at line 102 of file file.cc.

102 {
103 fml::FileVisitor recursive_cleanup = [&recursive_cleanup](
104 const fml::UniqueFD& directory,
105 const std::string& filename) {
106 bool removed;
107 if (fml::IsDirectory(directory, filename.c_str())) {
108 fml::UniqueFD sub_dir =
109 OpenDirectoryReadOnly(directory, filename.c_str());
110 removed = VisitFiles(sub_dir, recursive_cleanup) &&
111 fml::UnlinkDirectory(directory, filename.c_str());
112 } else {
113 removed = fml::UnlinkFile(directory, filename.c_str());
114 }
115 return removed;
116 };
117 return VisitFiles(directory, recursive_cleanup);
118}
bool VisitFiles(const fml::UniqueFD &directory, const FileVisitor &visitor)
fml::UniqueFD OpenDirectoryReadOnly(const fml::UniqueFD &base_directory, const char *path)
Definition file.cc:97
bool UnlinkFile(const char *path)
std::function< bool(const fml::UniqueFD &directory, const std::string &filename)> FileVisitor
Definition file.h:98

◆ RequestAffinity()

bool fml::RequestAffinity ( CpuAffinity  affinity)

Request the given affinity for the current thread.

   Returns true if successfull, or if it was a no-op. This function is
   only supported on Android devices.

   Affinity requests are based on documented CPU speed. This speed data
   is parsed from cpuinfo_max_freq files, see also:
   https://www.kernel.org/doc/Documentation/cpu-freq/user-guide.txt 

Definition at line 26 of file cpu_affinity.cc.

26 {
27#ifdef FML_OS_ANDROID
28 return AndroidRequestAffinity(affinity);
29#else
30 return true;
31#endif
32}
bool AndroidRequestAffinity(CpuAffinity affinity)
Android specific implementation of RequestAffinity.

◆ SetLogSettings()

void fml::SetLogSettings ( const LogSettings settings)

Definition at line 26 of file log_settings.cc.

26 {
27 // Validate the new settings as we set them.
28 state::g_log_settings.min_log_level =
29 std::min(kLogFatal, settings.min_log_level);
30}

◆ SetThreadName()

void fml::SetThreadName ( const std::string &  name)

Definition at line 104 of file thread.cc.

104 {
105 if (name == "") {
106 return;
107 }
108#if defined(FML_OS_MACOSX)
109 pthread_setname_np(name.c_str());
110#elif defined(FML_OS_LINUX) || defined(FML_OS_ANDROID)
111 // Linux thread names are limited to 16 characters including the terminating
112 // null.
113 constexpr std::string::size_type kLinuxMaxThreadNameLen = 15;
114 pthread_setname_np(pthread_self(),
115 name.substr(0, kLinuxMaxThreadNameLen).c_str());
116#elif defined(FML_OS_WIN)
117 THREADNAME_INFO info;
118 info.dwType = 0x1000;
119 info.szName = name.c_str();
120 info.dwThreadID = GetCurrentThreadId();
121 info.dwFlags = 0;
122 __try {
123 RaiseException(kVCThreadNameException, 0, sizeof(info) / sizeof(DWORD),
124 reinterpret_cast<DWORD_PTR*>(&info));
125 } __except (EXCEPTION_CONTINUE_EXECUTION) {
126 }
127#elif defined(OS_FUCHSIA)
128 zx::thread::self()->set_property(ZX_PROP_NAME, name.c_str(), name.size());
129#else
130 FML_DLOG(INFO) << "Could not set the thread name to '" << name
131 << "' on this platform.";
132#endif
133}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
#define FML_DLOG(severity)
Definition logging.h:102

◆ SetUpCPUTracker()

bool fml::SetUpCPUTracker ( )

Definition at line 40 of file cpu_affinity.cc.

40 {
41 // Populate CPU Info if uninitialized.
42 auto count = std::thread::hardware_concurrency();
43 std::call_once(gCPUTrackerFlag, [count]() { InitCPUInfo(count); });
44 if (gCPUTracker == nullptr || !gCPUTracker->IsValid()) {
45 return false;
46 }
47 return true;
48}
int count
bool IsValid() const
The class is valid if it has more than one CPU index and a distinct set of efficiency or performance ...
void InitCPUInfo(size_t cpu_count)

◆ ShouldCreateLogMessage()

bool fml::ShouldCreateLogMessage ( LogSeverity  severity)

Definition at line 216 of file logging.cc.

216 {
217 return severity >= GetMinLogLevel();
218}

◆ SignalHandler()

static void fml::SignalHandler ( int  signal)
static

Definition at line 101 of file backtrace.cc.

101 {
102 // We are a crash signal handler. This can only happen once. Since we don't
103 // want to catch crashes while we are generating the crash reports, disable
104 // all set signal handlers to their default values before reporting the crash
105 // and re-raising the signal.
107
108 FML_LOG(ERROR) << "Caught signal " << SignalNameToString(signal)
109 << " during program execution." << std::endl
110 << BacktraceHere(3);
111
112 ::raise(signal);
113}
#define FML_LOG(severity)
Definition logging.h:82
std::string BacktraceHere(size_t offset)
Definition backtrace.cc:43
static std::string SignalNameToString(int signal)
Definition backtrace.cc:75
#define ERROR(message)

◆ SignalNameToString()

static std::string fml::SignalNameToString ( int  signal)
static

Definition at line 75 of file backtrace.cc.

75 {
76 switch (signal) {
77 case SIGABRT:
78 return "SIGABRT";
79 case SIGFPE:
80 return "SIGFPE";
81 case SIGSEGV:
82 return "SIGSEGV";
83 case SIGTERM:
84 return "SIGTERM";
85#if !FML_OS_WIN
86 case SIGBUS:
87 return "SIGBUS";
88 case SIGSYS:
89 return "SIGSYS";
90 case SIGPIPE:
91 return "SIGPIPE";
92 case SIGALRM:
93 return "SIGALRM";
94#endif // !FML_OS_WIN
95 };
96 return std::to_string(signal);
97}

◆ size()

template<typename T , std::size_t N>
constexpr std::size_t fml::size ( T(&)  array[N])
constexpr

Definition at line 13 of file size.h.

13 {
14 return N;
15}
#define N
Definition beziers.cpp:19

◆ strdup()

char * fml::strdup ( const char *  str1)

Definition at line 11 of file posix_wrappers_posix.cc.

11 {
12 return ::strdup(str1);
13}

◆ swap() [1/2]

template<class T , class Traits >
void fml::swap ( const UniqueObject< T, Traits > &  a,
const UniqueObject< T, Traits > &  b 
)

Definition at line 121 of file unique_object.h.

121 {
122 a.swap(b);
123}
struct MyStruct a[10]

◆ swap() [2/2]

template<class C >
void fml::swap ( scoped_nsprotocol< C > &  p1,
scoped_nsprotocol< C > &  p2 
)

Definition at line 137 of file scoped_nsobject.h.

137 {
138 p1.swap(p2);
139}
void swap(ScopedTypeRef &that)

◆ TEST() [1/9]

fml::TEST ( CountDownLatchTest  ,
CanWait   
)

Definition at line 21 of file count_down_latch_unittests.cc.

21 {
22 fml::Thread thread("test_thread");
23 const size_t count = 100;
24 size_t current_count = 0;
25 CountDownLatch latch(count);
26 auto decrement_latch_on_thread = [runner = thread.GetTaskRunner(), &latch,
27 &current_count]() {
28 runner->PostTask([&latch, &current_count]() {
29 std::this_thread::sleep_for(std::chrono::microseconds(100));
30 current_count++;
31 latch.CountDown();
32 });
33 };
34 for (size_t i = 0; i < count; ++i) {
35 decrement_latch_on_thread();
36 }
37 latch.Wait();
38 ASSERT_EQ(current_count, count);
39}

◆ TEST() [2/9]

fml::TEST ( CountDownLatchTest  ,
CanWaitOnZero   
)

Definition at line 16 of file count_down_latch_unittests.cc.

16 {
17 CountDownLatch latch(0);
18 latch.Wait();
19}

◆ TEST() [3/9]

fml::TEST ( MallocMapping  ,
Copy   
)

Definition at line 36 of file mapping_unittests.cc.

36 {
37 size_t length = 10;
38 MallocMapping mapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
39 memset(const_cast<uint8_t*>(mapping.GetMapping()), 0xac, mapping.GetSize());
40 MallocMapping copied =
41 MallocMapping::Copy(mapping.GetMapping(), mapping.GetSize());
42
43 ASSERT_NE(mapping.GetMapping(), copied.GetMapping());
44 ASSERT_EQ(mapping.GetSize(), copied.GetSize());
45 ASSERT_EQ(
46 0, memcmp(mapping.GetMapping(), copied.GetMapping(), mapping.GetSize()));
47}
A Mapping like NonOwnedMapping, but uses Free as its release proc.
Definition mapping.h:144
size_t GetSize() const override
Definition mapping.cc:143
const uint8_t * GetMapping() const override
Definition mapping.cc:147
size_t length

◆ TEST() [4/9]

fml::TEST ( MallocMapping  ,
CopySizeZero   
)

Definition at line 64 of file mapping_unittests.cc.

64 {
65 char ch = 'a';
66 MallocMapping mapping = MallocMapping::Copy(&ch, &ch);
67 ASSERT_EQ(0u, mapping.GetSize());
68}

◆ TEST() [5/9]

fml::TEST ( MallocMapping  ,
EmptyContructor   
)

Definition at line 10 of file mapping_unittests.cc.

10 {
11 MallocMapping mapping;
12 ASSERT_EQ(nullptr, mapping.GetMapping());
13 ASSERT_EQ(0u, mapping.GetSize());
14}

◆ TEST() [6/9]

fml::TEST ( MallocMapping  ,
IsDontNeedSafe   
)

Definition at line 57 of file mapping_unittests.cc.

57 {
58 size_t length = 10;
59 MallocMapping mapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
60 ASSERT_NE(nullptr, mapping.GetMapping());
61 ASSERT_FALSE(mapping.IsDontNeedSafe());
62}

◆ TEST() [7/9]

fml::TEST ( MallocMapping  ,
MoveConstructor   
)

Definition at line 23 of file mapping_unittests.cc.

23 {
24 size_t length = 10;
25 MallocMapping mapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
26 MallocMapping moved = std::move(mapping);
27
28 ASSERT_EQ(nullptr,
29 mapping.GetMapping()); // NOLINT(clang-analyzer-cplusplus.Move,
30 // bugprone-use-after-move)
31 ASSERT_EQ(0u, mapping.GetSize());
32 ASSERT_NE(nullptr, moved.GetMapping());
33 ASSERT_EQ(length, moved.GetSize());
34}

◆ TEST() [8/9]

fml::TEST ( MallocMapping  ,
NotEmptyContructor   
)

Definition at line 16 of file mapping_unittests.cc.

16 {
17 size_t length = 10;
18 MallocMapping mapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
19 ASSERT_NE(nullptr, mapping.GetMapping());
20 ASSERT_EQ(length, mapping.GetSize());
21}

◆ TEST() [9/9]

fml::TEST ( MallocMapping  ,
Release   
)

Definition at line 49 of file mapping_unittests.cc.

49 {
50 size_t length = 10;
51 MallocMapping mapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
52 free(const_cast<uint8_t*>(mapping.Release()));
53 ASSERT_EQ(nullptr, mapping.GetMapping());
54 ASSERT_EQ(0u, mapping.GetSize());
55}

◆ TimerDrain()

bool fml::TimerDrain ( int  fd)

Drains the timer FD and returns true if it has expired. This may be false in case the timer read is non-blocking and this routine was called before the timer expiry.

Definition at line 59 of file timerfd.cc.

59 {
60 // 8 bytes must be read from a signaled timer file descriptor when signaled.
61 uint64_t fire_count = 0;
62 ssize_t size = FML_HANDLE_EINTR(::read(fd, &fire_count, sizeof(uint64_t)));
63 if (size != sizeof(uint64_t)) {
64 return false;
65 }
66 return fire_count > 0;
67}
static bool read(SkStream *stream, void *buffer, size_t amount)

◆ TimerRearm()

bool fml::TimerRearm ( int  fd,
fml::TimePoint  time_point 
)

Rearms the timer to expire at the given time point.

Definition at line 38 of file timerfd.cc.

38 {
39 uint64_t nano_secs = time_point.ToEpochDelta().ToNanoseconds();
40
41 // "0" will disarm the timer, desired behavior is to immediately
42 // trigger the timer.
43 if (nano_secs < 1) {
44 nano_secs = 1;
45 }
46
47 struct itimerspec spec = {};
48 spec.it_value.tv_sec = static_cast<time_t>(nano_secs / NSEC_PER_SEC);
49 spec.it_value.tv_nsec = nano_secs % NSEC_PER_SEC;
50 spec.it_interval = spec.it_value; // single expiry.
51
52 int result = ::timerfd_settime(fd, TFD_TIMER_ABSTIME, &spec, nullptr);
53 if (result != 0) {
54 FML_DLOG(ERROR) << "timerfd_settime err:" << strerror(errno);
55 }
56 return result == 0;
57}
constexpr int64_t ToNanoseconds() const
Definition time_delta.h:61
TimeDelta ToEpochDelta() const
Definition time_point.h:52
#define NSEC_PER_SEC
Definition timerfd.cc:35
int timerfd_settime(int ufc, int flags, const struct itimerspec *utmr, struct itimerspec *otmr)
Definition timerfd.cc:23
#define TFD_TIMER_ABSTIME
Definition timerfd.h:29

◆ ToggleSignalHandlers()

static void fml::ToggleSignalHandlers ( bool  set)
static

Definition at line 115 of file backtrace.cc.

115 {
116 for (size_t i = 0; i < sizeof(kKnownSignalHandlers) / sizeof(size_t); ++i) {
117 auto signal_name = kKnownSignalHandlers[i];
118 auto handler = set ? &SignalHandler : SIG_DFL;
119
120 if (::signal(signal_name, handler) == SIG_ERR) {
121 FML_LOG(ERROR) << "Could not attach signal handler for " << signal_name;
122 }
123 }
124}
static size_t kKnownSignalHandlers[]
Definition backtrace.cc:62
static void SignalHandler(int signal)
Definition backtrace.cc:101

◆ ToPosixAccessFlags()

static int fml::ToPosixAccessFlags ( FilePermission  permission)
static

Definition at line 34 of file file_posix.cc.

34 {
35 int flags = 0;
36 switch (permission) {
37 case FilePermission::kRead:
38 flags |= O_RDONLY; // read only
39 break;
40 case FilePermission::kWrite:
41 flags |= O_WRONLY; // write only
42 break;
43 case FilePermission::kReadWrite:
44 flags |= O_RDWR; // read-write
45 break;
46 }
47 return flags;
48}

◆ ToPosixCreateModeFlags()

static int fml::ToPosixCreateModeFlags ( FilePermission  permission)
static

Definition at line 50 of file file_posix.cc.

50 {
51 int mode = 0;
52 switch (permission) {
53 case FilePermission::kRead:
54 mode |= S_IRUSR;
55 break;
56 case FilePermission::kWrite:
57 mode |= S_IWUSR;
58 break;
59 case FilePermission::kReadWrite:
60 mode |= S_IRUSR | S_IWUSR;
61 break;
62 }
63 return mode;
64}

◆ ToPosixProtectionFlags()

static int fml::ToPosixProtectionFlags ( std::initializer_list< FileMapping::Protection protection_flags)
static

Definition at line 20 of file mapping_posix.cc.

21 {
22 int flags = 0;
23 for (auto protection : protection_flags) {
24 switch (protection) {
25 case FileMapping::Protection::kRead:
26 flags |= PROT_READ;
27 break;
28 case FileMapping::Protection::kWrite:
29 flags |= PROT_WRITE;
30 break;
31 case FileMapping::Protection::kExecute:
32 flags |= PROT_READ | PROT_EXEC;
33 break;
34 }
35 }
36 return flags;
37}

◆ TruncateFile()

bool fml::TruncateFile ( const fml::UniqueFD file,
size_t  size 
)

Definition at line 155 of file file_posix.cc.

155 {
156 if (!file.is_valid()) {
157 return false;
158 }
159
160 return ::ftruncate(file.get(), size) == 0;
161}

◆ UnlinkDirectory() [1/2]

bool fml::UnlinkDirectory ( const char *  path)

Definition at line 163 of file file_posix.cc.

163 {
164 return UnlinkDirectory(fml::UniqueFD{AT_FDCWD}, path);
165}

◆ UnlinkDirectory() [2/2]

bool fml::UnlinkDirectory ( const fml::UniqueFD base_directory,
const char *  path 
)

Definition at line 167 of file file_posix.cc.

167 {
168 return ::unlinkat(base_directory.get(), path, AT_REMOVEDIR) == 0;
169}

◆ UnlinkFile() [1/2]

bool fml::UnlinkFile ( const char *  path)

Definition at line 171 of file file_posix.cc.

171 {
172 return UnlinkFile(fml::UniqueFD{AT_FDCWD}, path);
173}

◆ UnlinkFile() [2/2]

bool fml::UnlinkFile ( const fml::UniqueFD base_directory,
const char *  path 
)

Definition at line 175 of file file_posix.cc.

175 {
176 int code = ::unlinkat(base_directory.get(), path, 0);
177 if (code != 0) {
178 FML_DLOG(ERROR) << strerror(errno);
179 }
180 return code == 0;
181}

◆ Utf16ToUtf8()

std::string fml::Utf16ToUtf8 ( const std::u16string_view  string)

Definition at line 37 of file string_conversion.cc.

37 {
38 Utf16StringConverter converter;
39 return converter.to_bytes(string.data());
40}
std::wstring_convert< std::codecvt_utf8_utf16< char16_t >, char16_t > Utf16StringConverter

◆ Utf16ToWideString()

std::wstring fml::Utf16ToWideString ( const std::u16string_view  str)

Definition at line 32 of file wstring_conversion.cc.

32 {
33 static_assert(sizeof(std::wstring::value_type) ==
34 sizeof(std::u16string::value_type));
35 return {begin(str), end(str)};
36}
static const char * begin(const StringSlice &s)
Definition editor.cpp:252
glong glong end

◆ Utf8ToUtf16()

std::u16string fml::Utf8ToUtf16 ( const std::string_view  string)

Definition at line 42 of file string_conversion.cc.

42 {
43 Utf16StringConverter converter;
44 return converter.from_bytes(string.data());
45}

◆ Utf8ToWideString()

std::wstring fml::Utf8ToWideString ( const std::string_view  str)

Definition at line 21 of file wstring_conversion.cc.

21 {
22 WideStringConverter converter;
23 return converter.from_bytes(str.data());
24}
std::wstring_convert< std::codecvt_utf8_utf16< wchar_t >, wchar_t > WideStringConverter

◆ VisitFiles()

bool fml::VisitFiles ( const fml::UniqueFD directory,
const FileVisitor visitor 
)

Call visitor on all files inside the directory non-recursively. The trivial file "." and ".." will not be visited.

Return false if and only if the visitor returns false during the traversal.

If recursive visiting is needed, call VisitFiles inside the visitor, or use our helper method VisitFilesRecursively.

See also
VisitFilesRecursively.
Note
Procedure doesn't copy all closures.

Definition at line 236 of file file_posix.cc.

236 {
237 fml::UniqueFD dup_fd(dup(directory.get()));
238 if (!dup_fd.is_valid()) {
239 FML_DLOG(ERROR) << "Can't dup the directory fd. Error: " << strerror(errno);
240 return true; // continue to visit other files
241 }
242
243 fml::UniqueDir dir(::fdopendir(dup_fd.get()));
244 if (!dir.is_valid()) {
245 FML_DLOG(ERROR) << "Can't open the directory. Error: " << strerror(errno);
246 return true; // continue to visit other files
247 }
248
249 // The directory fd will be closed by `closedir`.
250 (void)dup_fd.release();
251
252 // Without `rewinddir`, `readir` will directly return NULL (end of dir is
253 // reached) after a previuos `VisitFiles` call for the same `const
254 // fml::UniqueFd& directory`.
255 rewinddir(dir.get());
256 while (dirent* ent = readdir(dir.get())) {
257 std::string filename = ent->d_name;
258 if (filename != "." && filename != "..") {
259 if (!visitor(directory, filename)) {
260 return false;
261 }
262 }
263 }
264
265 return true;
266}
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 to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
Definition switches.h:145

◆ VisitFilesRecursively()

bool fml::VisitFilesRecursively ( const fml::UniqueFD directory,
const FileVisitor visitor 
)

Recursively call visitor on all files inside the directory. Return false if and only if the visitor returns false during the traversal.

This is a helper method that wraps the general VisitFiles method. The VisitFiles is strictly more powerful as it has the access of the recursion stack to the file. For example, VisitFiles may be able to maintain a vector of directory names that lead to a file. That could be useful to compute the relative path between the root directory and the visited file.

See also
VisitFiles.
Note
Procedure doesn't copy all closures.

Definition at line 71 of file file.cc.

72 {
73 FileVisitor recursive_visitor = [&recursive_visitor, &visitor](
74 const UniqueFD& directory,
75 const std::string& filename) {
76 if (!visitor(directory, filename)) {
77 return false;
78 }
79 if (IsDirectory(directory, filename.c_str())) {
80 UniqueFD sub_dir = OpenDirectoryReadOnly(directory, filename.c_str());
81 if (!sub_dir.is_valid()) {
82 FML_LOG(ERROR) << "Can't open sub-directory: " << filename;
83 return true;
84 }
85 return VisitFiles(sub_dir, recursive_visitor);
86 }
87 return true;
88 };
89 return VisitFiles(directory, recursive_visitor);
90}

◆ WaitWithTimeoutImpl()

template<typename ConditionFn >
bool fml::WaitWithTimeoutImpl ( std::unique_lock< std::mutex > *  locker,
std::condition_variable *  cv,
ConditionFn  condition,
TimeDelta  timeout 
)

Definition at line 20 of file waitable_event.cc.

23 {
24 FML_DCHECK(locker->owns_lock());
25
26 if (condition()) {
27 return false;
28 }
29
30 // We may get spurious wakeups.
31 TimeDelta wait_remaining = timeout;
32 TimePoint start = TimePoint::Now();
33 while (true) {
34 if (std::cv_status::timeout ==
35 cv->wait_for(*locker, std::chrono::nanoseconds(
36 wait_remaining.ToNanoseconds()))) {
37 return true; // Definitely timed out.
38 }
39
40 // We may have been awoken.
41 if (condition()) {
42 return false;
43 }
44
45 // Or the wakeup may have been spurious.
46 TimePoint now = TimePoint::Now();
47 FML_DCHECK(now >= start);
48 TimeDelta elapsed = now - start;
49 // It's possible that we may have timed out anyway.
50 if (elapsed >= timeout) {
51 return true;
52 }
53
54 // Otherwise, recalculate the amount that we have left to wait.
55 wait_remaining = timeout - elapsed;
56 }
57}
std::chrono::time_point< std::chrono::high_resolution_clock > TimePoint
Definition timing.h:15
timeout(deadline, cmd)

◆ WideStringToUtf16()

std::u16string fml::WideStringToUtf16 ( const std::wstring_view  str)

Definition at line 26 of file wstring_conversion.cc.

26 {
27 static_assert(sizeof(std::wstring::value_type) ==
28 sizeof(std::u16string::value_type));
29 return {begin(str), end(str)};
30}

◆ WideStringToUtf8()

std::string fml::WideStringToUtf8 ( const std::wstring_view  str)

Definition at line 16 of file wstring_conversion.cc.

16 {
17 WideStringConverter converter;
18 return converter.to_bytes(str.data());
19}

◆ WriteAtomically()

bool fml::WriteAtomically ( const fml::UniqueFD base_directory,
const char *  file_name,
const Mapping mapping 
)

Definition at line 191 of file file_posix.cc.

193 {
194 if (file_name == nullptr || data.GetMapping() == nullptr) {
195 return false;
196 }
197
198 std::stringstream stream;
199 stream << file_name << ".temp";
200 const auto temp_file_name = stream.str();
201
202 auto temp_file = OpenFile(base_directory, temp_file_name.c_str(), true,
203 FilePermission::kReadWrite);
204 if (!temp_file.is_valid()) {
205 return false;
206 }
207
208 if (!TruncateFile(temp_file, data.GetSize())) {
209 return false;
210 }
211
212 ssize_t remaining = data.GetSize();
213 ssize_t written = 0;
214 ssize_t offset = 0;
215
216 while (remaining > 0) {
218 ::write(temp_file.get(), data.GetMapping() + offset, remaining));
219
220 if (written == -1) {
221 return false;
222 }
223
224 remaining -= written;
225 offset += written;
226 }
227
228 if (::fsync(temp_file.get()) != 0) {
229 return false;
230 }
231
232 return ::renameat(base_directory.get(), temp_file_name.c_str(),
233 base_directory.get(), file_name) == 0;
234}
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
bool TruncateFile(const fml::UniqueFD &file, size_t size)
void write(SkWStream *wStream, const T &text)
Definition skqp.cpp:188

Variable Documentation

◆ gCPUTracker

CPUSpeedTracker* fml::gCPUTracker
static

Definition at line 21 of file cpu_affinity.cc.

◆ gCPUTrackerFlag

std::once_flag fml::gCPUTrackerFlag

The CPUSpeedTracker is initialized once the first time a thread affinity is requested.

Definition at line 20 of file cpu_affinity.cc.

◆ kClockType [1/2]

constexpr int fml::kClockType = CLOCK_MONOTONIC
staticconstexpr

Definition at line 14 of file message_loop_android.cc.

◆ kClockType [2/2]

constexpr int fml::kClockType = CLOCK_MONOTONIC
staticconstexpr

Definition at line 15 of file message_loop_linux.cc.

◆ kDecodeMap

constexpr signed char fml::kDecodeMap[]
staticconstexpr
Initial value:
= {
26, 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 0, 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}

Definition at line 46 of file base32.cc.

46 {
47 // starting from ASCII 50 '2'
48 26, 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -1, -1, -1,
49 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
50 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25};

◆ kDecodeMapSize

constexpr int fml::kDecodeMapSize
staticconstexpr
Initial value:
=
sizeof(kDecodeMap) / sizeof(kDecodeMap[0])
static constexpr signed char kDecodeMap[]
Definition base32.cc:46

Definition at line 52 of file base32.cc.

◆ kDefaultFrameBudget

constexpr Milliseconds fml::kDefaultFrameBudget = Milliseconds(1s) / 60
constexpr

Definition at line 21 of file time_delta.h.

◆ kDistantFuture

constexpr CFTimeInterval fml::kDistantFuture = 1.0e10
staticconstexpr

Definition at line 14 of file message_loop_darwin.mm.

◆ kEncoding [1/2]

constexpr char fml::kEncoding[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
staticconstexpr

Definition at line 13 of file base32.cc.

◆ kEncoding [2/2]

constexpr char fml::kEncoding[] = "0123456789abcdef"
staticconstexpr

Definition at line 12 of file hex_codec.cc.

◆ kIsByteSwappableV

template<typename T >
constexpr bool fml::kIsByteSwappableV = IsByteSwappable<T>::value
constexpr

Definition at line 35 of file endianness.h.

◆ kKnownSignalHandlers

size_t fml::kKnownSignalHandlers[]
static
Initial value:
= {
SIGABRT,
SIGFPE,
SIGTERM,
SIGSEGV,
SIGBUS,
SIGSYS,
SIGPIPE,
SIGALRM,
}

Definition at line 62 of file backtrace.cc.

62 {
63 SIGABRT, // abort program
64 SIGFPE, // floating-point exception
65 SIGTERM, // software termination signal
66 SIGSEGV, // segmentation violation
67#if !FML_OS_WIN
68 SIGBUS, // bus error
69 SIGSYS, // non-existent system call invoked
70 SIGPIPE, // write on a pipe with no reader
71 SIGALRM, // real-time timer expired
72#endif // !FML_OS_WIN
73};

◆ kKUnknownFrameName [1/2]

std::string fml::kKUnknownFrameName = "Unknown"
static

Definition at line 25 of file backtrace.cc.

◆ kKUnknownFrameName [2/2]

std::string fml::kKUnknownFrameName = "Unknown"
static

Definition at line 9 of file backtrace_stub.cc.

◆ kLogDFatal

const LogSeverity fml::kLogDFatal = kLogFatal

Definition at line 58 of file log_level.h.

◆ kLogError

constexpr LogSeverity fml::kLogError = 2
constexpr

Definition at line 15 of file log_level.h.

◆ kLogFatal

constexpr LogSeverity fml::kLogFatal = 4
constexpr

Definition at line 19 of file log_level.h.

◆ kLogImportant

constexpr LogSeverity fml::kLogImportant = 3
constexpr

Definition at line 18 of file log_level.h.

◆ kLogInfo

constexpr LogSeverity fml::kLogInfo = 0
constexpr

Definition at line 13 of file log_level.h.

◆ kLogNumSeverities

constexpr LogSeverity fml::kLogNumSeverities = 5
constexpr

Definition at line 20 of file log_level.h.

◆ kLogWarning

constexpr LogSeverity fml::kLogWarning = 1
constexpr

Definition at line 14 of file log_level.h.

◆ kUnmerged

const TaskQueueId fml::kUnmerged = TaskQueueId(TaskQueueId::kUnmerged)
static

Definition at line 25 of file message_loop_task_queues.h.

◆ LOG_DFATAL

const LogSeverity fml::LOG_DFATAL = kLogDFatal

Definition at line 64 of file log_level.h.

◆ LOG_ERROR

constexpr LogSeverity fml::LOG_ERROR = kLogError
constexpr

Definition at line 35 of file log_level.h.

◆ LOG_FATAL

constexpr LogSeverity fml::LOG_FATAL = kLogFatal
constexpr

Definition at line 45 of file log_level.h.

◆ LOG_IMPORTANT

constexpr LogSeverity fml::LOG_IMPORTANT = kLogImportant
constexpr

Definition at line 40 of file log_level.h.

◆ LOG_INFO

constexpr LogSeverity fml::LOG_INFO = kLogInfo
constexpr

Definition at line 25 of file log_level.h.

◆ LOG_WARNING

constexpr LogSeverity fml::LOG_WARNING = kLogWarning
constexpr

Definition at line 30 of file log_level.h.

◆ tls_message_loop

thread_local std::unique_ptr<MessageLoop> fml::tls_message_loop
static

Definition at line 17 of file message_loop.cc.

◆ tls_task_source_grade

thread_local std::unique_ptr<TaskSourceGradeHolder> fml::tls_task_source_grade
static

Definition at line 35 of file message_loop_task_queues.cc.

◆ tTaskObservers

thread_local std::map<intptr_t, fit::closure> fml::tTaskObservers

Definition at line 11 of file task_observers.cc.