<div dir="ltr"><div dir="ltr"><div>You are correct. I was missing the -D flag to teçl jextract the platform was Wayland.</div><div><br></div><div>The call should be cast to EGLNativeWindowType which varies by platform. On Windows it's a HWDN, on X11 its a Window and Wayland is a pointer to wl_egl_window.</div><div><br></div><div><div style="background-color:rgb(30,31,34);color:rgb(188,190,196)"><pre style="font-family:"JetBrains Mono",monospace;font-size:9.8pt"><span style="color:rgb(197,118,51)">jextract </span>--output src -t com.sun.glass.egl.extracted \<br> --header-class-name EGL \<br> -D WL_EGL_PLATFORM=<span style="color:rgb(42,172,184)">1</span> \<br> <span style="color:rgb(197,118,51)">`pkg-config </span>--libs egl<span style="color:rgb(197,118,51)">`</span> \<br> <span style="color:rgb(197,118,51)">`pkg-config </span>--cflags-only-I egl<span style="color:rgb(197,118,51)">`</span> \<br> /usr/include/EGL/egl.h</pre></div></div></div><div><br></div><div>Thanks!</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Em seg., 29 de abr. de 2024 às 10:24, Maurizio Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com">maurizio.cimadamore@oracle.com</a>> escreveu:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>
<div>
<p><br>
</p>
<div>On 29/04/2024 13:28, Thiago Milczarek
Sayão wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">Hi Maurizio,
<div><br>
</div>
<div>My mistake. It works.</div>
<div><br>
</div>
<div>I was playing around with it and my first version did not
work. But the problem was on another part of the code.</div>
<div><br>
</div>
<div>elgConfig is an array, so eglCreateWindowSurface only works
by passing like below (I might be mistaken again).</div>
</div>
</blockquote>
<p>I think that's correct. E.g. ELGConfig is defined as follows:</p>
<p><br>
```<br>
typedef void *EGLConfig;<br>
```</p>
<p>So it's an alias for a void pointer. If your "eglConfig" is
configured as "pointer to pointer" (which I think you need for the
call you showed earlier), then taking the first pointer in this
pointer-to-pointer is what you want.</p>
<p>I'm more suspicious about that "egWindow.address()" - the
function seems to take a void* - and you probably have "eglWindow"
which is a segment, so if you want to pass the segment "by
reference" you just need to pass the segment directly. Perhaps you
declared the function descriptor for this function as accepting a
JAVA_LONG instead of ADDRESS?<br>
</p>
<p>Maurizio<br>
</p>
<blockquote type="cite">
<div dir="ltr">
<div><br>
</div>
<div>Thanks for replying.</div>
<div><br>
</div>
<div>
<div style="background-color:rgb(30,31,34);color:rgb(188,190,196)">
<pre style="font-family:"JetBrains Mono",monospace;font-size:9.8pt"><span style="color:rgb(207,142,109)">if </span>(EGL.<span style="font-style:italic">eglChooseConfig</span>(eglDisplay, attributes, eglConfig, <span style="color:rgb(42,172,184)">1</span>, numConfigs) == <span style="color:rgb(42,172,184)">0</span>) {
System.<span style="color:rgb(199,125,187);font-style:italic">out</span>.println(<span style="color:rgb(106,171,115)">"eglChooseConfig Failed"</span>);
<span style="color:rgb(207,142,109)">return null</span>;
}
MemorySegment eglSurface = EGL.<span style="font-style:italic">eglCreateWindowSurface</span>(eglDisplay, eglConfig.get(<span style="color:rgb(199,125,187);font-style:italic">EGLConfig</span>, <span style="color:rgb(42,172,184)">0</span>), eglWindow.address(), MemorySegment.<span style="color:rgb(199,125,187);font-style:italic">NULL</span>);
<span style="color:rgb(207,142,109)">if </span>(eglSurface.equals(<span style="font-style:italic">EGL_NO_SURFACE</span>())) {
System.<span style="color:rgb(199,125,187);font-style:italic">out</span>.printf(<span style="color:rgb(106,171,115)">"eglCreateWindowSurface Failed %d%n"</span>, <span style="font-style:italic">eglGetError</span>());
<span style="color:rgb(207,142,109)">return null</span>;
}
</pre>
</div>
</div>
<div><br>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">Em seg., 29 de abr. de 2024 às
08:08, Maurizio Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com" target="_blank">maurizio.cimadamore@oracle.com</a>>
escreveu:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<p>Hi Thiago,<br>
</p>
<p>So, you have a memory segment with a given address,
called "attributes".</p>
<p>The code you have is:</p>
<p>1. obtaining the addres from "attributes"<br>
2. repackaging the address in a _new_ memory segment <br>
</p>
<p>Note that the segment you create in (2) is identical to
the one you started from. They have the same address. The
only difference is that the first segment has some
meaningful spatial bounds (e.g. it has a size), the
second segment is a zero-length memory segment (so you
can't dereference it).</p>
<p>But from the perspective of passing this segment "by
reference" to a native function, they are exactly the same
- e.g. when passing a segment by reference, the Linker
will call "MemorySegment::address()" and pass that to the
underlying function. Since the address of segments in (1)
and (2) is indeed the same, I don't think these segments
should behave differently at all - meaning your code can
be simplified, and you can just use "attributes".</p>
<p>This misconception might have originated from the fact
that FFM doesn't provide true "stack allocation". So when
you have a segment you already have some address. Meaning
that if the original C code said something like
"&foo", and "foo" is a segment in the FFM code, you
can just pass "foo" as a pointer instead.</p>
<p>I hope this helps.<br>
</p>
<p>Maurizio<br>
</p>
<div>On 29/04/2024 11:45, Thiago Milczarek Sayão wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">Hi,
<div><br>
</div>
<div>I'm doing some wayland binding experiments with
jextract and FFM.</div>
<div>So far, so good.</div>
<div><br>
</div>
<div>But there's one thing that could be better, or I am
doing it wrong (Please, excuse me if it's my
mistake.).</div>
<div><br>
</div>
<div>The eglChooseConfig call expects the pointer of an
address on the second argument.</div>
<div><a href="https://urldefense.com/v3/__https://registry.khronos.org/EGL/sdk/docs/man/html/eglChooseConfig.xhtml__;!!ACWV5N9M2RV99hQ!KNXTJkNJKuDXvkpPfP8ggUb2q4pK32qw-neOjb6Jem_gtbnVpR7KTYIhlbFAxzjIuITW6tZ9Zjjfcg4MNt-ybFdJ7zz2Mw$" target="_blank">https://registry.khronos.org/EGL/sdk/docs/man/html/eglChooseConfig.xhtml</a><br>
</div>
<div><br>
</div>
<div>The below code works, but I feel it could be
simpler. Maybe a call like attributes.addressPointer()
?</div>
<div>
<div style="background-color:rgb(30,31,34);color:rgb(188,190,196)">
<pre style="font-family:"JetBrains Mono",monospace;font-size:9.8pt">MemorySegment eglDisplay = EGL.<span style="font-style:italic">eglGetDisplay</span>(display.getSegment());
<span style="font-style:italic">eglBindAPI</span>(<span style="font-style:italic">EGL_OPENGL_API</span>());
<span style="color:rgb(207,142,109)">if </span>(eglDisplay.equals(<span style="font-style:italic">EGL_NO_DISPLAY</span>())) {
System.<span style="color:rgb(199,125,187);font-style:italic">out</span>.println(<span style="color:rgb(106,171,115)">"NO DISPLAY"</span>);
<span style="color:rgb(207,142,109)">return null</span>;
}
<span style="color:rgb(207,142,109)">if </span>(<span style="font-style:italic">eglInitialize</span>(eglDisplay, MemorySegment.<span style="color:rgb(199,125,187);font-style:italic">NULL</span>, MemorySegment.<span style="color:rgb(199,125,187);font-style:italic">NULL</span>) == <span style="color:rgb(42,172,184)">0</span>) {
System.<span style="color:rgb(199,125,187);font-style:italic">out</span>.println(<span style="color:rgb(106,171,115)">"eglInitialize Failed"</span>);
<span style="color:rgb(207,142,109)">return null</span>;
};
<span style="color:rgb(207,142,109)">int</span>[] attribs = {
<span style="font-style:italic">EGL_RENDERABLE_TYPE</span>(),
<span style="font-style:italic">EGL_OPENGL_BIT</span>(),
<span style="font-style:italic">EGL_SURFACE_TYPE</span>(),
<span style="font-style:italic">EGL_WINDOW_BIT</span>(),
<span style="font-style:italic">EGL_RED_SIZE</span>(),
<span style="color:rgb(42,172,184)">8</span>,
<span style="font-style:italic">EGL_GREEN_SIZE</span>(),
<span style="color:rgb(42,172,184)">8</span>,
<span style="font-style:italic">EGL_BLUE_SIZE</span>(),
<span style="color:rgb(42,172,184)">8</span>,
<span style="font-style:italic">EGL_ALPHA_SIZE</span>(),
<span style="color:rgb(42,172,184)">8</span>,
<span style="font-style:italic">EGL_NONE</span>()
};
MemorySegment eglConfig = Arena.<span style="font-style:italic">global</span>().allocate(<span style="color:rgb(199,125,187);font-style:italic">C_POINTER</span>);
MemorySegment numConfigs = Arena.<span style="font-style:italic">global</span>().allocate(<span style="color:rgb(199,125,187);font-style:italic">EGLint</span>);
MemorySegment attributes = Arena.<span style="font-style:italic">global</span>().allocateFrom(<span style="color:rgb(199,125,187);font-style:italic">EGLint</span>, attribs);
<span style="color:rgb(207,142,109)">if </span>(EGL.<span style="font-style:italic">eglChooseConfig</span>(eglDisplay, MemorySegment.<span style="font-style:italic">ofAddress</span>(attributes.address()), eglConfig, <span style="color:rgb(42,172,184)">1</span>, numConfigs) == <span style="color:rgb(42,172,184)">0</span>) {
System.<span style="color:rgb(199,125,187);font-style:italic">out</span>.println(<span style="color:rgb(106,171,115)">"eglChooseConfig Failed"</span>);
<span style="color:rgb(207,142,109)">return null</span>;
}</pre>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote>
</div>
</blockquote>
</div>
</blockquote></div></div>