{"id":15294751,"url":"https://github.com/kingtous/flutter_texture_rgba_renderer","last_synced_at":"2025-04-13T14:54:03.768Z","repository":{"id":65919649,"uuid":"602421127","full_name":"Kingtous/flutter_texture_rgba_renderer","owner":"Kingtous","description":"A texture helper which brings both high/low level api(s) to handle BGRA data for Flutter. 🔧","archived":false,"fork":false,"pushed_at":"2023-05-27T01:06:31.000Z","size":527,"stargazers_count":38,"open_issues_count":3,"forks_count":18,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-13T14:53:59.096Z","etag":null,"topics":["dart","flutter","flutter-desktop","flutter-plugins","linux","macos","texture","windows"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kingtous.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-02-16T07:04:22.000Z","updated_at":"2025-03-17T07:36:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"be6851de-ea10-4aa9-90b4-9f3dfd706ffe","html_url":"https://github.com/Kingtous/flutter_texture_rgba_renderer","commit_stats":null,"previous_names":["kdogeone/flutter_texture_rgba_renderer","ketadotcc/flutter_texture_rgba_renderer","kingtous/flutter_texture_rgba_renderer"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kingtous%2Fflutter_texture_rgba_renderer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kingtous%2Fflutter_texture_rgba_renderer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kingtous%2Fflutter_texture_rgba_renderer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kingtous%2Fflutter_texture_rgba_renderer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kingtous","download_url":"https://codeload.github.com/Kingtous/flutter_texture_rgba_renderer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248732512,"owners_count":21152851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","flutter","flutter-desktop","flutter-plugins","linux","macos","texture","windows"],"created_at":"2024-09-30T17:06:36.299Z","updated_at":"2025-04-13T14:54:03.748Z","avatar_url":"https://github.com/Kingtous.png","language":"C++","readme":"# Texture Rgba Renderer \n\nA general texture helper which brings both of high and low level api to handle **BGRA** data for Flutter. Only one time frame copy required, and aims to get a full hardware acceleration.\n\nThis plugin is originally developed for [RustDesk](https://github.com/rustdesk/rustdesk).\n\nNow it's in active development, which aims to improve the memory usage and performance. \n\n![](./res/banner.png)\n\n![Pub Version](https://img.shields.io/pub/v/texture_rgba_renderer)\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FKingtous%2Fflutter_texture_rgba_renderer.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FKingtous%2Fflutter_texture_rgba_renderer?ref=badge_shield)\n\n## Platform Support\n\nThe plugin aims to provide opengl impl for the texture, which bring a better performance instead of `FFI` + `CustomPainter`.\n\n- [x] Linux\n- [x] Windows\n- [x] MacOS\n\nNote: Please use the `BGRA` format for ALL platforms.\n\n## Getting Started\n\n### Create a texture by calling `createTexture`.\n\n```dart\n_textureRgbaRendererPlugin.createTexture(key).then((textureId) {\n      if (textureId != -1) {\n        debugPrint(\"Texture register success, textureId=$textureId\");\n        setState(() {\n          this.textureId = textureId;\n        });\n      } else {\n        return;\n      }\n    });\n```\n\n### Transfer rgba data by calling `onRgba`.\n\n```dart\ndata = mockPicture(width, height);\nfinal res = await _textureRgbaRendererPlugin.onRgba(key, data!, height, width);\nif (!res) {\n    debugPrint(\"WARN: render failed\");\n}\n```\n\n### Close a texture by calling `closeTexture`.\n```dart\nif (key != -1) {\n    _textureRgbaRendererPlugin.closeTexture(key);\n}\n```\n\nCheck the example for details.\n\n## API\n\nFor a better convienent interface for both dart and native developers, the plugin provides two kinds of APi to render the frame.\n\nBenchmark:\n\nmacOS Bigsur qemu vm (4+8G), with OpenGL accelerated. Release build.\n\n| API Kind | FPS(Average) | \n|----|-----|\n| Method Channel (Dart) API | ~45 |\n| Native API | ~**670** |\n\nConclusion:\n\nFor a better performance, please use `Native` API provided by this plugin.\n\n### Dart API\n\nYou 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.\n\n```dart\nclass TextureRgbaRenderer {\n\n  /// Create a texture with unique identifier [key].\n  /// \n  /// @return a texture id which can be used with\n  /// ```dart\n  /// Texture(textureId: textureId)\n  /// ```\n  Future\u003cint\u003e createTexture(int key) {\n    return TextureRgbaRendererPlatform.instance.createTexture(key); \n  }\n\n  /// Close a texture with unique identifier [key].\n  /// \n  /// @return a boolean to indicate whether the operation is sucessfully executed.\n  Future\u003cbool\u003e closeTexture(int key) {\n    return TextureRgbaRendererPlatform.instance.closeTexture(key); \n  }\n\n  /// Provide the rgba data to the texture.\n  Future\u003cbool\u003e onRgba(int key, Uint8List data, int height, int width) {\n     return TextureRgbaRendererPlatform.instance.onRgba(key, data, height, width); \n  }\n\n  /// For native API.\n  Future\u003cint\u003e getTexturePtr(int key) async {\n    final ptr =\n        await methodChannel.invokeMethod('getTexturePtr', {\"key\": key}) ??\n            false;\n    return ptr;\n  }\n}\n```\n\n## Native API\n\nNote 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.\n\n```c\nvoid FlutterRgbaRendererPluginOnRgba(void* texture_rgba_ptr, const uint8_t* buffer, int len, int width, int height, int stride_align)\n```\n\nYou could use the native API in other programing languages. A dart quick example:\n\n```dart\n/// The `Native` class is bundled in this plugin.\ntypedef F1 = Void Function(Pointer\u003cVoid\u003e ptr, Pointer\u003cUint8\u003e buffer, Int len,\n    Int32 width, Int32 height, Int stride_align);\ntypedef F1Dart = void Function(Pointer\u003cVoid\u003e ptr, Pointer\u003cUint8\u003e buffer,\n    int len, int width, int height, int stride_align);\n\nclass Native {\n  Native._();\n\n  static Native get _instance =\u003e Native._()..init();\n  static Native get instance =\u003e _instance;\n\n  late F1Dart onRgba;\n\n  init() {\n    final lib = DynamicLibrary.process();\n    onRgba = lib.lookupFunction\u003cF1, F1Dart\u003e(\"FlutterRgbaRendererPluginOnRgba\");\n  }\n}\n...\n\n// Call\nNative.instance.onRgba(ptr_from_method_getTexturePtr, bgra_data, width, height);\n```\n\nNote that the `buffer` is not taken by the plugin, you should handle the lifecycle of the `buffer` yourself.\n\nBoth example usages of two kinds of `onRgba` can be found in `example` folder.\n\n## Thanks\n\n- [Flutter](https://github.com/flutter/flutter)\n- [Flutter Engine](https://github.com/flutter/engine)\n- [Dart VLC](https://github.com/alexmercerind/dart_vlc) \n\n## License\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FKingtous%2Fflutter_texture_rgba_renderer.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FKingtous%2Fflutter_texture_rgba_renderer?ref=badge_large)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkingtous%2Fflutter_texture_rgba_renderer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkingtous%2Fflutter_texture_rgba_renderer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkingtous%2Fflutter_texture_rgba_renderer/lists"}