feat: support multiple ThermionWidget on Android

This commit is contained in:
Nick Fisher
2024-09-30 18:20:05 +08:00
parent 8a94b6a334
commit c4598637bb
25 changed files with 418 additions and 549 deletions

View File

@@ -15,6 +15,13 @@ extern "C" {
return window;
}
// int ThermionAndroid_createGLTexture(jobject )
// int ASurfaceTexture_attachToGLContext(
// ASurfaceTexture *st,
// uint32_t texName
// )
ResourceLoaderWrapper* make_resource_loader_wrapper_android(LoadFilamentResourceFromOwner loadFn, FreeFilamentResourceFromOwner freeFn, void* owner) {
ResourceLoaderWrapper *rlw = (ResourceLoaderWrapper *)malloc(sizeof(ResourceLoaderWrapper));
rlw->loadToOut = nullptr;

View File

@@ -25,6 +25,8 @@ import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.view.TextureRegistry.SurfaceTextureEntry
import java.io.File
import java.util.*
import android.opengl.GLES20;
class LoadFilamentResourceFromOwnerImpl(plugin:ThermionFlutterPlugin) : LoadFilamentResourceFromOwner {
var plugin = plugin
@@ -66,10 +68,18 @@ class ThermionFlutterPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, Lo
private var lifecycle: Lifecycle? = null
private lateinit var _lib : FilamentInterop
private data class TextureEntry(
val surfaceTextureEntry: SurfaceTextureEntry,
val surfaceTexture: SurfaceTexture,
val surface: Surface
)
var _surfaceTexture: SurfaceTexture? = null
private var _surfaceTextureEntry: SurfaceTextureEntry? = null
var _surface: Surface? = null
private val textures: MutableMap<Long, TextureEntry> = mutableMapOf()
private lateinit var activity:Activity
@@ -153,35 +163,55 @@ class ThermionFlutterPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, Lo
@RequiresApi(Build.VERSION_CODES.M)
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
Log.e("thermion_flutter", call.method, null)
when (call.method) {
"createTexture" -> {
if(_surfaceTextureEntry != null) {
result.error("TEXTURE_EXISTS", "Texture already exist. Make sure you call destroyTexture first", null)
return
}
val args = call.arguments as List<*>
val width = args[0] as Int
val height = args[1] as Int
if(width <1 || height < 1) {
result.error("DIMENSION_MISMATCH","Both dimensions must be greater than zero (you provided $width x $height)", null);
return;
}
Log.i("thermion_flutter", "Creating SurfaceTexture ${width}x${height}");
_surfaceTextureEntry = flutterPluginBinding.textureRegistry.createSurfaceTexture()
_surfaceTexture = _surfaceTextureEntry!!.surfaceTexture();
_surfaceTexture!!.setDefaultBufferSize(width, height)
val args = call.arguments as List<*>
val width = args[0] as Int
val height = args[1] as Int
if (width < 1 || height < 1) {
result.error("DIMENSION_MISMATCH", "Both dimensions must be greater than zero (you provided $width x $height)", null)
return
}
Log.i("thermion_flutter", "Creating SurfaceTexture ${width}x${height}")
val surfaceTextureEntry = flutterPluginBinding.textureRegistry.createSurfaceTexture()
val surfaceTexture = surfaceTextureEntry.surfaceTexture()
surfaceTexture.setDefaultBufferSize(width, height)
_surface = Surface(_surfaceTexture)
val surface = Surface(surfaceTexture)
if(!_surface!!.isValid) {
result.error("SURFACE_INVALID", "Failed to create valid surface", null)
} else {
val nativeWindow = _lib.get_native_window_from_surface(_surface!! as Object, JNIEnv.CURRENT)
result.success(listOf(_surfaceTextureEntry!!.id(), null, Pointer.nativeValue(nativeWindow)))
}
}
if (!surface.isValid) {
result.error("SURFACE_INVALID", "Failed to create valid surface", null)
} else {
val flutterTextureId = surfaceTextureEntry.id()
textures[flutterTextureId] = TextureEntry(surfaceTextureEntry, surfaceTexture, surface)
val nativeWindow = _lib.get_native_window_from_surface(surface as Object, JNIEnv.CURRENT)
result.success(listOf(flutterTextureId, flutterTextureId, Pointer.nativeValue(nativeWindow)))
}
}
"destroyTexture" -> {
val args = call.arguments as List<*>
val textureId = (args[0] as Int).toLong()
val textureEntry = textures[textureId]
if (textureEntry != null) {
textureEntry.surface.release()
textureEntry.surfaceTextureEntry.release()
textures.remove(textureId)
result.success(true)
} else {
result.error("TEXTURE_NOT_FOUND", "Texture with id $textureId not found", null)
}
}
"markTextureFrameAvailable" -> {
val textureId = (call.arguments as Int).toLong()
val textureEntry = textures[textureId]
if (textureEntry != null) {
//textureEntry.surfaceTexture.updateTexImage()
result.success(null)
} else {
result.error("TEXTURE_NOT_FOUND", "Texture with id $textureId not found", null)
}
}
"getResourceLoaderWrapper" -> {
val resourceLoader = _lib.make_resource_loader_wrapper_android(loadResourceWrapper, freeResourceWrapper, Pointer(0))
result.success(Pointer.nativeValue(resourceLoader))
@@ -196,13 +226,6 @@ class ThermionFlutterPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, Lo
val renderCallbackFnPointer = _lib.make_render_callback_fn_pointer(RenderCallbackImpl(this))
result.success(listOf(Pointer.nativeValue(renderCallbackFnPointer), 0))
}
"destroyTexture" -> {
_surface!!.release();
_surfaceTextureEntry!!.release();
_surface = null
_surfaceTextureEntry = null
result.success(true)
}
else -> {
result.notImplemented()
}
@@ -210,7 +233,13 @@ class ThermionFlutterPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, Lo
}
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
channel.setMethodCallHandler(null)
// Release all textures
for ((_, textureEntry) in textures) {
textureEntry.surface.release()
textureEntry.surfaceTextureEntry.release()
}
textures.clear()
}

