Unverified Commit 81ed0544 authored by Nikolay Igotti's avatar Nikolay Igotti Committed by GitHub

External linking mechanism for native and JS (#159)

parent b8510b66
...@@ -121,8 +121,6 @@ kotlin { ...@@ -121,8 +121,6 @@ kotlin {
if (supportNative) { if (supportNative) {
val nativeTarget = when (target) { val nativeTarget = when (target) {
"macos-x64", "macos-arm64" -> macosX64() "macos-x64", "macos-arm64" -> macosX64()
// "linux-x64" -> linuxX64()
// "windows-x64" -> mingwX64()
else -> null else -> null
} }
nativeTarget?.apply { nativeTarget?.apply {
......
...@@ -50,10 +50,18 @@ class BackendRenderTarget internal constructor(ptr: Long) : Managed(ptr, _Finali ...@@ -50,10 +50,18 @@ class BackendRenderTarget internal constructor(ptr: Long) : Managed(ptr, _Finali
return BackendRenderTarget(_nMakeDirect3D(width, height, texturePtr, format, sampleCnt, levelCnt)) return BackendRenderTarget(_nMakeDirect3D(width, height, texturePtr, format, sampleCnt, levelCnt))
} }
@JvmStatic external fun _nGetFinalizer(): Long @JvmStatic
@JvmStatic external fun _nMakeGL(width: Int, height: Int, sampleCnt: Int, stencilBits: Int, fbId: Int, fbFormat: Int): Long @ExternalSymbolName("BackendRenderTarget_nGetFinalizer")
@JvmStatic external fun _nMakeMetal(width: Int, height: Int, texturePtr: Long): Long external fun _nGetFinalizer(): Long
@JvmStatic external fun _nMakeDirect3D( @JvmStatic
@ExternalSymbolName("BackendRenderTarget_nMakeGL")
external fun _nMakeGL(width: Int, height: Int, sampleCnt: Int, stencilBits: Int, fbId: Int, fbFormat: Int): Long
@JvmStatic
@ExternalSymbolName("BackendRenderTarget_nMakeMetal")
external fun _nMakeMetal(width: Int, height: Int, texturePtr: Long): Long
@JvmStatic
@ExternalSymbolName("BackendRenderTarget_nMakeDirect3D")
external fun _nMakeDirect3D(
width: Int, width: Int,
height: Int, height: Int,
texturePtr: Long, texturePtr: Long,
......
...@@ -28,3 +28,7 @@ interface BooleanSupplier { ...@@ -28,3 +28,7 @@ interface BooleanSupplier {
*/ */
val asBoolean: Boolean val asBoolean: Boolean
} }
@OptIn(ExperimentalMultiplatform::class)
@OptionalExpectation
expect annotation class ExternalSymbolName(val name: String)
...@@ -21,3 +21,5 @@ actual class Matcher { ...@@ -21,3 +21,5 @@ actual class Matcher {
actual fun defaultLanguageTag(): String = TODO() actual fun defaultLanguageTag(): String = TODO()
actual fun compilePattern(regex: String): Pattern = TODO() actual fun compilePattern(regex: String): Pattern = TODO()
actual typealias ExternalSymbolName = kotlin.js.JsName
#include <iostream>
#include <jni.h>
#include "GrBackendSurface.h"
static void deleteBackendRenderTarget(GrBackendRenderTarget* rt) {
delete rt;
}
extern "C" jlong BackendRenderTarget_nGetFinalizer() {
return static_cast<jlong>(reinterpret_cast<uintptr_t>(&deleteBackendRenderTarget));
}
extern "C" jlong BackendRenderTarget_nMakeGL
(jint width, jint height, jint sampleCnt, jint stencilBits, jint fbId, jint fbFormat) {
GrGLFramebufferInfo glInfo = { static_cast<unsigned int>(fbId), static_cast<unsigned int>(fbFormat) };
GrBackendRenderTarget* instance = new GrBackendRenderTarget(width, height, sampleCnt, stencilBits, glInfo);
return reinterpret_cast<jlong>(instance);
}
extern "C" jlong BackendRenderTarget_nMakeMetal
(jint width, jint height, jlong texturePtr) {
#ifdef SK_METAL
GrMTLHandle texture = reinterpret_cast<GrMTLHandle>(static_cast<uintptr_t>(texturePtr));
GrMtlTextureInfo fbInfo;
fbInfo.fTexture.retain(texture);
GrBackendRenderTarget* instance = new GrBackendRenderTarget(width, height, fbInfo);
return reinterpret_cast<jlong>(instance);
#else
return 0;
#endif
}
#endif
#ifdef SK_DIRECT3D
#include "d3d/GrD3DTypes.h"
#endif
extern "C" jlong BackendRenderTarget_MakeDirect3D
(jint width, jint height, jlong texturePtr, jint format, jint sampleCnt, jint levelCnt) {#ifdef SK_DIRECT3D
#ifdef SK_DIRECT3D
GrD3DTextureResourceInfo texResInfo = {};
ID3D12Resource* resource = reinterpret_cast<ID3D12Resource*>(static_cast<uintptr_t>(texturePtr));
texResInfo.fResource.retain(resource);
texResInfo.fResourceState = D3D12_RESOURCE_STATE_COMMON;
texResInfo.fFormat = static_cast<DXGI_FORMAT>(format);
texResInfo.fSampleCount = static_cast<uint32_t>(sampleCnt);
texResInfo.fLevelCount = static_cast<uint32_t>(levelCnt);
GrBackendRenderTarget* instance = new GrBackendRenderTarget(width, height, texResInfo);
return reinterpret_cast<jlong>(instance);
#else
return 0;
#endif
}
\ No newline at end of file
...@@ -21,3 +21,5 @@ actual class Matcher { ...@@ -21,3 +21,5 @@ actual class Matcher {
actual fun defaultLanguageTag(): String = TODO() actual fun defaultLanguageTag(): String = TODO()
actual fun compilePattern(regex: String): Pattern = TODO() actual fun compilePattern(regex: String): Pattern = TODO()
actual typealias ExternalSymbolName = kotlin.native.SymbolName
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment