Unverified Commit 58d59a86 authored by Igor Demin's avatar Igor Demin Committed by GitHub

Merge pull request #54 from JetBrains/properties

Ability to disable vsync with "skiko.vsync.enabled"
parents 8f723ef8 9d621e5c
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="SkijaInjectSample (without vsync)" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$/samples/SkijaInjectSample" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="-Dskiko.vsync.enabled=false" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="run" />
</list>
</option>
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
<configuration default="false" name="SkijaInjectSample (without vsync)" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$/samples/SkijaInjectSample" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="-Dskiko.vsync.enabled=false" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="run" />
</list>
</option>
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2">
<option name="Gradle.BeforeRunTask" enabled="false" tasks="publishToMavenLocal" externalProjectPath="$PROJECT_DIR$/skiko" vmOptions="" scriptParameters="" />
</method>
</configuration>
</component>
\ No newline at end of file
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.72'
id 'application'
}
repositories {
mavenLocal()
jcenter()
maven {
url 'https://dl.bintray.com/kotlin/kotlin-eap'
}
maven {
url 'https://maven.pkg.jetbrains.space/public/p/compose/dev'
}
}
def osName = System.getProperty("os.name")
def targetOs = ""
if (osName == "Mac OS X") {
targetOs = "macos"
} else if (osName.startsWith("Win")) {
targetOs = "windows"
} else if (osName.startsWith("Linux")) {
targetOs = "linux"
} else {
throw Error("Unsupported OS: $osName")
}
def osArch = System.getProperty("os.arch")
def targetArch = ""
if (osArch == "x86_64" || osArch == "amd64") {
targetArch = "x64"
} else if (osArch == "aarch64") {
targetArch = "arm64"
} else {
throw Error("Unsupported arch: $osArch")
}
def target = "${targetOs}-${targetArch}"
def version = "0.0.0-SNAPSHOT"
if (project.hasProperty('skiko.version')) {
version = project.properties['skiko.version']
}
dependencies {
implementation platform('org.jetbrains.kotlin:kotlin-bom')
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-swing:1.4.1'
implementation "org.jetbrains.skiko:skiko-jvm-runtime-$target:$version"
testImplementation 'org.jetbrains.kotlin:kotlin-test'
testImplementation 'org.jetbrains.kotlin:kotlin-test-junit'
}
application {
mainClassName = 'SkijaInjectSample.AppKt'
}
run {
systemProperty("skiko.fps.enabled", "true")
}
test {
systemProperty("skiko.test.screenshots.dir", new File(project.projectDir, "src/test/screenshots").absolutePath)
// Tests should be deterministic, so disable scaling.
// On MacOs we need the actual scale, otherwise we will have aliased screenshots because of scaling.
if (System.getProperty("os.name") != "Mac OS X") {
systemProperty("sun.java2d.dpiaware", "false")
systemProperty("sun.java2d.uiScale", "1")
}
}
\ No newline at end of file
plugins {
kotlin("jvm") version "1.3.72"
application
}
repositories {
mavenLocal()
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
val osName = System.getProperty("os.name")
val targetOs = when {
osName == "Mac OS X" -> "macos"
osName.startsWith("Win") -> "windows"
osName.startsWith("Linux") -> "linux"
else -> error("Unsupported OS: $osName")
}
val osArch = System.getProperty("os.arch")
var targetArch = when (osArch) {
"x86_64", "amd64" -> "x64"
"aarch64" -> "arm64"
else -> error("Unsupported arch: $osArch")
}
val target = "${targetOs}-${targetArch}"
var version = "0.0.0-SNAPSHOT"
if (project.hasProperty("skiko.version")) {
version = project.properties["skiko.version"] as String
}
dependencies {
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:1.4.1")
implementation("org.jetbrains.skiko:skiko-jvm-runtime-$target:$version")
testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}
application {
mainClass.set("SkijaInjectSample.AppKt")
}
tasks.named<JavaExec>("run") {
systemProperty("skiko.fps.enabled", "true")
System.getProperties().entries
.associate {
(it.key as String) to (it.value as String)
}
.filterKeys { it.startsWith("skiko.") }
.forEach { systemProperty(it.key, it.value) }
}
tasks.withType<Test> {
systemProperty("skiko.test.screenshots.dir", File(project.projectDir, "src/test/screenshots").absolutePath)
// Tests should be deterministic, so disable scaling.
// On MacOs we need the actual scale, otherwise we will have aliased screenshots because of scaling.
if (System.getProperty("os.name") != "Mac OS X") {
systemProperty("sun.java2d.dpiaware", "false")
systemProperty("sun.java2d.uiScale", "1")
}
}
\ No newline at end of file
/*
* This file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user manual at https://docs.gradle.org/6.5/userguide/multi_project_builds.html
*/
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
maven {
url "https://dl.bintray.com/kotlin/kotlin-eap"
}
}
}
rootProject.name = 'SkijaInjectSample'
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
maven {
url = uri("https://dl.bintray.com/kotlin/kotlin-eap")
}
}
}
rootProject.name = "SkijaInjectSample"
package org.jetbrains.skiko
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.File
import java.io.InputStreamReader
import java.nio.file.Files
import java.nio.file.StandardCopyOption
......@@ -52,6 +52,7 @@ object Library {
loadOrGet(cacheDir, resourcePath, "icudtl.dat", false)
}
// TODO move properties to SkikoProperties
Setup.init(
System.getProperty("skiko.rendering.noerasebackground") != "false",
System.getProperty("skiko.rendering.laf.global") == "true",
......
......@@ -77,15 +77,15 @@ open class SkiaLayer : HardwareLayer() {
}
private val fpsCounter = FPSCounter(
count = System.getProperty("skiko.fps.count")?.toInt() ?: 500,
probability = System.getProperty("skiko.fps.probability")?.toDouble() ?: 0.97
count = SkikoProperties.fpsCount,
probability = SkikoProperties.fpsProbability
)
override suspend fun update(nanoTime: Long) {
check(!isDisposed)
check(isEventDispatchThread())
if (System.getProperty("skiko.fps.enabled") == "true") {
if (SkikoProperties.fpsEnabled) {
fpsCounter.tick()
}
......
package org.jetbrains.skiko
@Suppress("SameParameterValue")
internal object SkikoProperties {
val vsyncEnabled: Boolean by property("skiko.vsync.enabled", default = true)
val fpsEnabled: Boolean by property("skiko.fps.enabled", default = false)
val fpsCount: Int by property("skiko.fps.count", default = 300)
val fpsProbability: Double by property("skiko.fps.probability", default = 0.97)
private fun property(name: String, default: Boolean) = lazy {
System.getProperty(name)?.toBoolean() ?: default
}
private fun property(name: String, default: Int) = lazy {
System.getProperty(name)?.toInt() ?: default
}
private fun property(name: String, default: Double) = lazy {
System.getProperty(name)?.toDouble() ?: default
}
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ import kotlinx.coroutines.withContext
import org.jetbrains.skiko.FrameDispatcher
import org.jetbrains.skiko.HardwareLayer
import org.jetbrains.skiko.OpenGLApi
import org.jetbrains.skiko.SkikoProperties
internal class LinuxRedrawer(
private val layer: HardwareLayer
......@@ -15,7 +16,7 @@ internal class LinuxRedrawer(
private val context = layer.lockDrawingSurface {
val context = it.createContext()
it.makeCurrent(context)
it.setSwapInterval(1)
it.setSwapInterval(if (SkikoProperties.vsyncEnabled) 1 else 0)
context
}
private var isDisposed = false
......
......@@ -6,6 +6,7 @@ import kotlinx.coroutines.swing.Swing
import org.jetbrains.skiko.FrameDispatcher
import org.jetbrains.skiko.HardwareLayer
import org.jetbrains.skiko.OpenGLApi
import org.jetbrains.skiko.SkikoProperties
import javax.swing.SwingUtilities.convertPoint
import javax.swing.SwingUtilities.getRootPane
......@@ -76,7 +77,9 @@ internal class MacOsRedrawer(
private val frameDispatcher = FrameDispatcher(Dispatchers.Swing) {
layer.update(System.nanoTime())
drawLayer.setNeedsDisplay()
vsyncLayer.sync()
if (SkikoProperties.vsyncEnabled) {
vsyncLayer.sync()
}
}
override fun dispose() = synchronized(drawLock) {
......
......@@ -8,6 +8,7 @@ import kotlinx.coroutines.withContext
import org.jetbrains.skiko.FrameDispatcher
import org.jetbrains.skiko.HardwareLayer
import org.jetbrains.skiko.OpenGLApi
import org.jetbrains.skiko.SkikoProperties
internal class WindowsRedrawer(
private val layer: HardwareLayer
......@@ -86,8 +87,10 @@ internal class WindowsRedrawer(
OpenGLApi.instance.glFinish()
}
withContext(Dispatchers.IO) {
dwmFlush() // wait for vsync
if (SkikoProperties.vsyncEnabled) {
withContext(Dispatchers.IO) {
dwmFlush() // wait for vsync
}
}
}
}
......
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