diff --git a/README.md b/README.md index 13b6f21..e1d72b5 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ class TextureRgbaRenderer { Note that the `onRgba` function is not called immediately. It depends on the execution scheduler of Flutter. To solve the problem, the plugin provide the low level function on all 3 pc platforms, which can make them be executed immediately. ```c -void FlutterRgbaRendererPluginOnRgba(void* texture_rgba_ptr, const uint8_t* buffer, int len, int width, int height, int row_align_bytes) +void FlutterRgbaRendererPluginOnRgba(void* texture_rgba_ptr, const uint8_t* buffer, int len, int width, int height, int stride_align) ``` You could use the native API in other programing languages. A dart quick example: @@ -126,9 +126,9 @@ You could use the native API in other programing languages. A dart quick example ```dart /// The `Native` class is bundled in this plugin. typedef F1 = Void Function(Pointer ptr, Pointer buffer, Int len, - Int32 width, Int32 height, Int row_align_bytes); + Int32 width, Int32 height, Int stride_align); typedef F1Dart = void Function(Pointer ptr, Pointer buffer, - int len, int width, int height, int row_align_bytes); + int len, int width, int height, int stride_align); class Native { Native._(); diff --git a/example/lib/main.dart b/example/lib/main.dart index 53ae0ae..6773e45 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -34,7 +34,7 @@ class _MyAppState extends State { Timer? _timer; int time = 0; int method = 0; - final rowAlignBytes = Platform.isMacOS ? 64 : 1; + final strideAlign = Platform.isMacOS ? 64 : 1; @override void initState() { @@ -60,7 +60,7 @@ class _MyAppState extends State { void start(int methodId) { debugPrint("start mockPic"); method = methodId; - final rowBytes = (width * 4 + rowAlignBytes - 1) & (~(rowAlignBytes - 1)); + final rowBytes = (width * 4 + strideAlign - 1) & (~(strideAlign - 1)); final picDataLength = rowBytes * height; _timer?.cancel(); // 60 fps @@ -71,7 +71,7 @@ class _MyAppState extends State { data = mockPicture(width, height, rowBytes, picDataLength); final t1 = DateTime.now().microsecondsSinceEpoch; final res = await _textureRgbaRendererPlugin.onRgba( - key, data!, height, width, rowAlignBytes); + key, data!, height, width, strideAlign); final t2 = DateTime.now().microsecondsSinceEpoch; setState(() { time = t2 - t1; @@ -84,7 +84,7 @@ class _MyAppState extends State { // Method.2: with native ffi final t1 = DateTime.now().microsecondsSinceEpoch; Native.instance.onRgba(Pointer.fromAddress(texturePtr).cast(), - dataPtr, picDataLength, width, height, rowAlignBytes); + dataPtr, picDataLength, width, height, strideAlign); final t2 = DateTime.now().microsecondsSinceEpoch; setState(() { time = t2 - t1; diff --git a/lib/texture_rgba_ffi.dart b/lib/texture_rgba_ffi.dart index 6c341eb..94731b9 100644 --- a/lib/texture_rgba_ffi.dart +++ b/lib/texture_rgba_ffi.dart @@ -1,9 +1,9 @@ import 'dart:ffi'; typedef F1 = Void Function(Pointer ptr, Pointer buffer, Int len, - Int32 width, Int32 height, Int row_align_bytes); + Int32 width, Int32 height, Int stride_align); typedef F1Dart = void Function(Pointer ptr, Pointer buffer, - int len, int width, int height, int row_align_bytes); + int len, int width, int height, int stride_align); class Native { Native._(); diff --git a/lib/texture_rgba_renderer.dart b/lib/texture_rgba_renderer.dart index e66a61e..f3a1f02 100644 --- a/lib/texture_rgba_renderer.dart +++ b/lib/texture_rgba_renderer.dart @@ -24,9 +24,9 @@ class TextureRgbaRenderer { /// Provide the rgba data to the texture. Future onRgba( - int key, Uint8List data, int height, int width, int row_align_bytes) { + int key, Uint8List data, int height, int width, int stride_align) { return TextureRgbaRendererPlatform.instance - .onRgba(key, data, height, width, row_align_bytes); + .onRgba(key, data, height, width, stride_align); } Future getTexturePtr(int key) { diff --git a/lib/texture_rgba_renderer_method_channel.dart b/lib/texture_rgba_renderer_method_channel.dart index da6c2d8..f45fcc4 100644 --- a/lib/texture_rgba_renderer_method_channel.dart +++ b/lib/texture_rgba_renderer_method_channel.dart @@ -37,14 +37,14 @@ class MethodChannelTextureRgbaRenderer extends TextureRgbaRendererPlatform { } @override - Future onRgba(int key, Uint8List data, int height, int width, - int row_align_bytes) async { + Future onRgba( + int key, Uint8List data, int height, int width, int stride_align) async { return await methodChannel.invokeMethod('onRgba', { "data": data, "height": height, "width": width, "key": key, - "row_align_bytes": row_align_bytes, + "stride_align": stride_align, }) ?? false; } diff --git a/lib/texture_rgba_renderer_platform_interface.dart b/lib/texture_rgba_renderer_platform_interface.dart index 77af47a..6e56981 100644 --- a/lib/texture_rgba_renderer_platform_interface.dart +++ b/lib/texture_rgba_renderer_platform_interface.dart @@ -40,7 +40,7 @@ abstract class TextureRgbaRendererPlatform extends PlatformInterface { } Future onRgba( - int key, Uint8List data, int height, int width, int row_align_bytes) { + int key, Uint8List data, int height, int width, int stride_align) { throw UnimplementedError('onRgba() has not been implemented.'); } diff --git a/linux/include/texture_rgba_renderer/texture_rgba_renderer_plugin.h b/linux/include/texture_rgba_renderer/texture_rgba_renderer_plugin.h index f7c7745..6320593 100644 --- a/linux/include/texture_rgba_renderer/texture_rgba_renderer_plugin.h +++ b/linux/include/texture_rgba_renderer/texture_rgba_renderer_plugin.h @@ -22,7 +22,7 @@ FLUTTER_PLUGIN_EXPORT void texture_rgba_renderer_plugin_register_with_registrar( FlPluginRegistrar* registrar); // Keep the same symbol name with Windows. -FLUTTER_PLUGIN_EXPORT void FlutterRgbaRendererPluginOnRgba(void *texture_rgba, const uint8_t *buffer, int len, int width, int height, int row_align_bytes); +FLUTTER_PLUGIN_EXPORT void FlutterRgbaRendererPluginOnRgba(void *texture_rgba, const uint8_t *buffer, int len, int width, int height, int stride_align); G_END_DECLS diff --git a/linux/texture_rgba_renderer_plugin.cc b/linux/texture_rgba_renderer_plugin.cc index 0c6ba4b..434c90a 100644 --- a/linux/texture_rgba_renderer_plugin.cc +++ b/linux/texture_rgba_renderer_plugin.cc @@ -71,9 +71,9 @@ static void texture_rgba_renderer_plugin_handle_method_call( auto data_length = fl_value_get_length(fl_value_lookup_string(args, "data")); auto width = fl_value_get_int(fl_value_lookup_string(args, "width")); auto height = fl_value_get_int(fl_value_lookup_string(args, "height")); - auto row_align_bytes = fl_value_get_int(fl_value_lookup_string(args, "row_align_bytes")); + auto stride_align = fl_value_get_int(fl_value_lookup_string(args, "stride_align")); auto texture_rgba = g_renderer_map[key]; - FlutterRgbaRendererPluginOnRgba((void*)texture_rgba, data, data_length, width, height, row_align_bytes); + FlutterRgbaRendererPluginOnRgba((void*)texture_rgba, data, data_length, width, height, stride_align); response = FL_METHOD_RESPONSE(fl_method_success_response_new( fl_value_new_bool(fl_texture_registrar_mark_texture_frame_available(self->texture_registrar, FL_TEXTURE(texture_rgba))))); } @@ -141,7 +141,7 @@ void texture_rgba_renderer_plugin_register_with_registrar(FlPluginRegistrar *reg extern "C" { - void FlutterRgbaRendererPluginOnRgba(void *texture_rgba_ptr, const uint8_t *buffer, int len, int width, int height, int row_align_bytes) { + void FlutterRgbaRendererPluginOnRgba(void *texture_rgba_ptr, const uint8_t *buffer, int len, int width, int height, int stride_align) { TextureRgba* self = TEXTURE_RGBA(texture_rgba_ptr); g_mutex_lock(&self->mutex); // selfate has registered a texture_id, diff --git a/macos/Classes/TextRgba.swift b/macos/Classes/TextRgba.swift index ca8afbe..263ed98 100644 --- a/macos/Classes/TextRgba.swift +++ b/macos/Classes/TextRgba.swift @@ -34,7 +34,7 @@ import CoreVideo } - @objc public func markFrameAvaliable(data: Data, width: Int, height: Int, row_align_bytes: Int) -> Bool { + @objc public func markFrameAvaliable(data: Data, width: Int, height: Int, stride_align: Int) -> Bool { queue.sync { self.data = data.withUnsafeBytes { buffer in var pixelBufferCopy: CVPixelBuffer! diff --git a/macos/Classes/TextureRgbaApi.m b/macos/Classes/TextureRgbaApi.m index 2ab02ed..f934aa3 100644 --- a/macos/Classes/TextureRgbaApi.m +++ b/macos/Classes/TextureRgbaApi.m @@ -13,10 +13,10 @@ extern "C" { #endif /// Keep the same name with Windows. -void FlutterRgbaRendererPluginOnRgba(void* texture_rgba_ptr, const uint8_t* buffer, int len, int width, int height, int row_align_bytes) { +void FlutterRgbaRendererPluginOnRgba(void* texture_rgba_ptr, const uint8_t* buffer, int len, int width, int height, int stride_align) { TextRgba* texture_rgba = (__bridge TextRgba *)(texture_rgba_ptr); NSData* data = [NSData dataWithBytesNoCopy:(void*)buffer length:len freeWhenDone:FALSE]; - [texture_rgba markFrameAvaliableWithData:data width:width height:height row_align_bytes: row_align_bytes]; + [texture_rgba markFrameAvaliableWithData:data width:width height:height stride_align: stride_align]; } #if __cplusplus diff --git a/macos/Classes/TextureRgbaRendererPlugin.swift b/macos/Classes/TextureRgbaRendererPlugin.swift index 16f03f5..8c991a6 100644 --- a/macos/Classes/TextureRgbaRendererPlugin.swift +++ b/macos/Classes/TextureRgbaRendererPlugin.swift @@ -49,12 +49,12 @@ public class TextureRgbaRendererPlugin: NSObject, FlutterPlugin { let data = args["data"] as! FlutterStandardTypedData let height = args["height"] as! Int let width = args["width"] as! Int - let row_align_bytes = args["row_align_bytes"] as! Int + let stride_align = args["stride_align"] as! Int let textureRgba = renderer[key] if (textureRgba == nil) { result(false) } else { - result(textureRgba!.markFrameAvaliable(data: data.data, width: width, height: height, row_align_bytes: row_align_bytes)) + result(textureRgba!.markFrameAvaliable(data: data.data, width: width, height: height, stride_align: stride_align)) } case "getTexturePtr": let args = call.arguments as! Dictionary diff --git a/windows/include/texture_rgba_renderer/texture_rgba_renderer_plugin_c_api.h b/windows/include/texture_rgba_renderer/texture_rgba_renderer_plugin_c_api.h index 0e54994..ca55ccc 100644 --- a/windows/include/texture_rgba_renderer/texture_rgba_renderer_plugin_c_api.h +++ b/windows/include/texture_rgba_renderer/texture_rgba_renderer_plugin_c_api.h @@ -16,7 +16,7 @@ extern "C" { FLUTTER_PLUGIN_EXPORT void TextureRgbaRendererPluginCApiRegisterWithRegistrar( FlutterDesktopPluginRegistrarRef registrar); -FLUTTER_PLUGIN_EXPORT void FlutterRgbaRendererPluginOnRgba(void* texture_rgba, const uint8_t* buffer, int len, int width, int height, int row_align_bytes); +FLUTTER_PLUGIN_EXPORT void FlutterRgbaRendererPluginOnRgba(void* texture_rgba, const uint8_t* buffer, int len, int width, int height, int stride_align); #if defined(__cplusplus) } // extern "C" diff --git a/windows/texture_rgba_renderer_plugin_c_api.cpp b/windows/texture_rgba_renderer_plugin_c_api.cpp index 9e9a667..8d64947 100644 --- a/windows/texture_rgba_renderer_plugin_c_api.cpp +++ b/windows/texture_rgba_renderer_plugin_c_api.cpp @@ -14,7 +14,7 @@ void TextureRgbaRendererPluginCApiRegisterWithRegistrar( ->GetRegistrar(registrar)); } -void FlutterRgbaRendererPluginOnRgba(void *texture_rgba, const uint8_t *buffer, int len, int width, int height, int row_align_bytes) +void FlutterRgbaRendererPluginOnRgba(void *texture_rgba, const uint8_t *buffer, int len, int width, int height, int stride_align) { assert(texture_rgba != nullptr); assert(buffer != nullptr);