remove superseded cruft from MacOS plugin
This commit is contained in:
@@ -34,7 +34,7 @@ abstract class FilamentController {
|
|||||||
/// If you need to wait until a FilamentViewer has been created, [await] the [isReadyForScene] Future.
|
/// If you need to wait until a FilamentViewer has been created, [await] the [isReadyForScene] Future.
|
||||||
///
|
///
|
||||||
Future createViewer(int width, int height);
|
Future createViewer(int width, int height);
|
||||||
Future resize(int width, int height, {double contentScaleFactor = 1.0});
|
Future resize(int width, int height, {double scaleFactor = 1.0});
|
||||||
|
|
||||||
Future clearBackgroundImage();
|
Future clearBackgroundImage();
|
||||||
Future setBackgroundImage(String path, {bool fillHeight = false});
|
Future setBackgroundImage(String path, {bool fillHeight = false});
|
||||||
|
|||||||
@@ -145,13 +145,16 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
_isReadyForScene.complete(true);
|
_isReadyForScene.complete(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future resize(int width, int height,
|
Future resize(int width, int height, {double scaleFactor = 1.0}) async {
|
||||||
{double contentScaleFactor = 1.0}) async {
|
|
||||||
_resizing = true;
|
_resizing = true;
|
||||||
_textureId = await _channel.invokeMethod("resize",
|
setRendering(false);
|
||||||
[width * _pixelRatio, height * _pixelRatio, contentScaleFactor]);
|
_textureId = await _channel.invokeMethod(
|
||||||
|
"resize", [width * _pixelRatio, height * _pixelRatio, scaleFactor]);
|
||||||
_textureIdController.add(_textureId);
|
_textureIdController.add(_textureId);
|
||||||
|
_lib.update_viewport_and_camera_projection_ffi(
|
||||||
|
_viewer!, width, height, scaleFactor);
|
||||||
_resizing = false;
|
_resizing = false;
|
||||||
|
setRendering(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future clearBackgroundImage() async {
|
Future clearBackgroundImage() async {
|
||||||
|
|||||||
@@ -109,11 +109,10 @@ class FilamentControllerMethodChannel extends FilamentController {
|
|||||||
|
|
||||||
bool _resizing = false;
|
bool _resizing = false;
|
||||||
|
|
||||||
Future resize(int width, int height,
|
Future resize(int width, int height, {double scaleFactor = 1.0}) async {
|
||||||
{double contentScaleFactor = 1.0}) async {
|
|
||||||
_resizing = true;
|
_resizing = true;
|
||||||
_textureId = await _channel.invokeMethod("resize",
|
_textureId = await _channel.invokeMethod(
|
||||||
[width * _pixelRatio, height * _pixelRatio, contentScaleFactor]);
|
"resize", [width * _pixelRatio, height * _pixelRatio, scaleFactor]);
|
||||||
_textureIdController.add(_textureId);
|
_textureIdController.add(_textureId);
|
||||||
_resizing = false;
|
_resizing = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,13 +18,7 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
] as CFDictionary
|
] as CFDictionary
|
||||||
|
|
||||||
var resources:[UInt32:NSData] = [:]
|
var resources:[UInt32:NSData] = [:]
|
||||||
|
|
||||||
var viewer:UnsafeRawPointer? = nil
|
|
||||||
var displayLink:CVDisplayLink? = nil
|
|
||||||
var rendering:Bool = false
|
|
||||||
|
|
||||||
var frameInterval:Double = 1 / 60.0
|
|
||||||
|
|
||||||
static var messenger : FlutterBinaryMessenger? = nil;
|
static var messenger : FlutterBinaryMessenger? = nil;
|
||||||
|
|
||||||
var loadResource : @convention(c) (UnsafePointer<Int8>?, UnsafeMutableRawPointer?) -> ResourceBuffer = { uri, resourcesPtr in
|
var loadResource : @convention(c) (UnsafePointer<Int8>?, UnsafeMutableRawPointer?) -> ResourceBuffer = { uri, resourcesPtr in
|
||||||
@@ -74,35 +68,6 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
instance.registry.textureFrameAvailable(instance.flutterTextureId!)
|
instance.registry.textureFrameAvailable(instance.flutterTextureId!)
|
||||||
}
|
}
|
||||||
|
|
||||||
var displayLinkRenderCallback : @convention(c) (CVDisplayLink, UnsafePointer<CVTimeStamp>, UnsafePointer<CVTimeStamp>, CVOptionFlags, UnsafeMutablePointer<CVOptionFlags>, UnsafeMutableRawPointer?) -> CVReturn = { displayLink, ts1, ts2, options, optionsPtr, resourcesPtr in
|
|
||||||
let instance:SwiftPolyvoxFilamentPlugin = Unmanaged<SwiftPolyvoxFilamentPlugin>.fromOpaque(resourcesPtr!).takeUnretainedValue()
|
|
||||||
|
|
||||||
if(instance.viewer != nil && instance.rendering) {
|
|
||||||
instance.doRender()
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func doRender() {
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
render(self.viewer, 0)
|
|
||||||
self.registry.textureFrameAvailable(self.flutterTextureId!)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func createDisplayLink() {
|
|
||||||
let displayID = CGMainDisplayID()
|
|
||||||
let error = CVDisplayLinkCreateWithCGDisplay(displayID, &displayLink);
|
|
||||||
if (error != 0)
|
|
||||||
{
|
|
||||||
print("DisplayLink created with error \(error)");
|
|
||||||
}
|
|
||||||
CVDisplayLinkSetOutputCallback(displayLink!, displayLinkRenderCallback, unsafeBitCast(self, to:UnsafeMutableRawPointer.self))
|
|
||||||
|
|
||||||
CVDisplayLinkStart(displayLink!);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public func copyPixelBuffer() -> Unmanaged<CVPixelBuffer>? {
|
public func copyPixelBuffer() -> Unmanaged<CVPixelBuffer>? {
|
||||||
if(pixelBuffer == nil) {
|
if(pixelBuffer == nil) {
|
||||||
return nil;
|
return nil;
|
||||||
@@ -136,12 +101,6 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
self.flutterTextureId = self.registry.register(self)
|
self.flutterTextureId = self.registry.register(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func resize(width:Int32, height:Int32) {
|
|
||||||
if(self.flutterTextureId != nil) {
|
|
||||||
self.registry.unregisterTexture(self.flutterTextureId!)
|
|
||||||
}
|
|
||||||
createPixelBuffer(width: Int(width), height:Int(height))
|
|
||||||
}
|
|
||||||
|
|
||||||
var cvMetalTextureCache:CVMetalTextureCache? = nil
|
var cvMetalTextureCache:CVMetalTextureCache? = nil
|
||||||
var cvMetalTexture:CVMetalTexture? = nil
|
var cvMetalTexture:CVMetalTexture? = nil
|
||||||
@@ -185,7 +144,6 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
0,
|
0,
|
||||||
&cvMetalTexture);
|
&cvMetalTexture);
|
||||||
metalTexture = CVMetalTextureGetTexture(cvMetalTexture!);
|
metalTexture = CVMetalTextureGetTexture(cvMetalTexture!);
|
||||||
// createDisplayLink()
|
|
||||||
let pixelBufferPtr = CVPixelBufferGetBaseAddress(pixelBuffer!);
|
let pixelBufferPtr = CVPixelBufferGetBaseAddress(pixelBuffer!);
|
||||||
let pixelBufferAddress = Int(bitPattern:pixelBufferPtr);
|
let pixelBufferAddress = Int(bitPattern:pixelBufferPtr);
|
||||||
let metalTexturePtr = Unmanaged.passUnretained(metalTexture!).toOpaque()
|
let metalTexturePtr = Unmanaged.passUnretained(metalTexture!).toOpaque()
|
||||||
@@ -195,39 +153,21 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
|
|
||||||
result([self.flutterTextureId as Any, nil, metalTextureAddress])
|
result([self.flutterTextureId as Any, nil, metalTextureAddress])
|
||||||
case "destroyTexture":
|
case "destroyTexture":
|
||||||
if(viewer != nil) {
|
if(self.flutterTextureId != nil) {
|
||||||
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Destroy the viewer before destroying the texture", details: nil))
|
self.registry.unregisterTexture(self.flutterTextureId!)
|
||||||
} else {
|
|
||||||
|
|
||||||
if(self.flutterTextureId != nil) {
|
|
||||||
self.registry.unregisterTexture(self.flutterTextureId!)
|
|
||||||
}
|
|
||||||
self.flutterTextureId = nil
|
|
||||||
self.pixelBuffer = nil
|
|
||||||
}
|
}
|
||||||
case "destroyViewer":
|
self.flutterTextureId = nil
|
||||||
if(viewer != nil) {
|
self.pixelBuffer = nil
|
||||||
destroy_swap_chain(viewer)
|
self.metalTexture = nil
|
||||||
destroy_filament_viewer(viewer)
|
|
||||||
viewer = nil
|
|
||||||
}
|
|
||||||
result(true)
|
|
||||||
case "resize":
|
case "resize":
|
||||||
if(viewer == nil) {
|
|
||||||
print("Error: cannot resize before a viewer has been created")
|
|
||||||
result(nil);
|
|
||||||
}
|
|
||||||
rendering = false
|
|
||||||
destroy_swap_chain(viewer)
|
|
||||||
let args = call.arguments as! [Any]
|
let args = call.arguments as! [Any]
|
||||||
let width = UInt32(args[0] as! Int64)
|
let width = UInt32(args[0] as! Int64)
|
||||||
let height = UInt32(args[1] as! Int64)
|
let height = UInt32(args[1] as! Int64)
|
||||||
resize(width:Int32(width), height:Int32(height))
|
if(self.flutterTextureId != nil) {
|
||||||
create_swap_chain(viewer, CVPixelBufferGetBaseAddress(pixelBuffer!), width, height)
|
self.registry.unregisterTexture(self.flutterTextureId!)
|
||||||
|
}
|
||||||
|
createPixelBuffer(width: Int(width), height:Int(height))
|
||||||
let metalTextureId = Int(bitPattern:Unmanaged.passUnretained(metalTexture!).toOpaque())
|
let metalTextureId = Int(bitPattern:Unmanaged.passUnretained(metalTexture!).toOpaque())
|
||||||
create_render_target(viewer, metalTextureId, width, height);
|
|
||||||
update_viewport_and_camera_projection(viewer, width, height, Float(args[2] as! Double))
|
|
||||||
rendering = true
|
|
||||||
print("Resized to \(args[0])x\(args[1])")
|
print("Resized to \(args[0])x\(args[1])")
|
||||||
result(self.flutterTextureId);
|
result(self.flutterTextureId);
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user