Cloudef / wlc

High-level Wayland compositor library
MIT License
330 stars 58 forks source link

Got nothing after calling wlc_output_schedule_render #151

Closed xeechou closed 8 years ago

xeechou commented 8 years ago

I am writing simple testing code to add background image in server code.

void set_background(struct wl_client *client,
        struct wl_resource *resource,
        struct wl_resource *output,
        struct wl_resource *surface)
{
wlc_handle wlc_output = wlc_handle_from_wl_output_resource(output);
wlc_handle wlc_surface = wlc_handle_from_wl_surface_resource(surface);
wlc_output_schedule_render(wlc_output);
}

This code is very silly, but I should have screen painted with this api(I have client code as well). But I didn't get anything, did I miss something?

ammen99 commented 8 years ago

I don't really get what you are trying to do, but the code you have given does nothing to set the background. wlc_output_schedule_render is used to schedule another repaint after 16ms(or whatever your screen refresh rate is). If you are trying to use this test protocol, then see tests/wl-extension.c, there you can find example of what you need. Basically, you must create your surface and then draw it in output_render_pre hook

Cloudef commented 8 years ago

What @ammen99 said is correct, though the scheduling heuristics for repaint is not simple 16ms (as that would most likely causes stutter etc..). But fact is schedule_render only schedules next frame to be rendered, that is all the views will be painted and render hooks called.

If you want to render something you should do it in the hooks using the available *_render functions or write_pixels.

https://github.com/Cloudef/wlc/blob/master/tests/wl-extension.c You can look at this example which does exactly what you want. You can also look at sway's code which implements desktop-shell for backgrounds and others.

xeechou commented 8 years ago

So can I just get background painted with wlc_surface_render directly in *_set_background? I found that did work either.

Does wlc_surface_render call has to be used in specific context?

Cloudef commented 8 years ago

wlc_surface_render needs to be used in render hooks, you can't do it directly in _set_background. You can however convert surface to wlc_view if that's what you want.

xeechou commented 8 years ago

thanks