Skip to content

Commit

Permalink
update to m122 WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
eymar committed Jul 26, 2024
1 parent e7d2dd3 commit db453b2
Show file tree
Hide file tree
Showing 31 changed files with 181 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ fun skiaPreprocessorFlags(os: OS, buildType: SkiaBuildType): Array<String> {
"-DSK_GL",
"-DSK_SHAPER_HARFBUZZ_AVAILABLE",
"-DSK_UNICODE_AVAILABLE",
"-DSK_SHAPER_UNICODE_AVAILABLE",
"-DSK_SUPPORT_OPENCL=0",
"-DSK_UNICODE_AVAILABLE",
"-DU_DISABLE_RENAMING",
"-DSK_USING_THIRD_PARTY_ICU",
// For ICU symbols renaming:
"-DU_DISABLE_RENAMING=0",
"-DU_DISABLE_VERSION_SUFFIX=1",
"-DU_HAVE_LIB_SUFFIX=1",
"-DU_LIB_SUFFIX_C_NAME=_skiko",
// "-DU_DISABLE_RENAMING=0",
// "-DU_DISABLE_VERSION_SUFFIX=1",
// "-DU_HAVE_LIB_SUFFIX=1",
// "-DU_LIB_SUFFIX_C_NAME=_skiko",
*buildType.flags
)

Expand Down
2 changes: 1 addition & 1 deletion skiko/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kotlin.code.style=official
deploy.version=0.0.0


dependencies.skia=m116-47d3027-1
dependencies.skia=m122-6726cd3-1

# you can override general skia dependencies by passing platform-specific property:
# dependencies.skia.android-arm64
Expand Down
2 changes: 1 addition & 1 deletion skiko/src/awtMain/objectiveC/macos/MetalContextHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_context_MetalContextHandler_mak
device.drawableHandle = currentDrawable;
GrMtlTextureInfo info;
info.fTexture.retain((__bridge GrMTLHandle) currentDrawable.texture);
renderTarget = new GrBackendRenderTarget(width, height, 0, info);
renderTarget = new GrBackendRenderTarget(width, height, info);
return (jlong) renderTarget;
}
}
Expand Down
2 changes: 1 addition & 1 deletion skiko/src/awtMain/objectiveC/macos/MetalSwingRedrawer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_swing_MetalSwingRedrawer_makeMe
GrMtlTextureInfo info;
info.fTexture.retain((__bridge GrMTLHandle) texture);
GrBackendRenderTarget *renderTarget = NULL;
renderTarget = new GrBackendRenderTarget(texture.width, texture.height, 0, info);
renderTarget = new GrBackendRenderTarget(texture.width, texture.height, info);
return (jlong) renderTarget;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "FontMgrWithFallbackWrapper.hh"
#include "FontMgrDefaultFactory.hh"

FontMgrWithFallbackWrapper::FontMgrWithFallbackWrapper(sk_sp<TypefaceFontProviderWithFallback> fallbackTypefaceFontProvider)
: fallbackFontProvider(std::move(fallbackTypefaceFontProvider)) {
wrappedFntMgr = SkFontMgr::RefDefault();
wrappedFntMgr = SkFontMgrSkikoDefault();
}

