| Flutter Impeller |

proc_table.cc
Go to the documentation of this file.
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 #include "flutter/impeller/toolkit/android/proc_table.h"
6
7 #include "flutter/fml/build_config.h"
8 #include "impeller/base/validation.h"
9
10 namespace impeller::android {
11
12 const ProcTable& GetProcTable() {
13 static ProcTable gProcTable;
14 return gProcTable;
15 }
16
17 // Only used by tests.
18 ProcTable& GetMutableProcTable() {
19 return const_cast<ProcTable&>(GetProcTable());
20 }
21
22 template <class T>
23 void ResolveAndroidProc(
24 AndroidProc<T>& proc,
25 const std::vector<fml::RefPtr<fml::NativeLibrary>>& libs) {
26 for (const auto& lib : libs) {
27 proc.proc = lib->ResolveFunction<T*>(proc.proc_name).value_or(nullptr);
28 if (proc.proc) {
29 break;
30 }
31 }
32 }
33
34 ProcTable::ProcTable() {
35 auto lib_android = fml::NativeLibrary::Create("libandroid.so");
36 auto lib_egl = fml::NativeLibrary::Create("libEGL.so");
37
38 if (!lib_android || !lib_egl) {
39 VALIDATION_LOG << "Could not open Android libraries.";
40 return;
41 }
42
43 libraries_.push_back(std::move(lib_android));
44 libraries_.push_back(std::move(lib_egl));
45
46 #define RESOLVE_PROC(proc, api) ResolveAndroidProc(proc, libraries_);
47 FOR_EACH_ANDROID_PROC(RESOLVE_PROC);
48 #undef RESOLVE_PROC
49
50 if (AChoreographer_postFrameCallback64) {
51 AChoreographer_postFrameCallback.Reset();
52 }
53
54 #if FML_ARCH_CPU_32_BITS
55 // On 32-bit platforms, the nanosecond resolution timestamp causes overflow on
56 // the argument in the callback. Don't use it on those platforms.
57 AChoreographer_postFrameCallback.Reset();
58 #endif // FML_ARCH_CPU_32_BITS
59
60 is_valid_ = true;
61 }
62
63 ProcTable::~ProcTable() = default;
64
65 bool ProcTable::IsValid() const {
66 return is_valid_;
67 }
68
69 bool ProcTable::TraceIsEnabled() const {
70 return this->ATrace_isEnabled ? this->ATrace_isEnabled() : false;
71 }
72
73 } // namespace impeller::android
RESOLVE_PROC
#define RESOLVE_PROC(proc, api)
proc_table.h
impeller::android
Definition: ahb_texture_source_vk_unittests.cc:16
impeller::android::GetProcTable
const ProcTable & GetProcTable()
Definition: proc_table.cc:12
impeller::android::ResolveAndroidProc
void ResolveAndroidProc(AndroidProc< T > &proc, const std::vector< fml::RefPtr< fml::NativeLibrary >> &libs)
Definition: proc_table.cc:23
impeller::android::GetMutableProcTable
ProcTable & GetMutableProcTable()
Definition: proc_table.cc:18
impeller::interop::Create
ScopedObject< Object > Create(CtorArgs &&... args)
Definition: object.h:161
impeller::android::AndroidProc
Definition: proc_table.h:77
impeller::android::AndroidProc::proc_name
const char * proc_name
Definition: proc_table.h:80
impeller::android::AndroidProc::proc
AndroidProcType * proc
Definition: proc_table.h:82
impeller::android::ProcTable
The table of Android procs that are resolved dynamically.
Definition: proc_table.h:102
impeller::android::ProcTable::~ProcTable
~ProcTable()
impeller::android::ProcTable::FOR_EACH_ANDROID_PROC
FOR_EACH_ANDROID_PROC(DEFINE_PROC)
impeller::android::ProcTable::ProcTable
ProcTable()
Definition: proc_table.cc:34
impeller::android::ProcTable::IsValid
bool IsValid() const
If a valid proc table could be setup. This may fail in case of setup on non-Android platforms.
Definition: proc_table.cc:65
impeller::android::ProcTable::TraceIsEnabled
bool TraceIsEnabled() const
Check if tracing in enabled in the process. This call can be made at any API level.
Definition: proc_table.cc:69
validation.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91