mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This change adds additional Tonic templates for automatically generating bindings for Dart FFI, as well as serialisation of the bindings. - Adds parallel FfiDispather templates to the existing DartDispatcher used for (old) native bindings. - Adds serialisation of the bindings to enable automatic conversion and verification. - Extends existing DartConverters with conversions to and from the FFI transport types. - Adds new test (ffi_native_unittest.cc) for the above. This will allow us to replace the existing native functions in e.g. dart:ui with new Dart FFI native functions.
62 lines
2.1 KiB
C++
62 lines
2.1 KiB
C++
// Copyright 2013 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef FLUTTER_TESTING_TEST_DART_NATIVE_RESOLVER_H_
|
|
#define FLUTTER_TESTING_TEST_DART_NATIVE_RESOLVER_H_
|
|
|
|
#include <functional>
|
|
#include <map>
|
|
#include <memory>
|
|
|
|
#include "flutter/fml/macros.h"
|
|
#include "third_party/dart/runtime/include/dart_api.h"
|
|
|
|
#define CREATE_NATIVE_ENTRY(native_entry) \
|
|
([&]() { \
|
|
static ::flutter::testing::NativeEntry closure; \
|
|
static Dart_NativeFunction entrypoint = [](Dart_NativeArguments args) { \
|
|
closure(args); \
|
|
}; \
|
|
closure = (native_entry); \
|
|
return entrypoint; \
|
|
})()
|
|
|
|
namespace flutter {
|
|
namespace testing {
|
|
|
|
using NativeEntry = std::function<void(Dart_NativeArguments)>;
|
|
|
|
class TestDartNativeResolver
|
|
: public std::enable_shared_from_this<TestDartNativeResolver> {
|
|
public:
|
|
TestDartNativeResolver();
|
|
|
|
~TestDartNativeResolver();
|
|
|
|
void AddNativeCallback(std::string name, Dart_NativeFunction callback);
|
|
void AddFfiNativeCallback(std::string name, void* callback_ptr);
|
|
|
|
void SetNativeResolverForIsolate();
|
|
|
|
private:
|
|
std::map<std::string, Dart_NativeFunction> native_callbacks_;
|
|
std::map<std::string, void*> ffi_native_callbacks_;
|
|
|
|
Dart_NativeFunction ResolveCallback(std::string name) const;
|
|
void* ResolveFfiCallback(std::string name) const;
|
|
|
|
static Dart_NativeFunction DartNativeEntryResolverCallback(
|
|
Dart_Handle dart_name,
|
|
int num_of_arguments,
|
|
bool* auto_setup_scope);
|
|
static void* FfiNativeResolver(const char* name, uintptr_t args_n);
|
|
|
|
FML_DISALLOW_COPY_AND_ASSIGN(TestDartNativeResolver);
|
|
};
|
|
|
|
} // namespace testing
|
|
} // namespace flutter
|
|
|
|
#endif // FLUTTER_TESTING_TEST_DART_NATIVE_RESOLVER_H_
|