-
Notifications
You must be signed in to change notification settings - Fork 343
Add surface interface stubs in compositor example #41
Add surface interface stubs in compositor example #41
Conversation
I had to add a I think the I also have a semi-working implementation locally of attaching an shm buffer to the surface where I can at least access the buffer contents and the gl calls don't fail but I have yet to successfully paint anything on the screen. I'm working on that now. My test client is located in my notes repository here. |
|
There are some style issues here, but GitHub fucked up my web browser so I can't comment inline. Put |
f1268c6
to
9ff29fc
Compare
Ok I cleaned it up a bit. I think this is a good starting point for the surface implementation. Next I will add the surfaces to a list that can be accessed when they need to be rendered and implement attaching the shm buffer. |
examples/compositor/wl_compositor.c
Outdated
surface_commit, | ||
surface_set_buffer_transform, | ||
surface_set_buffer_scale, | ||
surface_damage_buffer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double indented?
9ff29fc
to
3d01e56
Compare
LGTM |
Add the wayland surface interface to the example compositor. Implement the create_surface method to create a new wlr surface from the wayland surface and add the interface.
3d01e56
to
555914a
Compare
Are you expecting this to be merged before you attach buffers? Also, side note, in the future wlr_surface is going to need to handle damage, likely in cooperation with wlr_renderer. A surface is going to have to keep track of what parts of it are damaged and bubble it up to the user somehow, and partial rerendering is something to be considered. |
However you want to work is fine. We can do one big pull request or I can just request comments on every commit. I have about a month off work and this is my main project right now so I should be moving fairly quickly.
I'll look at the weston and wlc implementation and use my best judgement on how to do this. |
Let's implement this up to the point of attaching buffers, and do the rest separately. Right now there's not really much going on here, not really worth merging. |
Also, the usual wisdom is to track damage with pixman. To some degree it will be necessary for compositors to combine this with their own information about where views are being rendered to composite the damaged regions with underlying transparent surfaces and so on. |
Ok, I implemented attaching the buffer to the surface. This commit actually makes shit show up on the screen. |
Pic? |
LGTM codewise |
This is made using my example client which attaches a buffer that consists of all green pixels. The weston-simple-shm won't work yet because we don't implement a shell interface. When you close the window, the server segfaults. |
Can you address the segfault before this is merged? |
47eb3f9
to
1b38485
Compare
surface->wlr_surface->format = format; | ||
surface->pixel_format = fmt; | ||
|
||
GL_CALL(glActiveTexture(GL_TEXTURE0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not exactly sure why I need this call to glActiveTexture, but it seems to be necessary. Here is my analysis.
GL_TEXTURE0
is the default active texture when the compositor starts. Upon the first render, the surface is bound with gles2_surface_bind()
which changes the active texture with GL_CALL(glActiveTexture(GL_TEXTURE0 + 1));
.
So the first surface is attached with active texture 0 and then it is rendered. Then the second texture is attached with active texture 1 which doesn't seem to work and I just get a black window. In fact, if I attach the first surface with texture 1, I get a black window as well so it seems we must do this with texture 0 active.
Anyway, this works but maybe there is a better way to manage this state. I guess I need to learn more about opengl.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FTR both wlc and weston do some special shit with GL textures that I don't fully understand and have not replicated here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really good explanation of texture units that I read: https://open.gl/textures#Textureunits
Implement surface_attach method. This is called when a client attaches an shm buffer with wl_surface_attach(). Implement the GLES2 interface for attaching shm buffers. This creates an opengl texture with the shm buffer contents for the surface. This commit also includes some working code to render the surfaces onto the screen for demonstration purposes.
1b38485
to
6610aa7
Compare
uint8_t *pixels = wl_shm_buffer_get_data(buffer); | ||
int width = wl_shm_buffer_get_width(buffer); | ||
int height = wl_shm_buffer_get_height(buffer); | ||
int pitch = wl_shm_buffer_get_stride(buffer) / (fmt->bpp / 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weston calls this variable pitch
although I don't know if that term is the same as stride
. This division I added is necessary for setting GL_UNPACK_ROW_LENGTH_EXT
because otherwise I get memory errors from stride being too large and the opengl skipping too many pixels.
Wayland seems to include some sanity checks for us so a buggy stride will never cause these memory errors as long as we do this calculation.
Add a signal for wlr_surface destruction on the wlr_surface that compositors can listen to to remove the surface from their state. Implement a listener for this in the example wl_compositor to remove the surface from its internal list of surfaces. Destroy the surface in the compositor destroy_surface callback given when the surface resource was created. Add a reference to the surface resource to the wlr_surface so a compositor can find it in its list of resources upon wlr_resource destruction.
The next commit implements destroying surfaces and is ready for review. I hate to add another callback for surface destruction (there are 3 now), but it was the best way I could find to get both the compositor state and the wlr_surface in the same callback. This fixes the segfault when surfaces are destroyed. |
Great work, thanks! |
Add the wayland surface interface to the example compositor.
Implement the create_surface method to create a new wlr surface from the
wayland surface and add the interface.