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
cf6413c8
Unverified
Commit
cf6413c8
authored
Oct 11, 2021
by
Roman Sedaikin
Committed by
GitHub
Oct 11, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Transparency in window support. (#232)
Transparency support.
parent
358ae344
Changes
24
Show whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
158 additions
and
29 deletions
+158
-29
build.gradle.kts
samples/SkiaJvmSample/build.gradle.kts
+5
-0
App.kt
samples/SkiaJvmSample/src/main/kotlin/SkiaJvmSample/App.kt
+10
-0
SkiaLayer.kt
skiko/src/commonMain/kotlin/org/jetbrains/skiko/SkiaLayer.kt
+2
-0
ContextHandler.kt
...Main/kotlin/org/jetbrains/skiko/context/ContextHandler.kt
+4
-3
SkiaLayer.ios.kt
...o/src/iosMain/kotlin/org/jetbrains/skiko/SkiaLayer.ios.kt
+6
-0
SkiaLayer.js.kt
skiko/src/jsMain/kotlin/org/jetbrains/skiko/SkiaLayer.js.kt
+6
-0
window_util.h
skiko/src/jvmMain/cpp/include/window_util.h
+6
-0
redrawer.cc
skiko/src/jvmMain/cpp/linux/redrawer.cc
+20
-3
SoftwareRedrawer.cc
skiko/src/jvmMain/cpp/windows/SoftwareRedrawer.cc
+7
-1
directXRedrawer.cc
skiko/src/jvmMain/cpp/windows/directXRedrawer.cc
+10
-1
openGLRedrawer.cc
skiko/src/jvmMain/cpp/windows/openGLRedrawer.cc
+10
-2
window_util.cc
skiko/src/jvmMain/cpp/windows/window_util.cc
+16
-0
SkiaLayer.jvm.kt
...o/src/jvmMain/kotlin/org/jetbrains/skiko/SkiaLayer.jvm.kt
+16
-2
DirectSoftwareContextHandler.kt
...g/jetbrains/skiko/context/DirectSoftwareContextHandler.kt
+0
-1
SoftwareContextHandler.kt
...lin/org/jetbrains/skiko/context/SoftwareContextHandler.kt
+10
-2
Direct3DRedrawer.kt
...n/kotlin/org/jetbrains/skiko/redrawer/Direct3DRedrawer.kt
+2
-2
LinuxOpenGLRedrawer.kt
...otlin/org/jetbrains/skiko/redrawer/LinuxOpenGLRedrawer.kt
+3
-3
MetalRedrawer.kt
...Main/kotlin/org/jetbrains/skiko/redrawer/MetalRedrawer.kt
+2
-2
WindowsOpenGLRedrawer.kt
...lin/org/jetbrains/skiko/redrawer/WindowsOpenGLRedrawer.kt
+2
-2
WindowsSoftwareRedrawer.kt
...n/org/jetbrains/skiko/redrawer/WindowsSoftwareRedrawer.kt
+2
-2
Drawlayer.mm
skiko/src/jvmMain/objectiveC/macos/Drawlayer.mm
+0
-2
MetalRedrawer.mm
skiko/src/jvmMain/objectiveC/macos/MetalRedrawer.mm
+7
-1
SkiaLayer.linux.kt
...c/linuxMain/kotlin/org/jetbrains/skiko/SkiaLayer.linux.kt
+6
-0
SkiaLayer.macos.kt
...c/macosMain/kotlin/org/jetbrains/skiko/SkiaLayer.macos.kt
+6
-0
No files found.
samples/SkiaJvmSample/build.gradle.kts
View file @
cf6413c8
...
@@ -71,6 +71,11 @@ tasks.register("runSoftware") {
...
@@ -71,6 +71,11 @@ tasks.register("runSoftware") {
dependsOn
(
casualRun
)
dependsOn
(
casualRun
)
}
}
tasks
.
register
(
"runWithTransparency"
)
{
additionalArguments
+=
mapOf
(
"skiko.transparency"
to
"true"
)
dependsOn
(
casualRun
)
}
tasks
.
withType
<
KotlinCompile
>().
configureEach
{
tasks
.
withType
<
KotlinCompile
>().
configureEach
{
kotlinOptions
.
freeCompilerArgs
+=
"-Xopt-in=kotlin.RequiresOptIn"
kotlinOptions
.
freeCompilerArgs
+=
"-Xopt-in=kotlin.RequiresOptIn"
}
}
samples/SkiaJvmSample/src/main/kotlin/SkiaJvmSample/App.kt
View file @
cf6413c8
...
@@ -110,6 +110,16 @@ fun createWindow(title: String, exitOnClose: Boolean) = SwingUtilities.invokeLat
...
@@ -110,6 +110,16 @@ fun createWindow(title: String, exitOnClose: Boolean) = SwingUtilities.invokeLat
}
}
})
})
// Window transparency
if
(
System
.
getProperty
(
"skiko.transparency"
)
==
"true"
)
{
window
.
setUndecorated
(
true
)
// On Windows we don't set transparent background to avoid event input issues (JDK specific)
if
(
hostOs
!=
OS
.
Windows
)
{
window
.
background
=
java
.
awt
.
Color
(
0
,
0
,
0
,
0
)
}
window
.
layer
.
transparency
=
true
}
// MANDATORY: set window preferred size before calling pack()
// MANDATORY: set window preferred size before calling pack()
window
.
preferredSize
=
Dimension
(
800
,
600
)
window
.
preferredSize
=
Dimension
(
800
,
600
)
window
.
pack
()
window
.
pack
()
...
...
skiko/src/commonMain/kotlin/org/jetbrains/skiko/SkiaLayer.kt
View file @
cf6413c8
...
@@ -10,6 +10,8 @@ interface SkiaRenderer {
...
@@ -10,6 +10,8 @@ interface SkiaRenderer {
expect
open
class
SkiaLayer
{
expect
open
class
SkiaLayer
{
var
renderApi
:
GraphicsApi
var
renderApi
:
GraphicsApi
val
contentScale
:
Float
val
contentScale
:
Float
var
fullscreen
:
Boolean
var
transparency
:
Boolean
}
}
internal
class
PictureHolder
(
val
instance
:
Picture
,
val
width
:
Int
,
val
height
:
Int
)
internal
class
PictureHolder
(
val
instance
:
Picture
,
val
width
:
Int
,
val
height
:
Int
)
skiko/src/commonMain/kotlin/org/jetbrains/skiko/context/ContextHandler.kt
View file @
cf6413c8
...
@@ -5,13 +5,13 @@ import org.jetbrains.skia.Canvas
...
@@ -5,13 +5,13 @@ import org.jetbrains.skia.Canvas
import
org.jetbrains.skia.DirectContext
import
org.jetbrains.skia.DirectContext
import
org.jetbrains.skia.Picture
import
org.jetbrains.skia.Picture
import
org.jetbrains.skia.Surface
import
org.jetbrains.skia.Surface
import
org.jetbrains.skiko.
OS
import
org.jetbrains.skiko.
GraphicsApi
import
org.jetbrains.skiko.SkiaLayer
import
org.jetbrains.skiko.SkiaLayer
import
org.jetbrains.skiko.hostArch
import
org.jetbrains.skiko.hostArch
import
org.jetbrains.skiko.hostOs
import
org.jetbrains.skiko.hostOs
internal
abstract
class
ContextHandler
(
val
layer
:
SkiaLayer
)
{
internal
abstract
class
ContextHandler
(
val
layer
:
SkiaLayer
)
{
open
val
bleachConstant
=
if
(
hostOs
==
OS
.
MacOS
)
0
else
-
1
open
val
clearColor
=
if
(
layer
.
transparency
)
0
else
-
1
var
context
:
DirectContext
?
=
null
var
context
:
DirectContext
?
=
null
var
renderTarget
:
BackendRenderTarget
?
=
null
var
renderTarget
:
BackendRenderTarget
?
=
null
var
surface
:
Surface
?
=
null
var
surface
:
Surface
?
=
null
...
@@ -21,7 +21,8 @@ internal abstract class ContextHandler(val layer: SkiaLayer) {
...
@@ -21,7 +21,8 @@ internal abstract class ContextHandler(val layer: SkiaLayer) {
abstract
fun
initCanvas
()
abstract
fun
initCanvas
()
fun
clearCanvas
()
{
fun
clearCanvas
()
{
canvas
?.
clear
(
bleachConstant
)
val
color
=
if
(
layer
.
fullscreen
)
-
1
else
clearColor
canvas
?.
clear
(
color
)
}
}
open
fun
drawOnCanvas
(
picture
:
Picture
)
{
open
fun
drawOnCanvas
(
picture
:
Picture
)
{
...
...
skiko/src/iosMain/kotlin/org/jetbrains/skiko/SkiaLayer.ios.kt
View file @
cf6413c8
...
@@ -6,4 +6,10 @@ actual open class SkiaLayer {
...
@@ -6,4 +6,10 @@ actual open class SkiaLayer {
set
(
value
)
{}
set
(
value
)
{}
actual
val
contentScale
:
Float
actual
val
contentScale
:
Float
get
()
=
TODO
(
"Not yet implemented"
)
get
()
=
TODO
(
"Not yet implemented"
)
actual
var
fullscreen
:
Boolean
get
()
=
TODO
(
"Not yet implemented"
)
set
(
value
)
{}
actual
var
transparency
:
Boolean
get
()
=
TODO
(
"Not yet implemented"
)
set
(
value
)
{}
}
}
\ No newline at end of file
skiko/src/jsMain/kotlin/org/jetbrains/skiko/SkiaLayer.js.kt
View file @
cf6413c8
...
@@ -4,4 +4,10 @@ actual open class SkiaLayer {
...
@@ -4,4 +4,10 @@ actual open class SkiaLayer {
actual
var
renderApi
:
GraphicsApi
=
GraphicsApi
.
WEBGL
actual
var
renderApi
:
GraphicsApi
=
GraphicsApi
.
WEBGL
actual
val
contentScale
:
Float
actual
val
contentScale
:
Float
get
()
=
1.0f
get
()
=
1.0f
actual
var
fullscreen
:
Boolean
get
()
=
false
set
(
value
)
=
throw
Exception
(
"Fullscreen is not supported!"
)
actual
var
transparency
:
Boolean
get
()
=
false
set
(
value
)
=
throw
Exception
(
"Transparency is not supported!"
)
}
}
skiko/src/jvmMain/cpp/include/window_util.h
0 → 100644
View file @
cf6413c8
#if SK_BUILD_FOR_WIN
#include <dwmapi.h>
void
enableTransparentWindow
(
HWND
hwnd
);
#endif
skiko/src/jvmMain/cpp/linux/redrawer.cc
View file @
cf6413c8
...
@@ -63,13 +63,30 @@ extern "C"
...
@@ -63,13 +63,30 @@ extern "C"
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
,
jboolean
transparency
)
{
{
Display
*
display
=
fromJavaPointer
<
Display
*>
(
displayPtr
);
Display
*
display
=
fromJavaPointer
<
Display
*>
(
displayPtr
);
if
(
!
display
)
return
0
;
if
(
!
display
)
return
0
;
XVisualInfo
*
vi
;
if
(
transparency
)
{
GLint
att
[]
=
{
GLX_RGBA
,
GLX_RED_SIZE
,
8
,
GLX_GREEN_SIZE
,
8
,
GLX_BLUE_SIZE
,
8
,
GLX_ALPHA_SIZE
,
8
,
GLX_DEPTH_SIZE
,
32
,
GLX_DOUBLEBUFFER
,
True
,
None
};
vi
=
glXChooseVisual
(
display
,
0
,
att
);
}
else
{
GLint
att
[]
=
{
GLX_RGBA
,
GLX_DOUBLEBUFFER
,
True
,
None
};
GLint
att
[]
=
{
GLX_RGBA
,
GLX_DOUBLEBUFFER
,
True
,
None
};
XVisualInfo
*
vi
=
glXChooseVisual
(
display
,
0
,
att
);
vi
=
glXChooseVisual
(
display
,
0
,
att
);
}
if
(
!
vi
)
return
0
;
if
(
!
vi
)
return
0
;
...
...
skiko/src/jvmMain/cpp/windows/SoftwareRedrawer.cc
View file @
cf6413c8
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#include <jawt_md.h>
#include <jawt_md.h>
#include "jni_helpers.h"
#include "jni_helpers.h"
#include "exceptions_handler.h"
#include "exceptions_handler.h"
#include "window_util.h"
#include "SkSurface.h"
#include "SkSurface.h"
#include "src/core/SkAutoMalloc.h"
#include "src/core/SkAutoMalloc.h"
...
@@ -20,10 +21,15 @@ public:
...
@@ -20,10 +21,15 @@ public:
extern
"C"
extern
"C"
{
{
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_redrawer_WindowsSoftwareRedrawer_createDevice
(
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_redrawer_WindowsSoftwareRedrawer_createDevice
(
JNIEnv
*
env
,
jobject
redrawer
,
jlong
contentHandle
)
JNIEnv
*
env
,
jobject
redrawer
,
jlong
contentHandle
,
jboolean
transparency
)
{
{
SoftwareDevice
*
device
=
new
SoftwareDevice
();
SoftwareDevice
*
device
=
new
SoftwareDevice
();
device
->
window
=
(
HWND
)
contentHandle
;
device
->
window
=
(
HWND
)
contentHandle
;
if
(
transparency
)
{
HWND
parent
=
GetAncestor
(
device
->
window
,
GA_PARENT
);
enableTransparentWindow
(
parent
);
}
GetClientRect
(
device
->
window
,
&
device
->
clientRect
);
GetClientRect
(
device
->
window
,
&
device
->
clientRect
);
return
toJavaPointer
(
device
);
return
toJavaPointer
(
device
);
}
}
...
...
skiko/src/jvmMain/cpp/windows/directXRedrawer.cc
View file @
cf6413c8
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#include <jawt_md.h>
#include <jawt_md.h>
#include "jni_helpers.h"
#include "jni_helpers.h"
#include "exceptions_handler.h"
#include "exceptions_handler.h"
#include "window_util.h"
#include "GrBackendSurface.h"
#include "GrBackendSurface.h"
#include "GrDirectContext.h"
#include "GrDirectContext.h"
...
@@ -289,7 +290,7 @@ extern "C"
...
@@ -289,7 +290,7 @@ extern "C"
}
}
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_redrawer_Direct3DRedrawer_createDirectXDevice
(
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skiko_redrawer_Direct3DRedrawer_createDirectXDevice
(
JNIEnv
*
env
,
jobject
redrawer
,
jint
adapterPriority
,
jlong
contentHandle
)
JNIEnv
*
env
,
jobject
redrawer
,
jint
adapterPriority
,
jlong
contentHandle
,
jboolean
transparency
)
{
{
gr_cp
<
IDXGIFactory4
>
deviceFactory
;
gr_cp
<
IDXGIFactory4
>
deviceFactory
;
if
(
!
SUCCEEDED
(
CreateDXGIFactory1
(
IID_PPV_ARGS
(
&
deviceFactory
))))
if
(
!
SUCCEEDED
(
CreateDXGIFactory1
(
IID_PPV_ARGS
(
&
deviceFactory
))))
...
@@ -329,6 +330,14 @@ extern "C"
...
@@ -329,6 +330,14 @@ extern "C"
d3dDevice
->
queue
=
queue
;
d3dDevice
->
queue
=
queue
;
d3dDevice
->
window
=
(
HWND
)
contentHandle
;
d3dDevice
->
window
=
(
HWND
)
contentHandle
;
if
(
transparency
)
{
//TODO: current swapChain does not support transparency
return
0
;
// HWND wnd = GetAncestor(d3dDevice->window, GA_PARENT);
// enableTransparentWindow(wnd);
}
return
toJavaPointer
(
d3dDevice
);
return
toJavaPointer
(
d3dDevice
);
}
}
...
...
skiko/src/jvmMain/cpp/windows/openGLRedrawer.cc
View file @
cf6413c8
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include <dwmapi.h>
#include <dwmapi.h>
#include "jni_helpers.h"
#include "jni_helpers.h"
#include "exceptions_handler.h"
#include "exceptions_handler.h"
#include "window_util.h"
extern
"C"
extern
"C"
{
{
...
@@ -20,10 +21,11 @@ extern "C"
...
@@ -20,10 +21,11 @@ extern "C"
memset
(
&
pixFormatDscr
,
0
,
sizeof
(
PIXELFORMATDESCRIPTOR
));
memset
(
&
pixFormatDscr
,
0
,
sizeof
(
PIXELFORMATDESCRIPTOR
));
pixFormatDscr
.
nSize
=
sizeof
(
PIXELFORMATDESCRIPTOR
);
pixFormatDscr
.
nSize
=
sizeof
(
PIXELFORMATDESCRIPTOR
);
pixFormatDscr
.
nVersion
=
1
;
pixFormatDscr
.
nVersion
=
1
;
pixFormatDscr
.
dwFlags
=
PFD_DRAW_TO_WINDOW
|
PFD_SUPPORT_OPENGL
|
PFD_DOUBLEBUFFER
;
pixFormatDscr
.
dwFlags
=
PFD_DRAW_TO_WINDOW
|
PFD_SUPPORT_OPENGL
|
PFD_DOUBLEBUFFER
|
PFD_SUPPORT_COMPOSITION
;
pixFormatDscr
.
iPixelType
=
PFD_TYPE_RGBA
;
pixFormatDscr
.
iPixelType
=
PFD_TYPE_RGBA
;
pixFormatDscr
.
cColorBits
=
32
;
pixFormatDscr
.
cColorBits
=
32
;
pixFormatDscr
.
cAlphaBits
=
8
;
int
iPixelFormat
=
ChoosePixelFormat
(
device
,
&
pixFormatDscr
);
int
iPixelFormat
=
ChoosePixelFormat
(
device
,
&
pixFormatDscr
);
SetPixelFormat
(
device
,
iPixelFormat
,
&
pixFormatDscr
);
SetPixelFormat
(
device
,
iPixelFormat
,
&
pixFormatDscr
);
DescribePixelFormat
(
device
,
iPixelFormat
,
sizeof
(
PIXELFORMATDESCRIPTOR
),
&
pixFormatDscr
);
DescribePixelFormat
(
device
,
iPixelFormat
,
sizeof
(
PIXELFORMATDESCRIPTOR
),
&
pixFormatDscr
);
...
@@ -76,10 +78,16 @@ extern "C"
...
@@ -76,10 +78,16 @@ extern "C"
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
,
jlong
contentHandle
,
jboolean
transparency
)
{
{
__try
__try
{
{
if
(
transparency
)
{
HWND
parent
=
GetAncestor
(
fromJavaPointer
<
HWND
>
(
contentHandle
),
GA_PARENT
);
enableTransparentWindow
(
parent
);
}
HDC
device
=
fromJavaPointer
<
HDC
>
(
devicePtr
);
HDC
device
=
fromJavaPointer
<
HDC
>
(
devicePtr
);
return
toJavaPointer
(
wglCreateContext
(
device
));
return
toJavaPointer
(
wglCreateContext
(
device
));
}
}
...
...
skiko/src/jvmMain/cpp/windows/window_util.cc
0 → 100644
View file @
cf6413c8
#if SK_BUILD_FOR_WIN
#include "window_util.h"
void
enableTransparentWindow
(
HWND
hwnd
)
{
HRGN
region
=
CreateRectRgn
(
0
,
0
,
-
1
,
-
1
);
DWM_BLURBEHIND
bb
=
{
0
};
bb
.
dwFlags
=
DWM_BB_ENABLE
|
DWM_BB_BLURREGION
;
bb
.
hRgnBlur
=
region
;
bb
.
fEnable
=
TRUE
;
DwmEnableBlurBehindWindow
(
hwnd
,
&
bb
);
DeleteObject
(
region
);
}
#endif
\ No newline at end of file
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkiaLayer.jvm.kt
View file @
cf6413c8
package
org.jetbrains.skiko
package
org.jetbrains.skiko
import
org.jetbrains.skia.*
import
org.jetbrains.skia.Canvas
import
org.jetbrains.skia.Bitmap
import
org.jetbrains.skia.ColorAlphaType
import
org.jetbrains.skia.ColorInfo
import
org.jetbrains.skia.ColorType
import
org.jetbrains.skia.ColorSpace
import
org.jetbrains.skia.ClipMode
import
org.jetbrains.skia.ImageInfo
import
org.jetbrains.skia.Picture
import
org.jetbrains.skia.PictureRecorder
import
org.jetbrains.skia.Rect
import
org.jetbrains.skiko.context.ContextHandler
import
org.jetbrains.skiko.context.ContextHandler
import
org.jetbrains.skiko.redrawer.Redrawer
import
org.jetbrains.skiko.redrawer.Redrawer
import
java.awt.Color
import
java.awt.Graphics
import
java.awt.Graphics
import
java.awt.event.*
import
java.awt.event.*
import
java.awt.im.InputMethodRequests
import
java.awt.im.InputMethodRequests
...
@@ -25,6 +36,8 @@ actual open class SkiaLayer internal constructor(
...
@@ -25,6 +36,8 @@ actual open class SkiaLayer internal constructor(
ContentScale
,
ContentScale
,
}
}
actual
var
transparency
:
Boolean
=
false
internal
val
backedLayer
:
HardwareLayer
internal
val
backedLayer
:
HardwareLayer
constructor
(
constructor
(
...
@@ -36,6 +49,7 @@ actual open class SkiaLayer internal constructor(
...
@@ -36,6 +49,7 @@ actual open class SkiaLayer internal constructor(
init
{
init
{
isOpaque
=
false
isOpaque
=
false
background
=
Color
(
0
,
0
,
0
,
0
)
layout
=
null
layout
=
null
backedLayer
=
object
:
HardwareLayer
()
{
backedLayer
=
object
:
HardwareLayer
()
{
override
fun
paint
(
g
:
Graphics
)
{
override
fun
paint
(
g
:
Graphics
)
{
...
@@ -98,7 +112,7 @@ actual open class SkiaLayer internal constructor(
...
@@ -98,7 +112,7 @@ actual open class SkiaLayer internal constructor(
val
windowHandle
:
Long
val
windowHandle
:
Long
get
()
=
backedLayer
.
windowHandle
get
()
=
backedLayer
.
windowHandle
var
fullscreen
:
Boolean
actual
var
fullscreen
:
Boolean
get
()
=
backedLayer
.
fullscreen
get
()
=
backedLayer
.
fullscreen
set
(
value
)
{
set
(
value
)
{
backedLayer
.
fullscreen
=
value
backedLayer
.
fullscreen
=
value
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/context/DirectSoftwareContextHandler.kt
View file @
cf6413c8
...
@@ -8,7 +8,6 @@ import org.jetbrains.skiko.redrawer.AbstractDirectSoftwareRedrawer
...
@@ -8,7 +8,6 @@ import org.jetbrains.skiko.redrawer.AbstractDirectSoftwareRedrawer
import
java.lang.ref.Reference
import
java.lang.ref.Reference
internal
class
DirectSoftwareContextHandler
(
layer
:
SkiaLayer
)
:
ContextHandler
(
layer
)
{
internal
class
DirectSoftwareContextHandler
(
layer
:
SkiaLayer
)
:
ContextHandler
(
layer
)
{
override
val
bleachConstant
=
-
1
var
isInited
=
false
var
isInited
=
false
val
softwareRedrawer
:
AbstractDirectSoftwareRedrawer
val
softwareRedrawer
:
AbstractDirectSoftwareRedrawer
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/context/SoftwareContextHandler.kt
View file @
cf6413c8
...
@@ -6,7 +6,10 @@ import org.jetbrains.skia.ColorAlphaType
...
@@ -6,7 +6,10 @@ import org.jetbrains.skia.ColorAlphaType
import
org.jetbrains.skia.ImageInfo
import
org.jetbrains.skia.ImageInfo
import
org.jetbrains.skia.Picture
import
org.jetbrains.skia.Picture
import
org.jetbrains.skiko.SkiaLayer
import
org.jetbrains.skiko.SkiaLayer
import
org.jetbrains.skiko.hostOs
import
org.jetbrains.skiko.OS
import
java.awt.Transparency
import
java.awt.Transparency
import
java.awt.Color
import
java.awt.color.ColorSpace
import
java.awt.color.ColorSpace
import
java.awt.image.BufferedImage
import
java.awt.image.BufferedImage
import
java.awt.image.ComponentColorModel
import
java.awt.image.ComponentColorModel
...
@@ -16,7 +19,7 @@ import java.awt.image.Raster
...
@@ -16,7 +19,7 @@ import java.awt.image.Raster
import
java.awt.image.WritableRaster
import
java.awt.image.WritableRaster
internal
class
SoftwareContextHandler
(
layer
:
SkiaLayer
)
:
ContextHandler
(
layer
)
{
internal
class
SoftwareContextHandler
(
layer
:
SkiaLayer
)
:
ContextHandler
(
layer
)
{
override
val
bleachConstant
=
-
1
// it looks like java.awt.Canvas doesn't support transparency
override
val
clearColor
=
if
(
layer
.
transparency
&&
hostOs
==
OS
.
MacOS
)
0
else
-
1
val
colorModel
=
ComponentColorModel
(
val
colorModel
=
ComponentColorModel
(
ColorSpace
.
getInstance
(
ColorSpace
.
CS_sRGB
),
ColorSpace
.
getInstance
(
ColorSpace
.
CS_sRGB
),
...
@@ -76,7 +79,12 @@ internal class SoftwareContextHandler(layer: SkiaLayer) : ContextHandler(layer)
...
@@ -76,7 +79,12 @@ internal class SoftwareContextHandler(layer: SkiaLayer) : ContextHandler(layer)
null
null
)
)
image
=
BufferedImage
(
colorModel
,
raster
!!
,
false
,
null
)
image
=
BufferedImage
(
colorModel
,
raster
!!
,
false
,
null
)
layer
.
backedLayer
.
getGraphics
()
?.
drawImage
(
image
!!
,
0
,
0
,
layer
.
width
,
layer
.
height
,
null
)
val
graphics
=
layer
.
backedLayer
.
getGraphics
()
if
(!
layer
.
fullscreen
&&
layer
.
transparency
&&
hostOs
==
OS
.
MacOS
)
{
graphics
?.
setColor
(
Color
(
0
,
0
,
0
,
0
))
graphics
?.
clearRect
(
0
,
0
,
w
,
h
)
}
graphics
?.
drawImage
(
image
!!
,
0
,
0
,
layer
.
width
,
layer
.
height
,
null
)
}
}
}
}
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/redrawer/Direct3DRedrawer.kt
View file @
cf6413c8
...
@@ -15,7 +15,7 @@ internal class Direct3DRedrawer(
...
@@ -15,7 +15,7 @@ internal class Direct3DRedrawer(
private
var
isDisposed
=
false
private
var
isDisposed
=
false
private
var
drawLock
=
Any
()
private
var
drawLock
=
Any
()
private
val
device
=
createDirectXDevice
(
getAdapterPriority
(),
layer
.
contentHandle
).
also
{
private
val
device
=
createDirectXDevice
(
getAdapterPriority
(),
layer
.
contentHandle
,
layer
.
transparency
).
also
{
if
(
it
==
0L
||
!
isVideoCardSupported
(
layer
.
renderApi
))
{
if
(
it
==
0L
||
!
isVideoCardSupported
(
layer
.
renderApi
))
{
throw
RenderException
(
"Failed to create DirectX12 device."
)
throw
RenderException
(
"Failed to create DirectX12 device."
)
}
}
...
@@ -92,7 +92,7 @@ internal class Direct3DRedrawer(
...
@@ -92,7 +92,7 @@ internal class Direct3DRedrawer(
val
adapterName
get
()
=
getAdapterName
(
device
)
val
adapterName
get
()
=
getAdapterName
(
device
)
val
adapterMemorySize
get
()
=
getAdapterMemorySize
(
device
)
val
adapterMemorySize
get
()
=
getAdapterMemorySize
(
device
)
private
external
fun
createDirectXDevice
(
adapterPriority
:
Int
,
contentHandle
:
Long
):
Long
private
external
fun
createDirectXDevice
(
adapterPriority
:
Int
,
contentHandle
:
Long
,
transparency
:
Boolean
):
Long
private
external
fun
makeDirectXContext
(
device
:
Long
):
Long
private
external
fun
makeDirectXContext
(
device
:
Long
):
Long
private
external
fun
makeDirectXSurface
(
device
:
Long
,
context
:
Long
,
width
:
Int
,
height
:
Int
,
index
:
Int
):
Long
private
external
fun
makeDirectXSurface
(
device
:
Long
,
context
:
Long
,
width
:
Int
,
height
:
Int
,
index
:
Int
):
Long
private
external
fun
resizeBuffers
(
device
:
Long
,
width
:
Int
,
height
:
Int
)
private
external
fun
resizeBuffers
(
device
:
Long
,
width
:
Int
,
height
:
Int
)
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/redrawer/LinuxOpenGLRedrawer.kt
View file @
cf6413c8
...
@@ -14,7 +14,7 @@ internal class LinuxOpenGLRedrawer(
...
@@ -14,7 +14,7 @@ internal class LinuxOpenGLRedrawer(
init
{
init
{
layer
.
backedLayer
.
lockLinuxDrawingSurface
{
layer
.
backedLayer
.
lockLinuxDrawingSurface
{
context
=
it
.
createContext
()
context
=
it
.
createContext
(
layer
.
transparency
)
if
(
context
==
0L
)
{
if
(
context
==
0L
)
{
throw
RenderException
(
"Cannot create Linux GL context"
)
throw
RenderException
(
"Cannot create Linux GL context"
)
}
}
...
@@ -150,14 +150,14 @@ internal class LinuxOpenGLRedrawer(
...
@@ -150,14 +150,14 @@ internal class LinuxOpenGLRedrawer(
}
}
}
}
private
fun
LinuxDrawingSurface
.
createContext
(
)
=
createContext
(
displa
y
)
private
fun
LinuxDrawingSurface
.
createContext
(
transparency
:
Boolean
)
=
createContext
(
display
,
transparenc
y
)
private
fun
LinuxDrawingSurface
.
destroyContext
(
context
:
Long
)
=
destroyContext
(
display
,
context
)
private
fun
LinuxDrawingSurface
.
destroyContext
(
context
:
Long
)
=
destroyContext
(
display
,
context
)
private
fun
LinuxDrawingSurface
.
makeCurrent
(
context
:
Long
)
=
makeCurrent
(
display
,
window
,
context
)
private
fun
LinuxDrawingSurface
.
makeCurrent
(
context
:
Long
)
=
makeCurrent
(
display
,
window
,
context
)
private
fun
LinuxDrawingSurface
.
swapBuffers
()
=
swapBuffers
(
display
,
window
)
private
fun
LinuxDrawingSurface
.
swapBuffers
()
=
swapBuffers
(
display
,
window
)
private
fun
LinuxDrawingSurface
.
setSwapInterval
(
interval
:
Int
)
=
setSwapInterval
(
display
,
window
,
interval
)
private
fun
LinuxDrawingSurface
.
setSwapInterval
(
interval
:
Int
)
=
setSwapInterval
(
display
,
window
,
interval
)
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
,
transparency
:
Boolean
):
Long
private
external
fun
destroyContext
(
display
:
Long
,
context
:
Long
)
private
external
fun
destroyContext
(
display
:
Long
,
context
:
Long
)
private
external
fun
setSwapInterval
(
display
:
Long
,
window
:
Long
,
interval
:
Int
)
private
external
fun
setSwapInterval
(
display
:
Long
,
window
:
Long
,
interval
:
Int
)
private
external
fun
swapBuffers
(
display
:
Long
,
window
:
Long
)
private
external
fun
swapBuffers
(
display
:
Long
,
window
:
Long
)
\ No newline at end of file
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/redrawer/MetalRedrawer.kt
View file @
cf6413c8
...
@@ -21,7 +21,7 @@ internal class MetalRedrawer(
...
@@ -21,7 +21,7 @@ internal class MetalRedrawer(
private
var
isDisposed
=
false
private
var
isDisposed
=
false
private
var
drawLock
=
Any
()
private
var
drawLock
=
Any
()
private
val
device
=
layer
.
backedLayer
.
useDrawingSurfacePlatformInfo
{
private
val
device
=
layer
.
backedLayer
.
useDrawingSurfacePlatformInfo
{
createMetalDevice
(
getAdapterPriority
(),
it
)
createMetalDevice
(
layer
.
windowHandle
,
layer
.
transparency
,
getAdapterPriority
(),
it
)
}
}
private
val
windowHandle
=
layer
.
windowHandle
private
val
windowHandle
=
layer
.
windowHandle
...
@@ -131,7 +131,7 @@ internal class MetalRedrawer(
...
@@ -131,7 +131,7 @@ internal class MetalRedrawer(
fun
getAdapterName
():
String
=
getAdapterName
(
device
)
fun
getAdapterName
():
String
=
getAdapterName
(
device
)
fun
getAdapterMemorySize
():
Long
=
getAdapterMemorySize
(
device
)
fun
getAdapterMemorySize
():
Long
=
getAdapterMemorySize
(
device
)
private
external
fun
createMetalDevice
(
adapterPriority
:
Int
,
platformInfo
:
Long
):
Long
private
external
fun
createMetalDevice
(
window
:
Long
,
transparency
:
Boolean
,
adapterPriority
:
Int
,
platformInfo
:
Long
):
Long
private
external
fun
makeMetalContext
(
device
:
Long
):
Long
private
external
fun
makeMetalContext
(
device
:
Long
):
Long
private
external
fun
makeMetalRenderTarget
(
device
:
Long
,
width
:
Int
,
height
:
Int
):
Long
private
external
fun
makeMetalRenderTarget
(
device
:
Long
,
width
:
Int
,
height
:
Int
):
Long
private
external
fun
disposeDevice
(
device
:
Long
)
private
external
fun
disposeDevice
(
device
:
Long
)
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/redrawer/WindowsOpenGLRedrawer.kt
View file @
cf6413c8
...
@@ -11,7 +11,7 @@ internal class WindowsOpenGLRedrawer(
...
@@ -11,7 +11,7 @@ internal class WindowsOpenGLRedrawer(
private
val
properties
:
SkiaLayerProperties
private
val
properties
:
SkiaLayerProperties
)
:
Redrawer
{
)
:
Redrawer
{
private
val
device
=
layer
.
backedLayer
.
useDrawingSurfacePlatformInfo
(
::
getDevice
)
private
val
device
=
layer
.
backedLayer
.
useDrawingSurfacePlatformInfo
(
::
getDevice
)
private
val
context
=
createContext
(
device
).
also
{
private
val
context
=
createContext
(
device
,
layer
.
contentHandle
,
layer
.
transparency
).
also
{
if
(
it
==
0L
)
{
if
(
it
==
0L
)
{
throw
RenderException
(
"Cannot create Windows GL context"
)
throw
RenderException
(
"Cannot create Windows GL context"
)
}
}
...
@@ -115,7 +115,7 @@ internal class WindowsOpenGLRedrawer(
...
@@ -115,7 +115,7 @@ internal class WindowsOpenGLRedrawer(
private
external
fun
makeCurrent
(
device
:
Long
,
context
:
Long
)
private
external
fun
makeCurrent
(
device
:
Long
,
context
:
Long
)
private
external
fun
getDevice
(
platformInfo
:
Long
):
Long
private
external
fun
getDevice
(
platformInfo
:
Long
):
Long
private
external
fun
createContext
(
device
:
Long
):
Long
private
external
fun
createContext
(
device
:
Long
,
contentHandle
:
Long
,
transparency
:
Boolean
):
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
)
private
external
fun
swapBuffers
(
device
:
Long
)
private
external
fun
swapBuffers
(
device
:
Long
)
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/redrawer/WindowsSoftwareRedrawer.kt
View file @
cf6413c8
...
@@ -10,12 +10,12 @@ internal class WindowsSoftwareRedrawer(
...
@@ -10,12 +10,12 @@ internal class WindowsSoftwareRedrawer(
)
:
AbstractDirectSoftwareRedrawer
(
layer
,
properties
)
{
)
:
AbstractDirectSoftwareRedrawer
(
layer
,
properties
)
{
init
{
init
{
device
=
createDevice
(
layer
.
contentHandle
).
also
{
device
=
createDevice
(
layer
.
contentHandle
,
layer
.
transparency
).
also
{
if
(
it
==
0L
)
{
if
(
it
==
0L
)
{
throw
RenderException
(
"Failed to create Software device"
)
throw
RenderException
(
"Failed to create Software device"
)
}
}
}
}
}
}
private
external
fun
createDevice
(
contentHandle
:
Long
):
Long
private
external
fun
createDevice
(
contentHandle
:
Long
,
transparency
:
Boolean
):
Long
}
}
\ No newline at end of file
skiko/src/jvmMain/objectiveC/macos/Drawlayer.mm
View file @
cf6413c8
...
@@ -211,6 +211,4 @@ void getMetalDeviceAndQueue(void** device, void** queue)
...
@@ -211,6 +211,4 @@ void getMetalDeviceAndQueue(void** device, void** queue)
*queue = (__bridge void*)fQueue;
*queue = (__bridge void*)fQueue;
}
}
} // extern C
} // extern C
\ No newline at end of file
skiko/src/jvmMain/objectiveC/macos/MetalRedrawer.mm
View file @
cf6413c8
...
@@ -183,7 +183,7 @@ id<MTLDevice> MTLCreateIntegratedDevice(int adapterPriority) {
...
@@ -183,7 +183,7 @@ id<MTLDevice> MTLCreateIntegratedDevice(int adapterPriority) {
}
}
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_redrawer_MetalRedrawer_createMetalDevice(
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_redrawer_MetalRedrawer_createMetalDevice(
JNIEnv *env, jobject redrawer, jint adapterPriority, jlong platformInfoPtr)
JNIEnv *env, jobject redrawer, j
long windowPtr, jboolean transparency, j
int adapterPriority, jlong platformInfoPtr)
{
{
MetalDevice *device = [MetalDevice new];
MetalDevice *device = [MetalDevice new];
...
@@ -214,6 +214,12 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_redrawer_MetalRedrawer_createMe
...
@@ -214,6 +214,12 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_redrawer_MetalRedrawer_createMe
device.layer.backgroundColor = CGColorCreate(CGColorSpaceCreateDeviceRGB(), transparent);
device.layer.backgroundColor = CGColorCreate(CGColorSpaceCreateDeviceRGB(), transparent);
device.layer.opaque = NO;
device.layer.opaque = NO;
if (transparency)
{
NSWindow* window = (NSWindow*)windowPtr;
window.hasShadow = NO;
}
return (jlong) device;
return (jlong) device;
}
}
...
...
skiko/src/linuxMain/kotlin/org/jetbrains/skiko/SkiaLayer.linux.kt
View file @
cf6413c8
...
@@ -6,4 +6,10 @@ actual open class SkiaLayer {
...
@@ -6,4 +6,10 @@ actual open class SkiaLayer {
set
(
value
)
{}
set
(
value
)
{}
actual
val
contentScale
:
Float
actual
val
contentScale
:
Float
get
()
=
TODO
(
"Not yet implemented"
)
get
()
=
TODO
(
"Not yet implemented"
)
actual
var
fullscreen
:
Boolean
get
()
=
TODO
(
"Not yet implemented"
)
set
(
value
)
{}
actual
var
transparency
:
Boolean
get
()
=
TODO
(
"Not yet implemented"
)
set
(
value
)
{}
}
}
\ No newline at end of file
skiko/src/macosMain/kotlin/org/jetbrains/skiko/SkiaLayer.macos.kt
View file @
cf6413c8
...
@@ -14,6 +14,12 @@ actual open class SkiaLayer(
...
@@ -14,6 +14,12 @@ actual open class SkiaLayer(
actual
val
contentScale
:
Float
actual
val
contentScale
:
Float
get
()
=
_contentScale
get
()
=
_contentScale
actual
var
fullscreen
:
Boolean
get
()
=
TODO
(
"Not yet implemented"
)
set
(
value
)
{}
actual
var
transparency
:
Boolean
=
false
val
nsView
=
NSView
(
NSMakeRect
(
0.0
,
0.0
,
640.0
,
480.0
))
val
nsView
=
NSView
(
NSMakeRect
(
0.0
,
0.0
,
640.0
,
480.0
))
var
_contentScale
:
Float
=
1.0f
var
_contentScale
:
Float
=
1.0f
...
...
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