<div dir="ltr">To clarify, what causes the wrong context to be bound is the call to cairo_destroy_surface(). Some of the cairo-gl functions do a cairo_gl_context_acquire() followed by some operation and finish by doing cairo_gl_context_release(). That last call is basically eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT), so when the call to glBindTexture() is made there is no current context.<div>
<br></div><div>Cheers,</div><div>Ander</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/7/16 Ander Conselvan de Oliveira <span dir="ltr"><<a href="mailto:ander.conselvan.de.oliveira@intel.com" target="_blank">ander.conselvan.de.oliveira@intel.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Calls into cairo-gles may change the current context, so it was only by<br>
chance that sometimes we had the proper one as current and updated the<br>
correct texture in surface_attach().<br>
<br>
In order to fix this, calling display_acquire_window_surface() before<br>
binding the texture for setup is necessary. However this call has the<br>
side effect of allocating a cairo surface for the window. At flush time,<br>
the existence of this surface will cause an eglSwapBuffers(), even<br>
if no rendering was done to it, leading to undefined contents on the<br>
screen. This happens when the idle redraw task runs while there is a<br>
pending frame callback.<br>
<br>
Workaround this by moving the texture setup from surface_attach() to the<br>
redraw handler, so that the cairo surface is only allocated when<br>
redering is done.<br>
---<br>
 clients/nested.c |   12 +++++++++---<br>
 1 file changed, 9 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/clients/nested.c b/clients/nested.c<br>
index a4e07f7..7137086 100644<br>
--- a/clients/nested.c<br>
+++ b/clients/nested.c<br>
@@ -136,6 +136,15 @@ redraw_handler(struct widget *widget, void *data)<br>
        cairo_fill(cr);<br>
<br>
        wl_list_for_each(s, &nested->surface_list, link) {<br>
+               display_acquire_window_surface(nested->display,<br>
+                                              nested->window, NULL);<br>
+<br>
+               glBindTexture(GL_TEXTURE_2D, s->texture);<br>
+               image_target_texture_2d(GL_TEXTURE_2D, s->image);<br>
+<br>
+               display_release_window_surface(nested->display,<br>
+                                              nested->window);<br>
+<br>
                cairo_set_operator(cr, CAIRO_OPERATOR_OVER);<br>
                cairo_set_source_surface(cr, s->cairo_surface,<br>
                                         allocation.x + 10,<br>
@@ -313,9 +322,6 @@ surface_attach(struct wl_client *client,<br>
                                                    surface->texture,<br>
                                                    width, height);<br>
<br>
-       glBindTexture(GL_TEXTURE_2D, surface->texture);<br>
-       image_target_texture_2d(GL_TEXTURE_2D, surface->image);<br>
-<br>
        window_schedule_redraw(nested->window);<br>
 }<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
1.7.10.4<br>
<br>
_______________________________________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
</font></span></blockquote></div><br></div>