Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Migrate @FfiNative to @Native #39034

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 25 additions & 26 deletions lib/ui/compositing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Scene extends NativeFieldWrapperClass1 {
return Image._(image, image.width, image.height);
}

@FfiNative<Handle Function(Pointer<Void>, Uint32, Uint32, Handle)>('Scene::toImageSync')
@Native<Handle Function(Pointer<Void>, Uint32, Uint32, Handle)>(symbol: 'Scene::toImageSync')
external String? _toImageSync(int width, int height, _Image outImage);

/// Creates a raster image representation of the current state of the scene.
Expand All @@ -58,7 +58,7 @@ class Scene extends NativeFieldWrapperClass1 {
);
}

@FfiNative<Handle Function(Pointer<Void>, Uint32, Uint32, Handle)>('Scene::toImage')
@Native<Handle Function(Pointer<Void>, Uint32, Uint32, Handle)>(symbol: 'Scene::toImage')
external String? _toImage(int width, int height, _Callback<_Image?> callback);

/// Releases the resources used by this scene.
Expand All @@ -67,7 +67,7 @@ class Scene extends NativeFieldWrapperClass1 {
///
/// This can't be a leaf call because the native function calls Dart API
/// (Dart_SetNativeInstanceField).
@FfiNative<Void Function(Pointer<Void>)>('Scene::dispose')
@Native<Void Function(Pointer<Void>)>(symbol: 'Scene::dispose')
external void dispose();
}

Expand Down Expand Up @@ -235,7 +235,7 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
_constructor();
}

@FfiNative<Void Function(Handle)>('SceneBuilder::Create')
@Native<Void Function(Handle)>(symbol: 'SceneBuilder::Create')
external void _constructor();

// Layers used in this scene.
Expand Down Expand Up @@ -332,7 +332,7 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
return layer;
}

@FfiNative<Void Function(Pointer<Void>, Handle, Handle, Handle)>('SceneBuilder::pushTransformHandle')
@Native<Void Function(Pointer<Void>, Handle, Handle, Handle)>(symbol: 'SceneBuilder::pushTransformHandle')
external void _pushTransform(EngineLayer layer, Float64List matrix4, EngineLayer? oldLayer);

/// Pushes an offset operation onto the operation stack.
Expand All @@ -357,7 +357,7 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
return layer;
}

@FfiNative<Void Function(Pointer<Void>, Handle, Double, Double, Handle)>('SceneBuilder::pushOffset')
@Native<Void Function(Pointer<Void>, Handle, Double, Double, Handle)>(symbol: 'SceneBuilder::pushOffset')
external void _pushOffset(EngineLayer layer, double dx, double dy, EngineLayer? oldLayer);

/// Pushes a rectangular clip operation onto the operation stack.
Expand Down Expand Up @@ -386,7 +386,7 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
return layer;
}

@FfiNative<Void Function(Pointer<Void>, Handle, Double, Double, Double, Double, Int32, Handle)>('SceneBuilder::pushClipRect')
@Native<Void Function(Pointer<Void>, Handle, Double, Double, Double, Double, Int32, Handle)>(symbol: 'SceneBuilder::pushClipRect')
external void _pushClipRect(
EngineLayer outEngineLayer,
double left,
Expand Down Expand Up @@ -421,7 +421,7 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
return layer;
}

@FfiNative<Void Function(Pointer<Void>, Handle, Handle, Int32, Handle)>('SceneBuilder::pushClipRRect')
@Native<Void Function(Pointer<Void>, Handle, Handle, Int32, Handle)>(symbol: 'SceneBuilder::pushClipRRect')
external void _pushClipRRect(EngineLayer layer, Float32List rrect, int clipBehavior, EngineLayer? oldLayer);

/// Pushes a path clip operation onto the operation stack.
Expand Down Expand Up @@ -449,7 +449,7 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
return layer;
}

@FfiNative<Void Function(Pointer<Void>, Handle, Pointer<Void>, Int32, Handle)>('SceneBuilder::pushClipPath')
@Native<Void Function(Pointer<Void>, Handle, Pointer<Void>, Int32, Handle)>(symbol: 'SceneBuilder::pushClipPath')
external void _pushClipPath(EngineLayer layer, Path path, int clipBehavior, EngineLayer? oldLayer);

