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
46716ddb
Unverified
Commit
46716ddb
authored
Oct 22, 2021
by
Roman Sedaikin
Committed by
GitHub
Oct 22, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added DPI support on macos-native. Fixed closing application on macos-native. (#298)
parent
7b51fa16
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
12 deletions
+56
-12
App.macos.kt
.../macosMain/kotlin/org/jetbrains/skiko/sample/App.macos.kt
+9
-3
SkiaLayer.macos.kt
...c/macosMain/kotlin/org/jetbrains/skiko/SkiaLayer.macos.kt
+21
-2
OpenGLRedrawer.macos.kt
...tlin/org/jetbrains/skiko/redrawer/OpenGLRedrawer.macos.kt
+26
-7
No files found.
samples/SkiaMultiplatformSample/src/macosMain/kotlin/org/jetbrains/skiko/sample/App.macos.kt
View file @
46716ddb
...
...
@@ -6,11 +6,17 @@ import org.jetbrains.skia.*
import
org.jetbrains.skiko.*
import
kotlinx.cinterop.*
import
platform.Foundation.NSMakeRect
import
platform.darwin.NSObject
fun
makeApp
()
=
BouncingBalls
(
true
)
fun
makeApp
()
=
Clocks
(
)
fun
main
()
{
NSApplication
.
sharedApplication
()
val
app
=
NSApplication
.
sharedApplication
()
app
.
delegate
=
object
:
NSObject
(),
NSApplicationDelegateProtocol
{
override
fun
applicationShouldTerminateAfterLastWindowClosed
(
sender
:
NSApplication
):
Boolean
{
return
true
}
}
val
windowStyle
=
NSWindowStyleMaskTitled
or
NSWindowStyleMaskMiniaturizable
or
NSWindowStyleMaskClosable
or
...
...
@@ -24,5 +30,5 @@ fun main() {
skiaLayer
.
skikoView
=
GenericSkikoView
(
skiaLayer
,
makeApp
())
skiaLayer
.
attachTo
(
window
)
window
.
orderFrontRegardless
()
NSApp
?
.
run
()
app
.
run
()
}
skiko/src/macosMain/kotlin/org/jetbrains/skiko/SkiaLayer.macos.kt
View file @
46716ddb
...
...
@@ -7,17 +7,19 @@ import org.jetbrains.skia.*
import
org.jetbrains.skiko.redrawer.Redrawer
import
platform.AppKit.*
import
platform.Foundation.NSMakeRect
import
platform.Foundation.NSNotification
import
platform.Foundation.NSNotificationCenter
import
platform.Foundation.NSSelectorFromString
import
platform.Foundation.addObserver
import
platform.darwin.NSObject
import
platform.CoreGraphics.CGRectMake
actual
open
class
SkiaLayer
(
private
val
properties
:
SkiaLayerProperties
=
makeDefaultSkiaLayerProperties
()
)
{
actual
var
renderApi
:
GraphicsApi
=
GraphicsApi
.
OPENGL
actual
val
contentScale
:
Float
get
()
=
_contentScale
get
()
=
if
(
this
::
nsView
.
isInitialized
)
nsView
.
window
!!
.
backingScaleFactor
.
toFloat
()
else
1.0f
actual
var
fullscreen
:
Boolean
get
()
=
false
...
...
@@ -32,7 +34,6 @@ actual open class SkiaLayer(
}
lateinit
var
nsView
:
NSView
var
_contentScale
:
Float
=
1.0f
actual
var
skikoView
:
SkikoView
?
=
null
...
...
@@ -123,8 +124,26 @@ actual open class SkiaLayer(
val
center
=
NSNotificationCenter
.
defaultCenter
()
center
.
addObserver
(
nsView
,
NSSelectorFromString
(
"onWindowClose:"
),
NSWindowWillCloseNotification
!!
,
window
)
window
.
delegate
=
object
:
NSObject
(),
NSWindowDelegateProtocol
{
override
fun
windowDidResize
(
notification
:
NSNotification
)
{
val
(
w
,
h
)
=
window
.
contentView
!!
.
frame
.
useContents
{
size
.
width
to
size
.
height
}
nsView
.
frame
=
CGRectMake
(
0.0
,
0.0
,
w
,
h
)
redrawer
?.
syncSize
()
initedCanvas
=
false
redrawer
?.
redrawImmediately
()
}
override
fun
windowDidChangeBackingProperties
(
notification
:
NSNotification
)
{
redrawer
?.
syncSize
()
initedCanvas
=
false
redrawer
?.
redrawImmediately
()
}
}
window
.
contentView
!!
.
addSubview
(
nsView
)
redrawer
=
createNativeRedrawer
(
this
,
GraphicsApi
.
OPENGL
,
properties
).
apply
{
syncSize
()
needRedraw
()
}
}
...
...
skiko/src/macosMain/kotlin/org/jetbrains/skiko/redrawer/OpenGLRedrawer.macos.kt
View file @
46716ddb
...
...
@@ -20,7 +20,11 @@ internal class MacOsOpenGLRedrawer(
private
val
skiaLayer
:
SkiaLayer
,
private
val
properties
:
SkiaLayerProperties
)
:
Redrawer
{
private
val
glLayer
=
MacosGLLayer
(
skiaLayer
)
private
val
glLayer
=
MacosGLLayer
()
init
{
glLayer
.
init
(
skiaLayer
)
}
private
val
frameDispatcher
=
FrameDispatcher
(
SkikoDispatchers
.
Main
)
{
redrawImmediately
()
...
...
@@ -31,7 +35,7 @@ internal class MacOsOpenGLRedrawer(
}
override
fun
syncSize
()
{
// TODO: What do we really do here?
syncContentScale
()
skiaLayer
.
nsView
.
frame
.
useContents
{
glLayer
.
setFrame
(
origin
.
x
.
toInt
(),
...
...
@@ -42,6 +46,14 @@ internal class MacOsOpenGLRedrawer(
}
}
private
fun
syncContentScale
()
{
CATransaction
.
begin
()
CATransaction
.
setDisableActions
(
true
)
glLayer
.
contentsScale
=
skiaLayer
.
nsView
.
window
!!
.
backingScaleFactor
CATransaction
.
commit
()
CATransaction
.
flush
()
}
override
fun
needRedraw
()
{
frameDispatcher
.
scheduleFrame
()
}
...
...
@@ -52,22 +64,29 @@ internal class MacOsOpenGLRedrawer(
}
}
internal
class
MacosGLLayer
(
val
layer
:
SkiaLayer
)
:
CAOpenGLLayer
()
{
init
{
internal
class
MacosGLLayer
:
CAOpenGLLayer
{
private
lateinit
var
layer
:
SkiaLayer
@OverrideInit
constructor
():
super
()
@OverrideInit
constructor
(
layer
:
Any
):
super
(
layer
)
fun
init
(
layer
:
SkiaLayer
)
{
this
.
layer
=
layer
this
.
setNeedsDisplayOnBoundsChange
(
true
)
this
.
removeAllAnimations
()
this
.
setAutoresizingMask
(
kCALayerWidthSizable
or
kCALayerHeightSizable
)
layer
.
nsView
.
layer
=
this
layer
.
nsView
.
wantsLayer
=
true
this
.
contentsGravity
=
kCAGravityTopLeft
;
}
fun
setFrame
(
x
:
Int
,
y
:
Int
,
width
:
Int
,
height
:
Int
)
{
val
newY
=
layer
.
nsView
.
frame
.
useContents
{
size
.
height
}
-
y
-
height
CATransaction
.
begin
()
CATransaction
.
setDisableActions
(
true
)
this
.
frame
=
CGRectMake
(
x
.
toDouble
(),
newY
,
width
.
toDouble
(),
height
.
toDouble
())
this
.
frame
=
CGRectMake
(
x
.
toDouble
(),
y
.
toDouble
()
,
width
.
toDouble
(),
height
.
toDouble
())
CATransaction
.
commit
()
CATransaction
.
flush
()
}
fun
dispose
()
{
...
...
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