feat: init repo

This commit is contained in:
Kingtous 2023-02-16 15:03:12 +08:00
commit b2bd5910e7
87 changed files with 4335 additions and 0 deletions

View file

@ -0,0 +1,28 @@
import 'dart:typed_data';
import 'texture_rgba_renderer_platform_interface.dart';
class TextureRgbaRenderer {
/// Create a texture with unique [key].
///
/// @return a texture id which can be used with
/// ```dart
/// Texture(textureId: textureId)
/// ```
Future<int> createTexture(int key) {
return TextureRgbaRendererPlatform.instance.createTexture(key);
}
/// Close a texture with unique identifier [key].
///
/// @return a boolean to indicate whether the operation is sucessfully executed.
Future<bool> closeTexture(int key) {
return TextureRgbaRendererPlatform.instance.closeTexture(key);
}
/// Provide the rgba data to the texture.
Future<bool> onRgba(int key, Uint8List data, int height, int width) {
return TextureRgbaRendererPlatform.instance
.onRgba(key, data, height, width);
}
}

View file

@ -0,0 +1,40 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'texture_rgba_renderer_platform_interface.dart';
/// An implementation of [TextureRgbaRendererPlatform] that uses method channels.
class MethodChannelTextureRgbaRenderer extends TextureRgbaRendererPlatform {
/// The method channel used to interact with the native platform.
@visibleForTesting
final methodChannel = const MethodChannel('texture_rgba_renderer');
@override
Future<String?> getPlatformVersion() async {
final version =
await methodChannel.invokeMethod<String>('getPlatformVersion');
return version;
}
@override
Future<int> createTexture(int key) async {
return await methodChannel
.invokeMethod<int>('createTexture', {"key": key}) ??
-1;
}
@override
Future<bool> closeTexture(int key) async {
return await methodChannel
.invokeMethod<bool>('closeTexture', {"key": key}) ??
false;
}
@override
Future<bool> onRgba(int key, Uint8List data, int height, int width) async {
assert(data.length == height * width * 4);
return await methodChannel.invokeMethod<bool>('onRgba',
{"data": data, "height": height, "width": width, "key": key}) ??
false;
}
}

View file

@ -0,0 +1,43 @@
import 'package:flutter/foundation.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'texture_rgba_renderer_method_channel.dart';
abstract class TextureRgbaRendererPlatform extends PlatformInterface {
/// Constructs a TextureRgbaRendererPlatform.
TextureRgbaRendererPlatform() : super(token: _token);
static final Object _token = Object();
static TextureRgbaRendererPlatform _instance =
MethodChannelTextureRgbaRenderer();
/// The default instance of [TextureRgbaRendererPlatform] to use.
///
/// Defaults to [MethodChannelTextureRgbaRenderer].
static TextureRgbaRendererPlatform get instance => _instance;
/// Platform-specific implementations should set this with their own
/// platform-specific class that extends [TextureRgbaRendererPlatform] when
/// they register themselves.
static set instance(TextureRgbaRendererPlatform instance) {
PlatformInterface.verifyToken(instance, _token);
_instance = instance;
}
Future<String?> getPlatformVersion() {
throw UnimplementedError('getPlatformVersion() has not been implemented.');
}
Future<int> createTexture(int key) {
throw UnimplementedError('createTexture() has not been implemented.');
}
Future<bool> closeTexture(int key) {
throw UnimplementedError('closeTexture() has not been implemented.');
}
Future<bool> onRgba(int key, Uint8List data, int height, int width) {
throw UnimplementedError('onRgba() has not been implemented.');
}
}