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
80002b14
Commit
80002b14
authored
Feb 03, 2021
by
Igor Demin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Encapsulate CompletableDeferred into Task
parent
930ab399
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
8 deletions
+26
-8
MacOsOpenGLRedrawer.kt
...otlin/org/jetbrains/skiko/redrawer/MacOsOpenGLRedrawer.kt
+26
-8
No files found.
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/redrawer/MacOsOpenGLRedrawer.kt
View file @
80002b14
...
...
@@ -120,8 +120,7 @@ private abstract class AWTGLLayer(private val containerPtr: Long, setNeedsDispla
@Suppress
(
"LeakingThis"
)
val
ptr
=
initAWTGLLayer
(
containerPtr
,
this
,
setNeedsDisplayOnBoundsChange
)
@Volatile
private
var
onDraw
:
CompletableDeferred
<
Unit
>?
=
null
private
val
display
=
Task
()
fun
setFrame
(
x
:
Int
,
y
:
Int
,
width
:
Int
,
height
:
Int
)
{
setFrame
(
containerPtr
,
ptr
,
x
.
toFloat
(),
y
.
toFloat
(),
width
.
toFloat
(),
height
.
toFloat
())
...
...
@@ -136,12 +135,8 @@ private abstract class AWTGLLayer(private val containerPtr: Long, setNeedsDispla
open
fun
setNeedsDisplay
()
=
setNeedsDisplayOnMainThread
(
ptr
)
suspend
fun
display
()
{
check
(
onDraw
==
null
)
onDraw
=
CompletableDeferred
()
suspend
fun
display
()
=
display
.
runAndAwait
{
setNeedsDisplay
()
onDraw
!!
.
await
()
onDraw
=
null
}
// Called in AppKit Thread
...
...
@@ -154,7 +149,7 @@ private abstract class AWTGLLayer(private val containerPtr: Long, setNeedsDispla
}
catch
(
e
:
Throwable
)
{
e
.
printStackTrace
()
}
onDraw
?.
complete
(
Unit
)
display
.
finish
(
)
}
// Called in AppKit Thread
...
...
@@ -170,3 +165,26 @@ private external fun initContainer(layer: HardwareLayer): Long
private
external
fun
setContentScale
(
layerNativePtr
:
Long
,
contentScale
:
Float
)
private
external
fun
initAWTGLLayer
(
containerPtr
:
Long
,
layer
:
AWTGLLayer
,
setNeedsDisplayOnBoundsChange
:
Boolean
):
Long
private
external
fun
disposeAWTGLLayer
(
ptr
:
Long
)
internal
class
Task
{
@Volatile
private
var
onFinish
:
CompletableDeferred
<
Unit
>?
=
null
/**
* Run task and await its finishing (i.e. calling of [finish])
*/
suspend
fun
runAndAwait
(
run
:
suspend
()
->
Unit
)
{
check
(
onFinish
==
null
)
onFinish
=
CompletableDeferred
()
run
()
onFinish
!!
.
await
()
onFinish
=
null
}
/**
* Finish running task. If there is no running task, do nothing.
*/
fun
finish
()
{
onFinish
?.
complete
(
Unit
)
}
}
\ No newline at end of file
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