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
2e73540a
Commit
2e73540a
authored
Aug 06, 2020
by
Nikolay Igotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Further simplification.
parent
a69f27f2
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
26 additions
and
109 deletions
+26
-109
App.kt
...kijaInjectSample/src/main/kotlin/SkijaInjectSample/App.kt
+1
-4
Engine.kt
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Engine.kt
+0
-49
HardwareLayer.kt
...o/src/jvmMain/kotlin/org/jetbrains/skiko/HardwareLayer.kt
+5
-2
Library.kt
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Library.kt
+1
-27
OSType.kt
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/OSType.kt
+6
-15
OpenGLApi.kt
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/OpenGLApi.kt
+1
-7
SkiaWindow.kt
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkiaWindow.kt
+7
-3
drawlayer.m
skiko/src/jvmMain/objectiveC/macos/drawlayer.m
+5
-2
No files found.
samples/SkijaInjectSample/src/main/kotlin/SkijaInjectSample/App.kt
View file @
2e73540a
package
SkijaInjectSample
import
org.jetbrains.skiko.OpenGLApi
import
org.jetbrains.skiko.Engine
import
org.jetbrains.skiko.SkiaWindow
import
java.awt.event.MouseEvent
...
...
@@ -18,7 +16,6 @@ fun main(args: Array<String>) {
}
fun
createWindow
(
title
:
String
)
{
val
engine
:
Engine
=
Engine
.
get
()
var
mouseX
=
0
var
mouseY
=
0
...
...
@@ -37,7 +34,7 @@ fun createWindow(title: String) {
override
fun
mouseMoved
(
event
:
MouseEvent
)
{
mouseX
=
event
.
x
mouseY
=
event
.
y
engine
.
render
(
window
.
layer
)
window
.
display
(
)
}
})
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Engine.kt
deleted
100644 → 0
View file @
a69f27f2
package
org.jetbrains.skiko
class
Engine
private
constructor
()
{
private
var
api
=
GraphicsApi
.
UNKNOWN
fun
currentApi
():
GraphicsApi
{
return
api
}
/**
* GAG - At the moment always initializes OpenGL.
* @param osType The current OS type of the device.
*/
private
fun
initSuitableGraphicsApi
(
osType
:
OSType
)
{
when
{
osType
===
OSType
.
MAC_OS
->
{
OpenGLApi
.
get
()
// for Metal
instance
.
api
=
GraphicsApi
.
OPENGL
}
osType
===
OSType
.
LINUX
->
{
OpenGLApi
.
get
()
// for Vulkan and OpenGL
instance
.
api
=
GraphicsApi
.
OPENGL
}
osType
===
OSType
.
WINDOWS
->
{
OpenGLApi
.
get
()
// for Vulkan and OpenGL
instance
.
api
=
GraphicsApi
.
OPENGL
}
else
->
{
OpenGLApi
.
get
()
// default
instance
.
api
=
GraphicsApi
.
OPENGL
}
}
}
fun
render
(
drawable
:
Drawable
)
{
drawable
.
updateLayer
()
drawable
.
redrawLayer
()
}
companion
object
{
private
lateinit
var
instance
:
Engine
fun
get
():
Engine
{
if
(!
this
::
instance
.
isInitialized
)
{
instance
=
Engine
()
instance
.
initSuitableGraphicsApi
(
OSType
.
getCurrent
())
}
return
instance
}
}
}
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/HardwareLayer.kt
View file @
2e73540a
...
...
@@ -5,9 +5,12 @@ import java.awt.Canvas
open
class
HardwareLayer
:
Canvas
(),
Drawable
{
override
fun
paint
(
g
:
Graphics
)
{
Engine
.
get
().
render
(
this
)
display
()
}
open
fun
display
()
{
this
.
updateLayer
()
this
.
redrawLayer
()
}
open
fun
draw
()
{}
external
override
fun
redrawLayer
()
external
override
fun
updateLayer
()
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Library.kt
View file @
2e73540a
...
...
@@ -14,7 +14,7 @@ object Library {
fun
load
(
resourcePath
:
String
,
name
:
String
)
{
if
(
loaded
)
return
val
libFileName
=
"$libPrefix$name$libExtension"
val
libFileName
=
System
.
mapLibraryName
(
name
)
val
url
=
Library
::
class
.
java
.
getResource
(
resourcePath
+
libFileName
)
val
libFile
=
when
{
url
==
null
->
error
(
"Library $libFileName is not found in $resourcePath"
)
...
...
@@ -28,33 +28,7 @@ object Library {
}
}
}
//println("Loading $url from ${libFile.absolutePath}")
System
.
load
(
libFile
.
absolutePath
)
loaded
=
true
}
private
val
libPrefix
:
String
get
()
=
if
(
currentOS
==
OS
.
Windows
)
""
else
"lib"
private
val
libExtension
:
String
get
()
=
when
(
currentOS
)
{
OS
.
Mac
->
".dylib"
OS
.
Linux
->
".so"
OS
.
Windows
->
".dll"
}
private
val
currentOS
by
lazy
{
val
osName
=
System
.
getProperty
(
"os.name"
)
?:
error
(
"Unknown OS: 'os.name' is null"
)
val
os
=
osName
.
toLowerCase
(
Locale
.
ROOT
)
when
{
os
.
contains
(
"mac"
)
||
os
.
contains
(
"darwin"
)
->
OS
.
Mac
os
.
contains
(
"win"
)
->
OS
.
Windows
os
.
contains
(
"nux"
)
->
OS
.
Linux
else
->
error
(
"Unknown OS: $osName"
)
}
}
private
enum
class
OS
{
Linux
,
Mac
,
Windows
}
}
\ No newline at end of file
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/OSType.kt
View file @
2e73540a
...
...
@@ -4,25 +4,16 @@ enum class OSType {
MAC_OS
,
LINUX
,
WINDOWS
,
UNKNOWN
;
companion
object
{
private
lateinit
var
currentOSType
:
OSType
fun
getCurrent
():
OSType
{
if
(!
this
::
currentOSType
.
isInitialized
)
{
currentOSType
=
defineOsType
()
}
return
currentOSType
}
val
currentOs
=
defineOsType
()
private
fun
defineOsType
():
OSType
{
val
osName
=
System
.
getProperty
(
"os.name"
).
toLowerCase
()
if
(
isWindows
(
osName
))
{
return
WINDOWS
}
if
(
isMac
(
osName
))
{
return
MAC_OS
return
when
{
isWindows
(
osName
)
->
WINDOWS
isMac
(
osName
)
->
MAC_OS
isUnix
(
osName
)
->
LINUX
else
->
UNKNOWN
}
return
if
(
isUnix
(
osName
))
{
LINUX
}
else
UNKNOWN
}
private
fun
isWindows
(
name
:
String
):
Boolean
{
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/OpenGLApi.kt
View file @
2e73540a
...
...
@@ -22,12 +22,6 @@ class OpenGLApi private constructor() {
external
fun
glGetIntegerv
(
pname
:
Int
):
Int
companion
object
{
private
lateinit
var
instance
:
OpenGLApi
fun
get
():
OpenGLApi
{
if
(!
this
::
instance
.
isInitialized
)
{
instance
=
OpenGLApi
()
}
return
instance
}
val
instance
=
OpenGLApi
()
}
}
\ No newline at end of file
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkiaWindow.kt
View file @
2e73540a
...
...
@@ -57,7 +57,7 @@ open class SkiaLayer : HardwareLayer() {
}
skijaState
.
apply
{
val
gl
=
OpenGLApi
.
get
()
val
gl
=
OpenGLApi
.
instance
gl
.
glClearColor
(
1.0f
,
1.0f
,
1.0f
,
1.0f
)
gl
.
glClear
(
gl
.
GL_COLOR_BUFFER_BIT
)
...
...
@@ -72,7 +72,7 @@ open class SkiaLayer : HardwareLayer() {
private
fun
initSkija
()
{
val
dpi
=
contentScale
skijaState
.
clear
()
val
gl
:
OpenGLApi
=
OpenGLApi
.
get
()
val
gl
:
OpenGLApi
=
OpenGLApi
.
instance
val
fbId
=
gl
.
glGetIntegerv
(
gl
.
GL_DRAW_FRAMEBUFFER_BINDING
)
skijaState
.
renderTarget
=
BackendRenderTarget
.
makeGL
(
(
width
*
dpi
).
toInt
(),
...
...
@@ -111,8 +111,12 @@ open class SkiaWindow : JFrame() {
override
fun
componentResized
(
e
:
ComponentEvent
)
{
layer
.
reinit
()
layer
.
setSize
(
width
,
height
)
Engine
.
get
().
render
(
layer
)
display
(
)
}
})
}
fun
display
()
{
layer
.
display
()
}
}
skiko/src/jvmMain/objectiveC/macos/drawlayer.m
View file @
2e73540a
...
...
@@ -46,11 +46,14 @@ JavaVM *jvm;
CGLSetCurrentContext
(
ctx
);
if
(
self
.
jvm
!=
NULL
)
{
// TODO: cache wndClass and drawMethod.
JNIEnv
*
env
;
(
*
self
.
jvm
)
->
AttachCurrentThread
(
self
.
jvm
,
(
void
**
)
&
env
,
NULL
);
jclass
wndClass
=
(
*
env
)
->
GetObjectClass
(
env
,
self
.
windowRef
);
jmethodID
drawMethod
=
(
*
env
)
->
GetMethodID
(
env
,
wndClass
,
"draw"
,
"()V"
);
static
jclass
wndClass
=
NULL
;
if
(
!
wndClass
)
wndClass
=
(
*
env
)
->
GetObjectClass
(
env
,
self
.
windowRef
);
static
jmethodID
drawMethod
=
NULL
;
if
(
!
drawMethod
)
drawMethod
=
(
*
env
)
->
GetMethodID
(
env
,
wndClass
,
"draw"
,
"()V"
);
if
(
NULL
==
drawMethod
)
{
NSLog
(
@"The method Window.draw() not found!"
);
return
;
...
...
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