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
b6e0411e
Unverified
Commit
b6e0411e
authored
Feb 03, 2021
by
Igor Demin
Committed by
GitHub
Feb 03, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #62 from JetBrains/refactor_jni
Refactoring. Move getDrawingSurface to Java from JNI
parents
7a24e47c
37d8787a
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
266 additions
and
285 deletions
+266
-285
build.gradle.kts
skiko/build.gradle.kts
+4
-0
awt_jni.cc
skiko/src/jvmMain/cpp/common/awt_jni.cc
+70
-0
jni_helpers.h
skiko/src/jvmMain/cpp/include/jni_helpers.h
+7
-0
drawlayer.cc
skiko/src/jvmMain/cpp/linux/drawlayer.cc
+8
-65
redrawer.cc
skiko/src/jvmMain/cpp/linux/redrawer.cc
+18
-62
drawlayer.cc
skiko/src/jvmMain/cpp/windows/drawlayer.cc
+5
-33
redrawer.cc
skiko/src/jvmMain/cpp/windows/redrawer.cc
+20
-39
AWT.kt
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/AWT.kt
+83
-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
-44
redrawer.m
skiko/src/jvmMain/objectiveC/macos/redrawer.m
+2
-22
No files found.
skiko/build.gradle.kts
View file @
b6e0411e
...
@@ -228,6 +228,7 @@ tasks.withType(CppCompile::class.java).configureEach {
...
@@ -228,6 +228,7 @@ tasks.withType(CppCompile::class.java).configureEach {
"-DSK_UNICODE_AVAILABLE"
,
"-DSK_UNICODE_AVAILABLE"
,
*
buildType
.
flags
*
buildType
.
flags
))
))
val
includeDir
=
"$projectDir/src/jvmMain/cpp/include"
when
(
targetOs
)
{
when
(
targetOs
)
{
OS
.
MacOS
->
{
OS
.
MacOS
->
{
compilerArgs
.
addAll
(
compilerArgs
.
addAll
(
...
@@ -235,6 +236,7 @@ tasks.withType(CppCompile::class.java).configureEach {
...
@@ -235,6 +236,7 @@ tasks.withType(CppCompile::class.java).configureEach {
"-fvisibility=hidden"
,
"-fvisibility=hidden"
,
"-fvisibility-inlines-hidden"
,
"-fvisibility-inlines-hidden"
,
"-I$jdkHome/include/darwin"
,
"-I$jdkHome/include/darwin"
,
"-I$includeDir"
,
"-DSK_SHAPER_CORETEXT_AVAILABLE"
,
"-DSK_SHAPER_CORETEXT_AVAILABLE"
,
"-DSK_BUILD_FOR_MAC"
,
"-DSK_BUILD_FOR_MAC"
,
"-DSK_METAL"
,
"-DSK_METAL"
,
...
@@ -248,6 +250,7 @@ tasks.withType(CppCompile::class.java).configureEach {
...
@@ -248,6 +250,7 @@ tasks.withType(CppCompile::class.java).configureEach {
"-fvisibility=hidden"
,
"-fvisibility=hidden"
,
"-fvisibility-inlines-hidden"
,
"-fvisibility-inlines-hidden"
,
"-I$jdkHome/include/linux"
,
"-I$jdkHome/include/linux"
,
"-I$includeDir"
,
"-DSK_BUILD_FOR_LINUX"
,
"-DSK_BUILD_FOR_LINUX"
,
"-DSK_R32_SHIFT=16"
,
"-DSK_R32_SHIFT=16"
,
*
buildType
.
clangFlags
*
buildType
.
clangFlags
...
@@ -258,6 +261,7 @@ tasks.withType(CppCompile::class.java).configureEach {
...
@@ -258,6 +261,7 @@ tasks.withType(CppCompile::class.java).configureEach {
compilerArgs
.
addAll
(
compilerArgs
.
addAll
(
listOf
(
listOf
(
"-I$jdkHome/include/win32"
,
"-I$jdkHome/include/win32"
,
"-I$includeDir"
,
"-DSK_BUILD_FOR_WIN"
,
"-DSK_BUILD_FOR_WIN"
,
"-D_CRT_SECURE_NO_WARNINGS"
,
"-D_CRT_SECURE_NO_WARNINGS"
,
"-D_HAS_EXCEPTIONS=0"
,
"-D_HAS_EXCEPTIONS=0"
,
...
...
skiko/src/jvmMain/cpp/common/awt_jni.cc
0 → 100644
View file @
b6e0411e
#include <cstdint>
#include <jawt_md.h>
#include "jni_helpers.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
toJavaPointer
(
awt
);
}
}
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_AWTKt_getDrawingSurface
(
JNIEnv
*
env
,
jobject
obj
,
jlong
awtPtr
,
jobject
layer
)
{
JAWT
*
awt
=
fromJavaPointer
<
JAWT
*>
(
awtPtr
);
JAWT_DrawingSurface
*
ds
=
awt
->
GetDrawingSurface
(
env
,
layer
);
return
toJavaPointer
(
ds
);
}
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_AWTKt_freeDrawingSurface
(
JNIEnv
*
env
,
jobject
obj
,
jlong
awtPtr
,
jlong
drawingSurfacePtr
)
{
JAWT
*
awt
=
fromJavaPointer
<
JAWT
*>
(
awtPtr
);
JAWT_DrawingSurface
*
ds
=
fromJavaPointer
<
JAWT_DrawingSurface
*>
(
drawingSurfacePtr
);
awt
->
FreeDrawingSurface
(
ds
);
}
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_AWTKt_lockDrawingSurface
(
JNIEnv
*
env
,
jobject
obj
,
jlong
drawingSurfacePtr
)
{
JAWT_DrawingSurface
*
ds
=
fromJavaPointer
<
JAWT_DrawingSurface
*>
(
drawingSurfacePtr
);
ds
->
Lock
(
ds
);
}
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_AWTKt_unlockDrawingSurface
(
JNIEnv
*
env
,
jobject
obj
,
jlong
drawingSurfacePtr
)
{
JAWT_DrawingSurface
*
ds
=
fromJavaPointer
<
JAWT_DrawingSurface
*>
(
drawingSurfacePtr
);
ds
->
Unlock
(
ds
);
}
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_AWTKt_getDrawingSurfaceInfo
(
JNIEnv
*
env
,
jobject
obj
,
jlong
drawingSurfacePtr
)
{
JAWT_DrawingSurface
*
ds
=
fromJavaPointer
<
JAWT_DrawingSurface
*>
(
drawingSurfacePtr
);
JAWT_DrawingSurfaceInfo
*
dsi
=
ds
->
GetDrawingSurfaceInfo
(
ds
);
return
toJavaPointer
(
dsi
);
}
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_AWTKt_freeDrawingSurfaceInfo
(
JNIEnv
*
env
,
jobject
obj
,
jlong
drawingSurfacePtr
,
jlong
drawingSurfaceInfoPtr
)
{
JAWT_DrawingSurface
*
ds
=
fromJavaPointer
<
JAWT_DrawingSurface
*>
(
drawingSurfacePtr
);
JAWT_DrawingSurfaceInfo
*
dsi
=
fromJavaPointer
<
JAWT_DrawingSurfaceInfo
*>
(
drawingSurfaceInfoPtr
);
ds
->
FreeDrawingSurfaceInfo
(
dsi
);
}
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_AWTKt_getPlatformInfo
(
JNIEnv
*
env
,
jobject
obj
,
jlong
drawingSurfaceInfoPtr
)
{
JAWT_DrawingSurfaceInfo
*
dsi
=
fromJavaPointer
<
JAWT_DrawingSurfaceInfo
*>
(
drawingSurfaceInfoPtr
);
return
toJavaPointer
(
dsi
->
platformInfo
);
}
}
\ No newline at end of file
skiko/src/jvmMain/cpp/include/jni_helpers.h
0 → 100644
View file @
b6e0411e
#pragma once
template
<
typename
T
>
T
inline
fromJavaPointer
(
jlong
ptr
)
{
return
reinterpret_cast
<
T
>
(
static_cast
<
uintptr_t
>
(
ptr
));
}
template
<
typename
T
>
jlong
inline
toJavaPointer
(
T
ptr
)
{
return
static_cast
<
jlong
>
(
reinterpret_cast
<
uintptr_t
>
(
ptr
));
}
\ No newline at end of file
skiko/src/jvmMain/cpp/linux/drawlayer.cc
View file @
b6e0411e
...
@@ -7,14 +7,13 @@
...
@@ -7,14 +7,13 @@
#include <cstdlib>
#include <cstdlib>
#include <unistd.h>
#include <unistd.h>
#include <stdio.h>
#include <stdio.h>
#include "jni_helpers.h"
typedef
GLXContext
(
*
glXCreateContextAttribsARBProc
)(
Display
*
,
GLXFBConfig
,
GLXContext
,
Bool
,
const
int
*
);
typedef
GLXContext
(
*
glXCreateContextAttribsARBProc
)(
Display
*
,
GLXFBConfig
,
GLXContext
,
Bool
,
const
int
*
);
extern
"C"
jboolean
Skiko_GetAWT
(
JNIEnv
*
env
,
JAWT
*
awt
);
extern
"C"
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 +21,10 @@ extern "C"
...
@@ -22,37 +21,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_X11DrawingSurfaceInfo
*
dsi_x11
=
fromJavaPointer
<
JAWT_X11DrawingSurfaceInfo
*>
(
platformInfoPtr
);
JAWT_DrawingSurface
*
ds
=
NULL
;
return
(
jlong
)
dsi_x11
->
drawable
;
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
;
}
}
double
getDpiScaleByDisplay
(
Display
*
display
)
double
getDpiScaleByDisplay
(
Display
*
display
)
...
@@ -77,38 +49,9 @@ extern "C"
...
@@ -77,38 +49,9 @@ extern "C"
return
1
;
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_X11DrawingSurfaceInfo
*
dsi_x11
=
fromJavaPointer
<
JAWT_X11DrawingSurfaceInfo
*>
(
platformInfoPtr
);
JAWT_DrawingSurface
*
ds
=
NULL
;
return
(
float
)
getDpiScaleByDisplay
(
dsi_x11
->
display
);
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
;
}
}
}
// extern "C"
}
// extern "C"
\ No newline at end of file
skiko/src/jvmMain/cpp/linux/redrawer.cc
View file @
b6e0411e
...
@@ -7,74 +7,30 @@
...
@@ -7,74 +7,30 @@
#include <cstdlib>
#include <cstdlib>
#include <unistd.h>
#include <unistd.h>
#include <stdio.h>
#include <stdio.h>
#include "jni_helpers.h"
typedef
GLXContext
(
*
glXCreateContextAttribsARBProc
)(
Display
*
,
GLXFBConfig
,
GLXContext
,
Bool
,
const
int
*
);
typedef
GLXContext
(
*
glXCreateContextAttribsARBProc
)(
Display
*
,
GLXFBConfig
,
GLXContext
,
Bool
,
const
int
*
);
extern
"C"
jboolean
Skiko_GetAWT
(
JNIEnv
*
env
,
JAWT
*
awt
);
extern
"C"
extern
"C"
{
{
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_redrawer_LinuxOpenGLRedrawerKt_lockDrawingSurfaceNative
(
JNIEnv
*
env
,
jobject
redrawer
,
jobject
layer
)
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_redrawer_LinuxOpenGLRedrawerKt_getDisplay
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
platformInfoPtr
)
{
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_X11DrawingSurfaceInfo
*
dsi_x11
=
fromJavaPointer
<
JAWT_X11DrawingSurfaceInfo
*>
(
platformInfoPtr
);
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
;
Display
*
display
=
dsi_x11
->
display
;
Display
*
display
=
dsi_x11
->
display
;
return
toJavaPointer
(
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_X11DrawingSurfaceInfo
*
dsi_x11
=
fromJavaPointer
<
JAWT_X11DrawingSurfaceInfo
*>
(
platformInfoPtr
);
JAWT_DrawingSurfaceInfo
*
dsi
=
ds
->
GetDrawingSurfaceInfo
(
ds
);
JAWT_X11DrawingSurfaceInfo
*
dsi_x11
=
(
JAWT_X11DrawingSurfaceInfo
*
)
dsi
->
platformInfo
;
Window
window
=
dsi_x11
->
drawable
;
Window
window
=
dsi_x11
->
drawable
;
return
toJavaPointer
(
window
);
ds
->
FreeDrawingSurfaceInfo
(
dsi
);
return
static_cast
<
jlong
>
(
reinterpret_cast
<
uintptr_t
>
(
window
));
}
}
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_redrawer_LinuxOpenGLRedrawerKt_setSwapInterval
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
displayPtr
,
jlong
windowPtr
,
jint
interval
)
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_redrawer_LinuxOpenGLRedrawerKt_setSwapInterval
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
displayPtr
,
jlong
windowPtr
,
jint
interval
)
{
{
Display
*
display
=
reinterpret_cast
<
Display
*>
(
static_cast
<
uintptr_t
>
(
displayPtr
)
);
Display
*
display
=
fromJavaPointer
<
Display
*>
(
displayPtr
);
Window
window
=
reinterpret_cast
<
Window
>
(
static_cast
<
uintptr_t
>
(
windowPtr
)
);
Window
window
=
fromJavaPointer
<
Window
>
(
windowPtr
);
// according to:
// according to:
// https://opengl.gpuinfo.org/listreports.php?extension=GLX_EXT_swap_control
// https://opengl.gpuinfo.org/listreports.php?extension=GLX_EXT_swap_control
...
@@ -106,35 +62,35 @@ extern "C"
...
@@ -106,35 +62,35 @@ extern "C"
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_redrawer_LinuxOpenGLRedrawerKt_swapBuffers
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
displayPtr
,
jlong
windowPtr
)
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_redrawer_LinuxOpenGLRedrawerKt_swapBuffers
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
displayPtr
,
jlong
windowPtr
)
{
{
Display
*
display
=
reinterpret_cast
<
Display
*>
(
static_cast
<
uintptr_t
>
(
displayPtr
)
);
Display
*
display
=
fromJavaPointer
<
Display
*>
(
displayPtr
);
Window
window
=
reinterpret_cast
<
Window
>
(
static_cast
<
uintptr_t
>
(
windowPtr
)
);
Window
window
=
fromJavaPointer
<
Window
>
(
windowPtr
);
glXSwapBuffers
(
display
,
window
);
glXSwapBuffers
(
display
,
window
);
}
}
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_redrawer_LinuxOpenGLRedrawerKt_makeCurrent
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
displayPtr
,
jlong
windowPtr
,
jlong
contextPtr
)
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_redrawer_LinuxOpenGLRedrawerKt_makeCurrent
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
displayPtr
,
jlong
windowPtr
,
jlong
contextPtr
)
{
{
Display
*
display
=
reinterpret_cast
<
Display
*>
(
static_cast
<
uintptr_t
>
(
displayPtr
)
);
Display
*
display
=
fromJavaPointer
<
Display
*>
(
displayPtr
);
Window
window
=
reinterpret_cast
<
Window
>
(
static_cast
<
uintptr_t
>
(
windowPtr
)
);
Window
window
=
fromJavaPointer
<
Window
>
(
windowPtr
);
GLXContext
*
context
=
reinterpret_cast
<
GLXContext
*>
(
static_cast
<
uintptr_t
>
(
contextPtr
)
);
GLXContext
*
context
=
fromJavaPointer
<
GLXContext
*>
(
contextPtr
);
glXMakeCurrent
(
display
,
window
,
*
context
);
glXMakeCurrent
(
display
,
window
,
*
context
);
}
}
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_redrawer_LinuxOpenGLRedrawerKt_createContext
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
displayPtr
)
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_redrawer_LinuxOpenGLRedrawerKt_createContext
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
displayPtr
)
{
{
Display
*
display
=
reinterpret_cast
<
Display
*>
(
static_cast
<
uintptr_t
>
(
displayPtr
)
);
Display
*
display
=
fromJavaPointer
<
Display
*>
(
displayPtr
);
GLint
att
[]
=
{
GLX_RGBA
,
GLX_DOUBLEBUFFER
,
True
,
None
};
GLint
att
[]
=
{
GLX_RGBA
,
GLX_DOUBLEBUFFER
,
True
,
None
};
XVisualInfo
*
vi
=
glXChooseVisual
(
display
,
0
,
att
);
XVisualInfo
*
vi
=
glXChooseVisual
(
display
,
0
,
att
);
GLXContext
*
context
=
new
GLXContext
(
glXCreateContext
(
display
,
vi
,
NULL
,
GL_TRUE
));
GLXContext
*
context
=
new
GLXContext
(
glXCreateContext
(
display
,
vi
,
NULL
,
GL_TRUE
));
return
static_cast
<
jlong
>
(
reinterpret_cast
<
uintptr_t
>
(
context
)
);
return
toJavaPointer
(
context
);
}
}
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_redrawer_LinuxOpenGLRedrawerKt_destroyContext
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
displayPtr
,
jlong
contextPtr
)
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_redrawer_LinuxOpenGLRedrawerKt_destroyContext
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
displayPtr
,
jlong
contextPtr
)
{
{
Display
*
display
=
reinterpret_cast
<
Display
*>
(
static_cast
<
uintptr_t
>
(
displayPtr
)
);
Display
*
display
=
fromJavaPointer
<
Display
*>
(
displayPtr
);
GLXContext
*
context
=
reinterpret_cast
<
GLXContext
*>
(
static_cast
<
uintptr_t
>
(
contextPtr
)
);
GLXContext
*
context
=
fromJavaPointer
<
GLXContext
*>
(
contextPtr
);
glXDestroyContext
(
display
,
*
context
);
glXDestroyContext
(
display
,
*
context
);
delete
context
;
delete
context
;
...
...
skiko/src/jvmMain/cpp/windows/drawlayer.cc
View file @
b6e0411e
#define WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#include <jawt_md.h>
#include <jawt_md.h>
#include "jni_helpers.h"
extern
"C"
jboolean
Skiko_GetAWT
(
JNIEnv
*
env
,
JAWT
*
awt
);
extern
"C"
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 +12,9 @@ extern "C"
...
@@ -13,36 +12,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_Win32DrawingSurfaceInfo
*
dsi_win
=
fromJavaPointer
<
JAWT_Win32DrawingSurfaceInfo
*>
(
platformInfoPtr
);
JAWT_DrawingSurface
*
ds
=
NULL
;
return
(
jlong
)
dsi_win
->
hwnd
;
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
;
}
}
}
// extern "C"
}
// extern "C"
\ No newline at end of file
skiko/src/jvmMain/cpp/windows/redrawer.cc
View file @
b6e0411e
...
@@ -3,49 +3,30 @@
...
@@ -3,49 +3,30 @@
#include <gl/GL.h>
#include <gl/GL.h>
#include <jawt_md.h>
#include <jawt_md.h>
#include <dwmapi.h>
#include <dwmapi.h>
#include "jni_helpers.h"
extern
"C"
jboolean
Skiko_GetAWT
(
JNIEnv
*
env
,
JAWT
*
awt
);
extern
"C"
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
;
JAWT_Win32DrawingSurfaceInfo
*
dsi_win
=
fromJavaPointer
<
JAWT_Win32DrawingSurfaceInfo
*>
(
platformInfoPtr
);
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
;
HWND
hwnd
=
dsi_win
->
hwnd
;
HWND
hwnd
=
dsi_win
->
hwnd
;
HDC
device
=
GetDC
(
hwnd
);
HDC
device
=
GetDC
(
hwnd
);
if
(
dsi
!=
NULL
)
PIXELFORMATDESCRIPTOR
pixFormatDscr
;
{
memset
(
&
pixFormatDscr
,
0
,
sizeof
(
PIXELFORMATDESCRIPTOR
));
PIXELFORMATDESCRIPTOR
pixFormatDscr
;
pixFormatDscr
.
nSize
=
sizeof
(
PIXELFORMATDESCRIPTOR
);
memset
(
&
pixFormatDscr
,
0
,
sizeof
(
PIXELFORMATDESCRIPTOR
));
pixFormatDscr
.
nVersion
=
1
;
pixFormatDscr
.
nSize
=
sizeof
(
PIXELFORMATDESCRIPTOR
);
pixFormatDscr
.
dwFlags
=
PFD_DRAW_TO_WINDOW
|
PFD_SUPPORT_OPENGL
|
PFD_DOUBLEBUFFER
;
pixFormatDscr
.
nVersion
=
1
;
pixFormatDscr
.
dwFlags
=
PFD_DRAW_TO_WINDOW
|
PFD_SUPPORT_OPENGL
|
PFD_DOUBLEBUFFER
;
pixFormatDscr
.
iPixelType
=
PFD_TYPE_RGBA
;
pixFormatDscr
.
cColorBits
=
32
;
int
iPixelFormat
=
ChoosePixelFormat
(
device
,
&
pixFormatDscr
);
SetPixelFormat
(
device
,
iPixelFormat
,
&
pixFormatDscr
);
DescribePixelFormat
(
device
,
iPixelFormat
,
sizeof
(
PIXELFORMATDESCRIPTOR
),
&
pixFormatDscr
);
}
ds
->
FreeDrawingSurfaceInfo
(
dsi
);
pixFormatDscr
.
iPixelType
=
PFD_TYPE_RGBA
;
ds
->
Unlock
(
ds
);
pixFormatDscr
.
cColorBits
=
32
;
awt
.
FreeDrawingSurface
(
ds
);
int
iPixelFormat
=
ChoosePixelFormat
(
device
,
&
pixFormatDscr
);
SetPixelFormat
(
device
,
iPixelFormat
,
&
pixFormatDscr
);
DescribePixelFormat
(
device
,
iPixelFormat
,
sizeof
(
PIXELFORMATDESCRIPTOR
),
&
pixFormatDscr
);
return
static_cast
<
jlong
>
(
reinterpret_cast
<
uintptr_t
>
(
device
)
);
return
toJavaPointer
(
device
);
}
}
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_redrawer_WindowsOpenGLRedrawerKt_setSwapInterval
(
JNIEnv
*
env
,
jobject
redrawer
,
jint
interval
)
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_redrawer_WindowsOpenGLRedrawerKt_setSwapInterval
(
JNIEnv
*
env
,
jobject
redrawer
,
jint
interval
)
...
@@ -62,26 +43,26 @@ extern "C"
...
@@ -62,26 +43,26 @@ extern "C"
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_redrawer_WindowsOpenGLRedrawerKt_swapBuffers
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
devicePtr
)
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_redrawer_WindowsOpenGLRedrawerKt_swapBuffers
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
devicePtr
)
{
{
HDC
device
=
reinterpret_cast
<
HDC
>
(
static_cast
<
uintptr_t
>
(
devicePtr
)
);
HDC
device
=
fromJavaPointer
<
HDC
>
(
devicePtr
);
SwapBuffers
(
device
);
SwapBuffers
(
device
);
}
}
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_redrawer_WindowsOpenGLRedrawerKt_makeCurrent
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
devicePtr
,
jlong
contextPtr
)
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_redrawer_WindowsOpenGLRedrawerKt_makeCurrent
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
devicePtr
,
jlong
contextPtr
)
{
{
HDC
device
=
reinterpret_cast
<
HDC
>
(
static_cast
<
uintptr_t
>
(
devicePtr
)
);
HDC
device
=
fromJavaPointer
<
HDC
>
(
devicePtr
);
HGLRC
context
=
reinterpret_cast
<
HGLRC
>
(
static_cast
<
uintptr_t
>
(
contextPtr
)
);
HGLRC
context
=
fromJavaPointer
<
HGLRC
>
(
contextPtr
);
wglMakeCurrent
(
device
,
context
);
wglMakeCurrent
(
device
,
context
);
}
}
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_redrawer_WindowsOpenGLRedrawerKt_createContext
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
devicePtr
)
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_redrawer_WindowsOpenGLRedrawerKt_createContext
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
devicePtr
)
{
{
HDC
device
=
reinterpret_cast
<
HDC
>
(
static_cast
<
uintptr_t
>
(
devicePtr
)
);
HDC
device
=
fromJavaPointer
<
HDC
>
(
devicePtr
);
return
static_cast
<
jlong
>
(
reinterpret_cast
<
uintptr_t
>
(
wglCreateContext
(
device
)
));
return
toJavaPointer
(
wglCreateContext
(
device
));
}
}
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_redrawer_WindowsOpenGLRedrawerKt_deleteContext
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
contextPtr
)
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_redrawer_WindowsOpenGLRedrawerKt_deleteContext
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
contextPtr
)
{
{
HGLRC
context
=
reinterpret_cast
<
HGLRC
>
(
static_cast
<
uintptr_t
>
(
contextPtr
)
);
HGLRC
context
=
fromJavaPointer
<
HGLRC
>
(
contextPtr
);
wglDeleteContext
(
context
);
wglDeleteContext
(
context
);
}
}
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/AWT.kt
0 → 100644
View file @
b6e0411e
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
{
var
ptr
=
getDrawingSurface
(
awt
,
component
).
also
{
check
(
it
!=
0L
)
}
private
set
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
)
ptr
=
0
}
}
internal
class
DrawingSurfaceInfo
(
private
val
drawingSurface
:
Long
)
:
AutoCloseable
{
var
ptr
=
getDrawingSurfaceInfo
(
drawingSurface
).
also
{
check
(
it
!=
0L
)
}
private
set
val
platformInfo
:
Long
get
()
=
getPlatformInfo
(
ptr
)
override
fun
close
()
{
freeDrawingSurfaceInfo
(
drawingSurface
,
ptr
)
ptr
=
0
}
}
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 @
b6e0411e
...
@@ -32,7 +32,13 @@ abstract class HardwareLayer : Canvas() {
...
@@ -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
()
open
external
fun
dispose
()
protected
open
fun
contentScaleChanged
()
=
Unit
protected
open
fun
contentScaleChanged
()
=
Unit
...
@@ -68,7 +74,7 @@ abstract class HardwareLayer : Canvas() {
...
@@ -68,7 +74,7 @@ abstract class HardwareLayer : Canvas() {
internal
abstract
fun
draw
()
internal
abstract
fun
draw
()
val
windowHandle
:
Long
val
windowHandle
:
Long
external
get
get
()
=
useDrawingSurfacePlatformInfo
(
::
getWindowHandle
)
val
contentScale
:
Float
val
contentScale
:
Float
get
()
=
_contentScale
!!
get
()
=
_contentScale
!!
...
@@ -76,4 +82,6 @@ abstract class HardwareLayer : Canvas() {
...
@@ -76,4 +82,6 @@ abstract class HardwareLayer : Canvas() {
var
fullscreen
:
Boolean
var
fullscreen
:
Boolean
get
()
=
platformOperations
.
isFullscreen
(
this
)
get
()
=
platformOperations
.
isFullscreen
(
this
)
set
(
value
)
=
platformOperations
.
setFullscreen
(
this
,
value
)
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 @
b6e0411e
...
@@ -88,7 +88,7 @@ internal val platformOperations: PlatformOperations by lazy {
...
@@ -88,7 +88,7 @@ internal val platformOperations: PlatformOperations by lazy {
// see also comment for HardwareLayer.checkContentScale
// see also comment for HardwareLayer.checkContentScale
// return linuxGetDpiScaleNative(component
)
// return component.useDrawingSurfacePlatformInfo(::linuxGetDpiScaleNative
)
}
}
override
fun
createRedrawer
(
layer
:
HardwareLayer
)
=
when
(
renderApi
)
{
override
fun
createRedrawer
(
layer
:
HardwareLayer
)
=
when
(
renderApi
)
{
...
@@ -105,4 +105,4 @@ external private fun osxIsFullscreenNative(component: Component): Boolean
...
@@ -105,4 +105,4 @@ external private fun osxIsFullscreenNative(component: Component): Boolean
external
private
fun
osxSetFullscreenNative
(
component
:
Component
,
value
:
Boolean
)
external
private
fun
osxSetFullscreenNative
(
component
:
Component
,
value
:
Boolean
)
// Linux
// 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 @
b6e0411e
...
@@ -3,10 +3,12 @@ package org.jetbrains.skiko.redrawer
...
@@ -3,10 +3,12 @@ package org.jetbrains.skiko.redrawer
import
kotlinx.coroutines.CancellationException
import
kotlinx.coroutines.CancellationException
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.swing.Swing
import
kotlinx.coroutines.swing.Swing
import
org.jetbrains.skiko.DrawingSurface
import
org.jetbrains.skiko.FrameDispatcher
import
org.jetbrains.skiko.FrameDispatcher
import
org.jetbrains.skiko.HardwareLayer
import
org.jetbrains.skiko.HardwareLayer
import
org.jetbrains.skiko.OpenGLApi
import
org.jetbrains.skiko.OpenGLApi
import
org.jetbrains.skiko.SkikoProperties
import
org.jetbrains.skiko.SkikoProperties
import
org.jetbrains.skiko.getDrawingSurface
internal
class
LinuxOpenGLRedrawer
(
internal
class
LinuxOpenGLRedrawer
(
private
val
layer
:
HardwareLayer
private
val
layer
:
HardwareLayer
...
@@ -92,7 +94,7 @@ internal class LinuxOpenGLRedrawer(
...
@@ -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
)
val
drawingSurface
=
lockDrawingSurface
(
this
)
try
{
try
{
return
action
(
drawingSurface
)
return
action
(
drawingSurface
)
...
@@ -101,17 +103,21 @@ private inline fun <T> HardwareLayer.lockDrawingSurface(action: (DrawingSurface)
...
@@ -101,17 +103,21 @@ private inline fun <T> HardwareLayer.lockDrawingSurface(action: (DrawingSurface)
}
}
}
}
private
fun
lockDrawingSurface
(
layer
:
HardwareLayer
):
DrawingSurface
{
private
fun
lockDrawingSurface
(
layer
:
HardwareLayer
):
LinuxDrawingSurface
{
val
ptr
=
lockDrawingSurfaceNative
(
layer
)
val
drawingSurface
=
layer
.
getDrawingSurface
()
return
DrawingSurface
(
ptr
,
getDisplay
(
ptr
),
getWindow
(
ptr
))
drawingSurface
.
lock
()
return
drawingSurface
.
getInfo
().
use
{
LinuxDrawingSurface
(
drawingSurface
,
getDisplay
(
it
.
platformInfo
),
getWindow
(
it
.
platformInfo
))
}
}
}
private
fun
unlockDrawingSurface
(
drawingSurface
:
DrawingSurface
)
{
private
fun
unlockDrawingSurface
(
drawingSurface
:
LinuxDrawingSurface
)
{
unlockDrawingSurfaceNative
(
drawingSurface
.
ptr
)
drawingSurface
.
common
.
unlock
()
drawingSurface
.
common
.
close
()
}
}
private
class
DrawingSurface
(
private
class
Linux
DrawingSurface
(
val
ptr
:
Long
,
val
common
:
DrawingSurface
,
val
display
:
Long
,
val
display
:
Long
,
val
window
:
Long
val
window
:
Long
)
{
)
{
...
@@ -122,10 +128,8 @@ private class DrawingSurface(
...
@@ -122,10 +128,8 @@ private class DrawingSurface(
fun
setSwapInterval
(
interval
:
Int
)
=
setSwapInterval
(
display
,
window
,
interval
)
fun
setSwapInterval
(
interval
:
Int
)
=
setSwapInterval
(
display
,
window
,
interval
)
}
}
private
external
fun
lockDrawingSurfaceNative
(
layer
:
HardwareLayer
):
Long
private
external
fun
getDisplay
(
platformInfo
:
Long
):
Long
private
external
fun
unlockDrawingSurfaceNative
(
drawingSurface
:
Long
)
private
external
fun
getWindow
(
platformInfo
:
Long
):
Long
private
external
fun
getDisplay
(
drawingSurface
:
Long
):
Long
private
external
fun
getWindow
(
drawingSurface
:
Long
):
Long
private
external
fun
makeCurrent
(
display
:
Long
,
window
:
Long
,
context
:
Long
)
private
external
fun
makeCurrent
(
display
:
Long
,
window
:
Long
,
context
:
Long
)
private
external
fun
createContext
(
display
:
Long
):
Long
private
external
fun
createContext
(
display
:
Long
):
Long
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/redrawer/MacOsOpenGLRedrawer.kt
View file @
b6e0411e
...
@@ -6,6 +6,7 @@ import org.jetbrains.skiko.FrameDispatcher
...
@@ -6,6 +6,7 @@ import org.jetbrains.skiko.FrameDispatcher
import
org.jetbrains.skiko.HardwareLayer
import
org.jetbrains.skiko.HardwareLayer
import
org.jetbrains.skiko.OpenGLApi
import
org.jetbrains.skiko.OpenGLApi
import
org.jetbrains.skiko.SkikoProperties
import
org.jetbrains.skiko.SkikoProperties
import
org.jetbrains.skiko.useDrawingSurfacePlatformInfo
import
org.jetbrains.skiko.Task
import
org.jetbrains.skiko.Task
import
javax.swing.SwingUtilities.convertPoint
import
javax.swing.SwingUtilities.convertPoint
import
javax.swing.SwingUtilities.getRootPane
import
javax.swing.SwingUtilities.getRootPane
...
@@ -13,7 +14,7 @@ import javax.swing.SwingUtilities.getRootPane
...
@@ -13,7 +14,7 @@ import javax.swing.SwingUtilities.getRootPane
internal
class
MacOsOpenGLRedrawer
(
internal
class
MacOsOpenGLRedrawer
(
private
val
layer
:
HardwareLayer
private
val
layer
:
HardwareLayer
)
:
Redrawer
{
)
:
Redrawer
{
private
val
containerLayerPtr
=
initContainer
(
lay
er
)
private
val
containerLayerPtr
=
layer
.
useDrawingSurfacePlatformInfo
(
::
initContain
er
)
private
val
drawLock
=
Any
()
private
val
drawLock
=
Any
()
private
var
isDisposed
=
false
private
var
isDisposed
=
false
...
@@ -161,7 +162,7 @@ private abstract class AWTGLLayer(private val containerPtr: Long, setNeedsDispla
...
@@ -161,7 +162,7 @@ private abstract class AWTGLLayer(private val containerPtr: Long, setNeedsDispla
protected
external
fun
setFrame
(
containerPtr
:
Long
,
ptr
:
Long
,
x
:
Float
,
y
:
Float
,
width
:
Float
,
height
:
Float
)
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
setContentScale
(
layerNativePtr
:
Long
,
contentScale
:
Float
)
private
external
fun
initAWTGLLayer
(
containerPtr
:
Long
,
layer
:
AWTGLLayer
,
setNeedsDisplayOnBoundsChange
:
Boolean
):
Long
private
external
fun
initAWTGLLayer
(
containerPtr
:
Long
,
layer
:
AWTGLLayer
,
setNeedsDisplayOnBoundsChange
:
Boolean
):
Long
private
external
fun
disposeAWTGLLayer
(
ptr
:
Long
)
private
external
fun
disposeAWTGLLayer
(
ptr
:
Long
)
\ No newline at end of file
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/redrawer/WindowsOpenGLRedrawer.kt
View file @
b6e0411e
...
@@ -8,11 +8,12 @@ import org.jetbrains.skiko.FrameDispatcher
...
@@ -8,11 +8,12 @@ import org.jetbrains.skiko.FrameDispatcher
import
org.jetbrains.skiko.HardwareLayer
import
org.jetbrains.skiko.HardwareLayer
import
org.jetbrains.skiko.OpenGLApi
import
org.jetbrains.skiko.OpenGLApi
import
org.jetbrains.skiko.SkikoProperties
import
org.jetbrains.skiko.SkikoProperties
import
org.jetbrains.skiko.useDrawingSurfacePlatformInfo
internal
class
WindowsOpenGLRedrawer
(
internal
class
WindowsOpenGLRedrawer
(
private
val
layer
:
HardwareLayer
private
val
layer
:
HardwareLayer
)
:
Redrawer
{
)
:
Redrawer
{
private
val
device
=
getDevice
(
layer
)
private
val
device
=
layer
.
useDrawingSurfacePlatformInfo
(
::
getDevice
)
private
val
context
=
createContext
(
device
)
private
val
context
=
createContext
(
device
)
private
var
isDisposed
=
false
private
var
isDisposed
=
false
...
@@ -101,7 +102,7 @@ internal class WindowsOpenGLRedrawer(
...
@@ -101,7 +102,7 @@ internal class WindowsOpenGLRedrawer(
}
}
private
external
fun
makeCurrent
(
device
:
Long
,
context
:
Long
)
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
createContext
(
device
:
Long
):
Long
private
external
fun
deleteContext
(
context
:
Long
)
private
external
fun
deleteContext
(
context
:
Long
)
private
external
fun
setSwapInterval
(
interval
:
Int
)
private
external
fun
setSwapInterval
(
interval
:
Int
)
...
...
skiko/src/jvmMain/objectiveC/macos/drawlayer.m
View file @
b6e0411e
...
@@ -79,66 +79,37 @@ LayerHandler * findByObject(JNIEnv *env, jobject object)
...
@@ -79,66 +79,37 @@ LayerHandler * findByObject(JNIEnv *env, jobject object)
return
NULL
;
return
NULL
;
}
}
extern
jboolean
Skiko_GetAWT
(
JNIEnv
*
env
,
JAWT
*
awt
);
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_HardwareLayer_nativeInit
(
JNIEnv
*
env
,
jobject
canvas
,
jlong
platformInfoPtr
)
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_HardwareLayer_init
(
JNIEnv
*
env
,
jobject
canvas
)
{
{
if
(
layerStorage
==
nil
)
if
(
layerStorage
==
nil
)
{
{
layerStorage
=
[[
NSMutableSet
alloc
]
init
];
layerStorage
=
[[
NSMutableSet
alloc
]
init
];
}
}
JAWT
awt
;
NSObject
<
JAWT_SurfaceLayers
>*
dsi_mac
=
(
__bridge
NSObject
<
JAWT_SurfaceLayers
>
*
)
platformInfoPtr
;
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
);
LayerHandler
*
layersSet
=
[[
LayerHandler
alloc
]
init
];
assert
(
ds
!=
NULL
);
lock
=
ds
->
Lock
(
ds
);
layersSet
.
container
=
[
dsi_mac
windowLayer
];
assert
((
lock
&
JAWT_LOCK_ERROR
)
==
0
);
jobject
canvasGlobalRef
=
(
*
env
)
->
NewGlobalRef
(
env
,
canvas
);
[
layersSet
setCanvasGlobalRef
:
canvasGlobalRef
];
dsi
=
ds
->
GetDrawingSurfaceInfo
(
ds
)
;
NSMutableArray
<
NSWindow
*>
*
windows
=
[
NSMutableArray
arrayWithArray
:
[[
NSApplication
sharedApplication
]
windows
]]
;
if
(
dsi
!=
NULL
)
for
(
LayerHandler
*
value
in
layerStorage
)
{
{
dsi_mac
=
(
__bridge
NSObject
<
JAWT_SurfaceLayers
>
*
)
dsi
->
platformInfo
;
if
(
layersSet
.
container
==
value
.
container
)
LayerHandler
*
layersSet
=
[[
LayerHandler
alloc
]
init
];
layersSet
.
container
=
[
dsi_mac
windowLayer
];
jobject
canvasGlobalRef
=
(
*
env
)
->
NewGlobalRef
(
env
,
canvas
);
[
layersSet
setCanvasGlobalRef
:
canvasGlobalRef
];
NSMutableArray
<
NSWindow
*>
*
windows
=
[
NSMutableArray
arrayWithArray
:
[[
NSApplication
sharedApplication
]
windows
]];
for
(
LayerHandler
*
value
in
layerStorage
)
{
if
(
layersSet
.
container
==
value
.
container
)
{
layersSet
.
window
=
value
.
window
;
}
}
if
(
layersSet
.
window
==
NULL
)
{
{
layersSet
.
window
=
[
windows
lastObject
]
;
layersSet
.
window
=
value
.
window
;
}
}
}
[
layerStorage
addObject
:
layersSet
];
if
(
layersSet
.
window
==
NULL
)
{
layersSet
.
window
=
[
windows
lastObject
];
}
}
ds
->
FreeDrawingSurfaceInfo
(
dsi
);
[
layerStorage
addObject
:
layersSet
];
ds
->
Unlock
(
ds
);
awt
.
FreeDrawingSurface
(
ds
);
}
}
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_HardwareLayer_dispose
(
JNIEnv
*
env
,
jobject
canvas
)
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skiko_HardwareLayer_dispose
(
JNIEnv
*
env
,
jobject
canvas
)
...
...
skiko/src/jvmMain/objectiveC/macos/redrawer.m
View file @
b6e0411e
...
@@ -7,8 +7,6 @@
...
@@ -7,8 +7,6 @@
#import <QuartzCore/QuartzCore.h>
#import <QuartzCore/QuartzCore.h>
#import <OpenGL/gl3.h>
#import <OpenGL/gl3.h>
extern
jboolean
Skiko_GetAWT
(
JNIEnv
*
env
,
JAWT
*
awt
);
JavaVM
*
jvm
=
NULL
;
JavaVM
*
jvm
=
NULL
;
@interface
AWTGLLayer
:
CAOpenGLLayer
@interface
AWTGLLayer
:
CAOpenGLLayer
...
@@ -69,35 +67,17 @@ JavaVM *jvm = NULL;
...
@@ -69,35 +67,17 @@ JavaVM *jvm = NULL;
@end
@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
);
(
*
env
)
->
GetJavaVM
(
env
,
&
jvm
);
JAWT_DrawingSurface
*
ds
=
awt
.
GetDrawingSurface
(
env
,
layer
);
NSObject
<
JAWT_SurfaceLayers
>*
dsi_mac
=
(
__bridge
NSObject
<
JAWT_SurfaceLayers
>
*
)
platformInfoPtr
;
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
;
CALayer
*
container
=
[
dsi_mac
windowLayer
];
CALayer
*
container
=
[
dsi_mac
windowLayer
];
[
container
removeAllAnimations
];
[
container
removeAllAnimations
];
[
container
setAutoresizingMask
:
(
kCALayerWidthSizable
|
kCALayerHeightSizable
)];
[
container
setAutoresizingMask
:
(
kCALayerWidthSizable
|
kCALayerHeightSizable
)];
[
container
setNeedsDisplayOnBoundsChange
:
YES
];
[
container
setNeedsDisplayOnBoundsChange
:
YES
];
ds
->
FreeDrawingSurfaceInfo
(
dsi
);
ds
->
Unlock
(
ds
);
awt
.
FreeDrawingSurface
(
ds
);
return
(
jlong
)
container
;
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