Unverified Commit 5ed970f0 authored by Elijah Semyonov's avatar Elijah Semyonov Committed by GitHub

Expose SkiaLayerProperties (#938)

parent 3f41f665
...@@ -71,6 +71,19 @@ actual open class SkiaLayer internal constructor( ...@@ -71,6 +71,19 @@ actual open class SkiaLayer internal constructor(
pixelGeometry pixelGeometry
) )
constructor(
externalAccessibleFactory: ((Component) -> Accessible)? = null,
properties: SkiaLayerProperties,
analytics: SkiaLayerAnalytics = SkiaLayerAnalytics.Empty,
pixelGeometry: PixelGeometry = PixelGeometry.UNKNOWN,
) : this(
externalAccessibleFactory,
properties,
RenderFactory.Default,
analytics,
pixelGeometry
)
val canvas: java.awt.Canvas val canvas: java.awt.Canvas
get() = backedLayer get() = backedLayer
......
...@@ -72,7 +72,7 @@ internal class MetalRedrawer( ...@@ -72,7 +72,7 @@ internal class MetalRedrawer(
} }
_device = initDevice _device = initDevice
contextHandler = MetalContextHandler(layer, initDevice, adapter) contextHandler = MetalContextHandler(layer, initDevice, adapter)
setVSyncEnabled(initDevice.ptr, properties.isVsyncEnabled) setDisplaySyncEnabled(initDevice.ptr, properties.isVsyncEnabled)
} }
override val renderInfo: String get() = contextHandler.rendererInfo() override val renderInfo: String get() = contextHandler.rendererInfo()
...@@ -190,5 +190,13 @@ internal class MetalRedrawer( ...@@ -190,5 +190,13 @@ internal class MetalRedrawer(
private external fun resizeLayers(device: Long, x: Int, y: Int, width: Int, height: Int) private external fun resizeLayers(device: Long, x: Int, y: Int, width: Int, height: Int)
private external fun setLayerVisible(device: Long, isVisible: Boolean) private external fun setLayerVisible(device: Long, isVisible: Boolean)
private external fun setContentScale(device: Long, contentScale: Float) private external fun setContentScale(device: Long, contentScale: Float)
private external fun setVSyncEnabled(device: Long, enabled: Boolean)
/**
* Set this value to true to synchronize the presentation of the layer’s contents with the display’s refresh,
* also known as vsync or vertical sync. If false, the layer presents new content more quickly,
* but possibly with brief visual artifacts (screen tearing).
*
* @note see https://developer.apple.com/documentation/quartzcore/cametallayer/2887087-displaysyncenabled
*/
private external fun setDisplaySyncEnabled(device: Long, enabled: Boolean)
} }
...@@ -231,7 +231,7 @@ JNIEXPORT void JNICALL Java_org_jetbrains_skiko_redrawer_MetalRedrawer_setConten ...@@ -231,7 +231,7 @@ JNIEXPORT void JNICALL Java_org_jetbrains_skiko_redrawer_MetalRedrawer_setConten
} }
} }
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_redrawer_MetalRedrawer_setVSyncEnabled(JNIEnv *env, jobject obj, jlong devicePtr, jboolean enabled) JNIEXPORT void JNICALL Java_org_jetbrains_skiko_redrawer_MetalRedrawer_setDisplaySyncEnabled(JNIEnv *env, jobject obj, jlong devicePtr, jboolean enabled)
{ {
@autoreleasepool { @autoreleasepool {
MetalDevice *device = (__bridge MetalDevice *) (void *) devicePtr; MetalDevice *device = (__bridge MetalDevice *) (void *) devicePtr;
......
...@@ -37,9 +37,9 @@ class BreakIteratorTests { ...@@ -37,9 +37,9 @@ class BreakIteratorTests {
@SkipJsTarget @SkipJsTarget
@SkipWasmTarget @SkipWasmTarget
fun breakIteratorCloneTest() { fun breakIteratorCloneTest() {
// Wasm and iOS builds of Skia do not include required data to implement those iterators, // Wasm, iOS, and tvOS builds of Skia do not include required data to implement those iterators,
// see `third_party/externals/icu/flutter/README.md`. // see `third_party/externals/icu/flutter/README.md`.
if (hostOs == OS.Ios) if (hostOs == OS.Ios || hostOs == OS.Tvos)
return return
if (isDebugModeOnJvm) if (isDebugModeOnJvm)
......
...@@ -15,6 +15,7 @@ private fun isMac() = (hostOs == OS.MacOS) ...@@ -15,6 +15,7 @@ private fun isMac() = (hostOs == OS.MacOS)
private fun isIos() = (hostOs == OS.Ios) private fun isIos() = (hostOs == OS.Ios)
private fun isLinux() = (hostOs == OS.Linux) private fun isLinux() = (hostOs == OS.Linux)
private fun isWindows() = (hostOs == OS.Windows) private fun isWindows() = (hostOs == OS.Windows)
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" private const val jbMonoPath = "./fonts/JetBrainsMono-Regular.ttf"
...@@ -91,6 +92,8 @@ class FontTests { ...@@ -91,6 +92,8 @@ class FontTests {
assertEquals(if (isLinux() || isJs()) 26 else 24, firstGlyphPath.pointsCount) assertEquals(if (isLinux() || isJs()) 26 else 24, firstGlyphPath.pointsCount)
//FontMetrics(_top=-11.64, _ascent=-11.64, _descent=3.24, _bottom=3.24, _leading=0.0, _avgCharWidth=29.46, _maxCharWidth=29.46, _xMin=-20.88, _xMax=8.58, _xHeight=6.6, _capHeight=8.64, _underlineThickness=0.54, _underlinePosition=1.44, _strikeoutThickness=0.54, _strikeoutPosition=-3.9), eps=0.01
//FontMetrics(_top=-11.64, _ascent=-11.64, _descent=3.2400002, _bottom=3.2400002, _leading=0.0, _avgCharWidth=7.2, _maxCharWidth=29.460001, _xMin=-20.880001, _xMax=8.58, _xHeight=6.6000004, _capHeight=8.64, _underlineThickness=0.54, _underlinePosition=1.4399999, _strikeoutThickness=0.54, _strikeoutPosition=-3.8999999)
assertCloseEnough(FontMetrics( assertCloseEnough(FontMetrics(
top = -11.64f, top = -11.64f,
ascent = -11.64f, ascent = -11.64f,
...@@ -99,7 +102,7 @@ class FontTests { ...@@ -99,7 +102,7 @@ class FontTests {
leading = 0f, leading = 0f,
avgCharWidth = when { avgCharWidth = when {
isJs() -> 7.2f isJs() -> 7.2f
isIos() || isMac() -> 29.460001f isIos() || isMac() || isTvos() -> 29.460001f
isWindows() -> 0f isWindows() -> 0f
else -> 7.2f else -> 7.2f
}, },
......
package org.jetbrains.skiko package org.jetbrains.skiko
internal data class SkiaLayerProperties(
/**
* SkiaLayerProperties is a class that represents the rendering configuration for a SkiaLayer.
*
* @property isVsyncEnabled Specifies whether vertical synchronization (VSync) is enabled.
* Default value is [SkikoProperties.vsyncEnabled]. Setting this to true is a hint toward underlying implementation
* to synchronize the rendering with the display presentation. It guarantees that the frame is presented without
* visual artifacts like tearing in exchange for a possible latency increase.
* @property isVsyncFramelimitFallbackEnabled Specifies whether framelimit fallback is enabled (software renderer).
* Default value is [SkikoProperties.vsyncFramelimitFallbackEnabled].
* @property renderApi Specifies the graphics API used for rendering.
* Default value is [SkikoProperties.renderApi].
* @property adapterPriority Specifies the GPU that will be selected for rendering.
* Default value is [SkikoProperties.gpuPriority].
*/
class SkiaLayerProperties(
val isVsyncEnabled: Boolean = SkikoProperties.vsyncEnabled, val isVsyncEnabled: Boolean = SkikoProperties.vsyncEnabled,
val isVsyncFramelimitFallbackEnabled: Boolean = SkikoProperties.vsyncFramelimitFallbackEnabled, val isVsyncFramelimitFallbackEnabled: Boolean = SkikoProperties.vsyncFramelimitFallbackEnabled,
val renderApi: GraphicsApi = SkikoProperties.renderApi, val renderApi: GraphicsApi = SkikoProperties.renderApi,
val adapterPriority: GpuPriority = SkikoProperties.gpuPriority, val adapterPriority: GpuPriority = SkikoProperties.gpuPriority,
) ) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
val rhs = other as? SkiaLayerProperties ?: return false
if (isVsyncEnabled != rhs.isVsyncEnabled) return false
if (isVsyncFramelimitFallbackEnabled != rhs.isVsyncFramelimitFallbackEnabled) return false
if (renderApi != rhs.renderApi) return false
if (adapterPriority != rhs.adapterPriority) return false
return true
}
fun copy(
isVsyncEnabled: Boolean = this.isVsyncEnabled,
isVsyncFramelimitFallbackEnabled: Boolean = this.isVsyncFramelimitFallbackEnabled,
renderApi: GraphicsApi = this.renderApi,
adapterPriority: GpuPriority = this.adapterPriority,
): SkiaLayerProperties {
return SkiaLayerProperties(
isVsyncEnabled = isVsyncEnabled,
isVsyncFramelimitFallbackEnabled = isVsyncFramelimitFallbackEnabled,
renderApi = renderApi,
adapterPriority = adapterPriority,
)
}
override fun hashCode(): Int {
var result = isVsyncEnabled.hashCode()
result = 31 * result + isVsyncFramelimitFallbackEnabled.hashCode()
result = 31 * result + renderApi.hashCode()
result = 31 * result + adapterPriority.hashCode()
return result
}
}
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