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
0a24e808
Commit
0a24e808
authored
Jan 18, 2021
by
Igor Demin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Vsync: review feedback
parent
1aecfc1a
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
19 additions
and
13 deletions
+19
-13
build.gradle
samples/SkijaInjectSample/build.gradle
+1
-1
SwingSkia.kt
...jectSample/src/main/kotlin/SkijaInjectSample/SwingSkia.kt
+2
-5
ScreenshotTestRule.kt
...src/test/kotlin/org/jetbrains/skiko/ScreenshotTestRule.kt
+4
-1
FPSCounter.kt
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/FPSCounter.kt
+1
-2
HardwareLayer.kt
...o/src/jvmMain/kotlin/org/jetbrains/skiko/HardwareLayer.kt
+8
-2
SkiaLayer.kt
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkiaLayer.kt
+1
-0
MacOsRedrawer.kt
...Main/kotlin/org/jetbrains/skiko/redrawer/MacOsRedrawer.kt
+2
-2
No files found.
samples/SkijaInjectSample/build.gradle
View file @
0a24e808
...
...
@@ -61,7 +61,7 @@ run {
test
{
systemProperty
(
"skiko.test.screenshots.dir"
,
new
File
(
project
.
projectDir
,
"src/test/screenshots"
).
absolutePath
)
// Tests should be determin
ed
, so disable scaling.
// Tests should be determin
istic
, 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"
)
...
...
samples/SkijaInjectSample/src/main/kotlin/SkijaInjectSample/SwingSkia.kt
View file @
0a24e808
...
...
@@ -7,10 +7,7 @@ import java.awt.event.ComponentAdapter
import
java.awt.event.ComponentEvent
import
java.awt.event.MouseEvent
import
java.awt.event.MouseMotionAdapter
import
javax.swing.JButton
import
javax.swing.JFrame
import
javax.swing.JPanel
import
javax.swing.WindowConstants
import
javax.swing.*
fun
Button
(
text
:
String
):
JButton
{
...
...
@@ -19,7 +16,7 @@ fun Button(text: String): JButton {
return
btn
}
fun
SwingSkia
()
{
fun
SwingSkia
()
=
SwingUtilities
.
invokeLater
{
val
window
=
JFrame
()
window
.
defaultCloseOperation
=
WindowConstants
.
EXIT_ON_CLOSE
...
...
samples/SkijaInjectSample/src/test/kotlin/org/jetbrains/skiko/ScreenshotTestRule.kt
View file @
0a24e808
...
...
@@ -8,7 +8,10 @@ import java.awt.Robot
import
java.io.File
import
javax.imageio.ImageIO
// TODO macOs has wrong colors. Only white, black, red and green are correct
// WARNING!!!
// macOS has wrong colors ([128, 128, 128] isn't [128, 128, 128] on screenshot). Only white, black, red and green are correct.
// So use only these color for cross-platform screenshots tests.
// TODO fix colors on macOS
class
ScreenshotTestRule
(
private
val
robot
:
Robot
)
:
TestRule
{
private
lateinit
var
testIdentifier
:
String
private
val
screenshotsDir
=
File
(
System
.
getProperty
(
"skiko.test.screenshots.dir"
)
!!
)
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/FPSCounter.kt
View file @
0a24e808
...
...
@@ -15,9 +15,8 @@ internal class FPSCounter(
* [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
]
return
sorted
()
[
index
]
}
fun
tick
()
{
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/HardwareLayer.kt
View file @
0a24e808
...
...
@@ -26,7 +26,7 @@ abstract class HardwareLayer : Canvas() {
private
fun
checkIsShowing
()
{
if
(!
isInit
&&
isShowing
)
{
_contentScale
=
platformOperations
.
getDpiScale
(
this
)
_contentScale
=
getDpiScale
(
)
init
()
isInit
=
true
}
...
...
@@ -38,13 +38,19 @@ abstract class HardwareLayer : Canvas() {
protected
open
fun
contentScaleChanged
()
=
Unit
override
fun
paint
(
g
:
Graphics
)
{
val
contentScale
=
platformOperations
.
getDpiScale
(
this
)
val
contentScale
=
getDpiScale
(
)
if
(
contentScale
!=
_contentScale
)
{
_contentScale
=
contentScale
contentScaleChanged
()
}
}
private
fun
getDpiScale
():
Float
{
val
scale
=
platformOperations
.
getDpiScale
(
this
)
check
(
scale
>
0
)
{
"HardwareLayer.contentScale isn't positive: $contentScale"
}
return
scale
}
// Should be called in Swing thread
internal
abstract
suspend
fun
update
(
nanoTime
:
Long
)
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkiaLayer.kt
View file @
0a24e808
...
...
@@ -42,6 +42,7 @@ open class SkiaLayer : HardwareLayer() {
private
val
pictureLock
=
Any
()
override
fun
init
()
{
super
.
init
()
redrawer
=
platformOperations
.
createHardwareRedrawer
(
this
)
redrawer
?.
syncSize
()
needRedraw
()
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/redrawer/MacOsRedrawer.kt
View file @
0a24e808
...
...
@@ -18,9 +18,9 @@ internal class MacOsRedrawer(
override
fun
draw
()
=
layer
.
draw
()
}
// use separate layer for vsync, because with single layer we cannot asynchronously update layer
// use
a
separate layer for vsync, because with single layer we cannot asynchronously update layer
// `update` is suspend, and runBlocking(Dispatchers.Swing) causes dead lock with AppKit Thread.
// AWT has
internal
method to avoid dead locks but it is internal (sun.lwawt.macosx.LWCToolkit.invokeAndWait)
// AWT has
a
method to avoid dead locks but it is internal (sun.lwawt.macosx.LWCToolkit.invokeAndWait)
private
val
vsyncLayer
=
object
:
AWTGLLayer
(
containerLayerPtr
)
{
@Volatile
private
var
needDraw
:
CompletableDeferred
<
Unit
>?
=
null
...
...
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