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
e8b56bd4
Unverified
Commit
e8b56bd4
authored
Oct 07, 2020
by
Nikolay Igotti
Committed by
GitHub
Oct 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleaner backend integration. (#14)
parent
2faf120c
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
120 additions
and
34 deletions
+120
-34
build.gradle.kts
skiko/build.gradle.kts
+3
-1
render.cc
skiko/src/jvmMain/cpp/common/render.cc
+47
-0
Library.kt
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Library.kt
+1
-1
OSType.kt
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/OSType.kt
+6
-20
RenderTargets.kt
...o/src/jvmMain/kotlin/org/jetbrains/skiko/RenderTargets.kt
+26
-0
SkiaWindow.kt
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkiaWindow.kt
+28
-12
drawlayer.m
skiko/src/jvmMain/objectiveC/macos/drawlayer.m
+9
-0
No files found.
skiko/build.gradle.kts
View file @
e8b56bd4
...
...
@@ -243,7 +243,8 @@ tasks.withType(CppCompile::class.java).configureEach {
"-fvisibility=hidden"
,
"-fvisibility-inlines-hidden"
,
"-I$jdkHome/include/darwin"
,
"-DSK_BUILD_FOR_MAC"
"-DSK_BUILD_FOR_MAC"
,
"-DSK_METAL"
)
)
}
...
...
@@ -312,6 +313,7 @@ tasks.withType(LinkSharedLibrary::class.java).configureEach {
"-framework"
,
"CoreServices"
,
"-framework"
,
"CoreText"
,
"-framework"
,
"Foundation"
,
"-framework"
,
"Metal"
,
"-framework"
,
"OpenGL"
,
"-framework"
,
"QuartzCore"
// for CoreAnimation
)
...
...
skiko/src/jvmMain/cpp/common/render.cc
0 → 100644
View file @
e8b56bd4
#include <jni.h>
#include "GrBackendSurface.h"
#include "GrContext.h"
extern
"C"
{
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_RenderTargetsKt_makeGLRenderTargetNative
(
JNIEnv
*
env
,
jclass
jclass
,
jint
width
,
jint
height
,
jint
sampleCnt
,
jint
stencilBits
,
jint
fbId
,
jint
fbFormat
)
{
GrGLFramebufferInfo
glInfo
=
{
static_cast
<
unsigned
int
>
(
fbId
),
static_cast
<
unsigned
int
>
(
fbFormat
)
};
GrBackendRenderTarget
*
obj
=
new
GrBackendRenderTarget
(
width
,
height
,
sampleCnt
,
stencilBits
,
glInfo
);
return
reinterpret_cast
<
jlong
>
(
obj
);
}
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_RenderTargetsKt_makeGLContextNative
(
JNIEnv
*
env
,
jclass
jclass
)
{
return
reinterpret_cast
<
jlong
>
(
GrContext
::
MakeGL
().
release
());
}
extern
void
getMetalDeviceAndQueue
(
void
**
device
,
void
**
queue
);
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_RenderTargetsKt_makeMetalRenderTargetNative
(
JNIEnv
*
env
,
jclass
jclass
,
jint
width
,
jint
height
,
jint
sampleCnt
)
{
#ifdef SK_METAL
// TODO: create properly.
GrMtlTextureInfo
mtlInfo
;
GrBackendRenderTarget
*
obj
=
new
GrBackendRenderTarget
(
width
,
height
,
sampleCnt
,
mtlInfo
);
return
reinterpret_cast
<
jlong
>
(
obj
);
#else
return
0
;
#endif
}
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_RenderTargetsKt_makeMetalContextNative
(
JNIEnv
*
env
,
jclass
jclass
)
{
#ifdef SK_METAL
void
*
device
=
nullptr
;
void
*
queue
=
nullptr
;
getMetalDeviceAndQueue
(
&
device
,
&
queue
);
return
reinterpret_cast
<
jlong
>
(
GrContext
::
MakeMetal
(
device
,
queue
).
release
());
#else
return
0
;
#endif
}
}
// extern "C"
\ No newline at end of file
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Library.kt
View file @
e8b56bd4
...
...
@@ -37,7 +37,7 @@ object Library {
if
(
loaded
)
return
loadOrGet
(
resourcePath
,
name
,
true
)
val
loadIcu
=
System
.
getProperty
(
"os.name"
).
toLowerCase
().
startsWith
(
"win"
)
val
loadIcu
=
OSType
.
currentOs
==
OSType
.
WINDOWS
if
(
loadIcu
)
{
loadOrGet
(
resourcePath
,
"icudtl.dat"
,
false
)
}
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/OSType.kt
View file @
e8b56bd4
...
...
@@ -4,28 +4,14 @@ enum class OSType {
MAC_OS
,
LINUX
,
WINDOWS
,
UNKNOWN
;
companion
object
{
val
currentOs
=
defineOsType
()
private
fun
defineOsType
():
OSType
{
val
osName
=
System
.
getProperty
(
"os.name"
).
toLowerCase
()
return
when
{
isWindows
(
osName
)
->
WINDOWS
isMac
(
osName
)
->
MAC_OS
isUnix
(
osName
)
->
LINUX
val
currentOs
by
lazy
{
val
name
=
System
.
getProperty
(
"os.name"
).
toLowerCase
()
when
{
name
.
indexOf
(
"win"
)
>=
0
->
WINDOWS
name
.
indexOf
(
"mac"
)
>=
0
->
MAC_OS
name
.
indexOf
(
"linux"
)
>=
0
->
LINUX
else
->
UNKNOWN
}
}
private
fun
isWindows
(
name
:
String
):
Boolean
{
return
name
.
indexOf
(
"win"
)
>=
0
}
private
fun
isMac
(
name
:
String
):
Boolean
{
return
name
.
indexOf
(
"mac"
)
>=
0
}
private
fun
isUnix
(
name
:
String
):
Boolean
{
return
name
.
indexOf
(
"nix"
)
>=
0
||
name
.
indexOf
(
"nux"
)
>=
0
||
name
.
indexOf
(
"aix"
)
>=
0
}
}
}
\ No newline at end of file
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/RenderTargets.kt
0 → 100644
View file @
e8b56bd4
package
org.jetbrains.skiko
import
org.jetbrains.skija.BackendRenderTarget
import
org.jetbrains.skija.Context
internal
fun
makeGLContext
()
=
Context
(
makeGLContextNative
()
)
internal
fun
makeGLRenderTarget
(
width
:
Int
,
height
:
Int
,
sampleCnt
:
Int
,
stencilBits
:
Int
,
fbId
:
Int
,
fbFormat
:
Int
)
=
BackendRenderTarget
(
makeGLRenderTargetNative
(
width
,
height
,
sampleCnt
,
stencilBits
,
fbId
,
fbFormat
)
)
internal
fun
makeMetalRenderTarget
(
width
:
Int
,
height
:
Int
,
sampleCnt
:
Int
)
=
BackendRenderTarget
(
makeMetalRenderTargetNative
(
width
,
height
,
sampleCnt
).
also
{
if
(
it
==
0L
)
TODO
(
"not yet supported"
)
}
)
internal
fun
makeMetalContext
()
=
Context
(
makeMetalContextNative
().
also
{
if
(
it
==
0L
)
TODO
(
"not yet supported"
)
}
)
external
private
fun
makeGLRenderTargetNative
(
width
:
Int
,
height
:
Int
,
sampleCnt
:
Int
,
stencilBits
:
Int
,
fbId
:
Int
,
fbFormat
:
Int
):
Long
external
private
fun
makeGLContextNative
():
Long
external
private
fun
makeMetalRenderTargetNative
(
width
:
Int
,
height
:
Int
,
sampleCnt
:
Int
):
Long
external
private
fun
makeMetalContextNative
():
Long
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkiaWindow.kt
View file @
e8b56bd4
...
...
@@ -31,7 +31,9 @@ interface SkiaRenderer {
fun
onDispose
()
}
open
class
SkiaLayer
:
HardwareLayer
()
{
open
class
SkiaLayer
()
:
HardwareLayer
()
{
open
val
api
:
GraphicsApi
=
GraphicsApi
.
OPENGL
var
renderer
:
SkiaRenderer
?
=
null
private
val
skijaState
=
SkijaState
()
...
...
@@ -49,7 +51,11 @@ open class SkiaLayer : HardwareLayer() {
override
fun
draw
()
{
if
(!
inited
)
{
if
(
skijaState
.
context
==
null
)
{
skijaState
.
context
=
Context
.
makeGL
()
skijaState
.
context
=
when
(
api
)
{
GraphicsApi
.
OPENGL
->
makeGLContext
()
GraphicsApi
.
METAL
->
makeMetalContext
()
else
->
TODO
(
"Unsupported yet"
)
}
}
renderer
?.
onInit
()
inited
=
true
...
...
@@ -73,9 +79,11 @@ open class SkiaLayer : HardwareLayer() {
private
fun
initRenderTarget
(
dpi
:
Float
)
{
skijaState
.
apply
{
clear
()
val
gl
:
OpenGLApi
=
OpenGLApi
.
instance
renderTarget
=
when
(
api
)
{
GraphicsApi
.
OPENGL
->
{
val
gl
=
OpenGLApi
.
instance
val
fbId
=
gl
.
glGetIntegerv
(
gl
.
GL_DRAW_FRAMEBUFFER_BINDING
)
renderTarget
=
BackendRenderTarget
.
makeGL
(
makeGLRenderTarget
(
(
width
*
dpi
).
toInt
(),
(
height
*
dpi
).
toInt
(),
0
,
...
...
@@ -84,6 +92,14 @@ open class SkiaLayer : HardwareLayer() {
FramebufferFormat
.
GR_GL_RGBA8
)
}
GraphicsApi
.
METAL
->
makeMetalRenderTarget
(
(
width
*
dpi
).
toInt
(),
(
height
*
dpi
).
toInt
(),
0
)
else
->
TODO
(
"Unsupported yet"
)
}
}
}
private
fun
initSurface
()
{
...
...
skiko/src/jvmMain/objectiveC/macos/drawlayer.m
View file @
e8b56bd4
...
...
@@ -8,6 +8,8 @@
#import <Cocoa/Cocoa.h>
#import <QuartzCore/QuartzCore.h>
#import <OpenGL/gl3.h>
#import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h>
JavaVM
*
jvm
=
NULL
;
...
...
@@ -252,3 +254,10 @@ JNIEXPORT jfloat JNICALL Java_org_jetbrains_skiko_HardwareLayer_getContentScale(
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_HardwareLayer_getWindowHandle
(
JNIEnv
*
env
,
jobject
window
)
{
return
(
jlong
)
kNullWindowHandle
;
}
void
getMetalDeviceAndQueue
(
void
**
device
,
void
**
queue
)
{
id
<
MTLDevice
>
fDevice
=
MTLCreateSystemDefaultDevice
();
id
<
MTLCommandQueue
>
fQueue
=
[
fDevice
newCommandQueue
];
*
device
=
(
__bridge
void
*
)
fDevice
;
*
queue
=
(
__bridge
void
*
)
fQueue
;
}
\ 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