int FontMgrWithFallbackWrapper::onCountFamilies() const {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef FONT_MGR_DEFAULT_FACTORY_H
#define FONT_MGR_DEFAULT_FACTORY_H

#include "SkFontMgr.h"

sk_sp<SkFontMgr> SkFontMgrSkikoDefault();

#endif
4 changes: 2 additions & 2 deletions skiko/src/commonMain/cpp/common/include/FontRunIterator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public:
, fApproximateSpaces(approximateSpaces)
, fApproximatePunctuation(approximatePunctuation)
{
fFont.setTypeface(font.refTypefaceOrDefault());
fFont.setTypeface(font.refTypeface());
fFallbackFont.setTypeface(nullptr);
}

Expand All @@ -45,7 +45,7 @@ public:
font,
std::move(fallbackMgr),
nullptr,
font.refTypefaceOrDefault()->fontStyle(),
font.refTypeface()->fontStyle(),
nullptr,
graphemeIter,
approximateSpaces,
Expand Down
10 changes: 9 additions & 1 deletion skiko/src/commonMain/kotlin/org/jetbrains/skia/ColorType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ enum class ColorType {
*/
BGR_101010X_XR,

/**
* 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
*/
Expand Down Expand Up @@ -136,6 +142,7 @@ enum class ColorType {
BGRA_1010102 -> 4
BGR_101010X -> 4
BGR_101010X_XR -> 4
RGBA_10x6 -> 8
GRAY_8 -> 1
RGBA_F16NORM -> 8
RGBA_F16 -> 8
Expand Down Expand Up @@ -163,6 +170,7 @@ enum class ColorType {
BGRA_1010102 -> 2
BGR_101010X -> 2
BGR_101010X_XR -> 2
RGBA_10x6 -> 2
GRAY_8 -> 0
RGBA_F16NORM -> 3
RGBA_F16 -> 3
Expand Down Expand Up @@ -196,7 +204,7 @@ enum class ColorType {
else if (ColorAlphaType.UNKNOWN == alphaType) null
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 ->
if (ColorAlphaType.UNKNOWN == alphaType) null
else alphaType
GRAY_8, R8G8_UNORM, R16G16_UNORM, R16G16_FLOAT, RGB_565, RGB_888X, RGB_101010X, BGR_101010X, BGR_101010X_XR ->
Expand Down
27 changes: 25 additions & 2 deletions skiko/src/commonMain/kotlin/org/jetbrains/skia/DirectContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ class DirectContext internal constructor(ptr: NativePointer) : RefCnt(ptr) {

fun flush(): DirectContext {
Stats.onNativeCall()
DirectContext_nFlush(_ptr)
DirectContext_nFlushDefault(_ptr)
return this
}

fun flush(surface: Surface): DirectContext {
Stats.onNativeCall()
DirectContext_nFlush(_ptr, surface._ptr)
return this
}

Expand Down Expand Up @@ -84,6 +90,15 @@ class DirectContext internal constructor(ptr: NativePointer) : RefCnt(ptr) {
_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
Expand Down Expand Up @@ -120,7 +135,11 @@ fun <R> DirectContext.useContext(block: (ctx: DirectContext) -> R): R = use {

@ExternalSymbolName("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__1nFlush")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_DirectContext__1nFlush")
private external fun DirectContext_nFlushDefault(ptr: NativePointer)

@ExternalSymbolName("org_jetbrains_skia_DirectContext__1nMakeGL")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_DirectContext__1nMakeGL")
Expand All @@ -138,6 +157,10 @@ private external fun _nMakeDirect3D(adapterPtr: NativePointer, devicePtr: Native
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_DirectContext__1nSubmit")
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")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_DirectContext__1nReset")
private external fun _nReset(ptr: NativePointer, flags: Int)
Expand Down
15 changes: 0 additions & 15 deletions skiko/src/commonMain/kotlin/org/jetbrains/skia/Font.kt
Original file line number Diff line number Diff line change
Expand Up @@ -261,17 +261,6 @@ class Font : Managed {
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
*/
Expand Down Expand Up @@ -705,10 +694,6 @@ private external fun _nSetHinting(ptr: NativePointer, value: Int)
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Font__1nGetTypeface")
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")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Font__1nGetScaleX")
private external fun _nGetScaleX(ptr: NativePointer): Float
Expand Down
16 changes: 16 additions & 0 deletions skiko/src/commonMain/kotlin/org/jetbrains/skia/FontMgr.kt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ open class FontMgr : RefCnt {
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)
}
}

internal constructor(ptr: NativePointer) : super(ptr)

internal constructor(ptr: NativePointer, allowClose: Boolean) : super(ptr, allowClose)
Expand Down Expand Up @@ -196,6 +208,10 @@ private external fun _nMatchFamilyStyleCharacter(
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_FontMgr__1nMakeFromData")
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")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_FontMgr__1nDefault")
private external fun _nDefault(): NativePointer
29 changes: 3 additions & 26 deletions skiko/src/commonMain/kotlin/org/jetbrains/skia/Surface.kt
Original file line number Diff line number Diff line change
Expand Up @@ -947,12 +947,7 @@ class Surface : RefCnt {
* a DirectContext.
*/
fun flushAndSubmit() {
try {
Stats.onNativeCall()
_nFlushAndSubmit(_ptr, false)
} finally {
reachabilityBarrier(this)
}
_context?.flushAndSubmit(this)
}

/**
Expand All @@ -969,21 +964,11 @@ class Surface : RefCnt {
* @param syncCpu a flag determining if cpu should be synced
*/
fun flushAndSubmit(syncCpu: Boolean) {
try {
Stats.onNativeCall()
_nFlushAndSubmit(_ptr, syncCpu)
} finally {
reachabilityBarrier(this)
}
_context?.flushAndSubmit(this, syncCpu)
}

fun flush() {
try {
Stats.onNativeCall()
Surface_nFlush(_ptr)
} finally {
reachabilityBarrier(this)
}
_context?.flush(this)
}

/**
Expand Down Expand Up @@ -1037,10 +1022,6 @@ private external fun Surface_nReadPixels(ptr: NativePointer, bitmapPtr: NativePo
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Surface__1nWritePixels")
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")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Surface__1nMakeRasterDirect")
private external fun _nMakeRasterDirect(
Expand Down Expand Up @@ -1176,10 +1157,6 @@ private external fun _nReadPixelsToPixmap(ptr: NativePointer, pixmapPtr: NativeP
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Surface__1nWritePixelsFromPixmap")
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")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Surface__1nUnique")
private external fun _nUnique(ptr: NativePointer): Boolean
52 changes: 0 additions & 52 deletions skiko/src/commonMain/kotlin/org/jetbrains/skia/Typeface.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,6 @@ import org.jetbrains.skia.impl.Library.Companion.staticLoad

class Typeface internal constructor(ptr: NativePointer) : RefCnt(ptr) {
companion object {
/**
* @return the default normal typeface, which is never null
*/
fun makeDefault(): Typeface {
Stats.onNativeCall()
return Typeface(Typeface_nMakeDefault())
}

/**
* 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()
return interopScope { Typeface(_nMakeFromName(toInterop(name), style._value)) }
}

/**
* @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()
}
Expand Down Expand Up @@ -403,10 +367,6 @@ private external fun Typeface_nGetUniqueId(ptr: NativePointer): Int
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Typeface__1nEquals")
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")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Typeface__1nGetUTF32Glyphs")
private external fun Typeface_nGetUTF32Glyphs(
Expand Down Expand Up @@ -448,18 +408,6 @@ private external fun _nGetVariationAxesCount(ptr: NativePointer): Int
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Typeface__1nGetVariationAxes")
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")
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_Typeface__1nMakeClone")
private external fun _nMakeClone(
Expand Down
8 changes: 4 additions & 4 deletions skiko/src/commonTest/kotlin/org/jetbrains/skia/FontMgrTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class FontMgrTest {
@Test
fun fontMgrTest() = runTest {

TypefaceFontProvider().let { fontManager ->
TypefaceFontProvider().let { outerFontManager ->
val fontManager = TypefaceFontProvider()

val jbMono = Typeface.makeFromResource("./fonts/JetBrainsMono-Regular.ttf")
Expand Down Expand Up @@ -78,12 +78,12 @@ class FontMgrTest {
assertEquals(jbMono, styleSet.matchStyle(FontStyle.ITALIC))
}

assertNull(fontManager.matchFamilyStyle("JetBrains Mono", FontStyle.BOLD))
assertNull(fontManager.matchFamilyStyle("Interface", FontStyle.NORMAL))
assertNull(outerFontManager.matchFamilyStyle("JetBrains Mono", FontStyle.BOLD))
assertNull(outerFontManager.matchFamilyStyle("Interface", FontStyle.NORMAL))

// TODO: it would be definitely beneficial to check the notNull branch as well
assertNull(
fontManager.matchFamilyStyleCharacter("JetBrains Mono", FontStyle.BOLD, arrayOf("en-US"), 65 /* A */)
outerFontManager.matchFamilyStyleCharacter("JetBrains Mono", FontStyle.BOLD, arrayOf("en-US"), 65 /* A */)
)

}
Expand Down
Loading

0 comments on commit db453b2

Please sign in to comment.