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:
parent
873919902e
commit
8d66a7c55e
13 changed files with 26 additions and 26 deletions
|
|
@ -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<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,
|
||||
int len, int width, int height, int row_align_bytes);
|
||||
int len, int width, int height, int stride_align);
|
||||
|
||||
class Native {
|
||||
Native._();
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class _MyAppState extends State<MyApp> {
|
|||
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<MyApp> {
|
|||
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<MyApp> {
|
|||
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<MyApp> {
|
|||
// Method.2: with native ffi
|
||||
final t1 = DateTime.now().microsecondsSinceEpoch;
|
||||
Native.instance.onRgba(Pointer.fromAddress(texturePtr).cast<Void>(),
|
||||
dataPtr, picDataLength, width, height, rowAlignBytes);
|
||||
dataPtr, picDataLength, width, height, strideAlign);
|
||||
final t2 = DateTime.now().microsecondsSinceEpoch;
|
||||
setState(() {
|
||||
time = t2 - t1;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import 'dart:ffi';
|
||||
|
||||
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,
|
||||
int len, int width, int height, int row_align_bytes);
|
||||
int len, int width, int height, int stride_align);
|
||||
|
||||
class Native {
|
||||
Native._();
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ class TextureRgbaRenderer {
|
|||
|
||||
/// Provide the rgba data to the texture.
|
||||
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
|
||||
.onRgba(key, data, height, width, row_align_bytes);
|
||||
.onRgba(key, data, height, width, stride_align);
|
||||
}
|
||||
|
||||
Future<int> getTexturePtr(int key) {
|
||||
|
|
|
|||
|
|
@ -37,14 +37,14 @@ class MethodChannelTextureRgbaRenderer extends TextureRgbaRendererPlatform {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<bool> onRgba(int key, Uint8List data, int height, int width,
|
||||
int row_align_bytes) async {
|
||||
Future<bool> onRgba(
|
||||
int key, Uint8List data, int height, int width, int stride_align) async {
|
||||
return await methodChannel.invokeMethod<bool>('onRgba', {
|
||||
"data": data,
|
||||
"height": height,
|
||||
"width": width,
|
||||
"key": key,
|
||||
"row_align_bytes": row_align_bytes,
|
||||
"stride_align": stride_align,
|
||||
}) ??
|
||||
false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ abstract class TextureRgbaRendererPlatform extends PlatformInterface {
|
|||
}
|
||||
|
||||
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.');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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!
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<String, Any?>
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ void TextureRgbaRendererPluginCApiRegisterWithRegistrar(
|
|||
->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(buffer != nullptr);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue