Passing pointer of address
Thiago Milczarek Sayão
thiago.sayao at gmail.com
Mon Apr 29 13:55:47 UTC 2024
You are correct. I was missing the -D flag to teçl jextract the
platform was Wayland.
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.
jextract --output src -t com.sun.glass.egl.extracted \
--header-class-name EGL \
-D WL_EGL_PLATFORM=1 \
`pkg-config --libs egl` \
`pkg-config --cflags-only-I egl` \
/usr/include/EGL/egl.h
Thanks!
Em seg., 29 de abr. de 2024 às 10:24, Maurizio Cimadamore <
maurizio.cimadamore at oracle.com> escreveu:
>
> On 29/04/2024 13:28, Thiago Milczarek Sayão wrote:
>
> Hi Maurizio,
>
> My mistake. It works.
>
> I was playing around with it and my first version did not work. But the
> problem was on another part of the code.
>
> elgConfig is an array, so eglCreateWindowSurface only works by passing
> like below (I might be mistaken again).
>
> I think that's correct. E.g. ELGConfig is defined as follows:
>
>
> ```
> typedef void *EGLConfig;
> ```
>
> 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.
>
> 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?
>
> Maurizio
>
>
> Thanks for replying.
>
> if (EGL.eglChooseConfig(eglDisplay, attributes, eglConfig, 1, numConfigs) == 0) {
> System.out.println("eglChooseConfig Failed");
> return null;
> }
>
> MemorySegment eglSurface = EGL.eglCreateWindowSurface(eglDisplay, eglConfig.get(EGLConfig, 0), eglWindow.address(), MemorySegment.NULL);
> if (eglSurface.equals(EGL_NO_SURFACE())) {
> System.out.printf("eglCreateWindowSurface Failed %d%n", eglGetError());
> return null;
> }
>
>
>
> Em seg., 29 de abr. de 2024 às 08:08, Maurizio Cimadamore <
> maurizio.cimadamore at oracle.com> escreveu:
>
>> Hi Thiago,
>>
>> So, you have a memory segment with a given address, called "attributes".
>>
>> The code you have is:
>>
>> 1. obtaining the addres from "attributes"
>> 2. repackaging the address in a _new_ memory segment
>>
>> 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).
>>
>> 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".
>>
>> 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.
>>
>> I hope this helps.
>>
>> Maurizio
>> On 29/04/2024 11:45, Thiago Milczarek Sayão wrote:
>>
>> Hi,
>>
>> I'm doing some wayland binding experiments with jextract and FFM.
>> So far, so good.
>>
>> But there's one thing that could be better, or I am doing it wrong
>> (Please, excuse me if it's my mistake.).
>>
>> The eglChooseConfig call expects the pointer of an address on the second
>> argument.
>> https://registry.khronos.org/EGL/sdk/docs/man/html/eglChooseConfig.xhtml
>> <https://urldefense.com/v3/__https://registry.khronos.org/EGL/sdk/docs/man/html/eglChooseConfig.xhtml__;!!ACWV5N9M2RV99hQ!KNXTJkNJKuDXvkpPfP8ggUb2q4pK32qw-neOjb6Jem_gtbnVpR7KTYIhlbFAxzjIuITW6tZ9Zjjfcg4MNt-ybFdJ7zz2Mw$>
>>
>> The below code works, but I feel it could be simpler. Maybe a call like
>> attributes.addressPointer() ?
>>
>> MemorySegment eglDisplay = EGL.eglGetDisplay(display.getSegment());eglBindAPI(EGL_OPENGL_API());
>> if (eglDisplay.equals(EGL_NO_DISPLAY())) {
>> System.out.println("NO DISPLAY");
>> return null;
>> }
>> if (eglInitialize(eglDisplay, MemorySegment.NULL, MemorySegment.NULL) == 0) {
>> System.out.println("eglInitialize Failed");
>> return null;
>> };
>> int[] attribs = {
>> EGL_RENDERABLE_TYPE(),
>> EGL_OPENGL_BIT(),
>> EGL_SURFACE_TYPE(),
>> EGL_WINDOW_BIT(),
>> EGL_RED_SIZE(),
>> 8,
>> EGL_GREEN_SIZE(),
>> 8,
>> EGL_BLUE_SIZE(),
>> 8,
>> EGL_ALPHA_SIZE(),
>> 8,
>> EGL_NONE()
>> };
>>
>> MemorySegment eglConfig = Arena.global().allocate(C_POINTER);
>> MemorySegment numConfigs = Arena.global().allocate(EGLint);
>> MemorySegment attributes = Arena.global().allocateFrom(EGLint, attribs);
>> if (EGL.eglChooseConfig(eglDisplay, MemorySegment.ofAddress(attributes.address()), eglConfig, 1, numConfigs) == 0) {
>> System.out.println("eglChooseConfig Failed");
>> return null;
>> }
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20240429/ff7dc908/attachment.htm>
More information about the panama-dev
mailing list