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
b6624360
Commit
b6624360
authored
Jan 13, 2021
by
Igor Demin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FPSCounter
parent
5c82039a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
0 deletions
+57
-0
build.gradle
samples/SkijaInjectSample/build.gradle
+4
-0
FPSCounter.kt
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/FPSCounter.kt
+44
-0
SkiaLayer.kt
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkiaLayer.kt
+9
-0
No files found.
samples/SkijaInjectSample/build.gradle
View file @
b6624360
...
@@ -53,3 +53,7 @@ dependencies {
...
@@ -53,3 +53,7 @@ dependencies {
application
{
application
{
mainClassName
=
'SkijaInjectSample.AppKt'
mainClassName
=
'SkijaInjectSample.AppKt'
}
}
run
{
systemProperty
(
"skiko.fps.enabled"
,
"true"
)
}
\ No newline at end of file
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/FPSCounter.kt
0 → 100644
View file @
b6624360
package
org.jetbrains.skiko
import
java.util.*
import
kotlin.math.roundToInt
internal
class
FPSCounter
(
private
val
count
:
Int
,
private
val
probability
:
Double
)
{
private
var
i
=
0
private
val
times
=
LinkedList
<
Double
>()
private
var
t1
=
System
.
nanoTime
()
/**
* [value] 0.0 - min, 1.0 - max, 0.5 - median
*/
private
fun
MutableList
<
Double
>.
quantile
(
value
:
Double
)
:
Double
{
sort
()
val
index
=
(
value
*
(
size
-
1
)).
toInt
()
return
this
[
index
]
}
fun
tick
()
{
val
t2
=
System
.
nanoTime
()
val
frameTime
=
(
t2
-
t1
)
/
1
E6
t1
=
t2
i
++
times
.
add
(
frameTime
)
if
(
times
.
size
>
count
)
{
times
.
removeFirst
()
}
if
(
i
%
count
==
0
)
{
val
quantile
=
(
1
-
probability
)
/
2.0
val
average
=
(
1000.0
/
times
.
average
()).
roundToInt
()
val
min
=
(
1000.0
/
times
.
quantile
(
1
-
quantile
)).
roundToInt
()
val
max
=
(
1000.0
/
times
.
quantile
(
quantile
)).
roundToInt
()
val
probability
=
(
100
*
probability
).
roundToInt
()
println
(
"FPS $average ($min-$max $probability%)"
)
}
}
}
\ No newline at end of file
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkiaLayer.kt
View file @
b6624360
...
@@ -50,7 +50,16 @@ open class SkiaLayer() : HardwareLayer() {
...
@@ -50,7 +50,16 @@ open class SkiaLayer() : HardwareLayer() {
renderer
?.
onDispose
()
renderer
?.
onDispose
()
}
}
private
val
fpsCounter
=
FPSCounter
(
count
=
System
.
getProperty
(
"skiko.fps.count"
)
?.
toInt
()
?:
500
,
probability
=
System
.
getProperty
(
"skiko.fps.probability"
)
?.
toDouble
()
?:
0.97
)
override
fun
draw
()
{
override
fun
draw
()
{
if
(
System
.
getProperty
(
"skiko.fps.enabled"
)
==
"true"
)
{
fpsCounter
.
tick
()
}
if
(!
inited
)
{
if
(!
inited
)
{
if
(
skijaState
.
context
==
null
)
{
if
(
skijaState
.
context
==
null
)
{
skijaState
.
context
=
when
(
api
)
{
skijaState
.
context
=
when
(
api
)
{
...
...
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