/// Pushes an opacity operation onto the operation stack.
Expand Down Expand Up @@ -477,7 +477,7 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
return layer;
}

@FfiNative<Void Function(Pointer<Void>, Handle, Int32, Double, Double, Handle)>('SceneBuilder::pushOpacity')
@Native<Void Function(Pointer<Void>, Handle, Int32, Double, Double, Handle)>(symbol: 'SceneBuilder::pushOpacity')
external void _pushOpacity(EngineLayer layer, int alpha, double dx, double dy, EngineLayer? oldLayer);

/// Pushes a color filter operation onto the operation stack.
Expand Down Expand Up @@ -505,7 +505,7 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
return layer;
}

@FfiNative<Void Function(Pointer<Void>, Handle, Pointer<Void>, Handle)>('SceneBuilder::pushColorFilter')
@Native<Void Function(Pointer<Void>, Handle, Pointer<Void>, Handle)>(symbol: 'SceneBuilder::pushColorFilter')
external void _pushColorFilter(EngineLayer layer, _ColorFilter filter, EngineLayer? oldLayer);

/// Pushes an image filter operation onto the operation stack.
Expand Down Expand Up @@ -534,7 +534,7 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
return layer;
}

@FfiNative<Void Function(Pointer<Void>, Handle, Pointer<Void>, Double, Double, Handle)>('SceneBuilder::pushImageFilter')
@Native<Void Function(Pointer<Void>, Handle, Pointer<Void>, Double, Double, Handle)>(symbol: 'SceneBuilder::pushImageFilter')
external void _pushImageFilter(EngineLayer outEngineLayer, _ImageFilter filter, double dx, double dy, EngineLayer? oldLayer);

/// Pushes a backdrop filter operation onto the operation stack.
Expand All @@ -561,7 +561,7 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
return layer;
}

@FfiNative<Void Function(Pointer<Void>, Handle, Pointer<Void>, Int32, Handle)>('SceneBuilder::pushBackdropFilter')
@Native<Void Function(Pointer<Void>, Handle, Pointer<Void>, Int32, Handle)>(symbol: 'SceneBuilder::pushBackdropFilter')
external void _pushBackdropFilter(EngineLayer outEngineLayer, _ImageFilter filter, int blendMode, EngineLayer? oldLayer);

/// Pushes a shader mask operation onto the operation stack.
Expand Down Expand Up @@ -599,8 +599,7 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
return layer;
}

@FfiNative<Void Function(Pointer<Void>, Handle, Pointer<Void>, Double, Double, Double, Double, Int32, Int32, Handle)>(
'SceneBuilder::pushShaderMask')
@Native<Void Function(Pointer<Void>, Handle, Pointer<Void>, Double, Double, Double, Double, Int32, Int32, Handle)>(symbol: 'SceneBuilder::pushShaderMask')
external void _pushShaderMask(
EngineLayer engineLayer,
Shader shader,
Expand Down Expand Up @@ -649,7 +648,7 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
return layer;
}

@FfiNative<Void Function(Pointer<Void>, Handle, Pointer<Void>, Double, Int32, Int32, Int32, Handle)>('SceneBuilder::pushPhysicalShape')
@Native<Void Function(Pointer<Void>, Handle, Pointer<Void>, Double, Int32, Int32, Int32, Handle)>(symbol: 'SceneBuilder::pushPhysicalShape')
external void _pushPhysicalShape(
EngineLayer outEngineLayer,
Path path,
Expand All @@ -672,7 +671,7 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
_pop();
}

@FfiNative<Void Function(Pointer<Void>)>('SceneBuilder::pop', isLeaf: true)
@Native<Void Function(Pointer<Void>)>(symbol: 'SceneBuilder::pop', isLeaf: true)
external void _pop();

/// Add a retained engine layer subtree from previous frames.
Expand Down Expand Up @@ -712,7 +711,7 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
_addRetained(wrapper._nativeLayer!);
}

@FfiNative<Void Function(Pointer<Void>, Handle)>('SceneBuilder::addRetained')
@Native<Void Function(Pointer<Void>, Handle)>(symbol: 'SceneBuilder::addRetained')
external void _addRetained(EngineLayer retainedLayer);

/// Adds an object to the scene that displays performance statistics.
Expand Down Expand Up @@ -743,7 +742,7 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
_addPerformanceOverlay(enabledOptions, bounds.left, bounds.right, bounds.top, bounds.bottom);
}

@FfiNative<Void Function(Pointer<Void>, Uint64, Double, Double, Double, Double)>('SceneBuilder::addPerformanceOverlay', isLeaf: true)
@Native<Void Function(Pointer<Void>, Uint64, Double, Double, Double, Double)>(symbol: 'SceneBuilder::addPerformanceOverlay', isLeaf: true)
external void _addPerformanceOverlay(int enabledOptions, double left, double right, double top, double bottom);

/// Adds a [Picture] to the scene.
Expand Down Expand Up @@ -778,7 +777,7 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
_addPicture(offset.dx, offset.dy, picture, hints);
}

@FfiNative<Void Function(Pointer<Void>, Double, Double, Pointer<Void>, Int32)>('SceneBuilder::addPicture')
@Native<Void Function(Pointer<Void>, Double, Double, Pointer<Void>, Int32)>(symbol: 'SceneBuilder::addPicture')
external void _addPicture(double dx, double dy, Picture picture, int hints);

/// Adds a backend texture to the scene.
Expand All @@ -804,7 +803,7 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
_addTexture(offset.dx, offset.dy, width, height, textureId, freeze, filterQuality.index);
}

@FfiNative<Void Function(Pointer<Void>, Double, Double, Double, Double, Int64, Bool, Int32)>('SceneBuilder::addTexture', isLeaf: true)
@Native<Void Function(Pointer<Void>, Double, Double, Double, Double, Int64, Bool, Int32)>(symbol: 'SceneBuilder::addTexture', isLeaf: true)
external void _addTexture(double dx, double dy, double width, double height, int textureId, bool freeze, int filterQuality);

/// Adds a platform view (e.g an iOS UIView) to the scene.
Expand Down Expand Up @@ -833,7 +832,7 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
_addPlatformView(offset.dx, offset.dy, width, height, viewId);
}

@FfiNative<Void Function(Pointer<Void>, Double, Double, Double, Double, Int64)>('SceneBuilder::addPlatformView', isLeaf: true)
@Native<Void Function(Pointer<Void>, Double, Double, Double, Double, Int64)>(symbol: 'SceneBuilder::addPlatformView', isLeaf: true)
external void _addPlatformView(double dx, double dy, double width, double height, int viewId);

/// Sets a threshold after which additional debugging information should be recorded.
Expand All @@ -842,7 +841,7 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
/// interested in using this feature, please contact [flutter-dev](https://groups.google.com/forum/#!forum/flutter-dev).
/// We'll hopefully be able to figure out how to make this feature more useful
/// to you.
@FfiNative<Void Function(Pointer<Void>, Uint32)>('SceneBuilder::setRasterizerTracingThreshold', isLeaf: true)
@Native<Void Function(Pointer<Void>, Uint32)>(symbol: 'SceneBuilder::setRasterizerTracingThreshold', isLeaf: true)
external void setRasterizerTracingThreshold(int frameInterval);

/// Sets whether the raster cache should checkerboard cached entries. This is
Expand All @@ -860,14 +859,14 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
///
/// Currently this interface is difficult to use by end-developers. If you're
/// interested in using this feature, please contact [flutter-dev](https://groups.google.com/forum/#!forum/flutter-dev).
@FfiNative<Void Function(Pointer<Void>, Bool)>('SceneBuilder::setCheckerboardRasterCacheImages', isLeaf: true)
@Native<Void Function(Pointer<Void>, Bool)>(symbol: 'SceneBuilder::setCheckerboardRasterCacheImages', isLeaf: true)
external void setCheckerboardRasterCacheImages(bool checkerboard);

/// Sets whether the compositor should checkerboard layers that are rendered
/// to offscreen bitmaps.
///
/// This is only useful for debugging purposes.
@FfiNative<Void Function(Pointer<Void>, Bool)>('SceneBuilder::setCheckerboardOffscreenLayers', isLeaf: true)
@Native<Void Function(Pointer<Void>, Bool)>(symbol: 'SceneBuilder::setCheckerboardOffscreenLayers', isLeaf: true)
external void setCheckerboardOffscreenLayers(bool checkerboard);

