[Kotlin/Native][Interop] Skia interop plugin for cinterop
This commit is contained in:
@@ -85,10 +85,12 @@ fun main() {
|
||||
val testRun = FeatureTest()
|
||||
testRun.ctorDefault()
|
||||
testRun.ctorWithParam()
|
||||
|
||||
val a0 = retByValue(null)
|
||||
println("a0.useContents {iPub} = ${a0.useContents {iPub}}" )
|
||||
println("a0.useContents { foo() } = ${a0.useContents { foo() }}" )
|
||||
|
||||
// By value for C++ requires further design of stubs mechanism.
|
||||
// So not supported for now.
|
||||
//val a0 = retByValue(null)
|
||||
//println("a0.useContents {iPub} = ${a0.useContents {iPub}}" )
|
||||
//println("a0.useContents { foo() } = ${a0.useContents { foo() }}" )
|
||||
|
||||
// retByValue(null)!!.getValue().foo()
|
||||
// val a1 = interpretPointed<CppTest>(retByValue(null).rawValue)
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
language = C++
|
||||
compilerOpts = -std=c++17
|
||||
plugin = org.jetbrains.kotlin.native.interop.skia
|
||||
|
||||
---
|
||||
// TODO: this one checks the syntactic aspect for now.
|
||||
// To be updated for proper c++ destructor and
|
||||
// kotlin garbage collection interaction.
|
||||
|
||||
|
||||
template <typename T> class sk_sp {
|
||||
public:
|
||||
sk_sp(T* obj) : data(obj) {}
|
||||
T* release() {
|
||||
return data;
|
||||
}
|
||||
private:
|
||||
T* data;
|
||||
};
|
||||
|
||||
template <typename T> sk_sp<T> sk_ref_sp(T* obj) {
|
||||
return sk_sp<T>(obj);
|
||||
}
|
||||
|
||||
class Value {
|
||||
public:
|
||||
int data;
|
||||
};
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
Foo() { }
|
||||
|
||||
virtual sk_sp<Value> foo(Value *obj) {
|
||||
return sk_sp<Value>(obj);
|
||||
}
|
||||
|
||||
virtual Value* bar(sk_sp<Value> obj) {
|
||||
return obj.release();
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import kotlinx.cinterop.*
|
||||
import kotlin.test.*
|
||||
|
||||
import skia.*
|
||||
|
||||
fun main() {
|
||||
val f = Foo()
|
||||
val a = nativeHeap.alloc<Value>()
|
||||
a.data = 17
|
||||
val x = f.foo(a.ptr)
|
||||
val z = f.bar(x)
|
||||
println("${a?.data} ${z?.pointed?.data}")
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import kotlin.test.*
|
||||
import kotlin.random.*
|
||||
|
||||
import cpptypes.*
|
||||
|
||||
/*
|
||||
@Test
|
||||
fun test_retByValue(k: Int) {
|
||||
memScoped {
|
||||
@@ -11,6 +11,7 @@ fun test_retByValue(k: Int) {
|
||||
assertEquals(k, x.get())
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@Test
|
||||
fun test_retByPtr(k: Int) {
|
||||
@@ -35,7 +36,7 @@ fun test_retByRefConst(k: Int) {
|
||||
val x = interpretPointed<CppTest>(retByRefConst(k).rawValue)
|
||||
assertEquals(k, x.get())
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
fun test_paramByValue(k: Int) {
|
||||
val x = nativeHeap.alloc<CppTest>() {}
|
||||
@@ -43,7 +44,7 @@ fun test_paramByValue(k: Int) {
|
||||
assertEquals(k, paramByValue(x.readValue()))
|
||||
nativeHeap.free(x)
|
||||
}
|
||||
|
||||
*/
|
||||
@Test
|
||||
fun test_paramByPtr(k: Int) {
|
||||
val x = nativeHeap.alloc<CppTest>() {}
|
||||
@@ -80,12 +81,12 @@ fun main() {
|
||||
val seed = Random.nextInt()
|
||||
val r = Random(seed)
|
||||
|
||||
test_retByValue(r.nextInt())
|
||||
//test_retByValue(r.nextInt())
|
||||
test_retByPtr(r.nextInt())
|
||||
test_retByPtrConst(r.nextInt())
|
||||
test_retByRef(r.nextInt())
|
||||
test_retByRefConst(r.nextInt())
|
||||
test_paramByValue(r.nextInt())
|
||||
//test_paramByValue(r.nextInt())
|
||||
test_paramByPtr(r.nextInt())
|
||||
test_paramByPtrConst(r.nextInt())
|
||||
test_paramByRef(r.nextInt())
|
||||
|
||||
Reference in New Issue
Block a user