chore: upgrade Swift interop gen
This commit is contained in:
1
Makefile
1
Makefile
@@ -12,6 +12,7 @@ flutter-example-web: dart-web-clean dart-web
|
|||||||
flutter-example-macos:
|
flutter-example-macos:
|
||||||
cd thermion_flutter_federated/thermion_flutter/example/web && flutter run -d macos
|
cd thermion_flutter_federated/thermion_flutter/example/web && flutter run -d macos
|
||||||
swift-bindings:
|
swift-bindings:
|
||||||
|
swiftc -c thermion_flutter/thermion_flutter/macos/Classes/ThermionTexture.swift -module-name swift_module -emit-objc-header-path thermion_dart/native/include/generated/ThermionTextureSwiftObjCAPI.h -emit-library -o thermion_dart/test/libThermionTextureSwift.dylib
|
||||||
cd thermion_dart/ && dart --enable-experiment=native-assets run ffigen --config ffigen/swift.yaml
|
cd thermion_dart/ && dart --enable-experiment=native-assets run ffigen --config ffigen/swift.yaml
|
||||||
bindings:
|
bindings:
|
||||||
cd thermion_dart/ && dart --enable-experiment=native-assets run ffigen --config ffigen/native.yaml
|
cd thermion_dart/ && dart --enable-experiment=native-assets run ffigen --config ffigen/native.yaml
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
name: ThermionDartTexture
|
name: ThermionTextureSwift
|
||||||
description: Bindings for ThermionDartTexture.
|
description: Bindings for ThermionTexture.
|
||||||
language: objc
|
language: objc
|
||||||
output: 'lib/thermion_dart/swift/swift_bindings.g.dart'
|
output: '../lib/src/swift/swift_bindings.g.dart'
|
||||||
exclude-all-by-default: true
|
exclude-all-by-default: true
|
||||||
objc-interfaces:
|
objc-interfaces:
|
||||||
include:
|
include:
|
||||||
- 'ThermionDartTexture'
|
- 'ThermionTextureSwift'
|
||||||
module:
|
module:
|
||||||
'ThermionDartTexture': 'thermion_dart_texture'
|
'ThermionTextureSwift': 'swift_module'
|
||||||
headers:
|
headers:
|
||||||
entry-points:
|
entry-points:
|
||||||
- 'native/lib/macos/swift/ThermionDartTexture.h'
|
- '../native/include/generated/ThermionTextureSwiftObjCAPI.h'
|
||||||
preamble: |
|
preamble: |
|
||||||
// ignore_for_file: camel_case_types, non_constant_identifier_names, unused_element, unused_field, return_of_invalid_type, void_checks, annotate_overrides, no_leading_underscores_for_local_identifiers, library_private_types_in_public_apia
|
// ignore_for_file: camel_case_types, non_constant_identifier_names, unused_element, unused_field, return_of_invalid_type, void_checks, annotate_overrides, no_leading_underscores_for_local_identifiers, library_private_types_in_public_apia
|
||||||
File diff suppressed because it is too large
Load Diff
111
thermion_dart/lib/src/swift/swift_bindings.g.dart.m
Normal file
111
thermion_dart/lib/src/swift/swift_bindings.g.dart.m
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#import "../../../native/include/generated/ThermionTextureSwiftObjCAPI.h"
|
||||||
|
|
||||||
|
typedef void (^ListenerBlock)(NSDictionary* , struct _NSRange , BOOL * );
|
||||||
|
ListenerBlock wrapListenerBlock_ObjCBlock_ffiVoid_NSDictionary_NSRange_bool(ListenerBlock block) {
|
||||||
|
ListenerBlock wrapper = [^void(NSDictionary* arg0, struct _NSRange arg1, BOOL * arg2) {
|
||||||
|
block([arg0 retain], arg1, arg2);
|
||||||
|
} copy];
|
||||||
|
[block release];
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef void (^ListenerBlock1)(id , struct _NSRange , BOOL * );
|
||||||
|
ListenerBlock1 wrapListenerBlock_ObjCBlock_ffiVoid_objcObjCObject_NSRange_bool(ListenerBlock1 block) {
|
||||||
|
ListenerBlock1 wrapper = [^void(id arg0, struct _NSRange arg1, BOOL * arg2) {
|
||||||
|
block([arg0 retain], arg1, arg2);
|
||||||
|
} copy];
|
||||||
|
[block release];
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef void (^ListenerBlock2)(NSTimer* );
|
||||||
|
ListenerBlock2 wrapListenerBlock_ObjCBlock_ffiVoid_NSTimer(ListenerBlock2 block) {
|
||||||
|
ListenerBlock2 wrapper = [^void(NSTimer* arg0) {
|
||||||
|
block([arg0 retain]);
|
||||||
|
} copy];
|
||||||
|
[block release];
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef void (^ListenerBlock3)(NSFileHandle* );
|
||||||
|
ListenerBlock3 wrapListenerBlock_ObjCBlock_ffiVoid_NSFileHandle(ListenerBlock3 block) {
|
||||||
|
ListenerBlock3 wrapper = [^void(NSFileHandle* arg0) {
|
||||||
|
block([arg0 retain]);
|
||||||
|
} copy];
|
||||||
|
[block release];
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef void (^ListenerBlock4)(NSError* );
|
||||||
|
ListenerBlock4 wrapListenerBlock_ObjCBlock_ffiVoid_NSError(ListenerBlock4 block) {
|
||||||
|
ListenerBlock4 wrapper = [^void(NSError* arg0) {
|
||||||
|
block([arg0 retain]);
|
||||||
|
} copy];
|
||||||
|
[block release];
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef void (^ListenerBlock5)(NSDictionary* , NSError* );
|
||||||
|
ListenerBlock5 wrapListenerBlock_ObjCBlock_ffiVoid_NSDictionary_NSError(ListenerBlock5 block) {
|
||||||
|
ListenerBlock5 wrapper = [^void(NSDictionary* arg0, NSError* arg1) {
|
||||||
|
block([arg0 retain], [arg1 retain]);
|
||||||
|
} copy];
|
||||||
|
[block release];
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef void (^ListenerBlock6)(NSArray* );
|
||||||
|
ListenerBlock6 wrapListenerBlock_ObjCBlock_ffiVoid_NSArray(ListenerBlock6 block) {
|
||||||
|
ListenerBlock6 wrapper = [^void(NSArray* arg0) {
|
||||||
|
block([arg0 retain]);
|
||||||
|
} copy];
|
||||||
|
[block release];
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef void (^ListenerBlock7)(NSTextCheckingResult* , NSMatchingFlags , BOOL * );
|
||||||
|
ListenerBlock7 wrapListenerBlock_ObjCBlock_ffiVoid_NSTextCheckingResult_NSMatchingFlags_bool(ListenerBlock7 block) {
|
||||||
|
ListenerBlock7 wrapper = [^void(NSTextCheckingResult* arg0, NSMatchingFlags arg1, BOOL * arg2) {
|
||||||
|
block([arg0 retain], arg1, arg2);
|
||||||
|
} copy];
|
||||||
|
[block release];
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef void (^ListenerBlock8)(NSCachedURLResponse* );
|
||||||
|
ListenerBlock8 wrapListenerBlock_ObjCBlock_ffiVoid_NSCachedURLResponse(ListenerBlock8 block) {
|
||||||
|
ListenerBlock8 wrapper = [^void(NSCachedURLResponse* arg0) {
|
||||||
|
block([arg0 retain]);
|
||||||
|
} copy];
|
||||||
|
[block release];
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef void (^ListenerBlock9)(NSURLResponse* , NSData* , NSError* );
|
||||||
|
ListenerBlock9 wrapListenerBlock_ObjCBlock_ffiVoid_NSURLResponse_NSData_NSError(ListenerBlock9 block) {
|
||||||
|
ListenerBlock9 wrapper = [^void(NSURLResponse* arg0, NSData* arg1, NSError* arg2) {
|
||||||
|
block([arg0 retain], [arg1 retain], [arg2 retain]);
|
||||||
|
} copy];
|
||||||
|
[block release];
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef void (^ListenerBlock10)(NSDictionary* );
|
||||||
|
ListenerBlock10 wrapListenerBlock_ObjCBlock_ffiVoid_NSDictionary(ListenerBlock10 block) {
|
||||||
|
ListenerBlock10 wrapper = [^void(NSDictionary* arg0) {
|
||||||
|
block([arg0 retain]);
|
||||||
|
} copy];
|
||||||
|
[block release];
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef void (^ListenerBlock11)(NSURLCredential* );
|
||||||
|
ListenerBlock11 wrapListenerBlock_ObjCBlock_ffiVoid_NSURLCredential(ListenerBlock11 block) {
|
||||||
|
ListenerBlock11 wrapper = [^void(NSURLCredential* arg0) {
|
||||||
|
block([arg0 retain]);
|
||||||
|
} copy];
|
||||||
|
[block release];
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
|
||||||
oid sha256:02859acdfdc2227784553f616bf55cd34e5931413b21c6fea7aaf79d2aa56af3
|
|
||||||
size 10694
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
|
||||||
oid sha256:1d0fb1cf7f63c52b5a82a25d2038a1b2d6b9bc9f54491d73345900f58b0b8087
|
|
||||||
size 224
|
|
||||||
Binary file not shown.
@@ -19,9 +19,11 @@ dependencies:
|
|||||||
http: ^1.2.2
|
http: ^1.2.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
ffigen: ^12.0.0
|
ffigen: ^13.0.0
|
||||||
|
objective_c: ^1.1.0
|
||||||
test:
|
test:
|
||||||
image:
|
image:
|
||||||
path:
|
path:
|
||||||
mockito: ^5.0.0
|
mockito: ^5.0.0
|
||||||
build_runner: ^2.0.0
|
build_runner: ^2.0.0
|
||||||
|
|
||||||
@@ -6,11 +6,11 @@ public class ThermionFlutterTexture : NSObject, FlutterTexture {
|
|||||||
|
|
||||||
var flutterTextureId: Int64 = -1
|
var flutterTextureId: Int64 = -1
|
||||||
var registry: FlutterTextureRegistry
|
var registry: FlutterTextureRegistry
|
||||||
var texture: ThermionDartTexture
|
var texture: ThermionTexture
|
||||||
|
|
||||||
init(registry:FlutterTextureRegistry, width:Int64, height:Int64) {
|
init(registry:FlutterTextureRegistry, width:Int64, height:Int64) {
|
||||||
self.registry = registry
|
self.registry = registry
|
||||||
self.texture = ThermionDartTexture(width:width, height: height)
|
self.texture = ThermionTexture(width:width, height: height)
|
||||||
super.init()
|
super.init()
|
||||||
self.flutterTextureId = registry.register(self)
|
self.flutterTextureId = registry.register(self)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import GLKit
|
import GLKit
|
||||||
|
|
||||||
@objc public class ThermionDartTexture : NSObject {
|
@objc public class ThermionTextureSwift : NSObject {
|
||||||
|
|
||||||
public var pixelBuffer: CVPixelBuffer?
|
public var pixelBuffer: CVPixelBuffer?
|
||||||
|
|
||||||
@@ -62,37 +62,6 @@ import GLKit
|
|||||||
metalTexture = CVMetalTextureGetTexture(cvMetalTexture!)
|
metalTexture = CVMetalTextureGetTexture(cvMetalTexture!)
|
||||||
let metalTexturePtr = Unmanaged.passRetained(metalTexture!).toOpaque()
|
let metalTexturePtr = Unmanaged.passRetained(metalTexture!).toOpaque()
|
||||||
metalTextureAddress = Int(bitPattern:metalTexturePtr)
|
metalTextureAddress = Int(bitPattern:metalTexturePtr)
|
||||||
|
|
||||||
// CVPixelBufferLockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0))
|
|
||||||
// let bufferWidth = Int(CVPixelBufferGetWidth(pixelBuffer!))
|
|
||||||
// let bufferHeight = Int(CVPixelBufferGetHeight(pixelBuffer!))
|
|
||||||
// let bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer!)
|
|
||||||
|
|
||||||
// guard let baseAddress = CVPixelBufferGetBaseAddress(pixelBuffer!) else {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// for row in 0..<bufferHeight {
|
|
||||||
// var pixel = baseAddress + row * bytesPerRow
|
|
||||||
// for col in 0..<bufferWidth {
|
|
||||||
// let blue = pixel
|
|
||||||
// blue.storeBytes(of: 255, as: UInt8.self)
|
|
||||||
|
|
||||||
// let red = pixel + 1
|
|
||||||
// red.storeBytes(of: 0, as: UInt8.self)
|
|
||||||
|
|
||||||
// let green = pixel + 2
|
|
||||||
// green.storeBytes(of: 0, as: UInt8.self)
|
|
||||||
|
|
||||||
// let alpha = pixel + 3
|
|
||||||
// alpha.storeBytes(of: 255, as: UInt8.self)
|
|
||||||
|
|
||||||
// pixel += 4;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// CVPixelBufferUnlockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func destroyTexture() {
|
@objc public func destroyTexture() {
|
||||||
@@ -104,5 +73,70 @@ import GLKit
|
|||||||
self.cvMetalTextureCache = nil
|
self.cvMetalTextureCache = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc public func fillColor() {
|
||||||
|
CVPixelBufferLockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0))
|
||||||
|
let bufferWidth = Int(CVPixelBufferGetWidth(pixelBuffer!))
|
||||||
|
let bufferHeight = Int(CVPixelBufferGetHeight(pixelBuffer!))
|
||||||
|
let bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer!)
|
||||||
|
|
||||||
|
guard let baseAddress = CVPixelBufferGetBaseAddress(pixelBuffer!) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for row in 0..<bufferHeight {
|
||||||
|
var pixel = baseAddress + row * bytesPerRow
|
||||||
|
for col in 0..<bufferWidth {
|
||||||
|
let blue = pixel
|
||||||
|
blue.storeBytes(of: 255, as: UInt8.self)
|
||||||
|
|
||||||
|
let red = pixel + 1
|
||||||
|
red.storeBytes(of: 0, as: UInt8.self)
|
||||||
|
|
||||||
|
let green = pixel + 2
|
||||||
|
green.storeBytes(of: 0, as: UInt8.self)
|
||||||
|
|
||||||
|
let alpha = pixel + 3
|
||||||
|
alpha.storeBytes(of: 255, as: UInt8.self)
|
||||||
|
|
||||||
|
pixel += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CVPixelBufferUnlockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0))
|
||||||
|
}
|
||||||
|
@objc public func getTextureBytes() -> NSData? {
|
||||||
|
guard let texture = self.metalTexture else {
|
||||||
|
print("Metal texture is not available")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let width = texture.width
|
||||||
|
let height = texture.height
|
||||||
|
let bytesPerPixel = 4 // RGBA
|
||||||
|
let bytesPerRow = width * bytesPerPixel
|
||||||
|
let byteCount = bytesPerRow * height
|
||||||
|
|
||||||
|
var bytes = [UInt8](repeating: 0, count: byteCount)
|
||||||
|
let region = MTLRegionMake2D(0, 0, width, height)
|
||||||
|
texture.getBytes(&bytes, bytesPerRow: bytesPerRow, from: region, mipmapLevel: 0)
|
||||||
|
|
||||||
|
// Swizzle bytes from BGRA to RGBA
|
||||||
|
for i in stride(from: 0, to: byteCount, by: 4) {
|
||||||
|
let blue = bytes[i]
|
||||||
|
let green = bytes[i + 1]
|
||||||
|
let red = bytes[i + 2]
|
||||||
|
let alpha = bytes[i + 3]
|
||||||
|
|
||||||
|
bytes[i] = red
|
||||||
|
bytes[i + 1] = green
|
||||||
|
bytes[i + 2] = blue
|
||||||
|
bytes[i + 3] = alpha
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert Swift Data to Objective-C NSData
|
||||||
|
let nsData = Data(bytes: &bytes, count: byteCount) as NSData
|
||||||
|
return nsData
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user