forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fuchsia] Use FFI to get System clockMonotonic (flutter#27353)
- Loading branch information
1 parent
9a22c68
commit 81621d6
Showing
17 changed files
with
222 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// 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. | ||
|
||
part of zircon; | ||
|
||
final _kLibZirconDartPath = '/pkg/lib/libzircon_ffi.so'; | ||
|
||
class _Bindings { | ||
static ZirconFFIBindings? _bindings; | ||
|
||
@pragma('vm:entry-point') | ||
static ZirconFFIBindings? get() { | ||
// For soft-transition until libzircon_ffi.so rolls into GI. | ||
if (!File(_kLibZirconDartPath).existsSync()) { | ||
return null; | ||
} | ||
|
||
if (_bindings == null) { | ||
final _dylib = DynamicLibrary.open(_kLibZirconDartPath); | ||
_bindings = ZirconFFIBindings(_dylib); | ||
} | ||
return _bindings; | ||
} | ||
} | ||
|
||
final ZirconFFIBindings? zirconFFIBindings = _Bindings.get(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# 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. | ||
|
||
import("//build/fuchsia/sdk.gni") | ||
|
||
config("zircon_ffi_config") { | ||
include_dirs = [ "." ] | ||
} | ||
|
||
shared_library("zircon_ffi") { | ||
public_configs = [ ":zircon_ffi_config" ] | ||
|
||
sources = [ | ||
"clock.cc", | ||
"clock.h", | ||
] | ||
|
||
deps = [ | ||
"$fuchsia_sdk_root/pkg:zx", | ||
"//third_party/dart/runtime:dart_api", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// 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. | ||
|
||
#include "clock.h" | ||
|
||
#include <zircon/syscalls.h> | ||
|
||
uint64_t zircon_dart_clock_get_monotonic() { | ||
return zx_clock_get_monotonic(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 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_SHELL_PLATFORM_FUCHSIA_DART_PKG_ZIRCON_SDK_FFI_CLOCK_H_ | ||
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_PKG_ZIRCON_SDK_FFI_CLOCK_H_ | ||
|
||
#include <stdint.h> | ||
|
||
#define ZIRCON_FFI_EXPORT __attribute__((visibility("default"))) | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
ZIRCON_FFI_EXPORT uint64_t zircon_dart_clock_get_monotonic(); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_PKG_ZIRCON_SDK_FFI_CLOCK_H_ |
36 changes: 36 additions & 0 deletions
36
shell/platform/fuchsia/dart-pkg/zircon_ffi/lib/zircon_ffi.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// AUTO GENERATED FILE, DO NOT EDIT. | ||
// | ||
// Generated by `package:ffigen`. | ||
import 'dart:ffi' as ffi; | ||
|
||
/// Bindings for `dart:zircon_ffi`. | ||
class ZirconFFIBindings { | ||
/// Holds the symbol lookup function. | ||
final ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName) | ||
_lookup; | ||
|
||
/// The symbols are looked up in [dynamicLibrary]. | ||
ZirconFFIBindings(ffi.DynamicLibrary dynamicLibrary) | ||
: _lookup = dynamicLibrary.lookup; | ||
|
||
/// The symbols are looked up with [lookup]. | ||
ZirconFFIBindings.fromLookup( | ||
ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName) | ||
lookup) | ||
: _lookup = lookup; | ||
|
||
int zircon_dart_clock_get_monotonic() { | ||
return _zircon_dart_clock_get_monotonic(); | ||
} | ||
|
||
late final _zircon_dart_clock_get_monotonic_ptr = | ||
_lookup<ffi.NativeFunction<_c_zircon_dart_clock_get_monotonic>>( | ||
'zircon_dart_clock_get_monotonic'); | ||
late final _dart_zircon_dart_clock_get_monotonic | ||
_zircon_dart_clock_get_monotonic = _zircon_dart_clock_get_monotonic_ptr | ||
.asFunction<_dart_zircon_dart_clock_get_monotonic>(); | ||
} | ||
|
||
typedef _c_zircon_dart_clock_get_monotonic = ffi.Uint64 Function(); | ||
|
||
typedef _dart_zircon_dart_clock_get_monotonic = int Function(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: zircon_ffi | ||
|
||
environment: | ||
sdk: '>=2.12.0 <3.0.0' | ||
|
||
dependencies: | ||
ffi: ^1.0.0 | ||
|
||
dev_dependencies: | ||
ffigen: ^3.0.0 | ||
lints: ^1.0.1 | ||
|
||
ffigen: | ||
name: ZirconFFIBindings | ||
description: Bindings for `dart:zircon_ffi`. | ||
output: 'lib/zircon_ffi.dart' | ||
headers: | ||
entry-points: | ||
- 'clock.h' | ||
functions: | ||
include: | ||
- 'zircon_dart_.*' | ||
macros: | ||
include: | ||
- nothing | ||
enums: | ||
include: | ||
- nothing | ||
unnamed-enums: | ||
include: | ||
- nothing | ||
globals: | ||
include: | ||
- nothing | ||
structs: | ||
include: | ||
- nothing | ||
dependency-only: opaque | ||
compiler-opts: | ||
- '-I../../../../../../../third_party/dart/runtime' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters