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 
6 
7 #include "flutter/fml/build_config.h"
9 
10 namespace impeller::android {
11 
13  static ProcTable gProcTable;
14  return gProcTable;
15 }
16 
17 // Only used by tests.
19  return const_cast<ProcTable&>(GetProcTable());
20 }
21 
22 template <class T>
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 
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_);
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 
70  return this->ATrace_isEnabled ? this->ATrace_isEnabled() : false;
71 }
72 
73 } // namespace impeller::android
#define RESOLVE_PROC(proc, api)
const ProcTable & GetProcTable()
Definition: proc_table.cc:12
void ResolveAndroidProc(AndroidProc< T > &proc, const std::vector< fml::RefPtr< fml::NativeLibrary >> &libs)
Definition: proc_table.cc:23
ProcTable & GetMutableProcTable()
Definition: proc_table.cc:18
ScopedObject< Object > Create(CtorArgs &&... args)
Definition: object.h:161
AndroidProcType * proc
Definition: proc_table.h:77
The table of Android procs that are resolved dynamically.
Definition: proc_table.h:97
FOR_EACH_ANDROID_PROC(DEFINE_PROC)
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
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
#define VALIDATION_LOG
Definition: validation.h:91