Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
skiko
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liuqiang
skiko
Commits
5bc7d314
Unverified
Commit
5bc7d314
authored
Jul 24, 2021
by
Nikolay Igotti
Committed by
GitHub
Jul 24, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create automated background memory manager. (#141)
parent
cd99819e
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
4 deletions
+54
-4
build.gradle.kts
skiko/build.gradle.kts
+2
-1
FrameWatcher.kt
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/FrameWatcher.kt
+41
-0
Setup.kt
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Setup.kt
+7
-2
SkiaLayer.kt
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkiaLayer.kt
+1
-0
SeveralClassloaders.kt
...jvmTest/kotlin/org/jetbrains/skiko/SeveralClassloaders.kt
+3
-1
No files found.
skiko/build.gradle.kts
View file @
5bc7d314
...
@@ -13,7 +13,7 @@ plugins {
...
@@ -13,7 +13,7 @@ plugins {
id
(
"de.undercouch.download"
)
version
"4.1.1"
id
(
"de.undercouch.download"
)
version
"4.1.1"
}
}
val
coroutinesVersion
=
"1.
4.1
"
val
coroutinesVersion
=
"1.
5.0
"
buildscript
{
buildscript
{
dependencies
{
dependencies
{
...
@@ -556,6 +556,7 @@ val createChecksums by project.tasks.registering(org.gradle.crypto.checksum.Chec
...
@@ -556,6 +556,7 @@ val createChecksums by project.tasks.registering(org.gradle.crypto.checksum.Chec
}
}
val
skikoJvmRuntimeJar
by
project
.
tasks
.
registering
(
Jar
::
class
)
{
val
skikoJvmRuntimeJar
by
project
.
tasks
.
registering
(
Jar
::
class
)
{
dependsOn
(
createChecksums
)
archiveBaseName
.
set
(
"skiko-$target"
)
archiveBaseName
.
set
(
"skiko-$target"
)
from
(
skikoJvmJar
.
map
{
zipTree
(
it
.
archiveFile
)
})
from
(
skikoJvmJar
.
map
{
zipTree
(
it
.
archiveFile
)
})
from
(
maybeSign
.
get
().
outputs
.
files
)
from
(
maybeSign
.
get
().
outputs
.
files
)
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/FrameWatcher.kt
0 → 100644
View file @
5bc7d314
package
org.jetbrains.skiko
import
kotlinx.coroutines.*
import
java.util.concurrent.atomic.AtomicInteger
/**
* This class is intended to mitigate issues coming from the situation that we have
* pretty large native peers (Skia objects) for rather tiny Java wrappers.
* It is especially visible for situation with paragraph classes.
* As a result, memory consumption grows dramatically.
* To solve this issue, we force periodic GC if certain amount of frames was rendered,
* making sure that we'll have memory consumption under control.
*/
internal
object
FrameWatcher
{
var
gcDelayMillis
=
30
_000L
var
minFramesToRenderer
=
1
_000
fun
start
()
{
// We initiate GC on IO threads, so that rendering is not blocked in
// cases of concurrent collectors.
@OptIn
(
DelicateCoroutinesApi
::
class
)
GlobalScope
.
launch
(
Dispatchers
.
IO
)
{
while
(
true
)
{
// Wait some time between collection attempts.
delay
(
gcDelayMillis
)
// Ensure that certain number of frames were rendered, as we allocate Skia
// garbage when rendering.
if
(
frameCounter
.
get
()
>
minFramesToRenderer
)
{
System
.
gc
()
frameCounter
.
set
(
0
)
}
}
}
}
fun
nextFrame
()
{
frameCounter
.
addAndGet
(
1
)
}
private
val
frameCounter
=
AtomicInteger
(
0
)
}
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Setup.kt
View file @
5bc7d314
...
@@ -2,12 +2,13 @@ package org.jetbrains.skiko
...
@@ -2,12 +2,13 @@ package org.jetbrains.skiko
import
javax.swing.UIManager
import
javax.swing.UIManager
object
Setup
{
internal
object
Setup
{
fun
init
(
fun
init
(
noEraseBackground
:
Boolean
=
System
.
getProperty
(
"skiko.rendering.noerasebackground"
)
!=
"false"
,
noEraseBackground
:
Boolean
=
System
.
getProperty
(
"skiko.rendering.noerasebackground"
)
!=
"false"
,
globalLAF
:
Boolean
=
System
.
getProperty
(
"skiko.rendering.laf.global"
)
==
"true"
,
globalLAF
:
Boolean
=
System
.
getProperty
(
"skiko.rendering.laf.global"
)
==
"true"
,
useScreenMenuBar
:
Boolean
=
System
.
getProperty
(
"skiko.rendering.useScreenMenuBar"
)
!=
"false"
,
useScreenMenuBar
:
Boolean
=
System
.
getProperty
(
"skiko.rendering.useScreenMenuBar"
)
!=
"false"
,
autoLinuxDpi
:
Boolean
=
System
.
getProperty
(
"skiko.linux.autodpi"
)
==
"true"
autoLinuxDpi
:
Boolean
=
System
.
getProperty
(
"skiko.linux.autodpi"
)
==
"true"
,
automateGC
:
Boolean
=
System
.
getProperty
(
"skiko.gc.auto"
)
!=
"false"
)
{
)
{
if
(
hostOs
==
OS
.
Linux
&&
autoLinuxDpi
)
{
if
(
hostOs
==
OS
.
Linux
&&
autoLinuxDpi
)
{
val
scale
=
linuxGetSystemDpiScale
()
val
scale
=
linuxGetSystemDpiScale
()
...
@@ -29,6 +30,10 @@ object Setup {
...
@@ -29,6 +30,10 @@ object Setup {
}
catch
(
e
:
UnsupportedOperationException
)
{
}
catch
(
e
:
UnsupportedOperationException
)
{
// Not all platforms allow this.
// Not all platforms allow this.
}
}
if
(
automateGC
)
{
FrameWatcher
.
start
()
}
}
}
}
}
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkiaLayer.kt
View file @
5bc7d314
...
@@ -350,6 +350,7 @@ open class SkiaLayer(
...
@@ -350,6 +350,7 @@ open class SkiaLayer(
}
}
flush
()
flush
()
}
}
FrameWatcher
.
nextFrame
()
}
}
// Captures current layer as bitmap.
// Captures current layer as bitmap.
...
...
skiko/src/jvmTest/kotlin/org/jetbrains/skiko/SeveralClassloaders.kt
View file @
5bc7d314
...
@@ -101,7 +101,9 @@ class SeveralClassloaders {
...
@@ -101,7 +101,9 @@ class SeveralClassloaders {
val
jar
=
System
.
getProperty
(
"skiko.jar.path"
)
val
jar
=
System
.
getProperty
(
"skiko.jar.path"
)
val
stdlibClass
=
Class
.
forName
(
"kotlin.jvm.internal.Intrinsics"
)
val
stdlibClass
=
Class
.
forName
(
"kotlin.jvm.internal.Intrinsics"
)
val
stdLibJar
=
stdlibClass
.
protectionDomain
.
codeSource
.
location
val
stdLibJar
=
stdlibClass
.
protectionDomain
.
codeSource
.
location
val
urls
=
listOf
(
Paths
.
get
(
jar
).
toUri
().
toURL
(),
stdLibJar
)
val
coroutinesClass
=
Class
.
forName
(
"kotlinx.coroutines.CoroutineDispatcher"
)
val
coroutinesJar
=
coroutinesClass
.
protectionDomain
.
codeSource
.
location
val
urls
=
listOf
(
Paths
.
get
(
jar
).
toUri
().
toURL
(),
stdLibJar
,
coroutinesJar
)
val
loaders
=
mutableListOf
<
ClassLoader
>()
val
loaders
=
mutableListOf
<
ClassLoader
>()
repeat
(
4
)
{
repeat
(
4
)
{
loaders
+=
PlatformAndURLClassLoader
(
urls
)
loaders
+=
PlatformAndURLClassLoader
(
urls
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment