feat: getTexturePtr
This commit is contained in:
parent
1a164ee5a0
commit
0f59fef831
5 changed files with 32 additions and 4 deletions
|
|
@ -25,6 +25,7 @@ class _MyAppState extends State<MyApp> {
|
||||||
int width = 500;
|
int width = 500;
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
var key = 0;
|
var key = 0;
|
||||||
|
int texturePtr = 0;
|
||||||
final random = Random();
|
final random = Random();
|
||||||
Uint8List? data;
|
Uint8List? data;
|
||||||
|
|
||||||
|
|
@ -34,6 +35,11 @@ class _MyAppState extends State<MyApp> {
|
||||||
_textureRgbaRendererPlugin.createTexture(key).then((textureId) {
|
_textureRgbaRendererPlugin.createTexture(key).then((textureId) {
|
||||||
if (textureId != -1) {
|
if (textureId != -1) {
|
||||||
debugPrint("Texture register success, textureId=$textureId");
|
debugPrint("Texture register success, textureId=$textureId");
|
||||||
|
_textureRgbaRendererPlugin.getTexturePtr(key).then((value) {
|
||||||
|
setState(() {
|
||||||
|
texturePtr = value;
|
||||||
|
});
|
||||||
|
});
|
||||||
setState(() {
|
setState(() {
|
||||||
this.textureId = textureId;
|
this.textureId = textureId;
|
||||||
});
|
});
|
||||||
|
|
@ -91,7 +97,8 @@ class _MyAppState extends State<MyApp> {
|
||||||
),
|
),
|
||||||
Align(
|
Align(
|
||||||
alignment: Alignment.topLeft,
|
alignment: Alignment.topLeft,
|
||||||
child: Text("texture id: $textureId"),
|
child: Text(
|
||||||
|
"texture id: $textureId, texture memory address: $texturePtr"),
|
||||||
),
|
),
|
||||||
Align(
|
Align(
|
||||||
alignment: Alignment.bottomCenter,
|
alignment: Alignment.bottomCenter,
|
||||||
|
|
|
||||||
|
|
@ -25,4 +25,8 @@ class TextureRgbaRenderer {
|
||||||
return TextureRgbaRendererPlatform.instance
|
return TextureRgbaRendererPlatform.instance
|
||||||
.onRgba(key, data, height, width);
|
.onRgba(key, data, height, width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<int> getTexturePtr(int key) {
|
||||||
|
return TextureRgbaRendererPlatform.instance.getTexturePtr(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
|
@ -32,9 +34,20 @@ class MethodChannelTextureRgbaRenderer extends TextureRgbaRendererPlatform {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> onRgba(int key, Uint8List data, int height, int width) async {
|
Future<bool> onRgba(int key, Uint8List data, int height, int width) async {
|
||||||
assert(data.length == height * width * 4);
|
|
||||||
return await methodChannel.invokeMethod<bool>('onRgba',
|
return await methodChannel.invokeMethod<bool>('onRgba',
|
||||||
{"data": data, "height": height, "width": width, "key": key}) ??
|
{"data": data, "height": height, "width": width, "key": key}) ??
|
||||||
false;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,4 +42,8 @@ abstract class TextureRgbaRendererPlatform extends PlatformInterface {
|
||||||
Future<bool> onRgba(int key, Uint8List data, int height, int width) {
|
Future<bool> onRgba(int key, Uint8List data, int height, int width) {
|
||||||
throw UnimplementedError('onRgba() has not been implemented.');
|
throw UnimplementedError('onRgba() has not been implemented.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<int> getTexturePtr(int key) {
|
||||||
|
throw UnimplementedError('onRgba() has not been implemented.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,8 +87,8 @@ void TextureRgbaRendererPlugin::HandleMethodCall(
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Return an address.
|
// Return an address.
|
||||||
void* rgba = (void*) textures_[key].get();
|
size_t rgba = reinterpret_cast<size_t>((void*) textures_[key].get());
|
||||||
result->Success(flutter::EncodableValue(rgba));
|
result->Success(flutter::EncodableValue(int64_t(rgba)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue