Unverified Commit d04654c6 authored by Oleksandr Karpovich's avatar Oleksandr Karpovich Committed by GitHub

update to skia m126 (#969)

Skia-pack used in this skiko:
https://github.com/JetBrains/skia-pack/releases/tag/m126-1d69d9b-2
parent 2a47e23a
...@@ -198,7 +198,7 @@ jobs: ...@@ -198,7 +198,7 @@ jobs:
retention-days: 5 retention-days: 5
windows: windows:
runs-on: windows-2019 runs-on: windows-2022
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
name: 'Check out code' name: 'Check out code'
......
...@@ -12,7 +12,7 @@ import kotlin.math.sin ...@@ -12,7 +12,7 @@ import kotlin.math.sin
open class ClocksAwt(private val scaleProvider: () -> Float) : SkikoRenderDelegate, MouseMotionListener { open class ClocksAwt(private val scaleProvider: () -> Float) : SkikoRenderDelegate, MouseMotionListener {
constructor(layer: SkiaLayer) : this({ layer.contentScale }) constructor(layer: SkiaLayer) : this({ layer.contentScale })
private val typeface = Typeface.makeFromFile("fonts/JetBrainsMono-Regular.ttf") private val typeface = FontMgr.default.makeFromFile("fonts/JetBrainsMono-Regular.ttf")
private val font = Font(typeface, 13f).apply { private val font = Font(typeface, 13f).apply {
edging = FontEdging.SUBPIXEL_ANTI_ALIAS edging = FontEdging.SUBPIXEL_ANTI_ALIAS
hinting = FontHinting.SLIGHT hinting = FontHinting.SLIGHT
......
...@@ -4,6 +4,7 @@ import kotlinx.browser.document ...@@ -4,6 +4,7 @@ import kotlinx.browser.document
import kotlinx.coroutines.MainScope import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.jetbrains.skia.Data import org.jetbrains.skia.Data
import org.jetbrains.skia.FontMgr
import org.jetbrains.skia.FontMgrWithFallback import org.jetbrains.skia.FontMgrWithFallback
import org.jetbrains.skia.Typeface import org.jetbrains.skia.Typeface
import org.jetbrains.skia.paragraph.TypefaceFontProviderWithFallback import org.jetbrains.skia.paragraph.TypefaceFontProviderWithFallback
...@@ -40,8 +41,8 @@ internal fun runEmojiStoryApp() { ...@@ -40,8 +41,8 @@ internal fun runEmojiStoryApp() {
MainScope().launch { MainScope().launch {
val notoEmojisBytes = loadRes(notoColorEmoji).toByteArray() val notoEmojisBytes = loadRes(notoColorEmoji).toByteArray()
val notoSansSCBytes = loadRes(notoSancSC).toByteArray() val notoSansSCBytes = loadRes(notoSancSC).toByteArray()
val notoEmojiTypeface = Typeface.makeFromData(Data.makeFromBytes(notoEmojisBytes)) val notoEmojiTypeface = FontMgr.default.makeFromData(Data.makeFromBytes(notoEmojisBytes))
val notoSansSCTypeface = Typeface.makeFromData(Data.makeFromBytes(notoSansSCBytes)) val notoSansSCTypeface = FontMgr.default.makeFromData(Data.makeFromBytes(notoSansSCBytes))
val tfp = TypefaceFontProviderWithFallback().apply { val tfp = TypefaceFontProviderWithFallback().apply {
registerTypeface(notoEmojiTypeface) registerTypeface(notoEmojiTypeface)
......
...@@ -53,6 +53,7 @@ fun skiaPreprocessorFlags(os: OS, buildType: SkiaBuildType): Array<String> { ...@@ -53,6 +53,7 @@ fun skiaPreprocessorFlags(os: OS, buildType: SkiaBuildType): Array<String> {
"-DSK_GL", "-DSK_GL",
"-DSK_SHAPER_HARFBUZZ_AVAILABLE", "-DSK_SHAPER_HARFBUZZ_AVAILABLE",
"-DSK_UNICODE_AVAILABLE", "-DSK_UNICODE_AVAILABLE",
"-DSK_SHAPER_UNICODE_AVAILABLE",
"-DSK_SUPPORT_OPENCL=0", "-DSK_SUPPORT_OPENCL=0",
"-DSK_UNICODE_AVAILABLE", "-DSK_UNICODE_AVAILABLE",
"-DU_DISABLE_RENAMING", "-DU_DISABLE_RENAMING",
......
...@@ -281,7 +281,9 @@ fun SkikoProjectContext.createLinkJvmBindings( ...@@ -281,7 +281,9 @@ fun SkikoProjectContext.createLinkJvmBindings(
// Hack to fix problem with linker not always finding certain declarations. // Hack to fix problem with linker not always finding certain declarations.
"$skiaBinDir/libsksg.a", "$skiaBinDir/libsksg.a",
"$skiaBinDir/libskia.a", "$skiaBinDir/libskia.a",
"$skiaBinDir/libskunicode.a" "$skiaBinDir/libskunicode_core.a",
"$skiaBinDir/libskunicode_icu.a",
"$skiaBinDir/libskshaper.a",
) )
} }
OS.Windows -> { OS.Windows -> {
......
...@@ -168,7 +168,8 @@ fun skiaStaticLibraries(skiaDir: String, targetString: String, buildType: SkiaBu ...@@ -168,7 +168,8 @@ fun skiaStaticLibraries(skiaDir: String, targetString: String, buildType: SkiaBu
"libpng.a", "libpng.a",
"libwebp_sse41.a", "libwebp_sse41.a",
"libsksg.a", "libsksg.a",
"libskunicode.a", "libskunicode_core.a",
"libskunicode_icu.a",
"libwebp.a", "libwebp.a",
"libdng_sdk.a", "libdng_sdk.a",
"libpiex.a", "libpiex.a",
...@@ -225,7 +226,8 @@ fun SkikoProjectContext.configureNativeTarget(os: OS, arch: Arch, target: Kotlin ...@@ -225,7 +226,8 @@ fun SkikoProjectContext.configureNativeTarget(os: OS, arch: Arch, target: Kotlin
// TODO: an ugly hack, Linux linker searches only unresolved symbols. // TODO: an ugly hack, Linux linker searches only unresolved symbols.
"$skiaBinDir/libsksg.a", "$skiaBinDir/libsksg.a",
"$skiaBinDir/libskshaper.a", "$skiaBinDir/libskshaper.a",
"$skiaBinDir/libskunicode.a", "$skiaBinDir/libskunicode_core.a",
"$skiaBinDir/libskunicode_icu.a",
"$skiaBinDir/libskia.a" "$skiaBinDir/libskia.a"
) )
else -> mutableListOf() else -> mutableListOf()
......
...@@ -2,7 +2,7 @@ kotlin.code.style=official ...@@ -2,7 +2,7 @@ kotlin.code.style=official
deploy.version=0.0.0 deploy.version=0.0.0
dependencies.skia=m116-47d3027-1 dependencies.skia=m126-1d69d9b-2
# you can override general skia dependencies by passing platform-specific property: # you can override general skia dependencies by passing platform-specific property:
# dependencies.skia.android-arm64 # dependencies.skia.android-arm64
......
...@@ -18,10 +18,8 @@ extern "C" ...@@ -18,10 +18,8 @@ extern "C"
{ {
SkSurface *surface = fromJavaPointer<SkSurface *>(surfacePtr); SkSurface *surface = fromJavaPointer<SkSurface *>(surfacePtr);
GrDirectContext *context = fromJavaPointer<GrDirectContext *>(contextPtr); GrDirectContext *context = fromJavaPointer<GrDirectContext *>(contextPtr);
surface->flushAndSubmit(true); context->flush(surface, SkSurfaces::BackendSurfaceAccess::kPresent, GrFlushInfo());
surface->flush(SkSurface::BackendSurfaceAccess::kPresent, GrFlushInfo()); context->submit(GrSyncCpu::kYes);
context->flush();
context->submit(true);
} }
__except(EXCEPTION_EXECUTE_HANDLER) { __except(EXCEPTION_EXECUTE_HANDLER) {
auto code = GetExceptionCode(); auto code = GetExceptionCode();
......
...@@ -8,10 +8,12 @@ ...@@ -8,10 +8,12 @@
#import <Metal/Metal.h> #import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h> #import <QuartzCore/CAMetalLayer.h>
#import <GrBackendSurface.h> #import "GrBackendSurface.h"
#import <GrDirectContext.h> #import "GrDirectContext.h"
#import <mtl/GrMtlBackendContext.h> #import "ganesh/mtl/GrMtlBackendContext.h"
#import <mtl/GrMtlTypes.h> #import "ganesh/mtl/GrMtlDirectContext.h"
#import "ganesh/mtl/GrMtlBackendSurface.h"
#import "ganesh/mtl/GrMtlTypes.h"
#import "MetalDevice.h" #import "MetalDevice.h"
......
...@@ -5,10 +5,12 @@ ...@@ -5,10 +5,12 @@
#import <QuartzCore/CAMetalLayer.h> #import <QuartzCore/CAMetalLayer.h>
#import <Metal/Metal.h> #import <Metal/Metal.h>
#import <GrDirectContext.h> #import "GrDirectContext.h"
#import <gpu/GrBackendSurface.h> #import "gpu/GrBackendSurface.h"
#import <mtl/GrMtlBackendContext.h> #import "ganesh/mtl/GrMtlBackendContext.h"
#import <mtl/GrMtlTypes.h> #import "ganesh/mtl/GrMtlDirectContext.h"
#import "ganesh/mtl/GrMtlBackendSurface.h"
#import "ganesh/mtl/GrMtlTypes.h"
#import "MetalDevice.h" #import "MetalDevice.h"
...@@ -22,7 +24,7 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_context_MetalContextHandler_mak ...@@ -22,7 +24,7 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_context_MetalContextHandler_mak
GrMtlBackendContext backendContext = {}; GrMtlBackendContext backendContext = {};
backendContext.fDevice.retain((__bridge GrMTLHandle) device.adapter); backendContext.fDevice.retain((__bridge GrMTLHandle) device.adapter);
backendContext.fQueue.retain((__bridge GrMTLHandle) device.queue); backendContext.fQueue.retain((__bridge GrMTLHandle) device.queue);
return (jlong) GrDirectContext::MakeMetal(backendContext).release(); return (jlong) GrDirectContexts::MakeMetal(backendContext).release();
} }
} }
...@@ -46,7 +48,8 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_context_MetalContextHandler_mak ...@@ -46,7 +48,8 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_context_MetalContextHandler_mak
device.drawableHandle = currentDrawable; device.drawableHandle = currentDrawable;
GrMtlTextureInfo info; GrMtlTextureInfo info;
info.fTexture.retain((__bridge GrMTLHandle) currentDrawable.texture); info.fTexture.retain((__bridge GrMTLHandle) currentDrawable.texture);
renderTarget = new GrBackendRenderTarget(width, height, 0, info); GrBackendRenderTarget obj = GrBackendRenderTargets::MakeMtl(width, height, info);
renderTarget = new GrBackendRenderTarget(obj);
return (jlong) renderTarget; return (jlong) renderTarget;
} }
} }
......
...@@ -8,10 +8,11 @@ ...@@ -8,10 +8,11 @@
#import <Metal/Metal.h> #import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h> #import <QuartzCore/CAMetalLayer.h>
#import <GrBackendSurface.h> #import "GrBackendSurface.h"
#import <GrDirectContext.h> #import "GrDirectContext.h"
#import <mtl/GrMtlBackendContext.h> #import "ganesh/mtl/GrMtlBackendContext.h"
#import <mtl/GrMtlTypes.h> #import "ganesh/mtl/GrMtlDirectContext.h"
#import "ganesh/mtl/GrMtlTypes.h"
#import "MetalDevice.h" #import "MetalDevice.h"
......
...@@ -5,10 +5,12 @@ ...@@ -5,10 +5,12 @@
#import <QuartzCore/CAMetalLayer.h> #import <QuartzCore/CAMetalLayer.h>
#import <Metal/Metal.h> #import <Metal/Metal.h>
#import <GrDirectContext.h> #import "GrDirectContext.h"
#import <gpu/GrBackendSurface.h> #import "gpu/GrBackendSurface.h"
#import <mtl/GrMtlBackendContext.h> #import "ganesh/mtl/GrMtlBackendContext.h"
#import <mtl/GrMtlTypes.h> #import "ganesh/mtl/GrMtlDirectContext.h"
#import "ganesh/mtl/GrMtlBackendSurface.h"
#import "ganesh/mtl/GrMtlTypes.h"
#import "MetalDevice.h" #import "MetalDevice.h"
...@@ -23,7 +25,7 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_swing_MetalSwingRedrawer_makeMe ...@@ -23,7 +25,7 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_swing_MetalSwingRedrawer_makeMe
backendContext.fDevice.retain((__bridge GrMTLHandle) adapter); backendContext.fDevice.retain((__bridge GrMTLHandle) adapter);
id <MTLCommandQueue> fQueue = [adapter newCommandQueue]; id <MTLCommandQueue> fQueue = [adapter newCommandQueue];
backendContext.fQueue.retain((__bridge GrMTLHandle) fQueue); backendContext.fQueue.retain((__bridge GrMTLHandle) fQueue);
return (jlong) GrDirectContext::MakeMetal(backendContext).release(); return (jlong) GrDirectContexts::MakeMetal(backendContext).release();
} }
} }
...@@ -58,7 +60,8 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_swing_MetalSwingRedrawer_makeMe ...@@ -58,7 +60,8 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_swing_MetalSwingRedrawer_makeMe
GrMtlTextureInfo info; GrMtlTextureInfo info;
info.fTexture.retain((__bridge GrMTLHandle) texture); info.fTexture.retain((__bridge GrMTLHandle) texture);
GrBackendRenderTarget *renderTarget = NULL; GrBackendRenderTarget *renderTarget = NULL;
renderTarget = new GrBackendRenderTarget(texture.width, texture.height, 0, info); GrBackendRenderTarget obj = GrBackendRenderTargets::MakeMtl(texture.width, texture.height, info);
renderTarget = new GrBackendRenderTarget(obj);
return (jlong) renderTarget; return (jlong) renderTarget;
} }
} }
......
#include "FontMgrDefaultFactory.hh"
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
#include "ports/SkFontMgr_mac_ct.h"
#endif
#ifdef SK_BUILD_FOR_WIN
#include "ports/SkTypeface_win.h"
#endif
#if (defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_LINUX)) && !defined(SKIKO_WASM)
#include "ports/SkFontMgr_fontconfig.h"
#endif
#ifdef SK_BUILD_FOR_ANDROID
#include "ports/SkFontMgr_android.h"
#endif
#ifdef SKIKO_WASM
#include <vector>
#include "SkData.h"
#include "ports/SkFontMgr_data.h"
struct SkEmbeddedResource { const uint8_t* data; size_t size; };
struct SkEmbeddedResourceHeader { const SkEmbeddedResource* entries; int count; };
extern "C" const SkEmbeddedResourceHeader SK_EMBEDDED_FONTS;
#endif
sk_sp<SkFontMgr> SkFontMgrSkikoDefault() {
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
return SkFontMgr_New_CoreText(nullptr);
#endif
#ifdef SK_BUILD_FOR_WIN
return SkFontMgr_New_DirectWrite();
#endif
#if (defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_LINUX)) && !defined(SKIKO_WASM)
return SkFontMgr_New_FontConfig(nullptr);
#endif
#ifdef SK_BUILD_FOR_ANDROID
return SkFontMgr_New_Android(nullptr);
#endif
#ifdef SKIKO_WASM
sk_sp<SkData> embeddedFontData =
SkData::MakeWithoutCopy(SK_EMBEDDED_FONTS.entries[0].data, SK_EMBEDDED_FONTS.entries[0].size);
std::vector<sk_sp<SkData>> fontDataVector = { embeddedFontData };
SkSpan<sk_sp<SkData>> dataSpan(fontDataVector);
return SkFontMgr_New_Custom_Data(dataSpan);
#endif
return nullptr;
}
#include "FontMgrWithFallbackWrapper.hh" #include "FontMgrWithFallbackWrapper.hh"
#include "FontMgrDefaultFactory.hh"
FontMgrWithFallbackWrapper::FontMgrWithFallbackWrapper(sk_sp<TypefaceFontProviderWithFallback> fallbackTypefaceFontProvider) FontMgrWithFallbackWrapper::FontMgrWithFallbackWrapper(sk_sp<TypefaceFontProviderWithFallback> fallbackTypefaceFontProvider)
: fallbackFontProvider(std::move(fallbackTypefaceFontProvider)) { : fallbackFontProvider(std::move(fallbackTypefaceFontProvider)) {
wrappedFntMgr = SkFontMgr::RefDefault(); wrappedFntMgr = SkFontMgrSkikoDefault();
} }
int FontMgrWithFallbackWrapper::onCountFamilies() const { int FontMgrWithFallbackWrapper::onCountFamilies() const {
...@@ -82,4 +83,11 @@ sk_sp<SkTypeface> TypefaceFontProviderWithFallback::fallbackForChar(SkUnichar ch ...@@ -82,4 +83,11 @@ sk_sp<SkTypeface> TypefaceFontProviderWithFallback::fallbackForChar(SkUnichar ch
} }
} }
return nullptr; return nullptr;
} }
\ No newline at end of file
sk_sp<SkFontStyleSet> TypefaceFontProviderWithFallback::onCreateStyleSet(int) const {
// override to revert this change made in the parent class: https://skia-review.googlesource.com/c/skia/+/834816
// This revert is only for our subtype, for Compose purposes:
// we have our own fallback implementation. The original fallback didn't work.
return nullptr;
};
\ No newline at end of file
#ifndef FONT_MGR_DEFAULT_FACTORY_H
#define FONT_MGR_DEFAULT_FACTORY_H
#include "SkFontMgr.h"
sk_sp<SkFontMgr> SkFontMgrSkikoDefault();
#endif
\ No newline at end of file
...@@ -18,6 +18,7 @@ public: ...@@ -18,6 +18,7 @@ public:
size_t registerTypeface(sk_sp<SkTypeface> typeface, const SkString& alias); size_t registerTypeface(sk_sp<SkTypeface> typeface, const SkString& alias);
sk_sp<SkTypeface> fallbackForChar(SkUnichar character) const; sk_sp<SkTypeface> fallbackForChar(SkUnichar character) const;
sk_sp<SkFontStyleSet> onCreateStyleSet(int) const override;
private: private:
std::vector<sk_sp<SkTypeface>> registeredTypefaces; std::vector<sk_sp<SkTypeface>> registeredTypefaces;
......
...@@ -29,7 +29,7 @@ public: ...@@ -29,7 +29,7 @@ public:
, fApproximateSpaces(approximateSpaces) , fApproximateSpaces(approximateSpaces)
, fApproximatePunctuation(approximatePunctuation) , fApproximatePunctuation(approximatePunctuation)
{ {
fFont.setTypeface(font.refTypefaceOrDefault()); fFont.setTypeface(font.refTypeface());
fFallbackFont.setTypeface(nullptr); fFallbackFont.setTypeface(nullptr);
} }
...@@ -45,7 +45,7 @@ public: ...@@ -45,7 +45,7 @@ public:
font, font,
std::move(fallbackMgr), std::move(fallbackMgr),
nullptr, nullptr,
font.refTypefaceOrDefault()->fontStyle(), font.refTypeface()->fontStyle(),
nullptr, nullptr,
graphemeIter, graphemeIter,
approximateSpaces, approximateSpaces,
......
...@@ -65,6 +65,17 @@ enum class ColorType { ...@@ -65,6 +65,17 @@ enum class ColorType {
*/ */
BGR_101010X_XR, BGR_101010X_XR,
/**
* Pixel with 10 bits each for blue, green, red, alpha; in 64-bit word, extended range
*/
BGRA_10101010_XR, // kBGRA_10101010_XR_SkColorType, added when updating to m126
/**
* pixel with 10 used bits (most significant) followed by 6 unused
* bits for red, green, blue, alpha; in 64-bit word
*/
RGBA_10x6, // added when updating from m116 to m122
/** /**
* Pixel with grayscale level in 8-bit byte * Pixel with grayscale level in 8-bit byte
*/ */
...@@ -136,6 +147,8 @@ enum class ColorType { ...@@ -136,6 +147,8 @@ enum class ColorType {
BGRA_1010102 -> 4 BGRA_1010102 -> 4
BGR_101010X -> 4 BGR_101010X -> 4
BGR_101010X_XR -> 4 BGR_101010X_XR -> 4
BGRA_10101010_XR -> 4
RGBA_10x6 -> 8
GRAY_8 -> 1 GRAY_8 -> 1
RGBA_F16NORM -> 8 RGBA_F16NORM -> 8
RGBA_F16 -> 8 RGBA_F16 -> 8
...@@ -163,6 +176,8 @@ enum class ColorType { ...@@ -163,6 +176,8 @@ enum class ColorType {
BGRA_1010102 -> 2 BGRA_1010102 -> 2
BGR_101010X -> 2 BGR_101010X -> 2
BGR_101010X_XR -> 2 BGR_101010X_XR -> 2
BGRA_10101010_XR -> 2
RGBA_10x6 -> 2
GRAY_8 -> 0 GRAY_8 -> 0
RGBA_F16NORM -> 3 RGBA_F16NORM -> 3
RGBA_F16 -> 3 RGBA_F16 -> 3
...@@ -196,7 +211,7 @@ enum class ColorType { ...@@ -196,7 +211,7 @@ enum class ColorType {
else if (ColorAlphaType.UNKNOWN == alphaType) null else if (ColorAlphaType.UNKNOWN == alphaType) null
else alphaType else alphaType
} }
ARGB_4444, RGBA_8888, BGRA_8888, RGBA_1010102, BGRA_1010102, RGBA_F16NORM, RGBA_F16, RGBA_F32, R16G16B16A16_UNORM -> RGBA_10x6, ARGB_4444, RGBA_8888, BGRA_8888, RGBA_1010102, BGRA_1010102, RGBA_F16NORM, RGBA_F16, RGBA_F32, R16G16B16A16_UNORM, BGRA_10101010_XR ->
if (ColorAlphaType.UNKNOWN == alphaType) null if (ColorAlphaType.UNKNOWN == alphaType) null
else alphaType else alphaType
GRAY_8, R8G8_UNORM, R16G16_UNORM, R16G16_FLOAT, RGB_565, RGB_888X, RGB_101010X, BGR_101010X, BGR_101010X_XR -> GRAY_8, R8G8_UNORM, R16G16_UNORM, R16G16_FLOAT, RGB_565, RGB_888X, RGB_101010X, BGR_101010X, BGR_101010X_XR ->
......
...@@ -45,7 +45,13 @@ class DirectContext internal constructor(ptr: NativePointer) : RefCnt(ptr) { ...@@ -45,7 +45,13 @@ class DirectContext internal constructor(ptr: NativePointer) : RefCnt(ptr) {
fun flush(): DirectContext { fun flush(): DirectContext {
Stats.onNativeCall() Stats.onNativeCall()
DirectContext_nFlush(_ptr) DirectContext_nFlushDefault(_ptr)
return this
}
fun flush(surface: Surface): DirectContext {
Stats.onNativeCall()
DirectContext_nFlush(_ptr, surface._ptr)
return this return this
} }
...@@ -84,6 +90,15 @@ class DirectContext internal constructor(ptr: NativePointer) : RefCnt(ptr) { ...@@ -84,6 +90,15 @@ class DirectContext internal constructor(ptr: NativePointer) : RefCnt(ptr) {
_nSubmit(_ptr, syncCpu) _nSubmit(_ptr, syncCpu)
} }
fun flushAndSubmit(surface: Surface, syncCpu: Boolean = false) {
try {
Stats.onNativeCall()
_nFlushAndSubmit(_ptr, surface._ptr, syncCpu)
} finally {
reachabilityBarrier(this)
}
}
/** /**
* *
* Abandons all GPU resources and assumes the underlying backend 3D API context is no longer * Abandons all GPU resources and assumes the underlying backend 3D API context is no longer
...@@ -120,7 +135,11 @@ fun <R> DirectContext.useContext(block: (ctx: DirectContext) -> R): R = use { ...@@ -120,7 +135,11 @@ fun <R> DirectContext.useContext(block: (ctx: DirectContext) -> R): R = use {
@ExternalSymbolName("org_jetbrains_skia_DirectContext__1nFlush") @ExternalSymbolName("org_jetbrains_skia_DirectContext__1nFlush")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_DirectContext__1nFlush") @ModuleImport("./skiko.mjs", "org_jetbrains_skia_DirectContext__1nFlush")
private external fun DirectContext_nFlush(ptr: NativePointer) private external fun DirectContext_nFlush(ptr: NativePointer, surfacePtr: NativePointer)
@ExternalSymbolName("org_jetbrains_skia_DirectContext__1nFlushDefault")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_DirectContext__1nFlushDefault")
private external fun DirectContext_nFlushDefault(ptr: NativePointer)
@ExternalSymbolName("org_jetbrains_skia_DirectContext__1nMakeGL") @ExternalSymbolName("org_jetbrains_skia_DirectContext__1nMakeGL")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_DirectContext__1nMakeGL") @ModuleImport("./skiko.mjs", "org_jetbrains_skia_DirectContext__1nMakeGL")
...@@ -138,6 +157,10 @@ private external fun _nMakeDirect3D(adapterPtr: NativePointer, devicePtr: Native ...@@ -138,6 +157,10 @@ private external fun _nMakeDirect3D(adapterPtr: NativePointer, devicePtr: Native
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_DirectContext__1nSubmit") @ModuleImport("./skiko.mjs", "org_jetbrains_skia_DirectContext__1nSubmit")
private external fun _nSubmit(ptr: NativePointer, syncCpu: Boolean) private external fun _nSubmit(ptr: NativePointer, syncCpu: Boolean)
@ExternalSymbolName("org_jetbrains_skia_DirectContext__1nFlushAndSubmit")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_DirectContext__1nFlushAndSubmit")
private external fun _nFlushAndSubmit(ptr: NativePointer, surfacePtr: NativePointer, syncCpu: Boolean)
@ExternalSymbolName("org_jetbrains_skia_DirectContext__1nReset") @ExternalSymbolName("org_jetbrains_skia_DirectContext__1nReset")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_DirectContext__1nReset") @ModuleImport("./skiko.mjs", "org_jetbrains_skia_DirectContext__1nReset")
private external fun _nReset(ptr: NativePointer, flags: Int) private external fun _nReset(ptr: NativePointer, flags: Int)
......
...@@ -261,17 +261,6 @@ class Font : Managed { ...@@ -261,17 +261,6 @@ class Font : Managed {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
/**
* @return [Typeface] if set, or the default typeface.
*/
val typefaceOrDefault: Typeface
get() = try {
Stats.onNativeCall()
Typeface(_nGetTypefaceOrDefault(_ptr))
} finally {
reachabilityBarrier(this)
}
/** /**
* @return text size in points * @return text size in points
*/ */
...@@ -705,10 +694,6 @@ private external fun _nSetHinting(ptr: NativePointer, value: Int) ...@@ -705,10 +694,6 @@ private external fun _nSetHinting(ptr: NativePointer, value: Int)
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Font__1nGetTypeface") @ModuleImport("./skiko.mjs", "org_jetbrains_skia_Font__1nGetTypeface")
private external fun _nGetTypeface(ptr: NativePointer): NativePointer private external fun _nGetTypeface(ptr: NativePointer): NativePointer
@ExternalSymbolName("org_jetbrains_skia_Font__1nGetTypefaceOrDefault")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Font__1nGetTypefaceOrDefault")
private external fun _nGetTypefaceOrDefault(ptr: NativePointer): NativePointer
@ExternalSymbolName("org_jetbrains_skia_Font__1nGetScaleX") @ExternalSymbolName("org_jetbrains_skia_Font__1nGetScaleX")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Font__1nGetScaleX") @ModuleImport("./skiko.mjs", "org_jetbrains_skia_Font__1nGetScaleX")
private external fun _nGetScaleX(ptr: NativePointer): Float private external fun _nGetScaleX(ptr: NativePointer): Float
......
...@@ -155,6 +155,30 @@ open class FontMgr : RefCnt { ...@@ -155,6 +155,30 @@ open class FontMgr : RefCnt {
reachabilityBarrier(data) reachabilityBarrier(data)
} }
fun makeFromFile(path: String, ttcIndex: Int = 0): Typeface? {
return try {
Stats.onNativeCall()
val ptr = interopScope {
_nMakeFromFile(_ptr, toInterop(path), ttcIndex)
}
if (ptr == NullPointer) null else Typeface(ptr)
} finally {
reachabilityBarrier(this)
}
}
fun legacyMakeTypeface(name: String, style: FontStyle): Typeface? {
return try {
Stats.onNativeCall()
val ptr = interopScope {
_nLegacyMakeTypeface(_ptr, toInterop(name), style._value)
}
if (ptr == NullPointer) null else Typeface(ptr)
} finally {
reachabilityBarrier(this)
}
}
internal constructor(ptr: NativePointer) : super(ptr) internal constructor(ptr: NativePointer) : super(ptr)
internal constructor(ptr: NativePointer, allowClose: Boolean) : super(ptr, allowClose) internal constructor(ptr: NativePointer, allowClose: Boolean) : super(ptr, allowClose)
...@@ -196,6 +220,14 @@ private external fun _nMatchFamilyStyleCharacter( ...@@ -196,6 +220,14 @@ private external fun _nMatchFamilyStyleCharacter(
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_FontMgr__1nMakeFromData") @ModuleImport("./skiko.mjs", "org_jetbrains_skia_FontMgr__1nMakeFromData")
private external fun _nMakeFromData(ptr: NativePointer, dataPtr: NativePointer, ttcIndex: Int): NativePointer private external fun _nMakeFromData(ptr: NativePointer, dataPtr: NativePointer, ttcIndex: Int): NativePointer
@ExternalSymbolName("org_jetbrains_skia_FontMgr__1nMakeFromFile")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_FontMgr__1nMakeFromFile")
private external fun _nMakeFromFile(ptr: NativePointer, pathPtr: InteropPointer, ttcIndex: Int): NativePointer
@ExternalSymbolName("org_jetbrains_skia_FontMgr__1nDefault") @ExternalSymbolName("org_jetbrains_skia_FontMgr__1nDefault")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_FontMgr__1nDefault") @ModuleImport("./skiko.mjs", "org_jetbrains_skia_FontMgr__1nDefault")
private external fun _nDefault(): NativePointer private external fun _nDefault(): NativePointer
@ExternalSymbolName("org_jetbrains_skia_FontMgr__1nLegacyMakeTypeface")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_FontMgr__1nLegacyMakeTypeface")
private external fun _nLegacyMakeTypeface(ptr: NativePointer, familyName: InteropPointer, fontStyle: Int): NativePointer
...@@ -947,12 +947,7 @@ class Surface : RefCnt { ...@@ -947,12 +947,7 @@ class Surface : RefCnt {
* a DirectContext. * a DirectContext.
*/ */
fun flushAndSubmit() { fun flushAndSubmit() {
try { _context?.flushAndSubmit(this)
Stats.onNativeCall()
_nFlushAndSubmit(_ptr, false)
} finally {
reachabilityBarrier(this)
}
} }
/** /**
...@@ -969,21 +964,11 @@ class Surface : RefCnt { ...@@ -969,21 +964,11 @@ class Surface : RefCnt {
* @param syncCpu a flag determining if cpu should be synced * @param syncCpu a flag determining if cpu should be synced
*/ */
fun flushAndSubmit(syncCpu: Boolean) { fun flushAndSubmit(syncCpu: Boolean) {
try { _context?.flushAndSubmit(this, syncCpu)
Stats.onNativeCall()
_nFlushAndSubmit(_ptr, syncCpu)
} finally {
reachabilityBarrier(this)
}
} }
fun flush() { fun flush() {
try { _context?.flush(this)
Stats.onNativeCall()
Surface_nFlush(_ptr)
} finally {
reachabilityBarrier(this)
}
} }
/** /**
...@@ -1037,10 +1022,6 @@ private external fun Surface_nReadPixels(ptr: NativePointer, bitmapPtr: NativePo ...@@ -1037,10 +1022,6 @@ private external fun Surface_nReadPixels(ptr: NativePointer, bitmapPtr: NativePo
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Surface__1nWritePixels") @ModuleImport("./skiko.mjs", "org_jetbrains_skia_Surface__1nWritePixels")
private external fun Surface_nWritePixels(ptr: NativePointer, bitmapPtr: NativePointer, x: Int, y: Int) private external fun Surface_nWritePixels(ptr: NativePointer, bitmapPtr: NativePointer, x: Int, y: Int)
@ExternalSymbolName("org_jetbrains_skia_Surface__1nFlush")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Surface__1nFlush")
private external fun Surface_nFlush(ptr: NativePointer)
@ExternalSymbolName("org_jetbrains_skia_Surface__1nMakeRasterDirect") @ExternalSymbolName("org_jetbrains_skia_Surface__1nMakeRasterDirect")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Surface__1nMakeRasterDirect") @ModuleImport("./skiko.mjs", "org_jetbrains_skia_Surface__1nMakeRasterDirect")
private external fun _nMakeRasterDirect( private external fun _nMakeRasterDirect(
...@@ -1176,10 +1157,6 @@ private external fun _nReadPixelsToPixmap(ptr: NativePointer, pixmapPtr: NativeP ...@@ -1176,10 +1157,6 @@ private external fun _nReadPixelsToPixmap(ptr: NativePointer, pixmapPtr: NativeP
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Surface__1nWritePixelsFromPixmap") @ModuleImport("./skiko.mjs", "org_jetbrains_skia_Surface__1nWritePixelsFromPixmap")
private external fun _nWritePixelsFromPixmap(ptr: NativePointer, pixmapPtr: NativePointer, x: Int, y: Int) private external fun _nWritePixelsFromPixmap(ptr: NativePointer, pixmapPtr: NativePointer, x: Int, y: Int)
@ExternalSymbolName("org_jetbrains_skia_Surface__1nFlushAndSubmit")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Surface__1nFlushAndSubmit")
private external fun _nFlushAndSubmit(ptr: NativePointer, syncCpu: Boolean)
@ExternalSymbolName("org_jetbrains_skia_Surface__1nUnique") @ExternalSymbolName("org_jetbrains_skia_Surface__1nUnique")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Surface__1nUnique") @ModuleImport("./skiko.mjs", "org_jetbrains_skia_Surface__1nUnique")
private external fun _nUnique(ptr: NativePointer): Boolean private external fun _nUnique(ptr: NativePointer): Boolean
...@@ -5,44 +5,13 @@ import org.jetbrains.skia.impl.Library.Companion.staticLoad ...@@ -5,44 +5,13 @@ import org.jetbrains.skia.impl.Library.Companion.staticLoad
class Typeface internal constructor(ptr: NativePointer) : RefCnt(ptr) { class Typeface internal constructor(ptr: NativePointer) : RefCnt(ptr) {
companion object { companion object {
/** init {
* @return the default normal typeface, which is never null staticLoad()
*/
fun makeDefault(): Typeface {
Stats.onNativeCall()
return Typeface(Typeface_nMakeDefault())
} }
/** fun makeEmpty(): Typeface {
* Creates a new reference to the typeface that most closely matches the
* requested name and style. This method allows extended font
* face specifiers as in the [FontStyle] type. Will never return null.
* @param name May be null. The name of the font family
* @param style The style of the typeface
* @return reference to the closest-matching typeface
*/
fun makeFromName(name: String?, style: FontStyle): Typeface {
Stats.onNativeCall() Stats.onNativeCall()
return interopScope { Typeface(_nMakeFromName(toInterop(name), style._value)) } return Typeface(_nMakeEmptyTypeface())
}
/**
* @return a new typeface given a Data
* @throws IllegalArgumentException If the data is null, or is not a valid font file
*/
fun makeFromData(data: Data, index: Int = 0): Typeface {
return try {
Stats.onNativeCall()
val ptr = _nMakeFromData(getPtr(data), index)
require(ptr != NullPointer) { "Failed to create Typeface from data $data" }
Typeface(ptr)
} finally {
reachabilityBarrier(data)
}
}
init {
staticLoad()
} }
} }
...@@ -403,10 +372,6 @@ private external fun Typeface_nGetUniqueId(ptr: NativePointer): Int ...@@ -403,10 +372,6 @@ private external fun Typeface_nGetUniqueId(ptr: NativePointer): Int
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Typeface__1nEquals") @ModuleImport("./skiko.mjs", "org_jetbrains_skia_Typeface__1nEquals")
private external fun Typeface_nEquals(ptr: NativePointer, otherPtr: NativePointer): Boolean private external fun Typeface_nEquals(ptr: NativePointer, otherPtr: NativePointer): Boolean
@ExternalSymbolName("org_jetbrains_skia_Typeface__1nMakeDefault")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Typeface__1nMakeDefault")
private external fun Typeface_nMakeDefault(): NativePointer
@ExternalSymbolName("org_jetbrains_skia_Typeface__1nGetUTF32Glyphs") @ExternalSymbolName("org_jetbrains_skia_Typeface__1nGetUTF32Glyphs")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Typeface__1nGetUTF32Glyphs") @ModuleImport("./skiko.mjs", "org_jetbrains_skia_Typeface__1nGetUTF32Glyphs")
private external fun Typeface_nGetUTF32Glyphs( private external fun Typeface_nGetUTF32Glyphs(
...@@ -448,18 +413,6 @@ private external fun _nGetVariationAxesCount(ptr: NativePointer): Int ...@@ -448,18 +413,6 @@ private external fun _nGetVariationAxesCount(ptr: NativePointer): Int
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Typeface__1nGetVariationAxes") @ModuleImport("./skiko.mjs", "org_jetbrains_skia_Typeface__1nGetVariationAxes")
private external fun _nGetVariationAxes(ptr: NativePointer, axisData: InteropPointer, axisCount: Int) private external fun _nGetVariationAxes(ptr: NativePointer, axisData: InteropPointer, axisCount: Int)
@ExternalSymbolName("org_jetbrains_skia_Typeface__1nMakeFromName")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Typeface__1nMakeFromName")
private external fun _nMakeFromName(name: InteropPointer, fontStyle: Int): NativePointer
@ExternalSymbolName("org_jetbrains_skia_Typeface__1nMakeFromFile")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Typeface__1nMakeFromFile")
internal external fun _nMakeFromFile(path: InteropPointer, index: Int): NativePointer
@ExternalSymbolName("org_jetbrains_skia_Typeface__1nMakeFromData")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Typeface__1nMakeFromData")
private external fun _nMakeFromData(dataPtr: NativePointer, index: Int): NativePointer
@ExternalSymbolName("org_jetbrains_skia_Typeface__1nMakeClone") @ExternalSymbolName("org_jetbrains_skia_Typeface__1nMakeClone")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Typeface__1nMakeClone") @ModuleImport("./skiko.mjs", "org_jetbrains_skia_Typeface__1nMakeClone")
private external fun _nMakeClone( private external fun _nMakeClone(
...@@ -469,6 +422,10 @@ private external fun _nMakeClone( ...@@ -469,6 +422,10 @@ private external fun _nMakeClone(
collectionIndex: Int collectionIndex: Int
): NativePointer ): NativePointer
@ExternalSymbolName("org_jetbrains_skia_Typeface__1nMakeEmptyTypeface")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Typeface__1nMakeEmptyTypeface")
private external fun _nMakeEmptyTypeface(): NativePointer
@ExternalSymbolName("org_jetbrains_skia_Typeface__1nGetGlyphsCount") @ExternalSymbolName("org_jetbrains_skia_Typeface__1nGetGlyphsCount")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Typeface__1nGetGlyphsCount") @ModuleImport("./skiko.mjs", "org_jetbrains_skia_Typeface__1nGetGlyphsCount")
private external fun _nGetGlyphsCount(ptr: NativePointer): Int private external fun _nGetGlyphsCount(ptr: NativePointer): Int
......
...@@ -7,13 +7,20 @@ enum class SVGTag { ...@@ -7,13 +7,20 @@ enum class SVGTag {
ELLIPSE, ELLIPSE,
FE_BLEND, FE_BLEND,
FE_COLOR_MATRIX, FE_COLOR_MATRIX,
FE_COMPONENT_TRANSFER, // kFeComponentTransfer
FE_COMPOSITE, FE_COMPOSITE,
FE_DIFFUSE_LIGHTING, FE_DIFFUSE_LIGHTING,
FE_DISPLACEMENT_MAP, FE_DISPLACEMENT_MAP,
FE_DISTANT_LIGHT, FE_DISTANT_LIGHT,
FE_FLOOD, FE_FLOOD,
FE_FUNC_A, // kFeFuncA
FE_FUNC_R, // kFeFuncR
FE_FUNC_G, // kFeFuncG
FE_FUNC_B, // kFeFuncB
FE_GAUSSIAN_BLUR, FE_GAUSSIAN_BLUR,
FE_IMAGE, FE_IMAGE,
FE_MERGE, // kFeMerge
FE_MERGE_NODE, // kFeMergeNode
FE_MORPHOLOGY, FE_MORPHOLOGY,
FE_OFFSET, FE_OFFSET,
FE_POINT_LIGHT, FE_POINT_LIGHT,
......
...@@ -12,7 +12,7 @@ class FontMgrTest { ...@@ -12,7 +12,7 @@ class FontMgrTest {
@Test @Test
fun fontMgrTest() = runTest { fun fontMgrTest() = runTest {
TypefaceFontProvider().let { fontManager -> TypefaceFontProvider().let { outerFontManager ->
val fontManager = TypefaceFontProvider() val fontManager = TypefaceFontProvider()
val jbMono = Typeface.makeFromResource("./fonts/JetBrainsMono-Regular.ttf") val jbMono = Typeface.makeFromResource("./fonts/JetBrainsMono-Regular.ttf")
...@@ -29,11 +29,15 @@ class FontMgrTest { ...@@ -29,11 +29,15 @@ class FontMgrTest {
assertEquals("Interface", fontManager.getFamilyName(1)) assertEquals("Interface", fontManager.getFamilyName(1))
fontManager.makeStyleSet(0)!!.use { styleSet -> fontManager.makeStyleSet(0)!!.use { styleSet ->
assertEquals(0, styleSet.count()) // assert was changed after update to m126 due to
// https://skia-review.googlesource.com/c/skia/+/834816
assertEquals(2, styleSet.count())
} }
fontManager.makeStyleSet(1)!!.use { styleSet -> fontManager.makeStyleSet(1)!!.use { styleSet ->
assertEquals(0, styleSet.count()) // assert was changed after update to m126 due to
// https://skia-review.googlesource.com/c/skia/+/834816
assertEquals(1, styleSet.count())
} }
fontManager.matchFamily("JetBrains Mono").use { styleSet -> fontManager.matchFamily("JetBrains Mono").use { styleSet ->
...@@ -78,12 +82,12 @@ class FontMgrTest { ...@@ -78,12 +82,12 @@ class FontMgrTest {
assertEquals(jbMono, styleSet.matchStyle(FontStyle.ITALIC)) assertEquals(jbMono, styleSet.matchStyle(FontStyle.ITALIC))
} }
assertNull(fontManager.matchFamilyStyle("JetBrains Mono", FontStyle.BOLD)) assertNull(outerFontManager.matchFamilyStyle("JetBrains Mono", FontStyle.BOLD))
assertNull(fontManager.matchFamilyStyle("Interface", FontStyle.NORMAL)) assertNull(outerFontManager.matchFamilyStyle("Interface", FontStyle.NORMAL))
// TODO: it would be definitely beneficial to check the notNull branch as well // TODO: it would be definitely beneficial to check the notNull branch as well
assertNull( assertNull(
fontManager.matchFamilyStyleCharacter("JetBrains Mono", FontStyle.BOLD, arrayOf("en-US"), 65 /* A */) outerFontManager.matchFamilyStyleCharacter("JetBrains Mono", FontStyle.BOLD, arrayOf("en-US"), 65 /* A */)
) )
} }
......
...@@ -18,7 +18,7 @@ private fun isWindows() = (hostOs == OS.Windows) ...@@ -18,7 +18,7 @@ private fun isWindows() = (hostOs == OS.Windows)
private fun isTvos() = (hostOs == OS.Tvos) private fun isTvos() = (hostOs == OS.Tvos)
private fun isJs() = (kotlinBackend == KotlinBackend.JS) private fun isJs() = (kotlinBackend == KotlinBackend.JS)
private val COARSE_EPSILON = 2.4f private val COARSE_EPSILON = 2.4f
private const val jbMonoPath = "./fonts/JetBrainsMono-Regular.ttf" internal const val jbMonoPath = "./fonts/JetBrainsMono-Regular.ttf"
class FontTests { class FontTests {
@Test @Test
...@@ -133,8 +133,36 @@ class FontTests { ...@@ -133,8 +133,36 @@ class FontTests {
} }
@Test @Test
fun emptyFontMetrics() { fun emptyFontMetricsAreZero() {
// The behaviour was changed in m122.
// https://github.com/google/skia/blob/main/RELEASE_NOTES.md#milestone-122
// There is no default font anymore.
Font(Typeface.makeEmpty()).use { font ->
val metrics = font.metrics
assertTrue(
metrics.top == 0f &&
metrics.bottom == 0f &&
metrics.ascent == 0f &&
metrics.descent == 0f
)
}
Font(null).use { font -> Font(null).use { font ->
val metrics = font.metrics
assertTrue(
metrics.top == 0f &&
metrics.bottom == 0f &&
metrics.ascent == 0f &&
metrics.descent == 0f
)
}
}
@Test
fun nonEmptyFontMetrics() = runTest {
val jbMono = Typeface.makeFromResource(jbMonoPath)
Font(jbMono).use { font ->
val metrics = font.metrics val metrics = font.metrics
assertFalse( assertFalse(
metrics.top == 0f && metrics.top == 0f &&
......
...@@ -6,6 +6,8 @@ import org.jetbrains.skia.shaper.Shaper ...@@ -6,6 +6,8 @@ import org.jetbrains.skia.shaper.Shaper
import org.jetbrains.skia.shaper.ShapingOptions import org.jetbrains.skia.shaper.ShapingOptions
import org.jetbrains.skia.tests.assertContentCloseEnough import org.jetbrains.skia.tests.assertContentCloseEnough
import org.jetbrains.skia.tests.makeFromResource import org.jetbrains.skia.tests.makeFromResource
import org.jetbrains.skiko.tests.SkipJsTarget
import org.jetbrains.skiko.tests.SkipWasmTarget
import org.jetbrains.skiko.tests.runTest import org.jetbrains.skiko.tests.runTest
import kotlin.test.* import kotlin.test.*
...@@ -45,6 +47,9 @@ class ShaperTest { ...@@ -45,6 +47,9 @@ class ShaperTest {
} }
@Test @Test
// TODO: m126 update: on web and windows callCount values are bigger than on other platforms.
// Although the shaper impl seems to be identical
@Ignore
fun canShapeWithRunHandler() = runTest { fun canShapeWithRunHandler() = runTest {
val callCount = object { val callCount = object {
var beginLine = 0 var beginLine = 0
......
...@@ -30,12 +30,12 @@ class SvgTest { ...@@ -30,12 +30,12 @@ class SvgTest {
dom.setContainerSize(101f, 101f) dom.setContainerSize(101f, 101f)
require(dom.root != null) require(dom.root != null)
val e = dom.root!! val e = dom.root!!
require(e.x.unit == SVGLengthUnit.NUMBER) assertEquals(SVGLengthUnit.NUMBER, e.x.unit)
require(e.y.unit == SVGLengthUnit.NUMBER) assertEquals(SVGLengthUnit.NUMBER, e.y.unit)
require(e.width.unit == SVGLengthUnit.NUMBER) assertEquals(SVGLengthUnit.NUMBER, e.width.unit)
require(e.height.unit == SVGLengthUnit.NUMBER) assertEquals(SVGLengthUnit.NUMBER, e.height.unit)
require(e.viewBox == null) assertEquals(null, e.viewBox)
require(e.tag == SVGTag.SVG) assertEquals(SVGTag.SVG, e.tag)
e.viewBox = Rect(0f, 1f, 100f, 200f) e.viewBox = Rect(0f, 1f, 100f, 200f)
assertCloseEnough(Rect(0f, 1f, 100f, 200f), e.viewBox!!) assertCloseEnough(Rect(0f, 1f, 100f, 200f), e.viewBox!!)
val aspectRatio = val aspectRatio =
......
...@@ -60,9 +60,17 @@ class FontCollectionTest { ...@@ -60,9 +60,17 @@ class FontCollectionTest {
} }
//TODO: commented out assertions seem not to be isolated and are turned off till further investigation //TODO: commented out assertions seem not to be isolated and are turned off till further investigation
assertContentEquals(arrayOf(), fontCollection.findTypefaces(arrayOf("No Such Font"), FontStyle.NORMAL))
// Note: thanks to https://skia-review.googlesource.com/c/skia/+/834816 there is a fallback,
// therefore the result is non-empty array (it used to be empty)
assertContentEquals(arrayOf(jbMono), fontCollection.findTypefaces(arrayOf("No Such Font"), FontStyle.NORMAL))
assertContentEquals(arrayOf(jbMono), fontCollection.findTypefaces(arrayOf("JetBrains Mono"), FontStyle.NORMAL)) assertContentEquals(arrayOf(jbMono), fontCollection.findTypefaces(arrayOf("JetBrains Mono"), FontStyle.NORMAL))
assertContentEquals(arrayOf(), fontCollection.findTypefaces(arrayOf("Inter"), FontStyle.NORMAL))
// Note: thanks to https://skia-review.googlesource.com/c/skia/+/834816 there is a fallback,
// therefore the result is non-empty array (it used to be empty)
assertContentEquals(arrayOf(jbMono), fontCollection.findTypefaces(arrayOf("Inter"), FontStyle.NORMAL))
assertContentEquals(arrayOf(inter), fontCollection.findTypefaces(arrayOf("Interface"), FontStyle.NORMAL)) assertContentEquals(arrayOf(inter), fontCollection.findTypefaces(arrayOf("Interface"), FontStyle.NORMAL))
assertContentEquals( assertContentEquals(
arrayOf(jbMono, inter), arrayOf(jbMono, inter),
......
...@@ -13,7 +13,9 @@ class TypefaceTest { ...@@ -13,7 +13,9 @@ class TypefaceTest {
val inter = Typeface.makeFromResource("./fonts/Inter-Hinted-Regular.ttf") val inter = Typeface.makeFromResource("./fonts/Inter-Hinted-Regular.ttf")
val interV = Typeface.makeFromResource("./fonts/Inter-V.ttf") val interV = Typeface.makeFromResource("./fonts/Inter-V.ttf")
val jbMono = Typeface.makeFromResource("./fonts/JetBrainsMono-Regular.ttf") val jbMono = Typeface.makeFromResource("./fonts/JetBrainsMono-Regular.ttf")
val jbMonoBold = Typeface.makeFromData(Data.makeFromResource("./fonts/JetBrainsMono-Bold.ttf")) val jbMonoBold = FontMgr.default.makeFromData(
Data.makeFromResource("./fonts/JetBrainsMono-Bold.ttf")
)!!
assertEquals(FontStyle.NORMAL, inter.fontStyle) assertEquals(FontStyle.NORMAL, inter.fontStyle)
assertFalse(inter.isBold) assertFalse(inter.isBold)
...@@ -27,7 +29,6 @@ class TypefaceTest { ...@@ -27,7 +29,6 @@ class TypefaceTest {
assertNotEquals(inter.uniqueId, interV.uniqueId) assertNotEquals(inter.uniqueId, interV.uniqueId)
assertNotEquals(inter, interV) assertNotEquals(inter, interV)
assertNotNull(Typeface.makeDefault())
assertEquals(394, inter.getUTF32Glyph(83)) assertEquals(394, inter.getUTF32Glyph(83))
assertEquals(2548, interV.glyphsCount) assertEquals(2548, interV.glyphsCount)
......
package org.jetbrains.skiko.paragraph package org.jetbrains.skiko.paragraph
import org.jetbrains.skia.Color import org.jetbrains.skia.*
import org.jetbrains.skia.FontFeature
import org.jetbrains.skia.impl.use import org.jetbrains.skia.impl.use
import org.jetbrains.skia.jbMonoPath
import org.jetbrains.skia.paragraph.DecorationLineStyle import org.jetbrains.skia.paragraph.DecorationLineStyle
import org.jetbrains.skia.paragraph.DecorationStyle import org.jetbrains.skia.paragraph.DecorationStyle
import org.jetbrains.skia.paragraph.Shadow import org.jetbrains.skia.paragraph.Shadow
import org.jetbrains.skia.paragraph.TextStyle import org.jetbrains.skia.paragraph.TextStyle
import org.jetbrains.skia.paragraph.TextStyleAttribute import org.jetbrains.skia.paragraph.TextStyleAttribute
import org.jetbrains.skia.tests.assertContentCloseEnough import org.jetbrains.skia.tests.assertContentCloseEnough
import org.jetbrains.skia.tests.makeFromResource
import org.jetbrains.skiko.KotlinBackend import org.jetbrains.skiko.KotlinBackend
import org.jetbrains.skiko.kotlinBackend import org.jetbrains.skiko.kotlinBackend
import org.jetbrains.skiko.tests.runTest
import kotlin.test.* import kotlin.test.*
class TextStyleTest { class TextStyleTest {
...@@ -142,16 +144,20 @@ class TextStyleTest { ...@@ -142,16 +144,20 @@ class TextStyleTest {
} }
@Test @Test
fun textStyleMetricsContainsMeaningfulValues() { fun textStyleMetricsContainsMeaningfulValues() = runTest {
val jbMono = Typeface.makeFromResource(jbMonoPath)
TextStyle().use { textStyle -> TextStyle().use { textStyle ->
textStyle.typeface = jbMono
val metrics = textStyle.fontMetrics val metrics = textStyle.fontMetrics
assertFalse(metrics.ascent == 0f && metrics.descent == 0f && metrics.leading == 0f) assertFalse(metrics.ascent == 0f && metrics.descent == 0f && metrics.leading == 0f)
} }
} }
@Test @Test
fun textStyleNotContainNaNValues() { fun textStyleNotContainNaNValues() = runTest {
val jbMono = Typeface.makeFromResource(jbMonoPath)
TextStyle().use { textStyle -> TextStyle().use { textStyle ->
textStyle.typeface = jbMono
textStyle.height = 32f textStyle.height = 32f
assertTrue(!textStyle.fontMetrics.ascent.isNaN()) assertTrue(!textStyle.fontMetrics.ascent.isNaN())
} }
......
package org.jetbrains.skia.tests package org.jetbrains.skia.tests
import org.jetbrains.skia.Data import org.jetbrains.skia.Data
import org.jetbrains.skia.FontMgr
import org.jetbrains.skia.Typeface import org.jetbrains.skia.Typeface
import org.jetbrains.skiko.loadResourceAsBytes import org.jetbrains.skiko.loadResourceAsBytes
actual suspend inline fun Typeface.Companion.makeFromResource(resourceId: String, index: Int): Typeface = actual suspend inline fun Typeface.Companion.makeFromResource(resourceId: String, index: Int): Typeface =
makeFromData(Data.makeFromResource(resourceId), index) FontMgr.default.makeFromData(Data.makeFromResource(resourceId), index)
?: error("Failed to makeFromFile with resourceId = $resourceId")
actual suspend inline fun Data.Companion.makeFromResource(resourceId: String) = actual suspend inline fun Data.Companion.makeFromResource(resourceId: String) =
makeFromBytes(loadResourceAsBytes(resourceId)) makeFromBytes(loadResourceAsBytes(resourceId))
#include <iostream> #include <iostream>
#include <jni.h> #include <jni.h>
#include <ganesh/gl/GrGLBackendSurface.h>
#include "GrBackendSurface.h" #include "GrBackendSurface.h"
#ifdef SK_METAL
#include "ganesh/mtl/GrMtlBackendSurface.h"
#include "ganesh/mtl/GrMtlTypes.h"
#endif
static void deleteBackendRenderTarget(GrBackendRenderTarget* rt) { static void deleteBackendRenderTarget(GrBackendRenderTarget* rt) {
// std::cout << "Deleting [GrBackendRenderTarget " << rt << "]" << std::endl; // std::cout << "Deleting [GrBackendRenderTarget " << rt << "]" << std::endl;
...@@ -15,7 +20,8 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_BackendRenderTargetKt ...@@ -15,7 +20,8 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_BackendRenderTargetKt
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_BackendRenderTargetKt__1nMakeGL extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_BackendRenderTargetKt__1nMakeGL
(JNIEnv* env, jclass jclass, jint width, jint height, jint sampleCnt, jint stencilBits, jint fbId, jint fbFormat) { (JNIEnv* env, jclass jclass, jint width, jint height, jint sampleCnt, jint stencilBits, jint fbId, jint fbFormat) {
GrGLFramebufferInfo glInfo = { static_cast<unsigned int>(fbId), static_cast<unsigned int>(fbFormat) }; GrGLFramebufferInfo glInfo = { static_cast<unsigned int>(fbId), static_cast<unsigned int>(fbFormat) };
GrBackendRenderTarget* instance = new GrBackendRenderTarget(width, height, sampleCnt, stencilBits, glInfo); GrBackendRenderTarget obj = GrBackendRenderTargets::MakeGL(width, height, sampleCnt, stencilBits, glInfo);
GrBackendRenderTarget* instance = new GrBackendRenderTarget(obj);
return reinterpret_cast<jlong>(instance); return reinterpret_cast<jlong>(instance);
} }
...@@ -25,7 +31,8 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_BackendRenderTargetKt ...@@ -25,7 +31,8 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_BackendRenderTargetKt
GrMTLHandle texture = reinterpret_cast<GrMTLHandle>(static_cast<uintptr_t>(texturePtr)); GrMTLHandle texture = reinterpret_cast<GrMTLHandle>(static_cast<uintptr_t>(texturePtr));
GrMtlTextureInfo fbInfo; GrMtlTextureInfo fbInfo;
fbInfo.fTexture.retain(texture); fbInfo.fTexture.retain(texture);
GrBackendRenderTarget* instance = new GrBackendRenderTarget(width, height, fbInfo); GrBackendRenderTarget obj = GrBackendRenderTargets::MakeMtl(width, height, fbInfo);
GrBackendRenderTarget* instance = new GrBackendRenderTarget(obj);
return reinterpret_cast<jlong>(instance); return reinterpret_cast<jlong>(instance);
} }
#endif #endif
......
#include <iostream> #include <iostream>
#include <jni.h> #include <jni.h>
#include "GrDirectContext.h" #include "GrDirectContext.h"
#include "ganesh/gl/GrGLDirectContext.h"
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_DirectContextKt__1nMakeGL extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_DirectContextKt__1nMakeGL
(JNIEnv* env, jclass jclass) { (JNIEnv* env, jclass jclass) {
return reinterpret_cast<jlong>(GrDirectContext::MakeGL().release()); return reinterpret_cast<jlong>(GrDirectContexts::MakeGL().release());
} }
#ifdef SK_METAL #ifdef SK_METAL
#include "mtl/GrMtlBackendContext.h" #include "ganesh/mtl/GrMtlBackendContext.h"
#include "ganesh/mtl/GrMtlDirectContext.h"
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_DirectContextKt__1nMakeMetal extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_DirectContextKt__1nMakeMetal
(JNIEnv* env, jclass jclass, long devicePtr, long queuePtr) { (JNIEnv* env, jclass jclass, long devicePtr, long queuePtr) {
...@@ -17,7 +19,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_DirectContextKt__1nMa ...@@ -17,7 +19,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_DirectContextKt__1nMa
GrMTLHandle queue = reinterpret_cast<GrMTLHandle>(static_cast<uintptr_t>(queuePtr)); GrMTLHandle queue = reinterpret_cast<GrMTLHandle>(static_cast<uintptr_t>(queuePtr));
backendContext.fDevice.retain(device); backendContext.fDevice.retain(device);
backendContext.fQueue.retain(queue); backendContext.fQueue.retain(queue);
sk_sp<GrDirectContext> instance = GrDirectContext::MakeMetal(backendContext); sk_sp<GrDirectContext> instance = GrDirectContexts::MakeMetal(backendContext);
return reinterpret_cast<jlong>(instance.release()); return reinterpret_cast<jlong>(instance.release());
} }
#endif #endif
...@@ -39,16 +41,35 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_DirectContextKt__1nMa ...@@ -39,16 +41,35 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_DirectContextKt__1nMa
} }
#endif //SK_DIRECT3D #endif //SK_DIRECT3D
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_DirectContextKt_DirectContext_1nFlush extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_DirectContextKt_DirectContext_1nFlushDefault
(JNIEnv* env, jclass jclass, jlong ptr) { (JNIEnv* env, jclass jclass, jlong ptr) {
GrDirectContext* context = reinterpret_cast<GrDirectContext*>(static_cast<uintptr_t>(ptr));
context->flush();
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_DirectContextKt_DirectContext_1nFlush
(JNIEnv* env, jclass jclass, jlong ptr, jlong skSurfacePtr) {
GrDirectContext* context = reinterpret_cast<GrDirectContext*>(static_cast<uintptr_t>(ptr)); GrDirectContext* context = reinterpret_cast<GrDirectContext*>(static_cast<uintptr_t>(ptr));
context->flush(GrFlushInfo()); SkSurface* skSurface = reinterpret_cast<SkSurface*>(static_cast<uintptr_t>(skSurfacePtr));
context->flush(skSurface);
}
GrSyncCpu grSyncCpuFromBool(bool syncCpu) {
if (syncCpu) return GrSyncCpu::kYes;
return GrSyncCpu::kNo;
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_DirectContextKt__1nFlushAndSubmit
(JNIEnv* env, jclass jclass, jlong ptr, jlong skSurfacePtr, jboolean syncCpu) {
GrDirectContext* context = reinterpret_cast<GrDirectContext*>(static_cast<uintptr_t>(ptr));
SkSurface* skSurface = reinterpret_cast<SkSurface*>(static_cast<uintptr_t>(skSurfacePtr));
context->flushAndSubmit(skSurface, grSyncCpuFromBool(syncCpu));
} }
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_DirectContextKt__1nSubmit extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_DirectContextKt__1nSubmit
(JNIEnv* env, jclass jclass, jlong ptr, jboolean syncCpu) { (JNIEnv* env, jclass jclass, jlong ptr, jboolean syncCpu) {
GrDirectContext* context = reinterpret_cast<GrDirectContext*>(static_cast<uintptr_t>(ptr)); GrDirectContext* context = reinterpret_cast<GrDirectContext*>(static_cast<uintptr_t>(ptr));
context->submit(syncCpu); context->submit(grSyncCpuFromBool(syncCpu));
} }
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_DirectContextKt__1nReset extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_DirectContextKt__1nReset
......
...@@ -158,13 +158,6 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_FontKt__1nGetTypeface ...@@ -158,13 +158,6 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_FontKt__1nGetTypeface
return reinterpret_cast<jlong>(typeface); return reinterpret_cast<jlong>(typeface);
} }
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_FontKt__1nGetTypefaceOrDefault
(JNIEnv* env, jclass jclass, jlong ptr) {
SkFont* instance = reinterpret_cast<SkFont*>(static_cast<uintptr_t>(ptr));
SkTypeface* typeface = instance->refTypefaceOrDefault().release();
return reinterpret_cast<jlong>(typeface);
}
extern "C" JNIEXPORT jfloat JNICALL Java_org_jetbrains_skia_FontKt_Font_1nGetSize extern "C" JNIEXPORT jfloat JNICALL Java_org_jetbrains_skia_FontKt_Font_1nGetSize
(JNIEnv* env, jclass jclass, jlong ptr) { (JNIEnv* env, jclass jclass, jlong ptr) {
SkFont* instance = reinterpret_cast<SkFont*>(static_cast<uintptr_t>(ptr)); SkFont* instance = reinterpret_cast<SkFont*>(static_cast<uintptr_t>(ptr));
......
#include "FontMgrDefaultFactory.hh"
#include <iostream> #include <iostream>
#include <jni.h> #include <jni.h>
#include "interop.hh" #include "interop.hh"
...@@ -67,9 +68,27 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_FontMgrKt__1nMakeFrom ...@@ -67,9 +68,27 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_FontMgrKt__1nMakeFrom
return reinterpret_cast<jlong>(typeface); return reinterpret_cast<jlong>(typeface);
} }
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_FontMgrKt__1nMakeFromFile
(JNIEnv* env, jclass jclass, jlong ptr, jstring pathStrPtr, jint ttcIndex) {
SkFontMgr* instance = reinterpret_cast<SkFontMgr*>(static_cast<uintptr_t>(ptr));
SkString path = skString(env, pathStrPtr);
SkTypeface* typeface = instance->makeFromFile(path.c_str(), ttcIndex).release();
return reinterpret_cast<jlong>(typeface);
}
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_FontMgrKt__1nLegacyMakeTypeface
(JNIEnv* env, jclass jclass, jlong ptr, jstring familyNameStr, jint fontStyle) {
SkFontMgr* instance = reinterpret_cast<SkFontMgr*>(static_cast<uintptr_t>(ptr));
SkString name = skString(env, familyNameStr);
SkTypeface* typeface = instance->legacyMakeTypeface(name.c_str(), skija::FontStyle::fromJava(fontStyle)).release();
return reinterpret_cast<jlong>(typeface);
}
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_FontMgrKt__1nDefault extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_FontMgrKt__1nDefault
(JNIEnv* env, jclass jclass) { (JNIEnv* env, jclass jclass) {
SkFontMgr* instance = SkFontMgr::RefDefault().release(); SkFontMgr* instance = SkFontMgrSkikoDefault().release();
return reinterpret_cast<jlong>(instance); return reinterpret_cast<jlong>(instance);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <jni.h> #include <jni.h>
#include "interop.hh" #include "interop.hh"
#include "SkDrawable.h" #include "SkDrawable.h"
#include "SkPicture.h"
#include "SkPictureRecorder.h" #include "SkPictureRecorder.h"
static void deletePictureRecorder(SkPictureRecorder* pr) { static void deletePictureRecorder(SkPictureRecorder* pr) {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#ifdef SK_METAL #ifdef SK_METAL
#include "include/gpu/ganesh/mtl/SkSurfaceMetal.h" #include "include/gpu/ganesh/mtl/SkSurfaceMetal.h"
#include "include/gpu/mtl/GrMtlTypes.h" #include "include/gpu/ganesh/mtl/GrMtlTypes.h"
#endif #endif
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRasterDirect extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRasterDirect
...@@ -212,18 +212,6 @@ extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_SurfaceKt_Surface_1nWr ...@@ -212,18 +212,6 @@ extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_SurfaceKt_Surface_1nWr
surface->writePixels(*bitmap, x, y); surface->writePixels(*bitmap, x, y);
} }
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_SurfaceKt__1nFlushAndSubmit
(JNIEnv* env, jclass jclass, jlong ptr, jboolean syncCpu) {
SkSurface* surface = reinterpret_cast<SkSurface*>(static_cast<uintptr_t>(ptr));
surface->flushAndSubmit(syncCpu);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_SurfaceKt_Surface_1nFlush
(JNIEnv* env, jclass jclass, jlong ptr) {
SkSurface* surface = reinterpret_cast<SkSurface*>(static_cast<uintptr_t>(ptr));
surface->flush();
}
extern "C" JNIEXPORT jboolean JNICALL Java_org_jetbrains_skia_SurfaceKt__1nUnique extern "C" JNIEXPORT jboolean JNICALL Java_org_jetbrains_skia_SurfaceKt__1nUnique
(JNIEnv* env, jclass jclass, jlong ptr) { (JNIEnv* env, jclass jclass, jlong ptr) {
SkSurface* surface = reinterpret_cast<SkSurface*>(static_cast<uintptr_t>(ptr)); SkSurface* surface = reinterpret_cast<SkSurface*>(static_cast<uintptr_t>(ptr));
......
...@@ -68,35 +68,6 @@ extern "C" JNIEXPORT jint JNICALL Java_org_jetbrains_skia_TypefaceKt_Typeface_1n ...@@ -68,35 +68,6 @@ extern "C" JNIEXPORT jint JNICALL Java_org_jetbrains_skia_TypefaceKt_Typeface_1n
return SkTypeface::Equal(instance, other); return SkTypeface::Equal(instance, other);
} }
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_TypefaceKt_Typeface_1nMakeDefault
(JNIEnv* env, jclass jclass) {
return reinterpret_cast<jlong>(SkTypeface::MakeDefault().release());
}
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_TypefaceKt__1nMakeFromName
(JNIEnv* env, jclass jclass, jstring nameStr, jint styleValue) {
SkString name = skString(env, nameStr);
SkFontStyle style = skija::FontStyle::fromJava(styleValue);
sk_sp<SkTypeface> instance = SkTypeface::MakeFromName(name.c_str(), style);
return reinterpret_cast<jlong>(instance.release());
}
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_TypefaceKt__1nMakeFromFile
(JNIEnv* env, jclass jclass, jstring pathStr, jint index) {
SkString path = skString(env, pathStr);
sk_sp<SkTypeface> instance = SkTypeface::MakeFromFile(path.c_str(), index);
SkTypeface* ptr = instance.release();
return reinterpret_cast<jlong>(ptr);
}
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_TypefaceKt__1nMakeFromData
(JNIEnv* env, jclass jclass, jlong dataPtr, jint index) {
SkData* data = reinterpret_cast<SkData*>(static_cast<uintptr_t>(dataPtr));
sk_sp<SkTypeface> instance = SkTypeface::MakeFromData(sk_ref_sp(data), index);
SkTypeface* ptr = instance.release();
return reinterpret_cast<jlong>(ptr);
}
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_TypefaceKt__1nMakeClone extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_TypefaceKt__1nMakeClone
(JNIEnv* env, jclass jclass, jlong typefacePtr, jintArray variationsArr, jint variationsCount, jint collectionIndex) { (JNIEnv* env, jclass jclass, jlong typefacePtr, jintArray variationsArr, jint variationsCount, jint collectionIndex) {
SkTypeface* typeface = reinterpret_cast<SkTypeface*>(static_cast<uintptr_t>(typefacePtr)); SkTypeface* typeface = reinterpret_cast<SkTypeface*>(static_cast<uintptr_t>(typefacePtr));
...@@ -227,4 +198,11 @@ extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_TypefaceKt_Typeface_1n ...@@ -227,4 +198,11 @@ extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_TypefaceKt_Typeface_1n
SkRect b = instance->getBounds(); SkRect b = instance->getBounds();
float r[4] = {b.left(), b.top(), b.right(), b.bottom()}; float r[4] = {b.left(), b.top(), b.right(), b.bottom()};
env->SetFloatArrayRegion(res, 0, 4, r); env->SetFloatArrayRegion(res, 0, 4, r);
}
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_TypefaceKt__1nMakeEmptyTypeface
(JNIEnv* env, jclass jclass) {
SkTypeface* res = SkTypeface::MakeEmpty().release();
return reinterpret_cast<jlong>(res);
} }
\ No newline at end of file
#include <jni.h> #include <jni.h>
#include "ganesh/gl/GrGLDirectContext.h" // TODO: skia update: check if it's correct
#include "ganesh/gl/GrGLBackendSurface.h" // TODO: skia update: check if it's correct
#if SK_BUILD_FOR_LINUX #if SK_BUILD_FOR_LINUX
#include <stdint.h> #include <stdint.h>
...@@ -8,6 +10,12 @@ ...@@ -8,6 +10,12 @@
#include "GrBackendSurface.h" #include "GrBackendSurface.h"
#include "GrDirectContext.h" #include "GrDirectContext.h"
#ifdef SK_METAL
#include "ganesh/mtl/GrMtlDirectContext.h"
#include "ganesh/mtl/GrMtlBackendSurface.h"
#include "ganesh/mtl/GrMtlBackendContext.h"
#endif
extern "C" { extern "C" {
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_RenderTargetsKt_makeGLRenderTargetNative( JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_RenderTargetsKt_makeGLRenderTargetNative(
...@@ -17,12 +25,13 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_RenderTargetsKt_makeGLRenderTar ...@@ -17,12 +25,13 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_RenderTargetsKt_makeGLRenderTar
jint fbId, jint fbFormat jint fbId, jint fbFormat
) { ) {
GrGLFramebufferInfo glInfo = { static_cast<unsigned int>(fbId), static_cast<unsigned int>(fbFormat) }; GrGLFramebufferInfo glInfo = { static_cast<unsigned int>(fbId), static_cast<unsigned int>(fbFormat) };
GrBackendRenderTarget* obj = new GrBackendRenderTarget(width, height, sampleCnt, stencilBits, glInfo); GrBackendRenderTarget obj = GrBackendRenderTargets::MakeGL(width, height, sampleCnt, stencilBits, glInfo);
return reinterpret_cast<jlong>(obj); GrBackendRenderTarget* target = new GrBackendRenderTarget(obj);
return reinterpret_cast<jlong>(target);
} }
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_RenderTargetsKt_makeGLContextNative(JNIEnv* env, jclass jclass) { JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_RenderTargetsKt_makeGLContextNative(JNIEnv* env, jclass jclass) {
return reinterpret_cast<jlong>(GrDirectContext::MakeGL().release()); return reinterpret_cast<jlong>(GrDirectContexts::MakeGL().release());
} }
extern void getMetalDeviceAndQueue(void** device, void** queue); extern void getMetalDeviceAndQueue(void** device, void** queue);
...@@ -32,8 +41,9 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_RenderTargetsKt_makeMetalRender ...@@ -32,8 +41,9 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_RenderTargetsKt_makeMetalRender
#ifdef SK_METAL #ifdef SK_METAL
// TODO: create properly. // TODO: create properly.
GrMtlTextureInfo mtlInfo; GrMtlTextureInfo mtlInfo;
GrBackendRenderTarget* obj = new GrBackendRenderTarget(width, height, sampleCnt, mtlInfo); GrBackendRenderTarget obj = GrBackendRenderTargets::MakeMtl(width, height, mtlInfo);
return reinterpret_cast<jlong>(obj); GrBackendRenderTarget* instance = new GrBackendRenderTarget(obj);
return reinterpret_cast<jlong>(instance);
#else #else
return 0; return 0;
#endif #endif
...@@ -44,7 +54,13 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_RenderTargetsKt_makeMetalContex ...@@ -44,7 +54,13 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_RenderTargetsKt_makeMetalContex
void* device = nullptr; void* device = nullptr;
void* queue = nullptr; void* queue = nullptr;
getMetalDeviceAndQueue(&device, &queue); getMetalDeviceAndQueue(&device, &queue);
return reinterpret_cast<jlong>(GrDirectContext::MakeMetal(device, queue).release());
GrMtlBackendContext backendContext = {};
GrMTLHandle deviceHandle = reinterpret_cast<GrMTLHandle>(device);
GrMTLHandle queueHandle = reinterpret_cast<GrMTLHandle>(queue);
backendContext.fDevice.retain(deviceHandle);
backendContext.fQueue.retain(queueHandle);
return reinterpret_cast<jlong>(GrDirectContexts::MakeMetal(backendContext).release());
#else #else
return 0; return 0;
#endif #endif
......
#include "FontMgrDefaultFactory.hh"
#include <jni.h> #include <jni.h>
#include "../interop.hh" #include "../interop.hh"
#include "interop.hh" #include "interop.hh"
...@@ -10,7 +11,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_shaper_FontMgrRunIter ...@@ -10,7 +11,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_shaper_FontMgrRunIter
SkString* text = reinterpret_cast<SkString*>(static_cast<uintptr_t>(textPtr)); SkString* text = reinterpret_cast<SkString*>(static_cast<uintptr_t>(textPtr));
SkFont* font = reinterpret_cast<SkFont*>(static_cast<uintptr_t>(fontPtr)); SkFont* font = reinterpret_cast<SkFont*>(static_cast<uintptr_t>(fontPtr));
sk_sp<SkFontMgr> fontMgr = fontMgrPtr == nullptr sk_sp<SkFontMgr> fontMgr = fontMgrPtr == nullptr
? SkFontMgr::RefDefault() ? SkFontMgrSkikoDefault()
: sk_ref_sp(reinterpret_cast<SkFontMgr*>(skija::impl::Native::fromJava(env, fontMgrPtr, skija::FontMgr::cls))); : sk_ref_sp(reinterpret_cast<SkFontMgr*>(skija::impl::Native::fromJava(env, fontMgrPtr, skija::FontMgr::cls)));
std::shared_ptr<UBreakIterator> graphemeIter = skija::shaper::graphemeBreakIterator(*text); std::shared_ptr<UBreakIterator> graphemeIter = skija::shaper::graphemeBreakIterator(*text);
if (!graphemeIter) return 0; if (!graphemeIter) return 0;
......
#include "FontMgrDefaultFactory.hh"
#include <iostream> #include <iostream>
#include <jni.h> #include <jni.h>
#include "../interop.hh" #include "../interop.hh"
#include "interop.hh" #include "interop.hh"
#include "FontRunIterator.hh" #include "FontRunIterator.hh"
#include "SkShaper.h" #include "SkShaper.h"
#include "SkShaper_harfbuzz.h"
#include "SkUnicode.h" #include "SkUnicode.h"
#include "src/base/SkUTF.h" #include "src/base/SkUTF.h"
#include "TextLineRunHandler.hh" #include "TextLineRunHandler.hh"
#include "unicode/ubidi.h" #include "unicode/ubidi.h"
#include "SkUnicode_icu.h"
#ifdef SK_SHAPER_CORETEXT_AVAILABLE
#include "SkShaper_coretext.h"
#endif
static void deleteShaper(SkShaper* instance) { static void deleteShaper(SkShaper* instance) {
// std::cout << "Deleting [SkShaper " << instance << "]" << std::endl; // std::cout << "Deleting [SkShaper " << instance << "]" << std::endl;
...@@ -20,7 +27,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_shaper_ShaperKt_Shape ...@@ -20,7 +27,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_shaper_ShaperKt_Shape
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_shaper_ShaperKt__1nMakePrimitive extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_shaper_ShaperKt__1nMakePrimitive
(JNIEnv* env, jclass jclass) { (JNIEnv* env, jclass jclass) {
return reinterpret_cast<jlong>(SkShaper::MakePrimitive().release()); return reinterpret_cast<jlong>(SkShapers::Primitive::PrimitiveText().release());
} }
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_shaper_ShaperKt__1nMakeShaperDrivenWrapper extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_shaper_ShaperKt__1nMakeShaperDrivenWrapper
...@@ -38,13 +45,15 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_shaper_ShaperKt__1nMa ...@@ -38,13 +45,15 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_shaper_ShaperKt__1nMa
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_shaper_ShaperKt__1nMakeShapeDontWrapOrReorder extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_shaper_ShaperKt__1nMakeShapeDontWrapOrReorder
(JNIEnv* env, jclass jclass, jlong fontMgrPtr) { (JNIEnv* env, jclass jclass, jlong fontMgrPtr) {
SkFontMgr* fontMgr = reinterpret_cast<SkFontMgr*>(static_cast<uintptr_t>(fontMgrPtr)); SkFontMgr* fontMgr = reinterpret_cast<SkFontMgr*>(static_cast<uintptr_t>(fontMgrPtr));
return reinterpret_cast<jlong>(SkShaper::MakeShapeDontWrapOrReorder(SkUnicode::Make(), sk_ref_sp(fontMgr)).release()); // TODO: consider if we need/want to use ICU4X or Libgrapheme (skuincode/include has those implementations too)
sk_sp<SkUnicode> unicode = SkUnicodes::ICU::Make();
return reinterpret_cast<jlong>(SkShapers::HB::ShapeDontWrapOrReorder(unicode, sk_ref_sp(fontMgr)).release());
} }
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_shaper_ShaperKt__1nMakeCoreText extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_shaper_ShaperKt__1nMakeCoreText
(JNIEnv* env, jclass jclass) { (JNIEnv* env, jclass jclass) {
#ifdef SK_SHAPER_CORETEXT_AVAILABLE #ifdef SK_SHAPER_CORETEXT_AVAILABLE
return reinterpret_cast<jlong>(SkShaper::MakeCoreText().release()); return reinterpret_cast<jlong>(SkShapers::CT::CoreText().release());
#else #else
return 0; return 0;
#endif #endif
...@@ -84,7 +93,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_shaper_ShaperKt__1nSh ...@@ -84,7 +93,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_shaper_ShaperKt__1nSh
text.c_str(), text.c_str(),
text.size(), text.size(),
*font, *font,
SkFontMgr::RefDefault(), SkFontMgrSkikoDefault(),
graphemeIter, graphemeIter,
aproximateSpaces, aproximateSpaces,
aproximatePunctuation aproximatePunctuation
...@@ -131,7 +140,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_shaper_ShaperKt__1nSh ...@@ -131,7 +140,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_shaper_ShaperKt__1nSh
text.c_str(), text.c_str(),
text.size(), text.size(),
*font, *font,
SkFontMgr::RefDefault(), SkFontMgrSkikoDefault(),
graphemeIter, graphemeIter,
aproximateSpaces, aproximateSpaces,
aproximatePunctuation); aproximatePunctuation);
......
package org.jetbrains.skia
import org.jetbrains.skia.impl.Native
import org.jetbrains.skia.impl.Stats
import org.jetbrains.skia.impl.interopScope
/**
* @return a new typeface given a file
* @throws IllegalArgumentException If the file does not exist, or is not a valid font file
*/
fun Typeface.Companion.makeFromFile(path: String, index: Int = 0): Typeface {
Stats.onNativeCall()
interopScope {
val ptr = _nMakeFromFile(toInterop(path), index)
require(ptr != Native.NullPointer) { "Failed to create Typeface from path=\"$path\" index=$index" }
return Typeface(ptr)
}
}
\ No newline at end of file
package org.jetbrains.skia.tests package org.jetbrains.skia.tests
import org.jetbrains.skia.Data import org.jetbrains.skia.*
import org.jetbrains.skia.Typeface
import org.jetbrains.skia.makeFromFile
import org.jetbrains.skia.makeFromFileName
import org.jetbrains.skiko.resourcePath import org.jetbrains.skiko.resourcePath
actual suspend fun Typeface.Companion.makeFromResource(resourceId: String, index: Int): Typeface = actual suspend fun Typeface.Companion.makeFromResource(resourceId: String, index: Int): Typeface =
makeFromFile(resourcePath(resourceId), index) FontMgr.default.makeFromFile(resourcePath(resourceId), index)
?: error("Failed to make from file with resourceId = $resourceId")
actual suspend fun Data.Companion.makeFromResource(resourceId: String) = actual suspend fun Data.Companion.makeFromResource(resourceId: String) =
makeFromFileName(resourcePath(resourceId)) makeFromFileName(resourcePath(resourceId))
...@@ -2,6 +2,12 @@ ...@@ -2,6 +2,12 @@
#include <stdint.h> #include <stdint.h>
#include "GrBackendSurface.h" #include "GrBackendSurface.h"
#include "common.h" #include "common.h"
#include "ganesh/gl/GrGLDirectContext.h"
#include "ganesh/gl/GrGLBackendSurface.h"
#ifdef SK_METAL
#include "ganesh/mtl/GrMtlBackendSurface.h"
#include "ganesh/mtl/GrMtlTypes.h"
#endif
static void deleteBackendRenderTarget(GrBackendRenderTarget* rt) { static void deleteBackendRenderTarget(GrBackendRenderTarget* rt) {
delete rt; delete rt;
...@@ -13,7 +19,8 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_BackendRenderTarget__1nGetFinaliz ...@@ -13,7 +19,8 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_BackendRenderTarget__1nGetFinaliz
SKIKO_EXPORT KNativePointer org_jetbrains_skia_BackendRenderTarget__1nMakeGL SKIKO_EXPORT KNativePointer org_jetbrains_skia_BackendRenderTarget__1nMakeGL
(KInt width, KInt height, KInt sampleCnt, KInt stencilBits, KInt fbId, KInt fbFormat) { (KInt width, KInt height, KInt sampleCnt, KInt stencilBits, KInt fbId, KInt fbFormat) {
GrGLFramebufferInfo glInfo = { static_cast<unsigned int>(fbId), static_cast<unsigned int>(fbFormat) }; GrGLFramebufferInfo glInfo = { static_cast<unsigned int>(fbId), static_cast<unsigned int>(fbFormat) };
GrBackendRenderTarget* instance = new GrBackendRenderTarget(width, height, sampleCnt, stencilBits, glInfo); GrBackendRenderTarget obj = GrBackendRenderTargets::MakeGL(width, height, sampleCnt, stencilBits, glInfo);
GrBackendRenderTarget* instance = new GrBackendRenderTarget(obj);
return instance; return instance;
} }
...@@ -23,7 +30,8 @@ SKIKO_EXPORT KNativePointer BackendRenderTarget_nMakeMetal ...@@ -23,7 +30,8 @@ SKIKO_EXPORT KNativePointer BackendRenderTarget_nMakeMetal
GrMTLHandle texture = reinterpret_cast<GrMTLHandle>((texturePtr)); GrMTLHandle texture = reinterpret_cast<GrMTLHandle>((texturePtr));
GrMtlTextureInfo fbInfo; GrMtlTextureInfo fbInfo;
fbInfo.fTexture.retain(texture); fbInfo.fTexture.retain(texture);
GrBackendRenderTarget* instance = new GrBackendRenderTarget(width, height, fbInfo); GrBackendRenderTarget obj = GrBackendRenderTargets::MakeMtl(width, height, fbInfo);
GrBackendRenderTarget* instance = new GrBackendRenderTarget(obj);
return instance; return instance;
#else #else
return 0; return 0;
......
#include "GrDirectContext.h" #include "GrDirectContext.h"
#include "include/gpu/gl/GrGLInterface.h" #include "include/gpu/gl/GrGLInterface.h"
#include "common.h" #include "common.h"
#include "ganesh/gl/GrGLDirectContext.h" // TODO: skia update: check if it's correct
#ifdef SK_METAL #ifdef SK_METAL
#include "mtl/GrMtlBackendContext.h" #include "ganesh/mtl/GrMtlBackendContext.h"
#include "ganesh/mtl/GrMtlDirectContext.h"
#endif #endif
#ifdef SK_DIRECT3D #ifdef SK_DIRECT3D
...@@ -12,13 +14,13 @@ ...@@ -12,13 +14,13 @@
SKIKO_EXPORT KNativePointer org_jetbrains_skia_DirectContext__1nMakeGL SKIKO_EXPORT KNativePointer org_jetbrains_skia_DirectContext__1nMakeGL
() { () {
return reinterpret_cast<KNativePointer>(GrDirectContext::MakeGL().release()); return reinterpret_cast<KNativePointer>(GrDirectContexts::MakeGL().release());
} }
SKIKO_EXPORT KNativePointer org_jetbrains_skia_DirectContext__1nMakeGLWithInterface SKIKO_EXPORT KNativePointer org_jetbrains_skia_DirectContext__1nMakeGLWithInterface
(KNativePointer ptr) { (KNativePointer ptr) {
sk_sp<GrGLInterface> iface = sk_ref_sp(reinterpret_cast<GrGLInterface*>(ptr)); sk_sp<GrGLInterface> iface = sk_ref_sp(reinterpret_cast<GrGLInterface*>(ptr));
return reinterpret_cast<KNativePointer>(GrDirectContext::MakeGL(iface).release()); return reinterpret_cast<KNativePointer>(GrDirectContexts::MakeGL(iface).release());
} }
SKIKO_EXPORT KNativePointer org_jetbrains_skia_DirectContext__1nMakeMetal SKIKO_EXPORT KNativePointer org_jetbrains_skia_DirectContext__1nMakeMetal
...@@ -29,7 +31,7 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_DirectContext__1nMakeMetal ...@@ -29,7 +31,7 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_DirectContext__1nMakeMetal
GrMTLHandle queue = reinterpret_cast<GrMTLHandle>((queuePtr)); GrMTLHandle queue = reinterpret_cast<GrMTLHandle>((queuePtr));
backendContext.fDevice.retain(device); backendContext.fDevice.retain(device);
backendContext.fQueue.retain(queue); backendContext.fQueue.retain(queue);
sk_sp<GrDirectContext> instance = GrDirectContext::MakeMetal(backendContext); sk_sp<GrDirectContext> instance = GrDirectContexts::MakeMetal(backendContext);
return reinterpret_cast<KNativePointer>(instance.release()); return reinterpret_cast<KNativePointer>(instance.release());
#else #else
return nullptr; return nullptr;
...@@ -53,16 +55,35 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_DirectContext__1nMakeDirect3D ...@@ -53,16 +55,35 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_DirectContext__1nMakeDirect3D
#endif // SK_DIRECT3D #endif // SK_DIRECT3D
} }
SKIKO_EXPORT void org_jetbrains_skia_DirectContext__1nFlush SKIKO_EXPORT void org_jetbrains_skia_DirectContext__1nFlushDefault
(KNativePointer ptr) { (KNativePointer ptr) {
GrDirectContext* context = reinterpret_cast<GrDirectContext*>((ptr)); GrDirectContext* context = reinterpret_cast<GrDirectContext*>((ptr));
context->flush(GrFlushInfo()); context->flush(GrFlushInfo());
} }
SKIKO_EXPORT void org_jetbrains_skia_DirectContext__1nFlush
(KNativePointer ptr, KNativePointer skSurfacePtr) {
GrDirectContext* context = reinterpret_cast<GrDirectContext*>(ptr);
SkSurface* skSurface = reinterpret_cast<SkSurface*>(skSurfacePtr);
context->flush(skSurface);
}
GrSyncCpu grSyncCpuFromBool(bool syncCpu) {
if (syncCpu) return GrSyncCpu::kYes;
return GrSyncCpu::kNo;
}
SKIKO_EXPORT void org_jetbrains_skia_DirectContext__1nFlushAndSubmit
(KNativePointer ptr, KNativePointer skSurfacePtr, KBoolean syncCpu) {
GrDirectContext* context = reinterpret_cast<GrDirectContext*>(ptr);
SkSurface* skSurface = reinterpret_cast<SkSurface*>(skSurfacePtr);
context->flushAndSubmit(skSurface, grSyncCpuFromBool(syncCpu));
}
SKIKO_EXPORT void org_jetbrains_skia_DirectContext__1nSubmit SKIKO_EXPORT void org_jetbrains_skia_DirectContext__1nSubmit
(KNativePointer ptr, KBoolean syncCpu) { (KNativePointer ptr, KBoolean syncCpu) {
GrDirectContext* context = reinterpret_cast<GrDirectContext*>((ptr)); GrDirectContext* context = reinterpret_cast<GrDirectContext*>((ptr));
context->submit(syncCpu); context->submit(grSyncCpuFromBool(syncCpu));
} }
SKIKO_EXPORT void org_jetbrains_skia_DirectContext__1nReset SKIKO_EXPORT void org_jetbrains_skia_DirectContext__1nReset
......
...@@ -157,13 +157,6 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_Font__1nGetTypeface ...@@ -157,13 +157,6 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_Font__1nGetTypeface
return reinterpret_cast<KNativePointer>(typeface); return reinterpret_cast<KNativePointer>(typeface);
} }
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Font__1nGetTypefaceOrDefault
(KNativePointer ptr) {
SkFont* instance = reinterpret_cast<SkFont*>(ptr);
SkTypeface* typeface = instance->refTypefaceOrDefault().release();
return reinterpret_cast<KNativePointer>(typeface);
}
SKIKO_EXPORT KFloat org_jetbrains_skia_Font__1nGetSize SKIKO_EXPORT KFloat org_jetbrains_skia_Font__1nGetSize
(KNativePointer ptr) { (KNativePointer ptr) {
SkFont* instance = reinterpret_cast<SkFont*>(ptr); SkFont* instance = reinterpret_cast<SkFont*>(ptr);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "SkFontMgr.h" #include "SkFontMgr.h"
#include "common.h" #include "common.h"
#include "FontMgrWithFallbackWrapper.hh" #include "FontMgrWithFallbackWrapper.hh"
#include "FontMgrDefaultFactory.hh"
SKIKO_EXPORT KInt org_jetbrains_skia_FontMgr__1nGetFamiliesCount SKIKO_EXPORT KInt org_jetbrains_skia_FontMgr__1nGetFamiliesCount
(KNativePointer ptr) { (KNativePointer ptr) {
...@@ -68,9 +69,31 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_FontMgr__1nMakeFromData ...@@ -68,9 +69,31 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_FontMgr__1nMakeFromData
return reinterpret_cast<KNativePointer>(typeface); return reinterpret_cast<KNativePointer>(typeface);
} }
SKIKO_EXPORT KNativePointer org_jetbrains_skia_FontMgr__1nMakeFromFile
(KNativePointer ptr, KNativePointer pathStrPtr, KInt ttcIndex) {
SkFontMgr* instance = reinterpret_cast<SkFontMgr*>(ptr);
SkString path = skString(pathStrPtr);
SkTypeface* typeface = instance->makeFromFile(path.c_str(), ttcIndex).release();
return reinterpret_cast<KNativePointer>(typeface);
}
SKIKO_EXPORT KNativePointer org_jetbrains_skia_FontMgr__1nLegacyMakeTypeface
(KNativePointer ptr, KInteropPointer familyNameStr, KInt fontStyle) {
SkFontMgr* instance = reinterpret_cast<SkFontMgr*>((ptr));
SkString name = skString(familyNameStr);
SkTypeface* typeface = instance->legacyMakeTypeface(
name.c_str(), skija::FontStyle::fromKotlin(fontStyle)
).release();
return reinterpret_cast<KNativePointer>(typeface);
}
SKIKO_EXPORT KNativePointer org_jetbrains_skia_FontMgr__1nDefault SKIKO_EXPORT KNativePointer org_jetbrains_skia_FontMgr__1nDefault
() { () {
SkFontMgr* instance = SkFontMgr::RefDefault().release(); SkFontMgr* instance = SkFontMgrSkikoDefault().release();
return reinterpret_cast<KNativePointer>(instance); return reinterpret_cast<KNativePointer>(instance);
} }
......
#include <iostream> #include <iostream>
#include "SkPicture.h"
#include "SkDrawable.h" #include "SkDrawable.h"
#include "SkPictureRecorder.h" #include "SkPictureRecorder.h"
#include "common.h" #include "common.h"
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#ifdef SK_METAL #ifdef SK_METAL
#include "include/gpu/ganesh/mtl/SkSurfaceMetal.h" #include "include/gpu/ganesh/mtl/SkSurfaceMetal.h"
#include "include/gpu/mtl/GrMtlTypes.h" #include "include/gpu/ganesh/mtl/GrMtlTypes.h"
#endif #endif
...@@ -216,18 +216,6 @@ SKIKO_EXPORT void org_jetbrains_skia_Surface__1nWritePixels ...@@ -216,18 +216,6 @@ SKIKO_EXPORT void org_jetbrains_skia_Surface__1nWritePixels
surface->writePixels(*bitmap, x, y); surface->writePixels(*bitmap, x, y);
} }
SKIKO_EXPORT void org_jetbrains_skia_Surface__1nFlushAndSubmit
(KNativePointer ptr, KBoolean syncCpu) {
SkSurface* surface = reinterpret_cast<SkSurface*>((ptr));
surface->flushAndSubmit(syncCpu);
}
SKIKO_EXPORT void org_jetbrains_skia_Surface__1nFlush
(KNativePointer ptr) {
SkSurface* surface = reinterpret_cast<SkSurface*>((ptr));
surface->flush();
}
SKIKO_EXPORT KBoolean org_jetbrains_skia_Surface__1nUnique SKIKO_EXPORT KBoolean org_jetbrains_skia_Surface__1nUnique
(KNativePointer ptr) { (KNativePointer ptr) {
SkSurface* surface = reinterpret_cast<SkSurface*>((ptr)); SkSurface* surface = reinterpret_cast<SkSurface*>((ptr));
......
...@@ -70,37 +70,6 @@ SKIKO_EXPORT KInt org_jetbrains_skia_Typeface__1nEquals ...@@ -70,37 +70,6 @@ SKIKO_EXPORT KInt org_jetbrains_skia_Typeface__1nEquals
return SkTypeface::Equal(instance, other); return SkTypeface::Equal(instance, other);
} }
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Typeface__1nMakeDefault
(){
return reinterpret_cast<KNativePointer>(SkTypeface::MakeDefault().release());
}
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Typeface__1nMakeFromName
(KInteropPointer nameStr, KInt styleValue) {
SkString name = skString(nameStr);
SkFontStyle style = skija::FontStyle::fromKotlin(styleValue);
sk_sp<SkTypeface> instance = SkTypeface::MakeFromName(name.c_str(), style);
return reinterpret_cast<KNativePointer>(instance.release());
}
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Typeface__1nMakeFromFile
(KInteropPointer pathStr, KInt index) {
SkString path = skString(pathStr);
sk_sp<SkTypeface> instance = SkTypeface::MakeFromFile(path.c_str(), index);
SkTypeface* ptr = instance.release();
return reinterpret_cast<KNativePointer>(ptr);
}
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Typeface__1nMakeFromData
(KNativePointer dataPtr, KInt index) {
SkData* data = reinterpret_cast<SkData*>((dataPtr));
sk_sp<SkTypeface> instance = SkTypeface::MakeFromData(sk_ref_sp(data), index);
SkTypeface* ptr = instance.release();
return reinterpret_cast<KNativePointer>(ptr);
}
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Typeface__1nMakeClone SKIKO_EXPORT KNativePointer org_jetbrains_skia_Typeface__1nMakeClone
(KNativePointer typefacePtr, KInt* variations, KInt variationsCount, KInt collectionIndex) { (KNativePointer typefacePtr, KInt* variations, KInt variationsCount, KInt collectionIndex) {
SkTypeface* typeface = reinterpret_cast<SkTypeface*>(typefacePtr); SkTypeface* typeface = reinterpret_cast<SkTypeface*>(typefacePtr);
...@@ -223,3 +192,10 @@ SKIKO_EXPORT void org_jetbrains_skia_Typeface__1nGetBounds ...@@ -223,3 +192,10 @@ SKIKO_EXPORT void org_jetbrains_skia_Typeface__1nGetBounds
bounds[2] = b.right(); bounds[2] = b.right();
bounds[3] = b.bottom(); bounds[3] = b.bottom();
} }
SKIKO_EXPORT KInteropPointer org_jetbrains_skia_Typeface__1nMakeEmptyTypeface
() {
SkTypeface* res = SkTypeface::MakeEmpty().release();
return reinterpret_cast<KInteropPointer>(res);
}
\ No newline at end of file
#include <ganesh/mtl/GrMtlTypes.h>
#include "GrBackendSurface.h" #include "GrBackendSurface.h"
#include "GrDirectContext.h" #include "GrDirectContext.h"
#include "common.h" #include "common.h"
#include "ganesh/gl/GrGLDirectContext.h"
#include "ganesh/gl/GrGLBackendSurface.h"
#ifdef SK_METAL
#include "ganesh/mtl/GrMtlBackendSurface.h"
#endif
SKIKO_EXPORT KNativePointer org_jetbrains_skiko_RenderTargetsKt_makeGLRenderTargetNative SKIKO_EXPORT KNativePointer org_jetbrains_skiko_RenderTargetsKt_makeGLRenderTargetNative
(KInt width, KInt height, KInt sampleCnt, KInt stencilBits, KInt fbId, KInt fbFormat) { (KInt width, KInt height, KInt sampleCnt, KInt stencilBits, KInt fbId, KInt fbFormat) {
GrGLFramebufferInfo glInfo = { static_cast<unsigned int>(fbId), static_cast<unsigned int>(fbFormat) }; GrGLFramebufferInfo glInfo = { static_cast<unsigned int>(fbId), static_cast<unsigned int>(fbFormat) };
GrBackendRenderTarget* obj = new GrBackendRenderTarget(width, height, sampleCnt, stencilBits, glInfo); GrBackendRenderTarget obj = GrBackendRenderTargets::MakeGL(width, height, sampleCnt, stencilBits, glInfo);
return reinterpret_cast<KNativePointer>(obj); GrBackendRenderTarget* target = new GrBackendRenderTarget(obj);
return reinterpret_cast<KNativePointer>(target);
} }
SKIKO_EXPORT KNativePointer org_jetbrains_skiko_RenderTargetsKt_makeGLContextNative() { SKIKO_EXPORT KNativePointer org_jetbrains_skiko_RenderTargetsKt_makeGLContextNative() {
return reinterpret_cast<KNativePointer>(GrDirectContext::MakeGL().release()); return reinterpret_cast<KNativePointer>(GrDirectContexts::MakeGL().release());
} }
SKIKO_EXPORT KNativePointer org_jetbrains_skiko_RenderTargetsKt_makeMetalRenderTargetNative SKIKO_EXPORT KNativePointer org_jetbrains_skiko_RenderTargetsKt_makeMetalRenderTargetNative
...@@ -18,8 +26,9 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skiko_RenderTargetsKt_makeMetalRenderT ...@@ -18,8 +26,9 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skiko_RenderTargetsKt_makeMetalRenderT
#ifdef SK_METAL #ifdef SK_METAL
// TODO: create properly. // TODO: create properly.
GrMtlTextureInfo mtlInfo; GrMtlTextureInfo mtlInfo;
GrBackendRenderTarget* obj = new GrBackendRenderTarget(width, height, sampleCnt, mtlInfo); GrBackendRenderTarget obj = GrBackendRenderTargets::MakeMtl(width, height, mtlInfo);
return reinterpret_cast<KNativePointer>(obj); GrBackendRenderTarget* instance = new GrBackendRenderTarget(obj);
return reinterpret_cast<KNativePointer>(instance);
#else #else
return 0; return 0;
#endif #endif
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "SkShaper.h" #include "SkShaper.h"
#include "common.h" #include "common.h"
#include "FontRunIterator.hh" #include "FontRunIterator.hh"
#include "FontMgrDefaultFactory.hh"
SKIKO_EXPORT KNativePointer org_jetbrains_skia_shaper_FontMgrRunIterator__1nMake SKIKO_EXPORT KNativePointer org_jetbrains_skia_shaper_FontMgrRunIterator__1nMake
...@@ -9,7 +10,7 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_shaper_FontMgrRunIterator__1nMake ...@@ -9,7 +10,7 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_shaper_FontMgrRunIterator__1nMake
SkString* text = reinterpret_cast<SkString*>(textPtr); SkString* text = reinterpret_cast<SkString*>(textPtr);
SkFont* font = reinterpret_cast<SkFont*>(fontPtr); SkFont* font = reinterpret_cast<SkFont*>(fontPtr);
sk_sp<SkFontMgr> fontMgr = fontMgrPtr == nullptr sk_sp<SkFontMgr> fontMgr = fontMgrPtr == nullptr
? SkFontMgr::RefDefault() ? SkFontMgrSkikoDefault()
: sk_ref_sp(reinterpret_cast<SkFontMgr*>(fontMgrPtr)); : sk_ref_sp(reinterpret_cast<SkFontMgr*>(fontMgrPtr));
std::shared_ptr<UBreakIterator> graphemeIter = skija::shaper::graphemeBreakIterator(*text); std::shared_ptr<UBreakIterator> graphemeIter = skija::shaper::graphemeBreakIterator(*text);
if (!graphemeIter) return nullptr; if (!graphemeIter) return nullptr;
......
#include <iostream> #include <iostream>
#include "SkShaper.h" #include "SkShaper.h"
#include "SkShaper_harfbuzz.h"
#include "SkUnicode.h" #include "SkUnicode.h"
#include "src/base/SkUTF.h" #include "src/base/SkUTF.h"
#include "unicode/ubidi.h" #include "unicode/ubidi.h"
#include "common.h" #include "common.h"
#include "FontRunIterator.hh" #include "FontRunIterator.hh"
#include "TextLineRunHandler.hh" #include "TextLineRunHandler.hh"
#include "FontMgrDefaultFactory.hh"
#include "SkUnicode_icu.h"
#ifdef SK_SHAPER_CORETEXT_AVAILABLE
#include "SkShaper_coretext.h"
#endif
static void deleteShaper(SkShaper* instance) { static void deleteShaper(SkShaper* instance) {
// std::cout << "Deleting [SkShaper " << instance << "]" << std::endl; // std::cout << "Deleting [SkShaper " << instance << "]" << std::endl;
...@@ -18,7 +25,7 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_shaper_Shaper__1nGetFinalizer() { ...@@ -18,7 +25,7 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_shaper_Shaper__1nGetFinalizer() {
SKIKO_EXPORT KNativePointer org_jetbrains_skia_shaper_Shaper__1nMakePrimitive SKIKO_EXPORT KNativePointer org_jetbrains_skia_shaper_Shaper__1nMakePrimitive
() { () {
return reinterpret_cast<KNativePointer>(SkShaper::MakePrimitive().release()); return reinterpret_cast<KNativePointer>(SkShapers::Primitive::PrimitiveText().release());
} }
SKIKO_EXPORT KNativePointer org_jetbrains_skia_shaper_Shaper__1nMakeShaperDrivenWrapper SKIKO_EXPORT KNativePointer org_jetbrains_skia_shaper_Shaper__1nMakeShaperDrivenWrapper
...@@ -36,12 +43,14 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_shaper_Shaper__1nMakeShapeThenWra ...@@ -36,12 +43,14 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_shaper_Shaper__1nMakeShapeThenWra
SKIKO_EXPORT KNativePointer org_jetbrains_skia_shaper_Shaper__1nMakeShapeDontWrapOrReorder SKIKO_EXPORT KNativePointer org_jetbrains_skia_shaper_Shaper__1nMakeShapeDontWrapOrReorder
(KNativePointer fontMgrPtr) { (KNativePointer fontMgrPtr) {
SkFontMgr* fontMgr = reinterpret_cast<SkFontMgr*>((fontMgrPtr)); SkFontMgr* fontMgr = reinterpret_cast<SkFontMgr*>((fontMgrPtr));
return reinterpret_cast<KNativePointer>(SkShaper::MakeShapeDontWrapOrReorder(SkUnicode::Make(), sk_ref_sp(fontMgr)).release()); // TODO: consider if we need/want to use ICU4X or Libgrapheme (skuincode/include has those implementations too)
sk_sp<SkUnicode> unicode = SkUnicodes::ICU::Make();
return reinterpret_cast<KNativePointer>(SkShapers::HB::ShapeDontWrapOrReorder(unicode, sk_ref_sp(fontMgr)).release());
} }
SKIKO_EXPORT KNativePointer org_jetbrains_skia_shaper_Shaper__1nMakeCoreText() { SKIKO_EXPORT KNativePointer org_jetbrains_skia_shaper_Shaper__1nMakeCoreText() {
#ifdef SK_SHAPER_CORETEXT_AVAILABLE #ifdef SK_SHAPER_CORETEXT_AVAILABLE
return reinterpret_cast<KNativePointer>(SkShaper::MakeCoreText().release()); return reinterpret_cast<KNativePointer>(SkShapers::CT::CoreText().release());
#else #else
return nullptr; return nullptr;
#endif #endif
...@@ -83,7 +92,7 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_shaper_Shaper__1nShapeBlob ...@@ -83,7 +92,7 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_shaper_Shaper__1nShapeBlob
text.c_str(), text.c_str(),
text.size(), text.size(),
*font, *font,
SkFontMgr::RefDefault(), SkFontMgrSkikoDefault(),
graphemeIter, graphemeIter,
aproximateSpaces, aproximateSpaces,
aproximatePunctuation aproximatePunctuation
...@@ -130,7 +139,7 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_shaper_Shaper__1nShapeLine ...@@ -130,7 +139,7 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_shaper_Shaper__1nShapeLine
text.c_str(), text.c_str(),
text.size(), text.size(),
*font, *font,
SkFontMgr::RefDefault(), SkFontMgrSkikoDefault(),
graphemeIter, graphemeIter,
aproximateSpaces, aproximateSpaces,
aproximatePunctuation); aproximatePunctuation);
......
package org.jetbrains.skia
import org.jetbrains.skia.impl.Native
import org.jetbrains.skia.impl.Stats
import org.jetbrains.skia.impl.interopScope
/**
* @return a new typeface given a file
* @throws IllegalArgumentException If the file does not exist, or is not a valid font file
*/
fun Typeface.Companion.makeFromFile(path: String, index: Int = 0): Typeface {
Stats.onNativeCall()
interopScope {
val ptr = _nMakeFromFile(toInterop(path), index)
require(ptr != Native.NullPointer) { "Failed to create Typeface from path=\"$path\" index=$index" }
return Typeface(ptr)
}
}
\ No newline at end of file
package org.jetbrains.skia.tests package org.jetbrains.skia.tests
import org.jetbrains.skia.Data import org.jetbrains.skia.*
import org.jetbrains.skia.Typeface
import org.jetbrains.skia.makeFromFile
import org.jetbrains.skia.makeFromFileName
import org.jetbrains.skiko.resourcePath import org.jetbrains.skiko.resourcePath
actual suspend fun Typeface.Companion.makeFromResource(resourceId: String, index: Int): Typeface = actual suspend fun Typeface.Companion.makeFromResource(resourceId: String, index: Int): Typeface =
makeFromFile(resourcePath(resourceId), index) FontMgr.default.makeFromFile(resourcePath(resourceId), index)
?: error("Failed to makeFromFile with resourceId = $resourceId")
actual suspend fun Data.Companion.makeFromResource(resourceId: String) = actual suspend fun Data.Companion.makeFromResource(resourceId: String) =
makeFromFileName(resourcePath(resourceId)) makeFromFileName(resourcePath(resourceId))
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