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
f96f8444
Commit
f96f8444
authored
May 22, 2021
by
Alexander Gorshenev
Committed by
alexander-gorshenev
Jun 04, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Native] Moved to 1.5.0 compiler branch.
Updated to a cleaner interop plugin syntax
parent
b898513c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
29 deletions
+30
-29
gradle.properties
samples/SkiaNativeSample/gradle.properties
+1
-1
App.kt
...osX64Main/kotlin/org.jetbrains.skiko.sample.native/App.kt
+8
-7
gradle.properties
skiko/gradle.properties
+1
-1
SkiaLayer.kt
.../src/macosX64Main/kotlin/org/jetbrains/skiko/SkiaLayer.kt
+4
-5
ContextHandler.kt
...Main/kotlin/org/jetbrains/skiko/context/ContextHandler.kt
+6
-6
OpenGLContextHandler.kt
...otlin/org/jetbrains/skiko/context/OpenGLContextHandler.kt
+10
-9
No files found.
samples/SkiaNativeSample/gradle.properties
View file @
f96f8444
kotlin.code.style
=
official
kotlin.code.style
=
official
kotlin.native.version
=
1.5.
30-dev-184
kotlin.native.version
=
1.5.
10-eap-81
samples/SkiaNativeSample/src/macosX64Main/kotlin/org.jetbrains.skiko.sample.native/App.kt
View file @
f96f8444
...
@@ -11,6 +11,9 @@ import kotlin.math.cos
...
@@ -11,6 +11,9 @@ import kotlin.math.cos
import
kotlin.math.sin
import
kotlin.math.sin
fun
main
(
args
:
Array
<
String
>)
{
fun
main
(
args
:
Array
<
String
>)
{
// TODO: Remove me! This is to run all cleaners before main() exits.
kotlin
.
native
.
internal
.
Debugging
.
forceCheckedShutdown
=
true
NSApplication
.
sharedApplication
()
NSApplication
.
sharedApplication
()
createWindow
(
"Skia/Native macos sample"
)
createWindow
(
"Skia/Native macos sample"
)
NSApp
?.
run
()
NSApp
?.
run
()
...
@@ -32,9 +35,9 @@ class Renderer(
...
@@ -32,9 +35,9 @@ class Renderer(
val
layer
:
SkiaLayer
,
val
layer
:
SkiaLayer
,
val
displayScene
:
(
Renderer
,
Int
,
Int
,
Long
)
->
Unit
val
displayScene
:
(
Renderer
,
Int
,
Int
,
Long
)
->
Unit
):
SkiaRenderer
{
):
SkiaRenderer
{
var
canvas
:
Sk
Canvas
?
=
null
var
canvas
:
Canvas
?
=
null
override
fun
onRender
(
canvas
:
Sk
Canvas
,
width
:
Int
,
height
:
Int
,
nanoTime
:
Long
)
{
override
fun
onRender
(
canvas
:
Canvas
,
width
:
Int
,
height
:
Int
,
nanoTime
:
Long
)
{
this
.
canvas
=
canvas
this
.
canvas
=
canvas
val
contentScale
=
layer
.
contentScale
val
contentScale
=
layer
.
contentScale
canvas
.
scale
(
contentScale
,
contentScale
)
canvas
.
scale
(
contentScale
,
contentScale
)
...
@@ -46,7 +49,7 @@ class Renderer(
...
@@ -46,7 +49,7 @@ class Renderer(
fun
displayScene
(
renderer
:
Renderer
,
nanoTime
:
Long
)
{
fun
displayScene
(
renderer
:
Renderer
,
nanoTime
:
Long
)
{
val
canvas
=
renderer
.
canvas
!!
val
canvas
=
renderer
.
canvas
!!
val
paint
=
Sk
Paint
()
val
paint
=
Paint
()
paint
.
setColor
(
SK_ColorGREEN
)
paint
.
setColor
(
SK_ColorGREEN
)
canvas
.
clear
(
SK_ColorRED
);
canvas
.
clear
(
SK_ColorRED
);
...
@@ -55,9 +58,7 @@ fun displayScene(renderer: Renderer, nanoTime: Long) {
...
@@ -55,9 +58,7 @@ fun displayScene(renderer: Renderer, nanoTime: Long) {
canvas
.
translate
(
128.0f
,
128.0f
)
canvas
.
translate
(
128.0f
,
128.0f
)
canvas
.
rotate
(
nanoTime
.
toFloat
()
/
1
e7f
)
canvas
.
rotate
(
nanoTime
.
toFloat
()
/
1
e7f
)
val
rect
=
SkRect
.
MakeXYWH
(-
90.5f
,
-
90.5f
,
181.0f
,
181.0f
)
val
rect
=
SkRect
.
MakeXYWH
(-
90.5f
,
-
90.5f
,
181.0f
,
181.0f
)
canvas
.
drawRect
(
rect
,
paint
.
ptr
)
canvas
.
drawRect
(
rect
,
paint
)
canvas
.
restore
();
canvas
.
restore
();
// TODO: need memory management.
// nativeHeap.free(paint)
}
}
skiko/gradle.properties
View file @
f96f8444
kotlin.code.style
=
official
kotlin.code.style
=
official
deploy.version
=
0.0.0
deploy.version
=
0.0.0
kotlin.native.version
=
1.5.
30-dev-184
kotlin.native.version
=
1.5.
10-eap-81
dependencies.skija.git.commit
=
adf4d3aac4402a32096cf0a79ed75a0dc82c796d
dependencies.skija.git.commit
=
adf4d3aac4402a32096cf0a79ed75a0dc82c796d
dependencies.skia.windows-x64
=
m91-71fcb16fc2/Skia-m91-71fcb16fc2-windows-Release-x64
dependencies.skia.windows-x64
=
m91-71fcb16fc2/Skia-m91-71fcb16fc2-windows-Release-x64
...
...
skiko/src/macosX64Main/kotlin/org/jetbrains/skiko/SkiaLayer.kt
View file @
f96f8444
...
@@ -7,11 +7,11 @@ import org.jetbrains.skiko.native.redrawer.*
...
@@ -7,11 +7,11 @@ import org.jetbrains.skiko.native.redrawer.*
import
org.jetbrains.skiko.skia.native.*
import
org.jetbrains.skiko.skia.native.*
interface
SkiaRenderer
{
interface
SkiaRenderer
{
fun
onRender
(
canvas
:
Sk
Canvas
,
width
:
Int
,
height
:
Int
,
nanoTime
:
Long
)
fun
onRender
(
canvas
:
Canvas
,
width
:
Int
,
height
:
Int
,
nanoTime
:
Long
)
}
}
// TODO: this is exact copy of jvm counterpart. Commonize!
// TODO: this is exact copy of jvm counterpart. Commonize!
private
class
PictureHolder
(
val
instance
:
Sk
Picture
,
val
width
:
Int
,
val
height
:
Int
)
private
class
PictureHolder
(
val
instance
:
Picture
,
val
width
:
Int
,
val
height
:
Int
)
open
class
SkiaLayer
(
open
class
SkiaLayer
(
private
val
properties
:
SkiaLayerProperties
=
SkiaLayerProperties
()
private
val
properties
:
SkiaLayerProperties
=
SkiaLayerProperties
()
...
@@ -25,7 +25,7 @@ open class SkiaLayer(
...
@@ -25,7 +25,7 @@ open class SkiaLayer(
private
var
redrawer
:
Redrawer
?
=
null
private
var
redrawer
:
Redrawer
?
=
null
private
var
picture
:
PictureHolder
?
=
null
private
var
picture
:
PictureHolder
?
=
null
private
val
pictureRecorder
=
Sk
PictureRecorder
()
private
val
pictureRecorder
=
PictureRecorder
()
private
val
pictureLock
=
Any
()
private
val
pictureLock
=
Any
()
override
fun
init
()
{
override
fun
init
()
{
...
@@ -56,8 +56,7 @@ open class SkiaLayer(
...
@@ -56,8 +56,7 @@ open class SkiaLayer(
val
bounds
=
SkRect
.
MakeWH
(
pictureWidth
.
toFloat
(),
pictureHeight
.
toFloat
())
val
bounds
=
SkRect
.
MakeWH
(
pictureWidth
.
toFloat
(),
pictureHeight
.
toFloat
())
val
canvas
=
pictureRecorder
.
beginRecording
(
bounds
,
null
)
!!
val
canvas
=
pictureRecorder
.
beginRecording
(
bounds
,
null
)
!!
// TODO: get rid of .pointed?
renderer
?.
onRender
(
canvas
,
pictureWidth
.
toInt
(),
pictureHeight
.
toInt
(),
nanoTime
)
renderer
?.
onRender
(
canvas
.
pointed
,
pictureWidth
.
toInt
(),
pictureHeight
.
toInt
(),
nanoTime
)
val
picture
=
pictureRecorder
.
finishRecordingAsPicture
()
!!
val
picture
=
pictureRecorder
.
finishRecordingAsPicture
()
!!
this
.
picture
=
PictureHolder
(
picture
,
pictureWidth
.
toInt
(),
pictureHeight
.
toInt
())
this
.
picture
=
PictureHolder
(
picture
,
pictureWidth
.
toInt
(),
pictureHeight
.
toInt
())
...
...
skiko/src/macosX64Main/kotlin/org/jetbrains/skiko/context/ContextHandler.kt
View file @
f96f8444
...
@@ -18,10 +18,10 @@ internal abstract class ContextHandler(val layer: HardwareLayer) {
...
@@ -18,10 +18,10 @@ internal abstract class ContextHandler(val layer: HardwareLayer) {
// TODO: hostOs is all written in jdk kotlin.
// TODO: hostOs is all written in jdk kotlin.
// open val bleachConstant = if (hostOs == OS.MacOS) 0 else -1
// open val bleachConstant = if (hostOs == OS.MacOS) 0 else -1
open
val
bleachConstant
=
0
U
open
val
bleachConstant
=
0
U
var
context
:
Gr
DirectContext
?
=
null
var
context
:
DirectContext
?
=
null
var
renderTarget
:
Gr
BackendRenderTarget
?
=
null
var
renderTarget
:
BackendRenderTarget
?
=
null
var
surface
:
S
kS
urface
?
=
null
var
surface
:
Surface
?
=
null
var
canvas
:
Sk
Canvas
?
=
null
var
canvas
:
Canvas
?
=
null
abstract
fun
initContext
():
Boolean
abstract
fun
initContext
():
Boolean
...
@@ -32,9 +32,9 @@ internal abstract class ContextHandler(val layer: HardwareLayer) {
...
@@ -32,9 +32,9 @@ internal abstract class ContextHandler(val layer: HardwareLayer) {
canvas
?.
clear
(
bleachConstant
)
canvas
?.
clear
(
bleachConstant
)
}
}
open
fun
drawOnCanvas
(
picture
:
Sk
Picture
)
{
open
fun
drawOnCanvas
(
picture
:
Picture
)
{
println
(
"ContextHandler::drawOnCanvas"
)
println
(
"ContextHandler::drawOnCanvas"
)
canvas
?.
drawPicture
(
picture
.
ptr
)
canvas
?.
drawPicture
(
picture
)
}
}
open
fun
flush
()
{
open
fun
flush
()
{
...
...
skiko/src/macosX64Main/kotlin/org/jetbrains/skiko/context/OpenGLContextHandler.kt
View file @
f96f8444
...
@@ -14,7 +14,7 @@ internal class OpenGLContextHandler(layer: HardwareLayer) : ContextHandler(layer
...
@@ -14,7 +14,7 @@ internal class OpenGLContextHandler(layer: HardwareLayer) : ContextHandler(layer
println
(
"OpenGLContextHandler::initContext"
)
println
(
"OpenGLContextHandler::initContext"
)
try
{
try
{
if
(
context
==
null
)
{
if
(
context
==
null
)
{
context
=
Gr
DirectContext
.
MakeGL
()
context
=
DirectContext
.
MakeGL
()
}
}
}
catch
(
e
:
Exception
)
{
}
catch
(
e
:
Exception
)
{
println
(
"Failed to create Skia OpenGL context!"
)
println
(
"Failed to create Skia OpenGL context!"
)
...
@@ -51,22 +51,23 @@ internal class OpenGLContextHandler(layer: HardwareLayer) : ContextHandler(layer
...
@@ -51,22 +51,23 @@ internal class OpenGLContextHandler(layer: HardwareLayer) : ContextHandler(layer
val
glInfo
:
GrGLFramebufferInfo
=
alloc
<
GrGLFramebufferInfo
>()
val
glInfo
:
GrGLFramebufferInfo
=
alloc
<
GrGLFramebufferInfo
>()
glInfo
.
fFBOID
=
fbId
glInfo
.
fFBOID
=
fbId
glInfo
.
fFormat
=
GL_RGBA8
.
toUInt
()
glInfo
.
fFormat
=
GL_RGBA8
.
toUInt
()
renderTarget
=
Gr
BackendRenderTarget
(
w
,
h
,
0
,
8
,
glInfo
.
readValue
())
renderTarget
=
BackendRenderTarget
(
w
,
h
,
0
,
8
,
glInfo
.
readValue
())
}
}
surface
=
S
kS
urface
.
MakeFromBackendRenderTarget
(
surface
=
Surface
.
MakeFromBackendRenderTarget
(
// TODO: C++ interop knows nothing about inheritance.
// TODO: C++ interop knows nothing about inheritance.
context
!!
.
ptr
.
reinterpret
<
GrRecordingContext
>(),
// As a bare minimum have an extension function for such conversions.
renderTarget
!!
.
ptr
,
RecordingContext
(
context
!!
.
cpp
.
ptr
.
reinterpret
<
GrRecordingContext
>().
pointed
,
managed
=
false
),
renderTarget
!!
,
GrSurfaceOrigin
.
kBottomLeft_GrSurfaceOrigin
,
GrSurfaceOrigin
.
kBottomLeft_GrSurfaceOrigin
,
colorType
=
kRGBA_8888_SkColorType
,
colorType
=
kRGBA_8888_SkColorType
,
colorSpace
=
Sk
ColorSpace
.
MakeSRGB
(),
colorSpace
=
ColorSpace
.
MakeSRGB
(),
surfaceProps
=
null
,
surfaceProps
=
null
,
releaseProc
=
null
,
releaseProc
=
null
,
releaseContext
=
null
releaseContext
=
null
)
?:
error
(
"Could not obtain S
kS
urface"
)
)
?:
error
(
"Could not obtain Surface"
)
canvas
=
surface
!!
.
getCanvas
()
?.
pointed
canvas
=
surface
!!
.
getCanvas
()
?:
error
(
"Could not obtain
SkCanvas from Sk
Surface"
)
?:
error
(
"Could not obtain
Canvas from
Surface"
)
}
}
}
}
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