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
07d5e63f
Commit
07d5e63f
authored
Feb 02, 2021
by
Igor Demin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring. Move getDrawingSurface to Java from JNI
parent
f6f67b81
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
222 additions
and
253 deletions
+222
-253
awt_jni.cc
skiko/src/jvmMain/cpp/common/awt_jni.cc
+67
-0
drawlayer.cc
skiko/src/jvmMain/cpp/linux/drawlayer.cc
+7
-63
redrawer.cc
skiko/src/jvmMain/cpp/linux/redrawer.cc
+4
-47
drawlayer.cc
skiko/src/jvmMain/cpp/windows/drawlayer.cc
+4
-31
redrawer.cc
skiko/src/jvmMain/cpp/windows/redrawer.cc
+12
-30
AWT.kt
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/AWT.kt
+77
-0
HardwareLayer.kt
...o/src/jvmMain/kotlin/org/jetbrains/skiko/HardwareLayer.kt
+10
-2
PlatformOperations.kt
.../jvmMain/kotlin/org/jetbrains/skiko/PlatformOperations.kt
+2
-2
LinuxOpenGLRedrawer.kt
...otlin/org/jetbrains/skiko/redrawer/LinuxOpenGLRedrawer.kt
+16
-12
MacOsOpenGLRedrawer.kt
...otlin/org/jetbrains/skiko/redrawer/MacOsOpenGLRedrawer.kt
+3
-2
WindowsOpenGLRedrawer.kt
...lin/org/jetbrains/skiko/redrawer/WindowsOpenGLRedrawer.kt
+3
-2
drawlayer.m
skiko/src/jvmMain/objectiveC/macos/drawlayer.m
+15
-42
redrawer.m
skiko/src/jvmMain/objectiveC/macos/redrawer.m
+2
-20
No files found.
skiko/src/jvmMain/cpp/common/awt_jni.cc
0 → 100644
View file @
07d5e63f
#include <cstdint>
#include <jawt_md.h>
extern
"C"
jboolean
Skiko_GetAWT
(
JNIEnv
*
env
,
JAWT
*
awt
);
extern
"C"
{
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_AWTKt_getAWT
(
JNIEnv
*
env
,
jobject
obj
)
{
JAWT
*
awt
=
new
JAWT
();
awt
->
version
=
(
jint
)
JAWT_VERSION_9
;
jboolean
result
=
Skiko_GetAWT
(
env
,
awt
);
if
(
result
==
JNI_FALSE
)
{
return
0
;
}
else
{
return
static_cast
<
jlong
>
(
reinterpret_cast
<
uintptr_t
>
(
awt
));
}
}
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_AWTKt_getDrawingSurface
(
JNIEnv
*
env
,
jobject
obj
,
jlong
awtPtr
,
jobject
layer
)
{
JAWT
*
awt
=
reinterpret_cast
<
JAWT
*>
(
static_cast
<
uintptr_t
>
(
awtPtr
));
JAWT_DrawingSurface
*
ds
=
awt
->
GetDrawingSurface
(
env
,
layer
);
return
static_cast
<
jlong
>
(
reinterpret_cast
<
uintptr_t
>
(
ds
));
}
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_AWTKt_freeDrawingSurface
(
JNIEnv
*
env
,
jobject
obj
,
jlong
awtPtr
,
jlong
drawingSurfacePtr
)
{
JAWT
*
awt
=
reinterpret_cast
<
JAWT
*>
(
static_cast
<
uintptr_t
>
(
awtPtr
));
JAWT_DrawingSurface
*
ds
=
reinterpret_cast
<
JAWT_DrawingSurface
*>
(
static_cast
<
uintptr_t
>
(
drawingSurfacePtr
));
awt
->
FreeDrawingSurface
(
ds
);
}
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_AWTKt_lockDrawingSurface
(
JNIEnv
*
env
,
jobject
obj
,
jlong
drawingSurfacePtr
)
{
JAWT_DrawingSurface
*
ds
=
reinterpret_cast
<
JAWT_DrawingSurface
*>
(
static_cast
<
uintptr_t
>
(
drawingSurfacePtr
));
ds
->
Lock
(
ds
);
}
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_AWTKt_unlockDrawingSurface
(
JNIEnv
*
env
,
jobject
obj
,
jlong
drawingSurfacePtr
)
{
JAWT_DrawingSurface
*
ds
=
reinterpret_cast
<
JAWT_DrawingSurface
*>
(
static_cast
<
uintptr_t
>
(
drawingSurfacePtr
));
ds
->
Unlock
(
ds
);
}
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_AWTKt_getDrawingSurfaceInfo
(
JNIEnv
*
env
,
jobject
obj
,
jlong
drawingSurfacePtr
)
{
JAWT_DrawingSurface
*
ds
=
reinterpret_cast
<
JAWT_DrawingSurface
*>
(
static_cast
<
uintptr_t
>
(
drawingSurfacePtr
));
JAWT_DrawingSurfaceInfo
*
dsi
=
ds
->
GetDrawingSurfaceInfo
(
ds
);
return
static_cast
<
jlong
>
(
reinterpret_cast
<
uintptr_t
>
(
dsi
));
}
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_AWTKt_freeDrawingSurfaceInfo
(
JNIEnv
*
env
,
jobject
obj
,
jlong
drawingSurfacePtr
,
jlong
drawingSurfaceInfoPtr
)
{
JAWT_DrawingSurface
*
ds
=
reinterpret_cast
<
JAWT_DrawingSurface
*>
(
static_cast
<
uintptr_t
>
(
drawingSurfacePtr
));
JAWT_DrawingSurfaceInfo
*
dsi
=
reinterpret_cast
<
JAWT_DrawingSurfaceInfo
*>
(
static_cast
<
uintptr_t
>
(
drawingSurfaceInfoPtr
));
ds
->
FreeDrawingSurfaceInfo
(
dsi
);
}
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_AWTKt_getPlatformInfo
(
JNIEnv
*
env
,
jobject
obj
,
jlong
drawingSurfaceInfoPtr
)
{
JAWT_DrawingSurfaceInfo
*
dsi
=
reinterpret_cast
<
JAWT_DrawingSurfaceInfo
*>
(
static_cast
<
uintptr_t
>
(
drawingSurfaceInfoPtr
));
return
static_cast
<
jlong
>
(
reinterpret_cast
<
uintptr_t
>
(
dsi
->
platformInfo
));
}
}
\ No newline at end of file
skiko/src/jvmMain/cpp/linux/drawlayer.cc
View file @
07d5e63f
...
...
@@ -14,7 +14,7 @@ extern "C" jboolean Skiko_GetAWT(JNIEnv *env, JAWT *awt);
extern
"C"
{
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_HardwareLayer_
init
(
JNIEnv
*
env
,
jobject
canvas
)
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_HardwareLayer_
nativeInit
(
JNIEnv
*
env
,
jobject
canvas
,
jlong
platformInfoPtr
)
{
}
...
...
@@ -22,37 +22,10 @@ extern "C"
{
}
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_HardwareLayer_getWindowHandle
(
JNIEnv
*
env
,
jobject
canvas
)
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_HardwareLayer_getWindowHandle
(
JNIEnv
*
env
,
jobject
canvas
,
jlong
platformInfoPtr
)
{
JAWT
awt
;
JAWT_DrawingSurface
*
ds
=
NULL
;
JAWT_DrawingSurfaceInfo
*
dsi
=
NULL
;
jboolean
result
=
JNI_FALSE
;
jint
lock
=
0
;
JAWT_X11DrawingSurfaceInfo
*
dsi_x11
;
awt
.
version
=
(
jint
)
JAWT_VERSION_9
;
result
=
Skiko_GetAWT
(
env
,
&
awt
);
if
(
result
==
JNI_FALSE
)
{
fprintf
(
stderr
,
"JAWT_GetAWT failed! Result is JNI_FALSE
\n
"
);
return
-
1
;
}
ds
=
awt
.
GetDrawingSurface
(
env
,
canvas
);
lock
=
ds
->
Lock
(
ds
);
dsi
=
ds
->
GetDrawingSurfaceInfo
(
ds
);
dsi_x11
=
(
JAWT_X11DrawingSurfaceInfo
*
)
dsi
->
platformInfo
;
Window
window
=
dsi_x11
->
drawable
;
ds
->
FreeDrawingSurfaceInfo
(
dsi
);
ds
->
Unlock
(
ds
);
awt
.
FreeDrawingSurface
(
ds
);
return
(
jlong
)
window
;
JAWT_X11DrawingSurfaceInfo
*
dsi_x11
=
reinterpret_cast
<
JAWT_X11DrawingSurfaceInfo
*>
(
static_cast
<
uintptr_t
>
(
platformInfoPtr
));
return
(
jlong
)
dsi_x11
->
drawable
;
}
double
getDpiScaleByDisplay
(
Display
*
display
)
...
...
@@ -77,38 +50,9 @@ extern "C"
return
1
;
}
JNIEXPORT
jfloat
JNICALL
Java_org_jetbrains_skiko_PlatformOperationsKt_linuxGetDpiScaleNative
(
JNIEnv
*
env
,
jobject
properties
,
j
object
component
)
JNIEXPORT
jfloat
JNICALL
Java_org_jetbrains_skiko_PlatformOperationsKt_linuxGetDpiScaleNative
(
JNIEnv
*
env
,
jobject
properties
,
j
long
platformInfoPtr
)
{
JAWT
awt
;
JAWT_DrawingSurface
*
ds
=
NULL
;
JAWT_DrawingSurfaceInfo
*
dsi
=
NULL
;
jboolean
result
=
JNI_FALSE
;
jint
lock
=
0
;
JAWT_X11DrawingSurfaceInfo
*
dsi_x11
;
awt
.
version
=
(
jint
)
JAWT_VERSION_9
;
result
=
Skiko_GetAWT
(
env
,
&
awt
);
if
(
result
==
JNI_FALSE
)
{
fprintf
(
stderr
,
"JAWT_GetAWT failed! Result is JNI_FALSE
\n
"
);
return
-
1
;
}
ds
=
awt
.
GetDrawingSurface
(
env
,
component
);
lock
=
ds
->
Lock
(
ds
);
dsi
=
ds
->
GetDrawingSurfaceInfo
(
ds
);
dsi_x11
=
(
JAWT_X11DrawingSurfaceInfo
*
)
dsi
->
platformInfo
;
Display
*
display
=
dsi_x11
->
display
;
float
dpi
=
(
float
)
getDpiScaleByDisplay
(
display
);
ds
->
FreeDrawingSurfaceInfo
(
dsi
);
ds
->
Unlock
(
ds
);
awt
.
FreeDrawingSurface
(
ds
);
return
dpi
;
JAWT_X11DrawingSurfaceInfo
*
dsi_x11
=
reinterpret_cast
<
JAWT_X11DrawingSurfaceInfo
*>
(
static_cast
<
uintptr_t
>
(
platformInfoPtr
));
return
(
float
)
getDpiScaleByDisplay
(
dsi_x11
->
display
);
}
}
// extern "C"
\ No newline at end of file
skiko/src/jvmMain/cpp/linux/redrawer.cc
View file @
07d5e63f
...
...
@@ -14,60 +14,17 @@ extern "C" jboolean Skiko_GetAWT(JNIEnv *env, JAWT *awt);
extern
"C"
{
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_redrawer_LinuxOpenGLRedrawerKt_
lockDrawingSurfaceNative
(
JNIEnv
*
env
,
jobject
redrawer
,
jobject
laye
r
)
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_redrawer_LinuxOpenGLRedrawerKt_
getDisplay
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
platformInfoPt
r
)
{
JAWT
awt
;
awt
.
version
=
(
jint
)
JAWT_VERSION_9
;
if
(
!
Skiko_GetAWT
(
env
,
&
awt
))
{
fprintf
(
stderr
,
"JAWT_GetAWT failed! Result is JNI_FALSE
\n
"
);
return
0
;
}
JAWT_DrawingSurface
*
ds
=
awt
.
GetDrawingSurface
(
env
,
layer
);
ds
->
Lock
(
ds
);
return
static_cast
<
jlong
>
(
reinterpret_cast
<
uintptr_t
>
(
ds
));
}
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_redrawer_LinuxOpenGLRedrawerKt_unlockDrawingSurfaceNative
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
drawingSurfacePtr
)
{
JAWT_DrawingSurface
*
ds
=
reinterpret_cast
<
JAWT_DrawingSurface
*>
(
static_cast
<
uintptr_t
>
(
drawingSurfacePtr
));
JAWT
awt
;
awt
.
version
=
(
jint
)
JAWT_VERSION_9
;
if
(
!
Skiko_GetAWT
(
env
,
&
awt
))
{
fprintf
(
stderr
,
"JAWT_GetAWT failed! Result is JNI_FALSE
\n
"
);
return
0
;
}
ds
->
Unlock
(
ds
);
awt
.
FreeDrawingSurface
(
ds
);
return
static_cast
<
jlong
>
(
reinterpret_cast
<
uintptr_t
>
(
ds
));
}
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_redrawer_LinuxOpenGLRedrawerKt_getDisplay
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
drawingSurfacePtr
)
{
JAWT_DrawingSurface
*
ds
=
reinterpret_cast
<
JAWT_DrawingSurface
*>
(
static_cast
<
uintptr_t
>
(
drawingSurfacePtr
));
JAWT_DrawingSurfaceInfo
*
dsi
=
ds
->
GetDrawingSurfaceInfo
(
ds
);
JAWT_X11DrawingSurfaceInfo
*
dsi_x11
=
(
JAWT_X11DrawingSurfaceInfo
*
)
dsi
->
platformInfo
;
JAWT_X11DrawingSurfaceInfo
*
dsi_x11
=
reinterpret_cast
<
JAWT_X11DrawingSurfaceInfo
*>
(
static_cast
<
uintptr_t
>
(
platformInfoPtr
));
Display
*
display
=
dsi_x11
->
display
;
ds
->
FreeDrawingSurfaceInfo
(
dsi
);
return
static_cast
<
jlong
>
(
reinterpret_cast
<
uintptr_t
>
(
display
));
}
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_redrawer_LinuxOpenGLRedrawerKt_getWindow
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
drawingSurface
Ptr
)
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_redrawer_LinuxOpenGLRedrawerKt_getWindow
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
platformInfo
Ptr
)
{
JAWT_DrawingSurface
*
ds
=
reinterpret_cast
<
JAWT_DrawingSurface
*>
(
static_cast
<
uintptr_t
>
(
drawingSurfacePtr
));
JAWT_DrawingSurfaceInfo
*
dsi
=
ds
->
GetDrawingSurfaceInfo
(
ds
);
JAWT_X11DrawingSurfaceInfo
*
dsi_x11
=
(
JAWT_X11DrawingSurfaceInfo
*
)
dsi
->
platformInfo
;
JAWT_X11DrawingSurfaceInfo
*
dsi_x11
=
reinterpret_cast
<
JAWT_X11DrawingSurfaceInfo
*>
(
static_cast
<
uintptr_t
>
(
platformInfoPtr
));
Window
window
=
dsi_x11
->
drawable
;
ds
->
FreeDrawingSurfaceInfo
(
dsi
);
return
static_cast
<
jlong
>
(
reinterpret_cast
<
uintptr_t
>
(
window
));
}
...
...
skiko/src/jvmMain/cpp/windows/drawlayer.cc
View file @
07d5e63f
...
...
@@ -5,7 +5,7 @@ extern "C" jboolean Skiko_GetAWT(JNIEnv *env, JAWT *awt);
extern
"C"
{
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_HardwareLayer_
init
(
JNIEnv
*
env
,
jobject
canvas
)
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_HardwareLayer_
nativeInit
(
JNIEnv
*
env
,
jobject
canvas
,
jlong
platformInfoPtr
)
{
}
...
...
@@ -13,36 +13,9 @@ extern "C"
{
}
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_HardwareLayer_getWindowHandle
(
JNIEnv
*
env
,
jobject
canvas
)
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_HardwareLayer_getWindowHandle
(
JNIEnv
*
env
,
jobject
canvas
,
jlong
platformInfoPtr
)
{
JAWT
awt
;
JAWT_DrawingSurface
*
ds
=
NULL
;
JAWT_DrawingSurfaceInfo
*
dsi
=
NULL
;
jboolean
result
=
JNI_FALSE
;
jint
lock
=
0
;
JAWT_Win32DrawingSurfaceInfo
*
dsi_win
;
awt
.
version
=
(
jint
)
JAWT_VERSION_9
;
result
=
Skiko_GetAWT
(
env
,
&
awt
);
if
(
result
==
JNI_FALSE
)
{
fprintf
(
stderr
,
"JAWT_GetAWT failed! Result is JNI_FALSE
\n
"
);
return
-
1
;
}
ds
=
awt
.
GetDrawingSurface
(
env
,
canvas
);
lock
=
ds
->
Lock
(
ds
);
dsi
=
ds
->
GetDrawingSurfaceInfo
(
ds
);
dsi_win
=
(
JAWT_Win32DrawingSurfaceInfo
*
)
dsi
->
platformInfo
;
HWND
hwnd
=
dsi_win
->
hwnd
;
ds
->
FreeDrawingSurfaceInfo
(
dsi
);
ds
->
Unlock
(
ds
);
awt
.
FreeDrawingSurface
(
ds
);
return
(
jlong
)
hwnd
;
JAWT_Win32DrawingSurfaceInfo
*
dsi_win
=
reinterpret_cast
<
JAWT_Win32DrawingSurfaceInfo
*>
(
static_cast
<
uintptr_t
>
(
platformInfoPtr
));
return
(
jlong
)
dsi_win
->
hwnd
;
}
}
// extern "C"
\ No newline at end of file
skiko/src/jvmMain/cpp/windows/redrawer.cc
View file @
07d5e63f
...
...
@@ -8,26 +8,13 @@ extern "C" jboolean Skiko_GetAWT(JNIEnv *env, JAWT *awt);
extern
"C"
{
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_redrawer_WindowsOpenGLRedrawerKt_getDevice
(
JNIEnv
*
env
,
jobject
redrawer
,
j
object
laye
r
)
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_redrawer_WindowsOpenGLRedrawerKt_getDevice
(
JNIEnv
*
env
,
jobject
redrawer
,
j
long
platformInfoPt
r
)
{
JAWT
awt
;
awt
.
version
=
(
jint
)
JAWT_VERSION_9
;
if
(
!
Skiko_GetAWT
(
env
,
&
awt
))
{
fprintf
(
stderr
,
"JAWT_GetAWT failed! Result is JNI_FALSE
\n
"
);
return
0
;
}
JAWT_DrawingSurface
*
ds
=
awt
.
GetDrawingSurface
(
env
,
layer
);
ds
->
Lock
(
ds
);
JAWT_DrawingSurfaceInfo
*
dsi
=
ds
->
GetDrawingSurfaceInfo
(
ds
);
JAWT_Win32DrawingSurfaceInfo
*
dsi_win
=
(
JAWT_Win32DrawingSurfaceInfo
*
)
dsi
->
platformInfo
;
JAWT_Win32DrawingSurfaceInfo
*
dsi_win
=
reinterpret_cast
<
JAWT_Win32DrawingSurfaceInfo
*>
(
static_cast
<
uintptr_t
>
(
platformInfoPtr
));
HWND
hwnd
=
dsi_win
->
hwnd
;
HDC
device
=
GetDC
(
hwnd
);
if
(
dsi
!=
NULL
)
{
PIXELFORMATDESCRIPTOR
pixFormatDscr
;
memset
(
&
pixFormatDscr
,
0
,
sizeof
(
PIXELFORMATDESCRIPTOR
));
pixFormatDscr
.
nSize
=
sizeof
(
PIXELFORMATDESCRIPTOR
);
...
...
@@ -39,11 +26,6 @@ extern "C"
int
iPixelFormat
=
ChoosePixelFormat
(
device
,
&
pixFormatDscr
);
SetPixelFormat
(
device
,
iPixelFormat
,
&
pixFormatDscr
);
DescribePixelFormat
(
device
,
iPixelFormat
,
sizeof
(
PIXELFORMATDESCRIPTOR
),
&
pixFormatDscr
);
}
ds
->
FreeDrawingSurfaceInfo
(
dsi
);
ds
->
Unlock
(
ds
);
awt
.
FreeDrawingSurface
(
ds
);
return
static_cast
<
jlong
>
(
reinterpret_cast
<
uintptr_t
>
(
device
));
}
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/AWT.kt
0 → 100644
View file @
07d5e63f
package
org.jetbrains.skiko
import
java.awt.Component
private
val
awt
=
getAWT
().
also
{
check
(
it
!=
0L
)
}
internal
fun
<
T
>
Component
.
useDrawingSurfacePlatformInfo
(
block
:
(
Long
)
->
T
)
=
useDrawingSurfaceInfo
{
block
(
it
.
platformInfo
)
}
internal
fun
<
T
>
Component
.
useDrawingSurfaceInfo
(
block
:
(
DrawingSurfaceInfo
)
->
T
):
T
=
getDrawingSurface
().
use
{
drawingSurface
->
drawingSurface
.
withLock
{
drawingSurface
.
getInfo
().
use
{
info
->
block
(
info
)
}
}
}
internal
fun
Component
.
getDrawingSurface
()
=
DrawingSurface
(
this
)
internal
class
DrawingSurface
(
component
:
Component
)
:
AutoCloseable
{
val
ptr
=
getDrawingSurface
(
awt
,
component
).
also
{
check
(
it
!=
0L
)
}
fun
lock
()
=
lockDrawingSurface
(
ptr
)
fun
unlock
()
=
unlockDrawingSurface
(
ptr
)
inline
fun
<
T
>
withLock
(
block
:
()
->
T
):
T
{
lock
()
try
{
return
block
()
}
finally
{
unlock
()
}
}
fun
getInfo
()
=
DrawingSurfaceInfo
(
ptr
)
override
fun
close
()
{
freeDrawingSurface
(
awt
,
ptr
)
}
}
internal
class
DrawingSurfaceInfo
(
private
val
drawingSurface
:
Long
)
:
AutoCloseable
{
val
ptr
=
getDrawingSurfaceInfo
(
drawingSurface
).
also
{
check
(
it
!=
0L
)
}
val
platformInfo
:
Long
get
()
=
getPlatformInfo
(
ptr
)
override
fun
close
()
{
freeDrawingSurfaceInfo
(
drawingSurface
,
ptr
)
}
}
private
external
fun
getAWT
():
Long
private
external
fun
getDrawingSurface
(
awt
:
Long
,
layer
:
Component
):
Long
private
external
fun
freeDrawingSurface
(
awt
:
Long
,
drawingSurface
:
Long
)
private
external
fun
lockDrawingSurface
(
drawingSurface
:
Long
)
private
external
fun
unlockDrawingSurface
(
drawingSurface
:
Long
)
private
external
fun
getDrawingSurfaceInfo
(
drawingSurface
:
Long
):
Long
private
external
fun
freeDrawingSurfaceInfo
(
drawingSurface
:
Long
,
drawingSurfaceInfo
:
Long
)
private
external
fun
getPlatformInfo
(
drawingSurfaceInfo
:
Long
):
Long
\ No newline at end of file
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/HardwareLayer.kt
View file @
07d5e63f
...
...
@@ -32,7 +32,13 @@ abstract class HardwareLayer : Canvas() {
}
}
protected
open
external
fun
init
()
protected
open
fun
init
()
{
useDrawingSurfacePlatformInfo
(
::
nativeInit
)
}
protected
open
external
fun
nativeInit
(
platformInfo
:
Long
)
open
external
fun
dispose
()
protected
open
fun
contentScaleChanged
()
=
Unit
...
...
@@ -68,7 +74,7 @@ abstract class HardwareLayer : Canvas() {
internal
abstract
fun
draw
()
val
windowHandle
:
Long
external
get
get
()
=
useDrawingSurfacePlatformInfo
(
::
getWindowHandle
)
val
contentScale
:
Float
get
()
=
_contentScale
!!
...
...
@@ -76,4 +82,6 @@ abstract class HardwareLayer : Canvas() {
var
fullscreen
:
Boolean
get
()
=
platformOperations
.
isFullscreen
(
this
)
set
(
value
)
=
platformOperations
.
setFullscreen
(
this
,
value
)
private
external
fun
getWindowHandle
(
platformInfo
:
Long
):
Long
}
\ No newline at end of file
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/PlatformOperations.kt
View file @
07d5e63f
...
...
@@ -88,7 +88,7 @@ internal val platformOperations: PlatformOperations by lazy {
// see also comment for HardwareLayer.checkContentScale
// return linuxGetDpiScaleNative(component
)
// return component.useDrawingSurfacePlatformInfo(::linuxGetDpiScaleNative
)
}
override
fun
createRedrawer
(
layer
:
HardwareLayer
)
=
when
(
renderApi
)
{
...
...
@@ -105,4 +105,4 @@ external private fun osxIsFullscreenNative(component: Component): Boolean
external
private
fun
osxSetFullscreenNative
(
component
:
Component
,
value
:
Boolean
)
// Linux
external
private
fun
linuxGetDpiScaleNative
(
component
:
Component
):
Float
external
private
fun
linuxGetDpiScaleNative
(
platformInfo
:
Long
):
Float
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/redrawer/LinuxOpenGLRedrawer.kt
View file @
07d5e63f
...
...
@@ -3,10 +3,12 @@ package org.jetbrains.skiko.redrawer
import
kotlinx.coroutines.CancellationException
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.swing.Swing
import
org.jetbrains.skiko.DrawingSurface
import
org.jetbrains.skiko.FrameDispatcher
import
org.jetbrains.skiko.HardwareLayer
import
org.jetbrains.skiko.OpenGLApi
import
org.jetbrains.skiko.SkikoProperties
import
org.jetbrains.skiko.getDrawingSurface
internal
class
LinuxOpenGLRedrawer
(
private
val
layer
:
HardwareLayer
...
...
@@ -92,7 +94,7 @@ internal class LinuxOpenGLRedrawer(
}
}
private
inline
fun
<
T
>
HardwareLayer
.
lockDrawingSurface
(
action
:
(
DrawingSurface
)
->
T
):
T
{
private
inline
fun
<
T
>
HardwareLayer
.
lockDrawingSurface
(
action
:
(
Linux
DrawingSurface
)
->
T
):
T
{
val
drawingSurface
=
lockDrawingSurface
(
this
)
try
{
return
action
(
drawingSurface
)
...
...
@@ -101,17 +103,21 @@ private inline fun <T> HardwareLayer.lockDrawingSurface(action: (DrawingSurface)
}
}
private
fun
lockDrawingSurface
(
layer
:
HardwareLayer
):
DrawingSurface
{
val
ptr
=
lockDrawingSurfaceNative
(
layer
)
return
DrawingSurface
(
ptr
,
getDisplay
(
ptr
),
getWindow
(
ptr
))
private
fun
lockDrawingSurface
(
layer
:
HardwareLayer
):
LinuxDrawingSurface
{
val
drawingSurface
=
layer
.
getDrawingSurface
()
drawingSurface
.
lock
()
return
drawingSurface
.
getInfo
().
use
{
LinuxDrawingSurface
(
drawingSurface
,
getDisplay
(
it
.
platformInfo
),
getWindow
(
it
.
platformInfo
))
}
}
private
fun
unlockDrawingSurface
(
drawingSurface
:
DrawingSurface
)
{
unlockDrawingSurfaceNative
(
drawingSurface
.
ptr
)
private
fun
unlockDrawingSurface
(
drawingSurface
:
LinuxDrawingSurface
)
{
drawingSurface
.
common
.
unlock
()
drawingSurface
.
common
.
close
()
}
private
class
DrawingSurface
(
val
ptr
:
Long
,
private
class
Linux
DrawingSurface
(
val
common
:
DrawingSurface
,
val
display
:
Long
,
val
window
:
Long
)
{
...
...
@@ -122,10 +128,8 @@ private class DrawingSurface(
fun
setSwapInterval
(
interval
:
Int
)
=
setSwapInterval
(
display
,
window
,
interval
)
}
private
external
fun
lockDrawingSurfaceNative
(
layer
:
HardwareLayer
):
Long
private
external
fun
unlockDrawingSurfaceNative
(
drawingSurface
:
Long
)
private
external
fun
getDisplay
(
drawingSurface
:
Long
):
Long
private
external
fun
getWindow
(
drawingSurface
:
Long
):
Long
private
external
fun
getDisplay
(
platformInfo
:
Long
):
Long
private
external
fun
getWindow
(
platformInfo
:
Long
):
Long
private
external
fun
makeCurrent
(
display
:
Long
,
window
:
Long
,
context
:
Long
)
private
external
fun
createContext
(
display
:
Long
):
Long
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/redrawer/MacOsOpenGLRedrawer.kt
View file @
07d5e63f
...
...
@@ -7,13 +7,14 @@ import org.jetbrains.skiko.FrameDispatcher
import
org.jetbrains.skiko.HardwareLayer
import
org.jetbrains.skiko.OpenGLApi
import
org.jetbrains.skiko.SkikoProperties
import
org.jetbrains.skiko.useDrawingSurfacePlatformInfo
import
javax.swing.SwingUtilities.convertPoint
import
javax.swing.SwingUtilities.getRootPane
internal
class
MacOsOpenGLRedrawer
(
private
val
layer
:
HardwareLayer
)
:
Redrawer
{
private
val
containerLayerPtr
=
initContainer
(
lay
er
)
private
val
containerLayerPtr
=
layer
.
useDrawingSurfacePlatformInfo
(
::
initContain
er
)
private
val
drawLock
=
Any
()
private
var
isDisposed
=
false
...
...
@@ -140,7 +141,7 @@ private open class AWTGLLayer(private val containerPtr: Long, setNeedsDisplayOnB
protected
external
fun
setFrame
(
containerPtr
:
Long
,
ptr
:
Long
,
x
:
Float
,
y
:
Float
,
width
:
Float
,
height
:
Float
)
}
private
external
fun
initContainer
(
layer
:
HardwareLayer
):
Long
private
external
fun
initContainer
(
platformInfo
:
Long
):
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
)
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/redrawer/WindowsOpenGLRedrawer.kt
View file @
07d5e63f
...
...
@@ -8,11 +8,12 @@ import org.jetbrains.skiko.FrameDispatcher
import
org.jetbrains.skiko.HardwareLayer
import
org.jetbrains.skiko.OpenGLApi
import
org.jetbrains.skiko.SkikoProperties
import
org.jetbrains.skiko.useDrawingSurfacePlatformInfo
internal
class
WindowsOpenGLRedrawer
(
private
val
layer
:
HardwareLayer
)
:
Redrawer
{
private
val
device
=
getDevice
(
layer
)
private
val
device
=
layer
.
useDrawingSurfacePlatformInfo
(
::
getDevice
)
private
val
context
=
createContext
(
device
)
private
var
isDisposed
=
false
...
...
@@ -101,7 +102,7 @@ internal class WindowsOpenGLRedrawer(
}
private
external
fun
makeCurrent
(
device
:
Long
,
context
:
Long
)
private
external
fun
getDevice
(
layer
:
HardwareLayer
):
Long
private
external
fun
getDevice
(
platformInfo
:
Long
):
Long
private
external
fun
createContext
(
device
:
Long
):
Long
private
external
fun
deleteContext
(
context
:
Long
)
private
external
fun
setSwapInterval
(
interval
:
Int
)
...
...
skiko/src/jvmMain/objectiveC/macos/drawlayer.m
View file @
07d5e63f
...
...
@@ -81,36 +81,14 @@ LayerHandler * findByObject(JNIEnv *env, jobject object)
extern
jboolean
Skiko_GetAWT
(
JNIEnv
*
env
,
JAWT
*
awt
);
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_HardwareLayer_
init
(
JNIEnv
*
env
,
jobject
canvas
)
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_HardwareLayer_
nativeInit
(
JNIEnv
*
env
,
jobject
canvas
,
jlong
platformInfoPtr
)
{
if
(
layerStorage
==
nil
)
{
layerStorage
=
[[
NSMutableSet
alloc
]
init
];
}
JAWT
awt
;
JAWT_DrawingSurface
*
ds
=
NULL
;
JAWT_DrawingSurfaceInfo
*
dsi
=
NULL
;
jboolean
result
=
JNI_FALSE
;
jint
lock
=
0
;
NSObject
<
JAWT_SurfaceLayers
>*
dsi_mac
=
NULL
;
awt
.
version
=
JAWT_VERSION_9
/* | JAWT_MACOSX_USE_CALAYER */
;
result
=
Skiko_GetAWT
(
env
,
&
awt
);
assert
(
result
!=
JNI_FALSE
);
ds
=
awt
.
GetDrawingSurface
(
env
,
canvas
);
assert
(
ds
!=
NULL
);
lock
=
ds
->
Lock
(
ds
);
assert
((
lock
&
JAWT_LOCK_ERROR
)
==
0
);
dsi
=
ds
->
GetDrawingSurfaceInfo
(
ds
);
if
(
dsi
!=
NULL
)
{
dsi_mac
=
(
__bridge
NSObject
<
JAWT_SurfaceLayers
>
*
)
dsi
->
platformInfo
;
NSObject
<
JAWT_SurfaceLayers
>*
dsi_mac
=
(
__bridge
NSObject
<
JAWT_SurfaceLayers
>
*
)
platformInfoPtr
;
LayerHandler
*
layersSet
=
[[
LayerHandler
alloc
]
init
];
...
...
@@ -134,11 +112,6 @@ JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_init(JNIEnv *env,
}
[
layerStorage
addObject
:
layersSet
];
}
ds
->
FreeDrawingSurfaceInfo
(
dsi
);
ds
->
Unlock
(
ds
);
awt
.
FreeDrawingSurface
(
ds
);
}
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_HardwareLayer_dispose
(
JNIEnv
*
env
,
jobject
canvas
)
...
...
skiko/src/jvmMain/objectiveC/macos/redrawer.m
View file @
07d5e63f
...
...
@@ -69,35 +69,17 @@ JavaVM *jvm = NULL;
@end
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_redrawer_MacOsOpenGLRedrawerKt_initContainer
(
JNIEnv
*
env
,
jobject
redrawer
,
j
object
laye
r
)
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_redrawer_MacOsOpenGLRedrawerKt_initContainer
(
JNIEnv
*
env
,
jobject
redrawer
,
j
long
platformInfoPt
r
)
{
JAWT
awt
;
awt
.
version
=
JAWT_VERSION_9
;
jboolean
result
=
Skiko_GetAWT
(
env
,
&
awt
);
assert
(
result
!=
JNI_FALSE
);
(
*
env
)
->
GetJavaVM
(
env
,
&
jvm
);
JAWT_DrawingSurface
*
ds
=
awt
.
GetDrawingSurface
(
env
,
layer
);
assert
(
ds
!=
NULL
);
jint
lock
=
ds
->
Lock
(
ds
);
assert
((
lock
&
JAWT_LOCK_ERROR
)
==
0
);
JAWT_DrawingSurfaceInfo
*
dsi
=
ds
->
GetDrawingSurfaceInfo
(
ds
);
assert
(
dsi
!=
NULL
);
NSObject
<
JAWT_SurfaceLayers
>*
dsi_mac
=
(
__bridge
NSObject
<
JAWT_SurfaceLayers
>
*
)
dsi
->
platformInfo
;
NSObject
<
JAWT_SurfaceLayers
>*
dsi_mac
=
(
__bridge
NSObject
<
JAWT_SurfaceLayers
>
*
)
platformInfoPtr
;
CALayer
*
container
=
[
dsi_mac
windowLayer
];
[
container
removeAllAnimations
];
[
container
setAutoresizingMask
:
(
kCALayerWidthSizable
|
kCALayerHeightSizable
)];
[
container
setNeedsDisplayOnBoundsChange
:
YES
];
ds
->
FreeDrawingSurfaceInfo
(
dsi
);
ds
->
Unlock
(
ds
);
awt
.
FreeDrawingSurface
(
ds
);
return
(
jlong
)
container
;
}
...
...
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