/// Finishes building the scene.
Expand All @@ -884,6 +883,6 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
return scene;
}

@FfiNative<Void Function(Pointer<Void>, Handle)>('SceneBuilder::build')
@Native<Void Function(Pointer<Void>, Handle)>(symbol: 'SceneBuilder::build')
external void _build(Scene outScene);
}
12 changes: 6 additions & 6 deletions lib/ui/dart_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ typedef CanvasPathMeasure PathMeasure;
typedef CanvasGradient Gradient;
typedef CanvasPath Path;

// List of native static functions used as @FfiNative functions.
// List of native static functions used as @Native functions.
// Items are tuples of ('function_name', 'parameter_count'), where:
// 'function_name' is the fully qualified name of the native function.
// 'parameter_count' is the number of parameters the function has.
Expand All @@ -65,8 +65,8 @@ typedef CanvasPath Path;
// bindings.
// If the name does not match a native function, the template will fail to
// instatiate, resulting in a compile time error.
// - Resolve the native function pointer associated with an @FfiNative function.
// If there is a mismatch between name or parameter count an @FfiNative is
// - Resolve the native function pointer associated with an @Native function.
// If there is a mismatch between name or parameter count an @Native is
// trying to resolve, an exception will be thrown.
#define FFI_FUNCTION_LIST(V) \
/* Constructors */ \
Expand Down Expand Up @@ -117,7 +117,7 @@ typedef CanvasPath Path;
V(DartPluginRegistrant_EnsureInitialized, 0) \
V(Vertices::init, 6)

// List of native instance methods used as @FfiNative functions.
// List of native instance methods used as @Native functions.
// Items are tuples of ('class_name', 'method_name', 'parameter_count'), where:
// 'class_name' is the name of the class containing the method.
// 'method_name' is the name of the method.
Expand All @@ -129,8 +129,8 @@ typedef CanvasPath Path;
// bindings.
// If the name does not match a native function, the template will fail to
// instatiate, resulting in a compile time error.
// - Resolve the native function pointer associated with an @FfiNative function.
// If there is a mismatch between names or parameter count an @FfiNative is
// - Resolve the native function pointer associated with an @Native function.
// If there is a mismatch between names or parameter count an @Native is
// trying to resolve, an exception will be thrown.
#define FFI_METHOD_LIST(V) \
V(Canvas, clipPath, 3) \
Expand Down
20 changes: 10 additions & 10 deletions lib/ui/experiments/scene.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,25 @@ class SceneNode extends NativeFieldWrapperClass1 {
});
}

@FfiNative<Void Function(Handle)>('SceneNode::Create')
@Native<Void Function(Handle)>(symbol: 'SceneNode::Create')
external void _constructor();

@FfiNative<Handle Function(Pointer<Void>, Handle, Handle)>('SceneNode::initFromAsset')
@Native<Handle Function(Pointer<Void>, Handle, Handle)>(symbol: 'SceneNode::initFromAsset')
external String _initFromAsset(String assetKey, _Callback<void> completionCallback);

@FfiNative<Void Function(Pointer<Void>, Handle)>('SceneNode::initFromTransform')
@Native<Void Function(Pointer<Void>, Handle)>(symbol: 'SceneNode::initFromTransform')
external void _initFromTransform(Float64List matrix4);

@FfiNative<Void Function(Pointer<Void>, Handle)>('SceneNode::AddChild')
@Native<Void Function(Pointer<Void>, Handle)>(symbol: 'SceneNode::AddChild')
external void _addChild(SceneNode sceneNode);

@FfiNative<Void Function(Pointer<Void>, Handle)>('SceneNode::SetTransform')
@Native<Void Function(Pointer<Void>, Handle)>(symbol: 'SceneNode::SetTransform')
external void _setTransform(Float64List matrix4);

@FfiNative<Void Function(Pointer<Void>, Handle, Bool, Bool, Double, Double)>('SceneNode::SetAnimationState')
@Native<Void Function(Pointer<Void>, Handle, Bool, Bool, Double, Double)>(symbol: 'SceneNode::SetAnimationState')
external void _setAnimationState(String animationName, bool playing, bool loop, double weight, double timeScale);

