Skip to content

Commit 5089c48

Browse files
committed
Add support for EGL
1 parent 989238e commit 5089c48

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

skiko/src/commonMain/kotlin/org/jetbrains/skia/DirectContext.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import org.jetbrains.skiko.loadOpenGLLibrary
77

88
class DirectContext internal constructor(ptr: NativePointer) : RefCnt(ptr) {
99
companion object {
10+
fun makeEGL(): DirectContext {
11+
Stats.onNativeCall()
12+
val ptr = _nMakeEGL()
13+
if (ptr == NullPointer) throw RenderException("Can't create EGL DirectContext")
14+
return DirectContext(ptr)
15+
}
16+
1017
fun makeGL(): DirectContext {
1118
Stats.onNativeCall()
1219
loadOpenGLLibrary()
@@ -141,6 +148,10 @@ private external fun DirectContext_nFlush(ptr: NativePointer, surfacePtr: Native
141148
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_DirectContext__1nFlushDefault")
142149
private external fun DirectContext_nFlushDefault(ptr: NativePointer)
143150

151+
@ExternalSymbolName("org_jetbrains_skia_DirectContext__1nMakeEGL")
152+
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_DirectContext__1nMakeEGL")
153+
private external fun _nMakeEGL(): NativePointer
154+
144155
@ExternalSymbolName("org_jetbrains_skia_DirectContext__1nMakeGL")
145156
@ModuleImport("./skiko.mjs", "org_jetbrains_skia_DirectContext__1nMakeGL")
146157
private external fun _nMakeGL(): NativePointer

skiko/src/commonTest/kotlin/org/jetbrains/skia/SurfaceTest.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,14 @@ class SurfaceTest {
115115
// TODO implement for other platforms and render targets
116116
return
117117
}
118-
if (hostArch == Arch.Arm64) {
119-
// TODO implement and test EGL on arm64
120-
return
121-
}
122118

123119
val pixels = TestGlContext.run {
124-
DirectContext.makeGL().useContext { ctx ->
120+
val ctx = when (hostArch) {
121+
Arch.X64 -> DirectContext.makeGL()
122+
Arch.Arm64 -> DirectContext.makeEGL()
123+
else -> error("Unsupported arch: $hostArch")
124+
}
125+
ctx.useContext {
125126
val imageInfo = ImageInfo.makeN32Premul(16, 16)
126127
val surface = Surface.makeRenderTarget(ctx, budgeted = false, imageInfo)
127128

skiko/src/nativeJsMain/cpp/DirectContext.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "ganesh/GrDirectContext.h"
22
#include "ganesh/gl/GrGLInterface.h"
3+
#include "ganesh/gl/egl/GrGLMakeEGLInterface.h"
34
#include "common.h"
45
#include "ganesh/gl/GrGLDirectContext.h" // TODO: skia update: check if it's correct
56

@@ -23,6 +24,11 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_DirectContext__1nMakeGLWithInterf
2324
return static_cast<KNativePointer>(GrDirectContexts::MakeGL(iface).release());
2425
}
2526

27+
SKIKO_EXPORT KNativePointer org_jetbrains_skia_DirectContext__1nMakeEGL
28+
() {
29+
return reinterpret_cast<KNativePointer>(GrDirectContexts::MakeGL(GrGLMakeEGLInterface()).release());
30+
}
31+
2632
SKIKO_EXPORT KNativePointer org_jetbrains_skia_DirectContext__1nMakeMetal
2733
(KNativePointer devicePtr, KNativePointer queuePtr) {
2834
#ifdef SK_METAL

0 commit comments

Comments
 (0)