Simple SHM Wayland Client

Marek Chalupa mchqwerty at gmail.com
Fri May 30 03:01:53 PDT 2014


On 30 May 2014 11:27, Philip Rushik <prushik at gmail.com> wrote:

>
>
>
> On Fri, May 30, 2014 at 3:57 PM, Marek Chalupa <mchqwerty at gmail.com>
> wrote:
>
>>
>> These protocols are not a part of libwayland, but Weston. You can find
>> their specification in weston/protocol directory (those xml files) and you
>> can generate sources from them using wayland-scanner. Then you can link
>> against these sources (namely xdg-shell-protocol.c for xdg_* stuff and
>> fullscreen-shell-procotol.c for the another). But as far as I know, the
>> common wl_surface should be enough for creating a window without borders
>> and buttons in Weston (that's how the
>> weston/tests/weston-test-client-helpers.c works). So if you want to use
>> only libwayland-client, as you wrote before, you should not use xdg_shell
>> and fullscreen_shell. What you need to do is:
>>
>> (connect to display and get registry)
>> 1. bind to compositor
>> 2. create surface from compositor
>> 3. create shm buffer
>> 4. set buffer's contents
>> 5. attach the buffer to surface
>> 6. commit the surface
>>
>> Hmm, I hope I didn't forget something xD
>>
>> Marek
>>
>>
> This looks like exactly what I am doing.
> I open a connection like so: display = wl_display_connect(NULL);
> get registry: registry = wl_display_get_registry(display);
>     wl_registry_add_listener(registry, &registry_listener, NULL);
>
> bind to compositor? Not sure about this, do you mean this:
>      if (strcmp(interface, "wl_compositor") == 0) {
>         compositor =
>             wl_registry_bind(registry,
>                      id, &wl_compositor_interface, 1);
> ...
>
> in the registry listener function?
>

Yes, that's what I meant.


>
> then I create the surface:
>     surface = wl_compositor_create_surface(compositor);
>
> create the buffer:
>     stride = WIDTH * 4;
>     size = stride * HEIGHT;
>
>     fd = shm_open("/wl_example",O_CREAT | O_RDWR, 0777);
>     if (fd==-1)
>         printf("SHM Failed to open\n");
>     data = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x0);
>     if (data==0)
>         printf("MMAP failed\n");
>
> Tell wayland about the buffer:
>     pool = wl_shm_create_pool(shm, fd, size);
>     buffer = wl_shm_pool_create_buffer(pool, 0, WIDTH, HEIGHT, stride, 0);
>     wl_buffer_add_listener(buffer, &buffer_listener, NULL);
>     wl_shm_pool_destroy(pool);
>
> Attach it to the surface:
>     wl_surface_attach(surface, buffer, 0, 0);
>
> Commit the surface:
>
>     wl_surface_commit(surface);
>
>
> Then I go into a loop of display dispatches cause I think thats what
> should happen, right?
>
>     int r;
>

Just a note: here you should initialize the variable r, or the loop can
break without calling wl_display_dispatch...

    while (r!=-1)
>         r = wl_display_dispatch(display);
>
>
>
> Nothing appears in Weston. No errors, but nothing happens.
>

And what is the content of the buffer? Since you are creating the buffer
with ARGB888 format (or at least on my system 0 is this format), then if
it's mapped on zeroed page the surface will be transparent. Try to set all
bytes to 255, then the surface should be white.

Regards,
Marek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20140530/144df915/attachment.html>


More information about the wayland-devel mailing list