Skip to content

Commit

Permalink
update to skia m126 (#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
eymar authored Aug 12, 2024
1 parent 2a47e23 commit d04654c
Show file tree
Hide file tree
Showing 56 changed files with 498 additions and 341 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ jobs:
retention-days: 5

windows:
runs-on: windows-2019
runs-on: windows-2022
steps:
- uses: actions/checkout@v3
name: 'Check out code'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlin.math.sin
open class ClocksAwt(private val scaleProvider: () -> Float) : SkikoRenderDelegate, MouseMotionListener {
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 {
edging = FontEdging.SUBPIXEL_ANTI_ALIAS
hinting = FontHinting.SLIGHT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.browser.document
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import org.jetbrains.skia.Data
import org.jetbrains.skia.FontMgr
import org.jetbrains.skia.FontMgrWithFallback
import org.jetbrains.skia.Typeface
import org.jetbrains.skia.paragraph.TypefaceFontProviderWithFallback
Expand Down Expand Up @@ -40,8 +41,8 @@ internal fun runEmojiStoryApp() {
MainScope().launch {
val notoEmojisBytes = loadRes(notoColorEmoji).toByteArray()
val notoSansSCBytes = loadRes(notoSancSC).toByteArray()
val notoEmojiTypeface = Typeface.makeFromData(Data.makeFromBytes(notoEmojisBytes))
val notoSansSCTypeface = Typeface.makeFromData(Data.makeFromBytes(notoSansSCBytes))
val notoEmojiTypeface = FontMgr.default.makeFromData(Data.makeFromBytes(notoEmojisBytes))
val notoSansSCTypeface = FontMgr.default.makeFromData(Data.makeFromBytes(notoSansSCBytes))

val tfp = TypefaceFontProviderWithFallback().apply {
registerTypeface(notoEmojiTypeface)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ 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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ fun SkikoProjectContext.createLinkJvmBindings(
// Hack to fix problem with linker not always finding certain declarations.
"$skiaBinDir/libsksg.a",
"$skiaBinDir/libskia.a",
"$skiaBinDir/libskunicode.a"
"$skiaBinDir/libskunicode_core.a",
"$skiaBinDir/libskunicode_icu.a",
"$skiaBinDir/libskshaper.a",
)
}
OS.Windows -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ fun skiaStaticLibraries(skiaDir: String, targetString: String, buildType: SkiaBu
"libpng.a",
"libwebp_sse41.a",
"libsksg.a",
"libskunicode.a",
"libskunicode_core.a",
"libskunicode_icu.a",
"libwebp.a",
"libdng_sdk.a",
"libpiex.a",
Expand Down Expand Up @@ -225,7 +226,8 @@ fun SkikoProjectContext.configureNativeTarget(os: OS, arch: Arch, target: Kotlin
// TODO: an ugly hack, Linux linker searches only unresolved symbols.
"$skiaBinDir/libsksg.a",
"$skiaBinDir/libskshaper.a",
"$skiaBinDir/libskunicode.a",
"$skiaBinDir/libskunicode_core.a",
"$skiaBinDir/libskunicode_icu.a",
"$skiaBinDir/libskia.a"
)
else -> mutableListOf()
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=m126-1d69d9b-2

# you can override general skia dependencies by passing platform-specific property:
# dependencies.skia.android-arm64
Expand Down
6 changes: 2 additions & 4 deletions skiko/src/awtMain/cpp/windows/direct3DContext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ extern "C"
{
SkSurface *surface = fromJavaPointer<SkSurface *>(surfacePtr);
GrDirectContext *context = fromJavaPointer<GrDirectContext *>(contextPtr);
surface->flushAndSubmit(true);
surface->flush(SkSurface::BackendSurfaceAccess::kPresent, GrFlushInfo());
context->flush();
context->submit(true);
context->flush(surface, SkSurfaces::BackendSurfaceAccess::kPresent, GrFlushInfo());
context->submit(GrSyncCpu::kYes);
}
__except(EXCEPTION_EXECUTE_HANDLER) {
auto code = GetExceptionCode();
Expand Down
10 changes: 6 additions & 4 deletions skiko/src/awtMain/objectiveC/macos/MetalApi.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
#import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h>

#import <GrBackendSurface.h>
#import <GrDirectContext.h>
#import <mtl/GrMtlBackendContext.h>
#import <mtl/GrMtlTypes.h>
#import "GrBackendSurface.h"
#import "GrDirectContext.h"
#import "ganesh/mtl/GrMtlBackendContext.h"
#import "ganesh/mtl/GrMtlDirectContext.h"
#import "ganesh/mtl/GrMtlBackendSurface.h"
#import "ganesh/mtl/GrMtlTypes.h"

#import "MetalDevice.h"

Expand Down
15 changes: 9 additions & 6 deletions skiko/src/awtMain/objectiveC/macos/MetalContextHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

#import <QuartzCore/CAMetalLayer.h>
#import <Metal/Metal.h>
#import <GrDirectContext.h>
#import <gpu/GrBackendSurface.h>
#import <mtl/GrMtlBackendContext.h>
#import <mtl/GrMtlTypes.h>
#import "GrDirectContext.h"
#import "gpu/GrBackendSurface.h"
#import "ganesh/mtl/GrMtlBackendContext.h"
#import "ganesh/mtl/GrMtlDirectContext.h"
#import "ganesh/mtl/GrMtlBackendSurface.h"
#import "ganesh/mtl/GrMtlTypes.h"

#import "MetalDevice.h"

Expand All @@ -22,7 +24,7 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_context_MetalContextHandler_mak
GrMtlBackendContext backendContext = {};
backendContext.fDevice.retain((__bridge GrMTLHandle) device.adapter);
backendContext.fQueue.retain((__bridge GrMTLHandle) device.queue);
return (jlong) GrDirectContext::MakeMetal(backendContext).release();
return (jlong) GrDirectContexts::MakeMetal(backendContext).release();
}
}

Expand All @@ -46,7 +48,8 @@ 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);
GrBackendRenderTarget obj = GrBackendRenderTargets::MakeMtl(width, height, info);
renderTarget = new GrBackendRenderTarget(obj);
return (jlong) renderTarget;
}
}
Expand Down
9 changes: 5 additions & 4 deletions skiko/src/awtMain/objectiveC/macos/MetalRedrawer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
#import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h>

#import <GrBackendSurface.h>
#import <GrDirectContext.h>
#import <mtl/GrMtlBackendContext.h>
#import <mtl/GrMtlTypes.h>
#import "GrBackendSurface.h"
#import "GrDirectContext.h"
#import "ganesh/mtl/GrMtlBackendContext.h"
#import "ganesh/mtl/GrMtlDirectContext.h"
#import "ganesh/mtl/GrMtlTypes.h"

#import "MetalDevice.h"

Expand Down
15 changes: 9 additions & 6 deletions skiko/src/awtMain/objectiveC/macos/MetalSwingRedrawer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

#import <QuartzCore/CAMetalLayer.h>
#import <Metal/Metal.h>
#import <GrDirectContext.h>
#import <gpu/GrBackendSurface.h>
#import <mtl/GrMtlBackendContext.h>
#import <mtl/GrMtlTypes.h>
#import "GrDirectContext.h"
#import "gpu/GrBackendSurface.h"
#import "ganesh/mtl/GrMtlBackendContext.h"
#import "ganesh/mtl/GrMtlDirectContext.h"
#import "ganesh/mtl/GrMtlBackendSurface.h"
#import "ganesh/mtl/GrMtlTypes.h"

#import "MetalDevice.h"

Expand All @@ -23,7 +25,7 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_swing_MetalSwingRedrawer_makeMe
backendContext.fDevice.retain((__bridge GrMTLHandle) adapter);
id <MTLCommandQueue> fQueue = [adapter newCommandQueue];
backendContext.fQueue.retain((__bridge GrMTLHandle) fQueue);
return (jlong) GrDirectContext::MakeMetal(backendContext).release();
return (jlong) GrDirectContexts::MakeMetal(backendContext).release();
}
}

Expand Down Expand Up @@ -58,7 +60,8 @@ 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);
GrBackendRenderTarget obj = GrBackendRenderTargets::MakeMtl(texture.width, texture.height, info);
renderTarget = new GrBackendRenderTarget(obj);
return (jlong) renderTarget;
}
}
Expand Down
55 changes: 55 additions & 0 deletions skiko/src/commonMain/cpp/common/FontMgrDefaultFactory.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#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;
}
12 changes: 10 additions & 2 deletions skiko/src/commonMain/cpp/common/FontMgrWithFallbackWrapper.cc
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 Expand Up @@ -82,4 +83,11 @@ sk_sp<SkTypeface> TypefaceFontProviderWithFallback::fallbackForChar(SkUnichar ch
}
}
return nullptr;
}
}

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;
};
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public:
size_t registerTypeface(sk_sp<SkTypeface> typeface, const SkString& alias);

sk_sp<SkTypeface> fallbackForChar(SkUnichar character) const;
sk_sp<SkFontStyleSet> onCreateStyleSet(int) const override;

private:
std::vector<sk_sp<SkTypeface>> registeredTypefaces;
Expand Down
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
17 changes: 16 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,17 @@ enum class ColorType {
*/
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
*/
Expand Down Expand Up @@ -136,6 +147,8 @@ enum class ColorType {
BGRA_1010102 -> 4
BGR_101010X -> 4
BGR_101010X_XR -> 4
BGRA_10101010_XR -> 4
RGBA_10x6 -> 8
GRAY_8 -> 1
RGBA_F16NORM -> 8
RGBA_F16 -> 8
Expand Down Expand Up @@ -163,6 +176,8 @@ enum class ColorType {
BGRA_1010102 -> 2
BGR_101010X -> 2
BGR_101010X_XR -> 2
BGRA_10101010_XR -> 2
RGBA_10x6 -> 2
GRAY_8 -> 0
RGBA_F16NORM -> 3
RGBA_F16 -> 3
Expand Down Expand Up @@ -196,7 +211,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, BGRA_10101010_XR ->
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
Loading

0 comments on commit d04654c

Please sign in to comment.