@FfiNative<Void Function(Pointer<Void>, Handle, Double)>('SceneNode::SeekAnimation')
@Native<Void Function(Pointer<Void>, Handle, Double)>(symbol: 'SceneNode::SeekAnimation')
external void _seekAnimation(String animationName, double time);

/// Returns a fresh instance of [SceneShader].
Expand Down Expand Up @@ -203,12 +203,12 @@ class SceneShader extends Shader {
_dispose();
}

@FfiNative<Void Function(Handle, Handle)>('SceneShader::Create')
@Native<Void Function(Handle, Handle)>(symbol: 'SceneShader::Create')
external void _constructor(SceneNode node);

@FfiNative<Void Function(Pointer<Void>, Handle)>('SceneShader::SetCameraTransform')
@Native<Void Function(Pointer<Void>, Handle)>(symbol: 'SceneShader::SetCameraTransform')
external void _setCameraTransform(Float64List matrix4);

@FfiNative<Void Function(Pointer<Void>)>('SceneShader::Dispose')
@Native<Void Function(Pointer<Void>)>(symbol: 'SceneShader::Dispose')
external void _dispose();
}
6 changes: 3 additions & 3 deletions lib/ui/isolate_name_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ class IsolateNameServer {
return _removePortNameMapping(name);
}

@FfiNative<Handle Function(Handle)>('IsolateNameServerNatives::LookupPortByName')
@Native<Handle Function(Handle)>(symbol: 'IsolateNameServerNatives::LookupPortByName')
external static SendPort? _lookupPortByName(String name);

@FfiNative<Bool Function(Handle, Handle)>('IsolateNameServerNatives::RegisterPortWithName')
@Native<Bool Function(Handle, Handle)>(symbol: 'IsolateNameServerNatives::RegisterPortWithName')
external static bool _registerPortWithName(SendPort port, String name);

@FfiNative<Bool Function(Handle)>('IsolateNameServerNatives::RemovePortNameMapping')
@Native<Bool Function(Handle)>(symbol: 'IsolateNameServerNatives::RemovePortNameMapping')
external static bool _removePortNameMapping(String name);
}
12 changes: 6 additions & 6 deletions lib/ui/natives.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DartPluginRegistrant {
_ensureInitialized();
}
}
@FfiNative<Void Function()>('DartPluginRegistrant_EnsureInitialized')
@Native<Void Function()>(symbol: 'DartPluginRegistrant_EnsureInitialized')
external static void _ensureInitialized();
}

Expand All @@ -32,10 +32,10 @@ void _printDebug(String arg) {
}

class _Logger {
@FfiNative<Void Function(Handle)>('DartRuntimeHooks::Logger_PrintString')
@Native<Void Function(Handle)>(symbol: 'DartRuntimeHooks::Logger_PrintString')
external static void _printString(String? s);

@FfiNative<Void Function(Handle)>('DartRuntimeHooks::Logger_PrintDebugString')
@Native<Void Function(Handle)>(symbol: 'DartRuntimeHooks::Logger_PrintDebugString')
external static void _printDebugString(String? s);
}

Expand Down Expand Up @@ -108,13 +108,13 @@ List<int> saveCompilationTrace() {
throw UnimplementedError();
}

@FfiNative<Void Function(Handle)>('DartRuntimeHooks::ScheduleMicrotask')
@Native<Void Function(Handle)>(symbol: 'DartRuntimeHooks::ScheduleMicrotask')
external void _scheduleMicrotask(void Function() callback);

@FfiNative<Handle Function(Handle)>('DartRuntimeHooks::GetCallbackHandle')
@Native<Handle Function(Handle)>(symbol: 'DartRuntimeHooks::GetCallbackHandle')
external int? _getCallbackHandle(Function closure);

@FfiNative<Handle Function(Int64)>('DartRuntimeHooks::GetCallbackFromHandle')
@Native<Handle Function(Int64)>(symbol: 'DartRuntimeHooks::GetCallbackFromHandle')
external Function? _getCallbackFromHandle(int handle);

typedef _PrintClosure = void Function(String line);
Expand Down
Loading