bump: 0.0.7
This commit is contained in:
parent
4f059a9138
commit
0cda2d38d4
8 changed files with 144 additions and 66 deletions
68
README.md
68
README.md
|
|
@ -10,18 +10,10 @@ A texture helper which brings a high level api to handle **BGRA** data. No frame
|
|||
The plugin aims to provide opengl impl for the texture, which bring a better performance instead of `FFI` + `CustomPainter`.
|
||||
|
||||
- [x] Linux
|
||||
- [x] Windows (No gpu acceleration yet due to the limitation of Flutter.)
|
||||
|
||||
```c++
|
||||
// The available texture variants.
|
||||
// Only PixelBufferTexture is currently implemented.
|
||||
// Other variants are expected to be added in the future.
|
||||
typedef std::variant<PixelBufferTexture, GpuSurfaceTexture> TextureVariant;
|
||||
```
|
||||
|
||||
- [x] Windows
|
||||
- [x] MacOS
|
||||
|
||||
Note: Please use the `BGRA` format.
|
||||
Note: Please use the `BGRA` format for ALL platforms.
|
||||
|
||||
## Getting Started
|
||||
|
||||
|
|
@ -61,6 +53,13 @@ Check the example for details.
|
|||
|
||||
## API
|
||||
|
||||
To improving better convienent interface for both dart and native developers, the plugin provides two kinds of APi to render the frame.
|
||||
|
||||
|
||||
### Dart API
|
||||
|
||||
You can create/close a texure with the dart API provided by this plugin. And you can also provide the BGRA data to the texure via `onRgba` function.
|
||||
|
||||
```dart
|
||||
class TextureRgbaRenderer {
|
||||
|
||||
|
|
@ -85,12 +84,61 @@ class TextureRgbaRenderer {
|
|||
Future<bool> onRgba(int key, Uint8List data, int height, int width) {
|
||||
return TextureRgbaRendererPlatform.instance.onRgba(key, data, height, width);
|
||||
}
|
||||
|
||||
/// For native API.
|
||||
Future<int> getTexturePtr(int key) async {
|
||||
final ptr =
|
||||
await methodChannel.invokeMethod('getTexturePtr', {"key": key}) ??
|
||||
false;
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Native API
|
||||
|
||||
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 width, int height)
|
||||
```
|
||||
|
||||
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, Int32 width, Int32 height);
|
||||
typedef F1Dart = void Function(
|
||||
Pointer<Void> ptr, Pointer<Uint8> buffer, int width, int height);
|
||||
|
||||
class Native {
|
||||
Native._();
|
||||
|
||||
static Native get _instance => Native._()..init();
|
||||
static Native get instance => _instance;
|
||||
|
||||
late F1Dart onRgba;
|
||||
|
||||
init() {
|
||||
final lib = DynamicLibrary.process();
|
||||
onRgba = lib.lookupFunction<F1, F1Dart>("FlutterRgbaRendererPluginOnRgba");
|
||||
}
|
||||
}
|
||||
...
|
||||
|
||||
// Call
|
||||
Native.instance.onRgba(ptr_from_method_getTexturePtr, bgra_data, width, height);
|
||||
```
|
||||
|
||||
Note that the `buffer` is not taken by the plugin, you should handle the lifecycle of the `buffer` yourself.
|
||||
|
||||
Both example usages of two kinds of `onRgba` can be found in `example` folder.
|
||||
|
||||
## Thanks
|
||||
|
||||
- [Flutter](https://github.com/flutter/flutter)
|
||||
- [Flutter Engine](https://github.com/flutter/engine)
|
||||
- [Dart VLC](https://github.com/alexmercerind/dart_vlc)
|
||||
|
||||
## License
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue