Refact/stride align (#8)

* rename row_align_bytes  to stride_align

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* trivail changes

Signed-off-by: fufesou <shuanglongchen@yeah.net>

---------

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-03-03 09:46:33 +08:00 • committed by GitHub
parent 873919902e
commit 8d66a7c55e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 26 additions and 26 deletions

View file

@ -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. 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 ```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: 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 ```dart
/// The `Native` class is bundled in this plugin. /// The `Native` class is bundled in this plugin.
typedef F1 = Void Function(Pointer<Void> ptr, Pointer<Uint8> buffer, Int len, typedef F1 = Void Function(Pointer<Void> ptr, Pointer<Uint8> buffer, Int len,
Int32 width, Int32 height, Int row_align_bytes); Int32 width, Int32 height, Int stride_align);
typedef F1Dart = void Function(Pointer<Void> ptr, Pointer<Uint8> buffer, typedef F1Dart = void Function(Pointer<Void> ptr, Pointer<Uint8> buffer,
int len, int width, int height, int row_align_bytes); int len, int width, int height, int stride_align);
class Native { class Native {
Native._(); Native._();

View file

@ -34,7 +34,7 @@ class _MyAppState extends State<MyApp> {
Timer? _timer; Timer? _timer;
int time = 0; int time = 0;
int method = 0; int method = 0;
final rowAlignBytes = Platform.isMacOS ? 64 : 1; final strideAlign = Platform.isMacOS ? 64 : 1;
@override @override
void initState() { void initState() {
@ -60,7 +60,7 @@ class _MyAppState extends State<MyApp> {
void start(int methodId) { void start(int methodId) {
debugPrint("start mockPic"); debugPrint("start mockPic");
method = methodId; method = methodId;
final rowBytes = (width * 4 + rowAlignBytes - 1) & (~(rowAlignBytes - 1)); final rowBytes = (width * 4 + strideAlign - 1) & (~(strideAlign - 1));
final picDataLength = rowBytes * height; final picDataLength = rowBytes * height;
_timer?.cancel(); _timer?.cancel();
// 60 fps // 60 fps
@ -71,7 +71,7 @@ class _MyAppState extends State<MyApp> {
data = mockPicture(width, height, rowBytes, picDataLength); data = mockPicture(width, height, rowBytes, picDataLength);
final t1 = DateTime.now().microsecondsSinceEpoch; final t1 = DateTime.now().microsecondsSinceEpoch;
final res = await _textureRgbaRendererPlugin.onRgba( final res = await _textureRgbaRendererPlugin.onRgba(
key, data!, height, width, rowAlignBytes); key, data!, height, width, strideAlign);
final t2 = DateTime.now().microsecondsSinceEpoch; final t2 = DateTime.now().microsecondsSinceEpoch;
setState(() { setState(() {
time = t2 - t1; time = t2 - t1;
@ -84,7 +84,7 @@ class _MyAppState extends State<MyApp> {
// Method.2: with native ffi // Method.2: with native ffi
final t1 = DateTime.now().microsecondsSinceEpoch; final t1 = DateTime.now().microsecondsSinceEpoch;
Native.instance.onRgba(Pointer.fromAddress(texturePtr).cast<Void>(), Native.instance.onRgba(Pointer.fromAddress(texturePtr).cast<Void>(),
dataPtr, picDataLength, width, height, rowAlignBytes); dataPtr, picDataLength, width, height, strideAlign);
final t2 = DateTime.now().microsecondsSinceEpoch; final t2 = DateTime.now().microsecondsSinceEpoch;
setState(() { setState(() {
time = t2 - t1; time = t2 - t1;

View file

@ -1,9 +1,9 @@
import 'dart:ffi'; import 'dart:ffi';
typedef F1 = Void Function(Pointer<Void> ptr, Pointer<Uint8> buffer, Int len, typedef F1 = Void Function(Pointer<Void> ptr, Pointer<Uint8> buffer, Int len,
Int32 width, Int32 height, Int row_align_bytes); Int32 width, Int32 height, Int stride_align);
typedef F1Dart = void Function(Pointer<Void> ptr, Pointer<Uint8> buffer, typedef F1Dart = void Function(Pointer<Void> ptr, Pointer<Uint8> buffer,
int len, int width, int height, int row_align_bytes); int len, int width, int height, int stride_align);
class Native { class Native {
Native._(); Native._();

View file

@ -24,9 +24,9 @@ class TextureRgbaRenderer {
/// Provide the rgba data to the texture. /// Provide the rgba data to the texture.
Future<bool> onRgba( Future<bool> 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 return TextureRgbaRendererPlatform.instance
.onRgba(key, data, height, width, row_align_bytes); .onRgba(key, data, height, width, stride_align);
} }
Future<int> getTexturePtr(int key) { Future<int> getTexturePtr(int key) {

View file

@ -37,14 +37,14 @@ class MethodChannelTextureRgbaRenderer extends TextureRgbaRendererPlatform {
} }
@override @override
Future<bool> onRgba(int key, Uint8List data, int height, int width, Future<bool> onRgba(
int row_align_bytes) async { int key, Uint8List data, int height, int width, int stride_align) async {
return await methodChannel.invokeMethod<bool>('onRgba', { return await methodChannel.invokeMethod<bool>('onRgba', {
"data": data, "data": data,
"height": height, "height": height,
"width": width, "width": width,
"key": key, "key": key,
"row_align_bytes": row_align_bytes, "stride_align": stride_align,
}) ?? }) ??
false; false;
} }

View file

@ -40,7 +40,7 @@ abstract class TextureRgbaRendererPlatform extends PlatformInterface {
} }
Future<bool> onRgba( Future<bool> 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.'); throw UnimplementedError('onRgba() has not been implemented.');
} }

View file

@ -22,7 +22,7 @@ FLUTTER_PLUGIN_EXPORT void texture_rgba_renderer_plugin_register_with_registrar(
FlPluginRegistrar* registrar); FlPluginRegistrar* registrar);
// Keep the same symbol name with Windows. // 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 G_END_DECLS

View file

@ -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 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 width = fl_value_get_int(fl_value_lookup_string(args, "width"));
auto height = fl_value_get_int(fl_value_lookup_string(args, "height")); 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]; 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( 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))))); 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" { 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); TextureRgba* self = TEXTURE_RGBA(texture_rgba_ptr);
g_mutex_lock(&self->mutex); g_mutex_lock(&self->mutex);
// selfate has registered a texture_id, // selfate has registered a texture_id,

View file

@ -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 { queue.sync {
self.data = data.withUnsafeBytes { buffer in self.data = data.withUnsafeBytes { buffer in
var pixelBufferCopy: CVPixelBuffer! var pixelBufferCopy: CVPixelBuffer!

View file

@ -13,10 +13,10 @@ extern "C" {
#endif #endif
/// Keep the same name with Windows. /// 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); TextRgba* texture_rgba = (__bridge TextRgba *)(texture_rgba_ptr);
NSData* data = [NSData dataWithBytesNoCopy:(void*)buffer length:len freeWhenDone:FALSE]; 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 #if __cplusplus

View file

@ -49,12 +49,12 @@ public class TextureRgbaRendererPlugin: NSObject, FlutterPlugin {
let data = args["data"] as! FlutterStandardTypedData let data = args["data"] as! FlutterStandardTypedData
let height = args["height"] as! Int let height = args["height"] as! Int
let width = args["width"] 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] let textureRgba = renderer[key]
if (textureRgba == nil) { if (textureRgba == nil) {
result(false) result(false)
} else { } 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": case "getTexturePtr":
let args = call.arguments as! Dictionary<String, Any?> let args = call.arguments as! Dictionary<String, Any?>

View file

@ -16,7 +16,7 @@ extern "C" {
FLUTTER_PLUGIN_EXPORT void TextureRgbaRendererPluginCApiRegisterWithRegistrar( FLUTTER_PLUGIN_EXPORT void TextureRgbaRendererPluginCApiRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar); 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) #if defined(__cplusplus)
} // extern "C" } // extern "C"

View file

@ -14,7 +14,7 @@ void TextureRgbaRendererPluginCApiRegisterWithRegistrar(
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar)); ->GetRegistrar<flutter::PluginRegistrarWindows>(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(texture_rgba != nullptr);
assert(buffer != nullptr); assert(buffer != nullptr);