feat: getTexturePtr

This commit is contained in:
Kingtous 2023-02-18 00:53:26 +08:00
parent 1a164ee5a0
commit 0f59fef831
5 changed files with 32 additions and 4 deletions

View file

@ -25,4 +25,8 @@ class TextureRgbaRenderer {
return TextureRgbaRendererPlatform.instance
.onRgba(key, data, height, width);
}
Future<int> getTexturePtr(int key) {
return TextureRgbaRendererPlatform.instance.getTexturePtr(key);
}
}

View file

@ -1,3 +1,5 @@
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
@ -32,9 +34,20 @@ class MethodChannelTextureRgbaRenderer extends TextureRgbaRendererPlatform {
@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;
}
@override
Future<int> getTexturePtr(int key) async {
// TODO: currently only supports Windows.
if (!Platform.isWindows) {
return -1;
}
final ptr =
await methodChannel.invokeMethod('getTexturePtr', {"key": key}) ??
false;
return ptr;
}
}

View file

@ -42,4 +42,8 @@ abstract class TextureRgbaRendererPlatform extends PlatformInterface {
Future<bool> onRgba(int key, Uint8List data, int height, int width) {
throw UnimplementedError('onRgba() has not been implemented.');
}
Future<int> getTexturePtr(int key) {
throw UnimplementedError('onRgba() has not been implemented.');
}
}