View File

@@ -50,13 +50,8 @@ class _ThermionTextureWidgetState extends State<ThermionTextureWidget> {
var width = (size.width * dpr).ceil();
var height = (size.height * dpr).ceil();
_texture =
await ThermionFlutterPlatform.instance.createTexture(width, height);
_renderTarget = await widget.viewer.createRenderTarget(
_texture!.width, _texture!.height, _texture!.hardwareId);
await widget.view.setRenderTarget(_renderTarget!);
_texture = await ThermionFlutterPlatform.instance
.createTexture(widget.view, width, height);
await widget.view.updateViewport(_texture!.width, _texture!.height);
var camera = await widget.view.getCamera();
@@ -74,13 +69,7 @@ class _ThermionTextureWidgetState extends State<ThermionTextureWidget> {
if (mounted) {
setState(() {});
}
if (texture != null) {
_renderTarget = await widget.viewer.createRenderTarget(
texture.width, texture.height, texture.flutterId);
await widget.view.setRenderTarget(null);
await _renderTarget!.destroy();
texture.destroy();
}
await texture?.destroy();
_views.clear();
});
});
@@ -100,7 +89,7 @@ class _ThermionTextureWidgetState extends State<ThermionTextureWidget> {
WidgetsBinding.instance.scheduleFrameCallback((d) async {
if (widget.viewer.rendering && !_rendering) {
_rendering = true;
if (_callbackId == _primaryCallback) {
if (_callbackId == _primaryCallback && _texture != null) {
await widget.viewer.requestFrame();
lastRender = d.inMilliseconds;
}
@@ -140,8 +129,6 @@ class _ThermionTextureWidgetState extends State<ThermionTextureWidget> {
var newWidth = newSize.width.ceil();
var newHeight = newSize.height.ceil();
var lastTextureId = _texture?.hardwareId;
await _texture?.resize(
newWidth,
newHeight,
@@ -149,12 +136,6 @@ class _ThermionTextureWidgetState extends State<ThermionTextureWidget> {
0,
);
if (_texture?.hardwareId != lastTextureId) {
await _renderTarget?.destroy();
_renderTarget = await widget.viewer.createRenderTarget(
_texture!.width, _texture!.height, _texture!.hardwareId);
await widget.view.setRenderTarget(_renderTarget!);
}
await widget.view.updateViewport(_texture!.width, _texture!.height);
var camera = await widget.view.getCamera();

View File

@@ -0,0 +1,97 @@
import 'package:logging/logging.dart';
import 'package:thermion_dart/thermion_dart.dart';
import 'thermion_flutter_method_channel_interface.dart';
class FlutterPlatformTexture extends MethodChannelFlutterTexture {
final _logger = Logger("ThermionFlutterTexture");
final ThermionViewer viewer;
final View view;
int flutterId = -1;
int _lastFlutterId = -1;
int _lastHardwareId = -1;
int hardwareId = -1;
int width = -1;
int height = -1;
SwapChain? swapChain;
RenderTarget? _renderTarget;
late bool destroySwapChainOnResize;
FlutterPlatformTexture(
super.channel, this.viewer, this.view, this.swapChain) {
if (swapChain == null) {
destroySwapChainOnResize = true;
} else {
destroySwapChainOnResize = false;
}
}
@override
Future<void> resize(
int newWidth, int newHeight, int newLeft, int newTop) async {
if (newWidth == this.width &&
newHeight == this.height &&
newLeft == 0 &&
newTop == 0) {
return;
}
this.width = newWidth;
this.height = newHeight;
var result =
await channel.invokeMethod("createTexture", [width, height, 0, 0]);
if (result == null || (result[0] == -1)) {
throw Exception("Failed to create texture");
}
_lastFlutterId = flutterId;
_lastHardwareId = hardwareId;
flutterId = result[0] as int;
hardwareId = result[1] as int;
if (destroySwapChainOnResize) {
await swapChain?.destroy();
swapChain = await viewer.createSwapChain(result[2]);
}
_logger.info(
"Created new texture: flutter id $flutterId, hardware id $hardwareId");
if (destroySwapChainOnResize) {
await view.setRenderable(true, swapChain!);
} else if (hardwareId != _lastHardwareId) {
await _renderTarget?.destroy();
_renderTarget =
await viewer.createRenderTarget(width, height, hardwareId);
await view.setRenderTarget(_renderTarget!);
await view.setRenderable(true, swapChain!);
await _destroyTexture(_lastFlutterId, _lastHardwareId);
}
}
Future<void> _destroyTexture(int flutterId, int? hardwareId) async {
try {
await channel.invokeMethod("destroyTexture", [flutterId, hardwareId]);
_logger.info(
"Destroyed old texture: flutter id $flutterId, hardware id $hardwareId");
} catch (e) {
_logger.severe("Failed to destroy texture: $e");
}
}
Future destroy() async {
await view.setRenderTarget(null);
await _renderTarget?.destroy();
await swapChain?.destroy();
await channel.invokeMethod("destroyTexture", hardwareId);
}
Future markFrameAvailable() async {
await channel.invokeMethod("markTextureFrameAvailable", this.flutterId);
}
}

View File

@@ -0,0 +1,11 @@
class TextureCacheEntry {
final int flutterId;
final int hardwareId;
final DateTime creationTime;
DateTime? removalTime;
bool inUse;
TextureCacheEntry(this.flutterId, this.hardwareId,
{this.removalTime, this.inUse = true})
: creationTime = DateTime.now();
}

View File

@@ -1,130 +0,0 @@
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:thermion_dart/thermion_dart.dart';
import 'package:thermion_dart/src/viewer/src/ffi/thermion_viewer_ffi.dart';
import 'package:thermion_flutter_ffi/thermion_flutter_method_channel_interface.dart';
import 'package:thermion_flutter_platform_interface/thermion_flutter_platform_interface.dart';
import 'package:thermion_flutter_platform_interface/thermion_flutter_texture.dart';
import 'package:logging/logging.dart';
///
/// An implementation of [ThermionFlutterPlatform] that uses
/// Flutter platform channels to create a rendering context,
/// resource loaders, and surface/render target(s).
///
class ThermionFlutterAndroid
extends ThermionFlutterMethodChannelInterface {
final _channel = const MethodChannel("dev.thermion.flutter/event");
final _logger = Logger("ThermionFlutterFFI");
ThermionViewerFFI? _viewer;
ThermionFlutterAndroid._() {}
RenderTarget? _renderTarget;
SwapChain? _swapChain;
static void registerWith() {
ThermionFlutterPlatform.instance = ThermionFlutterAndroid._();
}
final _textures = <ThermionFlutterTexture>{};
bool _creatingTexture = false;
bool _destroyingTexture = false;
bool _resizing = false;
///
/// Create a rendering surface.
///
/// This is internal; unless you are [thermion_*] package developer, don't
/// call this yourself.
///
/// The name here is slightly misleading because we only create
/// a texture render target on macOS and iOS; on Android, we render into
/// a native window derived from a Surface, and on Windows we render into
/// a HWND.
///
/// Currently, this only supports a single "texture" (aka rendering surface)
/// at any given time. If a [ThermionWidget] is disposed, it will call
/// [destroyTexture]; if it is resized, it will call [resizeTexture].
///
/// In future, we probably want to be able to create multiple distinct
/// textures/render targets. This would make it possible to have multiple
/// Flutter Texture widgets, each with its own Filament View attached.
/// The current design doesn't accommodate this (for example, it seems we can
/// only create a single native window from a Surface at any one time).
///
Future<ThermionFlutterTexture?> createTexture(int width, int height) async {
throw Exception("TODO");
// note that when [ThermionWidget] is disposed, we don't destroy the
// texture; instead, we keep it around in case a subsequent call requests
// a texture of the same size.
// if (_textures.length > 1) {
// throw Exception("Multiple textures not yet supported");
// } else if (_textures.length == 1) {
// if (_textures.first.height == physicalHeight &&
// _textures.first.width == physicalWidth) {
// return _textures.first;
// } else {
// await _viewer!.setRendering(false);
// await _swapChain?.destroy();
// await destroyTexture(_textures.first);
// _textures.clear();
// }
// }
// _creatingTexture = true;
// var result = await _channel.invokeMethod("createTexture",
// [physicalWidth, physicalHeight, offsetLeft, offsetLeft]);
// if (result == null || (result[0] == -1)) {
// throw Exception("Failed to create texture");
// }
// final flutterTextureId = result[0] as int?;
// final hardwareTextureId = result[1] as int?;
// final surfaceAddress = result[2] as int?;
// _logger.info(
// "Created texture with flutter texture id ${flutterTextureId}, hardwareTextureId $hardwareTextureId and surfaceAddress $surfaceAddress");
// final texture = ThermionFlutterTexture(flutterTextureId, hardwareTextureId,
// physicalWidth, physicalHeight, surfaceAddress);
// await _viewer?.createSwapChain(physicalWidth, physicalHeight,
// surface: texture.surfaceAddress == null
// ? nullptr
// : Pointer<Void>.fromAddress(texture.surfaceAddress!));
// if (texture.hardwareTextureId != null) {
// if (_renderTarget != null) {
// await _renderTarget!.destroy();
// }
// // ignore: unused_local_variable
// _renderTarget = await _viewer?.createRenderTarget(
// physicalWidth, physicalHeight, texture.hardwareTextureId!);
// }
// await _viewer?.updateViewportAndCameraProjection(
// physicalWidth.toDouble(), physicalHeight.toDouble());
// _creatingTexture = false;
// _textures.add(texture);
// return texture;
}
///
/// Called by [ThermionWidget] to resize a texture. Don't call this yourself.
///
@override
Future resizeWindow(
int width,
int height,
int offsetLeft,
int offsetTop,
) async {
throw Exception("Not supported on iOS");
}
}

View File

@@ -1,3 +1,2 @@
export 'thermion_flutter_android.dart';
export 'thermion_flutter_windows.dart';
export 'thermion_flutter_texture_backed_platform.dart';

View File

@@ -14,11 +14,11 @@ import 'package:thermion_flutter_platform_interface/thermion_flutter_texture.dar
///
abstract class ThermionFlutterMethodChannelInterface
extends ThermionFlutterPlatform {
final _channel = const MethodChannel("dev.thermion.flutter/event");
final channel = const MethodChannel("dev.thermion.flutter/event");
final _logger = Logger("ThermionFlutterMethodChannelInterface");
ThermionViewerFFI? viewer;
SwapChain? _swapChain;
Future<ThermionViewer> createViewer({ThermionFlutterOptions? options}) async {
if (viewer != null) {
@@ -27,25 +27,18 @@ abstract class ThermionFlutterMethodChannelInterface
}
var resourceLoader = Pointer<Void>.fromAddress(
await _channel.invokeMethod("getResourceLoaderWrapper"));
await channel.invokeMethod("getResourceLoaderWrapper"));
if (resourceLoader == nullptr) {
throw Exception("Failed to get resource loader");
}
// var renderCallbackResult = await _channel.invokeMethod("getRenderCallback");
var renderCallback = nullptr;
// Pointer<NativeFunction<Void Function(Pointer<Void>)>>.fromAddress(
// renderCallbackResult[0]);
var renderCallbackOwner = nullptr;
// Pointer<Void>.fromAddress(renderCallbackResult[1]);
var driverPlatform = await _channel.invokeMethod("getDriverPlatform");
var driverPlatform = await channel.invokeMethod("getDriverPlatform");
var driverPtr = driverPlatform == null
? nullptr
: Pointer<Void>.fromAddress(driverPlatform);
var sharedContext = await _channel.invokeMethod("getSharedContext");
var sharedContext = await channel.invokeMethod("getSharedContext");
var sharedContextPtr = sharedContext == null
? nullptr
@@ -53,8 +46,6 @@ abstract class ThermionFlutterMethodChannelInterface
viewer = ThermionViewerFFI(
resourceLoader: resourceLoader,
renderCallback: renderCallback,
renderCallbackOwner: renderCallbackOwner,
driver: driverPtr,
sharedContext: sharedContextPtr,
uberArchivePath: options?.uberarchivePath);
@@ -69,9 +60,7 @@ abstract class MethodChannelFlutterTexture extends ThermionFlutterTexture {
MethodChannelFlutterTexture(this.channel);
Future destroy() async {
await channel.invokeMethod("destroyTexture", hardwareId);
}
@override
int get flutterId;
@@ -85,7 +74,5 @@ abstract class MethodChannelFlutterTexture extends ThermionFlutterTexture {
@override
int get width;
Future markFrameAvailable() async {
await channel.invokeMethod("markTextureFrameAvailable", this.flutterId);
}
}

View File

@@ -1,18 +1,22 @@
import 'dart:async';
import 'package:flutter/services.dart';
import 'dart:io';
import 'package:thermion_dart/thermion_dart.dart';
import 'package:thermion_dart/thermion_dart.dart' as t;
import 'package:thermion_flutter_ffi/thermion_flutter_method_channel_interface.dart';
import 'package:thermion_flutter_platform_interface/thermion_flutter_platform_interface.dart';
import 'package:thermion_flutter_platform_interface/thermion_flutter_texture.dart';
import 'package:logging/logging.dart';
import 'package:thermion_flutter_platform_interface/thermion_flutter_texture.dart';
import 'platform_texture.dart';
///
/// An implementation of [ThermionFlutterPlatform] that uses
/// Flutter platform channels to create a rendering context,
/// resource loaders, and surface/render target(s).
///
class ThermionFlutterTextureBackedPlatform extends ThermionFlutterMethodChannelInterface {
final _channel = const MethodChannel("dev.thermion.flutter/event");
class ThermionFlutterTextureBackedPlatform
extends ThermionFlutterMethodChannelInterface {
final _logger = Logger("ThermionFlutterTextureBackedPlatform");
static SwapChain? _swapChain;
@@ -32,16 +36,19 @@ class ThermionFlutterTextureBackedPlatform extends ThermionFlutterMethodChannelI
if (_swapChain != null) {
throw Exception("Only a single swapchain can be created");
}
// this implementation renders directly into a texture/render target
// we still need to create a (headless) swapchain, but the actual dimensions
// we still need to create a (headless) swapchain, but the actual dimensions
// don't matter
_swapChain = await viewer.createSwapChain(1, 1);
if (Platform.isMacOS || Platform.isIOS) {
_swapChain = await viewer.createHeadlessSwapChain(1, 1);
}
return viewer;
}
// On desktop platforms, textures are always created
Future<ThermionFlutterTexture?> createTexture(int width, int height) async {
var texture = ThermionFlutterTexture(_channel);
Future<ThermionFlutterTexture?> createTexture(t.View view, int width, int height) async {
var texture = FlutterPlatformTexture(channel, viewer!, view, (Platform.isMacOS || Platform.isIOS)? _swapChain : null);
await texture.resize(width, height, 0, 0);
return texture;
}
@@ -54,119 +61,3 @@ class ThermionFlutterTextureBackedPlatform extends ThermionFlutterMethodChannelI
}
}
class TextureCacheEntry {
final int flutterId;
final int hardwareId;
final DateTime creationTime;
DateTime? removalTime;
bool inUse;
TextureCacheEntry(this.flutterId, this.hardwareId, {this.removalTime, this.inUse = true})
: creationTime = DateTime.now();
}
class ThermionFlutterTexture extends MethodChannelFlutterTexture {
final _logger = Logger("ThermionFlutterTexture");
int flutterId = -1;
int hardwareId = -1;
int width = -1;
int height = -1;
static final Map<String, List<TextureCacheEntry>> _textureCache = {};
ThermionFlutterTexture(super.channel);
@override
Future<void> resize(
int newWidth, int newHeight, int newLeft, int newTop) async {
if (newWidth == this.width &&
newHeight == this.height &&
newLeft == 0 &&
newTop == 0) {
return;
}
this.width = newWidth;
this.height = newHeight;
// Clean up old textures
await _cleanupOldTextures();
final cacheKey = '${width}x$height';
final availableTextures =
_textureCache[cacheKey]?.where((entry) => !entry.inUse) ?? [];
if (availableTextures.isNotEmpty) {
final cachedTexture = availableTextures.first;
flutterId = cachedTexture.flutterId;
hardwareId = cachedTexture.hardwareId;
cachedTexture.inUse = true;
_logger.info(
"Using cached texture: flutter id $flutterId, hardware id $hardwareId");
} else {
var result =
await channel.invokeMethod("createTexture", [width, height, 0, 0]);
if (result == null || (result[0] == -1)) {
throw Exception("Failed to create texture");
}
flutterId = result[0] as int;
hardwareId = result[1] as int;
final newEntry = TextureCacheEntry(flutterId, hardwareId, inUse: true);
_textureCache.putIfAbsent(cacheKey, () => []).add(newEntry);
_logger.info(
"Created new texture: flutter id $flutterId, hardware id $hardwareId");
}
// Mark old texture as not in use
if (this.width != -1 && this.height != -1) {
final oldCacheKey = '${this.width}x${this.height}';
final oldEntry = _textureCache[oldCacheKey]?.firstWhere(
(entry) => entry.flutterId == this.flutterId,
orElse: () => TextureCacheEntry(-1, -1),
);
if (oldEntry != null && oldEntry.flutterId != -1) {
oldEntry.inUse = false;
oldEntry.removalTime = DateTime.now();
}
}
}
Future _cleanupOldTextures() async {
final now = DateTime.now();
final entriesToRemove = <String, List<TextureCacheEntry>>{};
for (var entry in _textureCache.entries) {
final expiredTextures = entry.value.where((texture) {
return !texture.inUse &&
texture.removalTime != null &&
now.difference(texture.removalTime!).inSeconds > 5;
}).toList();
if (expiredTextures.isNotEmpty) {
entriesToRemove[entry.key] = expiredTextures;
}
}
for (var entry in entriesToRemove.entries) {
for (var texture in entry.value) {
await _destroyTexture(texture.flutterId, texture.hardwareId);
_logger.info("Destroying texture: ${texture.flutterId}");
_textureCache[entry.key]?.remove(texture);
}
if (_textureCache[entry.key]?.isEmpty ?? false) {
_textureCache.remove(entry.key);
}
}
}
Future<void> _destroyTexture(int flutterId, int? hardwareId) async {
try {
await channel.invokeMethod("destroyTexture", [flutterId, hardwareId]);
_logger.info("Destroyed old texture: flutter id $flutterId, hardware id $hardwareId");
} catch (e) {
_logger.severe("Failed to destroy texture: $e");
}
}
}

View File

@@ -32,8 +32,9 @@ class ThermionFlutterWindows
///
/// Not supported on Windows. Throws an exception.
///
Future<ThermionFlutterTexture?> createTexture(int width, int height) async {
throw Exception("Texture not supported on Windows");
@override
Future<ThermionFlutterTexture?> createTexture(View view, int width, int height) {
throw UnimplementedError();
}
bool _resizing = false;
@@ -94,4 +95,6 @@ class ThermionFlutterWindows
// _resizing = false;
// return newTexture;
}
}

View File

@@ -13,7 +13,7 @@ flutter:
ios:
dartPluginClass: ThermionFlutterTextureBackedPlatform
android:
dartPluginClass: ThermionFlutterAndroid
dartPluginClass: ThermionFlutterTextureBackedPlatform
macos:
dartPluginClass: ThermionFlutterTextureBackedPlatform
windows:

View File

@@ -1,5 +1,6 @@
import 'dart:async';
import 'package:thermion_dart/thermion_dart.dart' as t;
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'package:thermion_dart/thermion_dart.dart';
import 'thermion_flutter_texture.dart';
@@ -36,11 +37,11 @@ abstract class ThermionFlutterPlatform extends PlatformInterface {
/// This is internal; unless you are [thermion_*] package developer, don't
/// call this yourself. May not be supported on all platforms.
///
Future<ThermionFlutterTexture?> createTexture(int width, int height);
Future<ThermionFlutterTexture?> createTexture(
t.View view, int width, int height);
///
///
///
Future resizeWindow(
int width, int height, int offsetTop, int offsetRight);
Future resizeWindow(int width, int height, int offsetTop, int offsetRight);
}

View File

@@ -1,18 +1,5 @@
// class ThermionFlutterTextureImpl {
// final int width;
// final int height;
// final int? flutterTextureId;
// final int? hardwareTextureId;
// final int? surfaceAddress;
// bool get usesBackingWindow => flutterTextureId == null;
// ThermionFlutterTexture(this.flutterTextureId, this.hardwareTextureId,
// this.width, this.height, this.surfaceAddress) {
// }
// }
abstract class ThermionFlutterTexture {
int get width;
int get height;