Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pavel.sergeev/set skia m116 #808

Merged
merged 6 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion skiko/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ fun skiaHeadersDirs(skiaDir: File): List<File> =
skiaDir.resolve("modules/skottie/include"),
skiaDir.resolve("modules/skparagraph/include"),
skiaDir.resolve("modules/skshaper/include"),
skiaDir.resolve("modules/skunicode/include"),
skiaDir.resolve("modules/sksg/include"),
skiaDir.resolve("modules/svg/include"),
skiaDir.resolve("third_party/externals/harfbuzz/src"),
Expand All @@ -607,6 +608,7 @@ fun skiaPreprocessorFlags(os: OS): Array<String> {
"-DSK_GAMMA_SRGB",
"-DSK_SCALAR_TO_FLOAT_EXCLUDED",
"-DSK_SUPPORT_GPU=1",
"-DSK_GANESH",
"-DSK_GL",
"-DSK_SHAPER_HARFBUZZ_AVAILABLE",
"-DSK_UNICODE_AVAILABLE",
Expand Down Expand Up @@ -657,7 +659,6 @@ fun skiaStaticLibraries(skiaDir: String, targetString: String): List<String> {
val skiaBinSubdir = "$skiaDir/out/${buildType.id}-$targetString"
return listOf(
"libskresources.a",
"libparticles.a",
"libskparagraph.a",
"libskia.a",
"libicu.a",
Expand Down
3 changes: 1 addition & 2 deletions skiko/buildSrc/src/main/kotlin/properties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ class SkikoProperties(private val myProject: Project) {
fun skiaReleaseFor(os: OS, arch: Arch, buildType: SkiaBuildType, isIosSim: Boolean = false): String {
val target = "${os.idWithSuffix(isIosSim = isIosSim)}-${arch.id}"
val tag = myProject.property("dependencies.skia.$target") as String
val suffix = if (os == OS.Linux && arch == Arch.X64) "-ubuntu18" else ""
return "${tag}/Skia-${tag}-${os.idWithSuffix(isIosSim = isIosSim)}-${buildType.id}-${arch.id}$suffix"
return "${tag}/Skia-${tag}-${os.idWithSuffix(isIosSim = isIosSim)}-${buildType.id}-${arch.id}"
}

val releaseGithubVersion: String
Expand Down
26 changes: 13 additions & 13 deletions skiko/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ deploy.version=0.0.0
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false

dependencies.skia.windows-x64=m110-ad42464-1
dependencies.skia.linux-x64=m110-ad42464-1
dependencies.skia.macos-x64=m110-ad42464-1
dependencies.skia.windows-arm64=m110-ad42464-1
dependencies.skia.linux-arm64=m110-ad42464-1
dependencies.skia.macos-arm64=m110-ad42464-1
dependencies.skia.wasm-wasm=m110-ad42464-1
dependencies.skia.ios-x64=m110-ad42464-1
dependencies.skia.ios-arm64=m110-ad42464-1
dependencies.skia.iosSim-arm64=m110-ad42464-1
dependencies.skia.iosSim-x64=m110-ad42464-1
dependencies.skia.android-x64=m110-ad42464-1
dependencies.skia.android-arm64=m110-ad42464-1
dependencies.skia.windows-x64=m116-51072f3-1
dependencies.skia.linux-x64=m116-51072f3-1
dependencies.skia.macos-x64=m116-51072f3-1
dependencies.skia.windows-arm64=m116-51072f3-1
dependencies.skia.linux-arm64=m116-51072f3-1
dependencies.skia.macos-arm64=m116-51072f3-1
dependencies.skia.wasm-wasm=m116-51072f3-1
dependencies.skia.ios-x64=m116-51072f3-1
dependencies.skia.ios-arm64=m116-51072f3-1
dependencies.skia.iosSim-arm64=m116-51072f3-1
dependencies.skia.iosSim-x64=m116-51072f3-1
dependencies.skia.android-x64=m116-51072f3-1
dependencies.skia.android-arm64=m116-51072f3-1

org.gradle.jvmargs=-Xmx3G -XX:MaxMetaspaceSize=512m
kotlin.native.cacheKind.macosX64=none
Expand Down
6 changes: 3 additions & 3 deletions skiko/src/awtMain/cpp/linux/SoftwareRedrawer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "SkColorSpace.h"
#include "SkSurface.h"
#include "src/core/SkAutoMalloc.h"
#include "src/base/SkAutoMalloc.h"

class SoftwareDevice
{
Expand Down Expand Up @@ -64,7 +64,7 @@ extern "C"
SkImageInfo info = SkImageInfo::Make(
width, height, device->colorSpace, kPremul_SkAlphaType,
SkColorSpace::MakeSRGB());
device->surface = SkSurface::MakeRaster(info);
device->surface = SkSurfaces::Raster(info);

return toJavaPointer(device);
}
Expand All @@ -77,7 +77,7 @@ extern "C"
SkImageInfo info = SkImageInfo::Make(
width, height, device->colorSpace, kPremul_SkAlphaType,
SkColorSpace::MakeSRGB());
device->surface = SkSurface::MakeRaster(info);
device->surface = SkSurfaces::Raster(info);
}

JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_redrawer_AbstractDirectSoftwareRedrawer_acquireSurface(
Expand Down
4 changes: 2 additions & 2 deletions skiko/src/awtMain/cpp/windows/SoftwareRedrawer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "SkColorSpace.h"
#include "SkSurface.h"
#include "src/core/SkAutoMalloc.h"
#include "src/base/SkAutoMalloc.h"
#include "../common/interop.hh"

class SoftwareDevice
Expand Down Expand Up @@ -59,7 +59,7 @@ extern "C"
SkImageInfo info = SkImageInfo::Make(
width, height, kBGRA_8888_SkColorType, kPremul_SkAlphaType,
SkColorSpace::MakeSRGB());
device->surface = SkSurface::MakeRasterDirect(info, pixels, sizeof(uint32_t) * width, device->surfaceProps.get());
device->surface = SkSurfaces::WrapPixels(info, pixels, sizeof(uint32_t) * width, device->surfaceProps.get());
GetClientRect(device->window, &device->clientRect);
}
__except(EXCEPTION_EXECUTE_HANDLER) {
Expand Down
2 changes: 1 addition & 1 deletion skiko/src/awtMain/cpp/windows/direct3DContext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern "C"
GrDirectContext *context = fromJavaPointer<GrDirectContext *>(contextPtr);
surface->flushAndSubmit(true);
surface->flush(SkSurface::BackendSurfaceAccess::kPresent, GrFlushInfo());
context->flush({});
context->flush();
context->submit(true);
}
__except(EXCEPTION_EXECUTE_HANDLER) {
Expand Down
3 changes: 2 additions & 1 deletion skiko/src/awtMain/cpp/windows/directXRedrawer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "GrBackendSurface.h"
#include "GrDirectContext.h"
#include "SkSurface.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "../common/interop.hh"

#include "d3d/GrD3DTypes.h"
Expand Down Expand Up @@ -371,7 +372,7 @@ extern "C"

std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(env, surfacePropsInts);
GrBackendTexture backendTexture((int)d3dDevice->buffers[index]->GetDesc().Width, (int)d3dDevice->buffers[index]->GetDesc().Height, info);
auto result = SkSurface::MakeFromBackendTexture(
auto result = SkSurfaces::WrapBackendTexture(
context, backendTexture, kTopLeft_GrSurfaceOrigin, 0,
kRGBA_8888_SkColorType, SkColorSpace::MakeSRGB(), surfaceProps.get())
.release();
Expand Down
1 change: 1 addition & 0 deletions skiko/src/awtMain/objectiveC/macos/MetalContextHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#import <QuartzCore/CAMetalLayer.h>
#import <Metal/Metal.h>
#import <GrDirectContext.h>
#import <gpu/GrBackendSurface.h>
#import <mtl/GrMtlBackendContext.h>
#import <mtl/GrMtlTypes.h>

Expand Down
1 change: 1 addition & 0 deletions skiko/src/awtMain/objectiveC/macos/MetalSwingRedrawer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#import <QuartzCore/CAMetalLayer.h>
#import <Metal/Metal.h>
#import <GrDirectContext.h>
#import <gpu/GrBackendSurface.h>
#import <mtl/GrMtlBackendContext.h>
#import <mtl/GrMtlTypes.h>

Expand Down
2 changes: 1 addition & 1 deletion skiko/src/commonMain/cpp/common/mppinterop.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "mppinterop.h"
#include "RunRecordClone.hh"
#include "src/utils/SkUTF.h"
#include "src/base/SkUTF.h"
#include <iostream>

namespace skikoMpp {
Expand Down
2 changes: 1 addition & 1 deletion skiko/src/commonMain/cpp/common/shaper/FontRunIterator.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "SkShaper.h"
#include "FontRunIterator.hh"
#include "src/utils/SkUTF.h"
#include "src/base/SkUTF.h"
#include "unicode/uchar.h"
#include <iostream>

Expand Down
9 changes: 8 additions & 1 deletion skiko/src/commonMain/kotlin/org/jetbrains/skia/ColorType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ enum class ColorType {
*/
BGR_101010X,

/**
* Pixel with 10 bits each for blue, green, red; in 32-bit word, extended range
*/
BGR_101010X_XR,

/**
* Pixel with grayscale level in 8-bit byte
*/
Expand Down Expand Up @@ -130,6 +135,7 @@ enum class ColorType {
RGB_101010X -> 4
BGRA_1010102 -> 4
BGR_101010X -> 4
BGR_101010X_XR -> 4
GRAY_8 -> 1
RGBA_F16NORM -> 8
RGBA_F16 -> 8
Expand All @@ -156,6 +162,7 @@ enum class ColorType {
RGB_101010X -> 2
BGRA_1010102 -> 2
BGR_101010X -> 2
BGR_101010X_XR -> 2
GRAY_8 -> 0
RGBA_F16NORM -> 3
RGBA_F16 -> 3
Expand Down Expand Up @@ -192,7 +199,7 @@ enum class ColorType {
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 ->
GRAY_8, R8G8_UNORM, R16G16_UNORM, R16G16_FLOAT, RGB_565, RGB_888X, RGB_101010X, BGR_101010X, BGR_101010X_XR ->
ColorAlphaType.OPAQUE
}
}
Expand Down
42 changes: 7 additions & 35 deletions skiko/src/commonMain/kotlin/org/jetbrains/skia/ImageFilter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,6 @@ import org.jetbrains.skia.impl.*

class ImageFilter internal constructor(ptr: NativePointer) : RefCnt(ptr) {
companion object {
fun makeAlphaThreshold(
r: Region?,
innerMin: Float,
outerMax: Float,
input: ImageFilter?,
crop: IRect?
): ImageFilter {
return try {
Stats.onNativeCall()
interopScope {
ImageFilter(
_nMakeAlphaThreshold(
getPtr(r),
innerMin, outerMax, getPtr(input),
toInterop(crop?.serializeToIntArray())
)
)
}

} finally {
reachabilityBarrier(r)
reachabilityBarrier(input)
}
}

fun makeArithmetic(
k1: Float,
k2: Float,
Expand Down Expand Up @@ -251,7 +226,7 @@ class ImageFilter internal constructor(ptr: NativePointer) : RefCnt(ptr) {
}
}

fun makeMagnifier(r: Rect, inset: Float, input: ImageFilter?, crop: IRect?): ImageFilter {
fun makeMagnifier(r: Rect, zoomAmount: Float, inset: Float, samplingMode: SamplingMode, input: ImageFilter?, crop: IRect?): ImageFilter {
return try {
Stats.onNativeCall()
interopScope {
Expand All @@ -261,7 +236,10 @@ class ImageFilter internal constructor(ptr: NativePointer) : RefCnt(ptr) {
r.top,
r.right,
r.bottom,
zoomAmount,
inset,
samplingMode._packedInt1(),
samplingMode._packedInt2(),
getPtr(input),
toInterop(crop?.serializeToIntArray())
)
Expand Down Expand Up @@ -681,15 +659,6 @@ class ImageFilter internal constructor(ptr: NativePointer) : RefCnt(ptr) {
}
}

@ExternalSymbolName("org_jetbrains_skia_ImageFilter__1nMakeAlphaThreshold")
private external fun _nMakeAlphaThreshold(
regionPtr: NativePointer,
innerMin: Float,
outerMax: Float,
input: NativePointer,
crop: InteropPointer
): NativePointer

@ExternalSymbolName("org_jetbrains_skia_ImageFilter__1nMakeArithmetic")
private external fun _nMakeArithmetic(
k1: Float,
Expand Down Expand Up @@ -763,7 +732,10 @@ private external fun _nMakeMagnifier(
t: Float,
r: Float,
b: Float,
zoomAmount: Float,
inset: Float,
samplingModeVal1: Int,
samplingModeVal2: Int,
input: NativePointer,
crop: InteropPointer
): NativePointer
Expand Down
78 changes: 31 additions & 47 deletions skiko/src/commonTest/kotlin/org/jetbrains/skia/FontTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ import org.jetbrains.skia.impl.use
import org.jetbrains.skia.tests.assertCloseEnough
import org.jetbrains.skia.tests.assertContentCloseEnough
import org.jetbrains.skia.tests.makeFromResource
import org.jetbrains.skiko.KotlinBackend
import org.jetbrains.skiko.OS
import org.jetbrains.skiko.hostOs
import org.jetbrains.skiko.kotlinBackend
import org.jetbrains.skiko.tests.runTest
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals

private fun isLinuxOrJs() = (hostOs == OS.Linux) || (hostOs == OS.JS)
private fun isWin() = (hostOs == OS.Windows)
private fun isMac() = (hostOs == OS.MacOS)
private fun isIos() = (hostOs == OS.Ios)
private fun isLinux() = (hostOs == OS.Linux)
private fun isWindows() = (hostOs == OS.Windows)
private fun isJs() = (kotlinBackend == KotlinBackend.JS)
private val COARSE_EPSILON = 2.4f

class FontTests {
Expand Down Expand Up @@ -85,51 +90,30 @@ class FontTests {
assertCloseEnough(expected, actual, COARSE_EPSILON)
}


if (isLinuxOrJs()) {
assertEquals(26, firstGlyphPath.pointsCount)

assertCloseEnough(FontMetrics(
-11.64f,
-11.64f,
3.2400002f,
3.2400002f,
0f,
7.2000003f,
29.460001f,
-20.880001f,
8.58f,
6.6000004f,
8.64f,
0.54f,
1.4399999f,
0.54f,
-3.8999999f
), font.metrics, 10e-3f)
} else {
assertEquals(24, firstGlyphPath.pointsCount)

// TODO: this cross-platform differences look very suspicious and need to be addressed separately

assertCloseEnough(FontMetrics(
-11.64f,
-11.64f,
3.2400002f,
3.2400002f,
0f,
if (isWin()) 0f else 29.460001f,
29.460001f,
-20.880001f,
8.58f,
6.6000004f,
8.64f,
0.54f,
1.4399999f,
if (isWin()) 0.54f else null,
if (isWin()) -3.8999999f else null
), font.metrics, 10e-3f)

}
assertEquals(if (isLinux() || isJs()) 26 else 24, firstGlyphPath.pointsCount)

assertCloseEnough(FontMetrics(
top = -11.64f,
ascent = -11.64f,
descent = 3.2400002f,
bottom = 3.2400002f,
leading = 0f,
avgCharWidth = when {
isJs() -> 7.2f
isIos() || isMac() -> 29.460001f
isWindows() -> 0f
else -> 7.2f
},
maxCharWidth = 29.460001f,
xMin = -20.880001f,
xMax = 8.58f,
xHeight = 6.6000004f,
capHeight = 8.64f,
underlineThickness = 0.54f,
underlinePosition = 1.4399999f,
strikeoutThickness = 0.54f,
strikeoutPosition = -3.8999999f
), font.metrics, 10e-3f)

// assertEquals(Rect(1f, -12f, 21f, 0f), font.measureText("ЕЁЫ"))

Expand Down
Loading
Loading