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

@@ -2,6 +2,7 @@ import 'dart:ffi';
import 'package:thermion_dart/src/viewer/src/ffi/src/thermion_dart.g.dart';
import 'package:thermion_dart/src/viewer/src/shared_types/camera.dart';
import 'package:thermion_dart/src/viewer/src/shared_types/shared_types.dart';
import '../../shared_types/view.dart';
import '../thermion_viewer_ffi.dart';
@@ -50,7 +51,7 @@ class FFIView extends View {
View_setPostProcessing(view, enabled);
}
Future setRenderable(bool renderable) async {
Viewer_markViewRenderable(viewer, view, renderable);
Future setRenderable(bool renderable, FFISwapChain swapChain) async {
Viewer_setViewRenderable(viewer, swapChain.swapChain, view, renderable);
}
}

View File

@@ -46,11 +46,18 @@ external void Viewer_destroyRenderTarget(
);
@ffi.Native<
ffi.Pointer<TSwapChain> Function(ffi.Pointer<TViewer>,
ffi.Pointer<ffi.Void>, ffi.Uint32, ffi.Uint32)>(isLeaf: true)
ffi.Pointer<TSwapChain> Function(
ffi.Pointer<TViewer>, ffi.Pointer<ffi.Void>)>(isLeaf: true)
external ffi.Pointer<TSwapChain> Viewer_createSwapChain(
ffi.Pointer<TViewer> viewer,
ffi.Pointer<ffi.Void> window,
);
@ffi.Native<
ffi.Pointer<TSwapChain> Function(
ffi.Pointer<TViewer>, ffi.Uint32, ffi.Uint32)>(isLeaf: true)
external ffi.Pointer<TSwapChain> Viewer_createHeadlessSwapChain(
ffi.Pointer<TViewer> viewer,
int width,
int height,
);
@@ -62,28 +69,9 @@ external void Viewer_destroySwapChain(
ffi.Pointer<TSwapChain> swapChain,
);
@ffi.Native<
ffi.Bool Function(
ffi.Pointer<TViewer>,
ffi.Pointer<TSwapChain>,
ffi.Uint64,
ffi.Pointer<ffi.Void>,
ffi.Pointer<
ffi.NativeFunction<
ffi.Void Function(ffi.Pointer<ffi.Void> buf, ffi.Size size,
ffi.Pointer<ffi.Void> data)>>,
ffi.Pointer<ffi.Void>)>(isLeaf: true)
external bool Viewer_render(
@ffi.Native<ffi.Void Function(ffi.Pointer<TViewer>)>(isLeaf: true)
external void Viewer_render(
ffi.Pointer<TViewer> viewer,
ffi.Pointer<TSwapChain> swapChain,
int frameTimeInNanos,
ffi.Pointer<ffi.Void> pixelBuffer,
ffi.Pointer<
ffi.NativeFunction<
ffi.Void Function(ffi.Pointer<ffi.Void> buf, ffi.Size size,
ffi.Pointer<ffi.Void> data)>>
callback,
ffi.Pointer<ffi.Void> data,
);
@ffi.Native<
@@ -145,10 +133,11 @@ external ffi.Pointer<TSwapChain> Viewer_getSwapChainAt(
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TViewer>, ffi.Pointer<TView>, ffi.Bool)>(isLeaf: true)
external void Viewer_markViewRenderable(
ffi.Void Function(ffi.Pointer<TViewer>, ffi.Pointer<TSwapChain>,
ffi.Pointer<TView>, ffi.Bool)>(isLeaf: true)
external void Viewer_setViewRenderable(
ffi.Pointer<TViewer> viewer,
ffi.Pointer<TSwapChain> swapChain,
ffi.Pointer<TView> view,
bool renderable,
);
@@ -1374,7 +1363,7 @@ external void MaterialInstance_setParameterFloat2(
ffi.Pointer<
ffi.NativeFunction<
ffi.Void Function(ffi.Pointer<TViewer> viewer)>>)>(isLeaf: true)
external void create_filament_viewer_render_thread(
external void Viewer_createOnRenderThread(
ffi.Pointer<ffi.Void> context,
ffi.Pointer<ffi.Void> platform,
ffi.Pointer<ffi.Char> uberArchivePath,
@@ -1393,8 +1382,6 @@ external void create_filament_viewer_render_thread(
ffi.Void Function(
ffi.Pointer<TViewer>,
ffi.Pointer<ffi.Void>,
ffi.Uint32,
ffi.Uint32,
ffi.Pointer<
ffi
.NativeFunction<ffi.Void Function(ffi.Pointer<TSwapChain>)>>)>(
@@ -1402,6 +1389,21 @@ external void create_filament_viewer_render_thread(
external void Viewer_createSwapChainRenderThread(
ffi.Pointer<TViewer> viewer,
ffi.Pointer<ffi.Void> surface,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TSwapChain>)>>
onComplete,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TViewer>,
ffi.Uint32,
ffi.Uint32,
ffi.Pointer<
ffi
.NativeFunction<ffi.Void Function(ffi.Pointer<TSwapChain>)>>)>(
isLeaf: true)
external void Viewer_createHeadlessSwapChainRenderThread(
ffi.Pointer<TViewer> viewer,
int width,
int height,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TSwapChain>)>>
@@ -1459,11 +1461,10 @@ external void Viewer_captureRenderTargetRenderThread(
);
@ffi.Native<
ffi.Void Function(ffi.Pointer<TViewer>, ffi.Pointer<TSwapChain>,
ffi.Void Function(ffi.Pointer<TViewer>,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
external void Viewer_requestFrameRenderThread(
ffi.Pointer<TViewer> viewer,
ffi.Pointer<TSwapChain> tSwapChain,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onComplete,
);

View File

@@ -149,11 +149,24 @@ class ThermionViewerFFI extends ThermionViewer {
}
}
Future<SwapChain> createSwapChain(int width, int height,
{Pointer<Void>? surface}) async {
///
///
///
Future<SwapChain> createHeadlessSwapChain(int width, int height) async {
var swapChain = await withPointerCallback<TSwapChain>((callback) {
return Viewer_createHeadlessSwapChainRenderThread(
_viewer!, width, height, callback);
});
return FFISwapChain(swapChain, _viewer!);
}
///
///
///
Future<SwapChain> createSwapChain(int surface) async {
var swapChain = await withPointerCallback<TSwapChain>((callback) {
return Viewer_createSwapChainRenderThread(
_viewer!, surface ?? nullptr, width, height, callback);
_viewer!, Pointer<Void>.fromAddress(surface), callback);
});
return FFISwapChain(swapChain, _viewer!);
}
@@ -167,7 +180,7 @@ class ThermionViewerFFI extends ThermionViewer {
nullptr;
_viewer = await withPointerCallback(
(Pointer<NativeFunction<Void Function(Pointer<TViewer>)>> callback) {
create_filament_viewer_render_thread(
Viewer_createOnRenderThread(
_sharedContext,
_driver,
uberarchivePtr,
@@ -2039,10 +2052,8 @@ class ThermionViewerFFI extends ThermionViewer {
completer.complete(true);
});
final swapChain = Viewer_getSwapChainAt(_viewer!, 0);
Viewer_requestFrameRenderThread(
_viewer!, swapChain, callback.nativeFunction);
_viewer!, callback.nativeFunction);
await completer.future.timeout(Duration(seconds: 1));
}

View File

@@ -1,4 +1,5 @@
import 'package:thermion_dart/thermion_dart.dart';
import 'swap_chain.dart';
class Viewport {
final int left;
@@ -17,5 +18,5 @@ abstract class View {
Camera getCamera();
Future setPostProcessing(bool enabled);
Future setAntiAliasing(bool msaa, bool fxaa, bool taa);
Future setRenderable(bool renderable);
Future setRenderable(bool renderable, covariant SwapChain swapChain);
}

View File

@@ -62,7 +62,12 @@ abstract class ThermionViewer {
///
///
///
Future<SwapChain> createSwapChain(int width, int height);
Future<SwapChain> createHeadlessSwapChain(int width, int height);
///
///
///
Future<SwapChain> createSwapChain(int handle);
///
///

View File

@@ -1006,12 +1006,6 @@ class ThermionViewerStub extends ThermionViewer {
throw UnimplementedError();
}
@override
Future<SwapChain> createSwapChain(int width, int height) {
// TODO: implement createSwapChain
throw UnimplementedError();
}
@override
Future<RenderTarget> createRenderTarget(int width, int height, int textureHandle) {
// TODO: implement createRenderTarget
@@ -1036,23 +1030,36 @@ class ThermionViewerStub extends ThermionViewer {
throw UnimplementedError();
}
@override
Future render(covariant SwapChain swapChain) {
// TODO: implement render
throw UnimplementedError();
}
@override
Future<Uint8List> capture(covariant SwapChain swapChain, {covariant View? view, covariant RenderTarget? renderTarget}) {
// TODO: implement capture
throw UnimplementedError();
}
@override
Future<Gizmo> createGizmo(covariant View view) {
// TODO: implement createGizmo
throw UnimplementedError();
}
@override
Future<SwapChain> createHeadlessSwapChain(int width, int height) {
// TODO: implement createHeadlessSwapChain
throw UnimplementedError();
}
@override
Future<Uint8List> capture({covariant SwapChain? swapChain, covariant View? view, covariant RenderTarget? renderTarget}) {
// TODO: implement capture
throw UnimplementedError();
}
@override
Future<SwapChain> createSwapChain(handle) {
// TODO: implement createSwapChain
throw UnimplementedError();
}
@override
Future render({covariant SwapChain? swapChain}) {
// TODO: implement render
throw UnimplementedError();
}
}