[Cogl] [PATCH] egl-winsys: eglSwapBuffersRegion expects coordinates relative to top-left

Robert Bragg robert at sixbynine.org
Tue Sep 18 07:25:49 PDT 2012


I think actually this is a bug in Mesa as I recall. I've been sitting
on a patch for Mesa for ages to fix but have been too lazy to send
upstream.

The annoying thing about this is that Nokia did a pretty good job of
retrospectively removing all public copies of their
NOK_swap_buffers_region spec so it's not that easy to point people to
a copy of the spec. I think it can only be found in the Khronos SVN
repo these days which isn't public :-(

Anyway below is the patch for Mesa, which I should probably send to
the Mesa mailing list.

kind regards,
- Robert

commit f12b95e07d670a4b92eee1237ad7f77b616fea6a
Author: Robert Bragg <robert at linux.intel.com>
Date:   Fri Jul 29 16:31:04 2011 +0100

    SwapBuffersRegionNOK: invert rectangles on y axis

    The EGL_NOK_swap_region2 spec states that the rectangles are specified
    with a bottom-left origin within a surface coordinate space also with a
    bottom left origin, so this patch ensures the rectangles are flipped
    before passing them on to dri2_copy_region.

diff --git a/src/egl/drivers/dri2/platform_x11.c
b/src/egl/drivers/dri2/platform_x11.c
index a100f4d..08325d3 100644
--- a/src/egl/drivers/dri2/platform_x11.c
+++ b/src/egl/drivers/dri2/platform_x11.c
@@ -778,10 +778,9 @@ dri2_swap_buffers_region(_EGLDriver *drv,
_EGLDisplay *disp, _EGLSurface *draw,
    if (numRects > (int)ARRAY_SIZE(rectangles))
       return dri2_copy_region(drv, disp, draw, dri2_surf->region);

-   /* FIXME: Invert y here? */
    for (i = 0; i < numRects; i++) {
       rectangles[i].x = rects[i * 4];
-      rectangles[i].y = rects[i * 4 + 1];
+      rectangles[i].y = dri2_surf->base.Height - rects[i * 4 + 1] -
rects[i * 4 + 3];
       rectangles[i].width = rects[i * 4 + 2];
       rectangles[i].height = rects[i * 4 + 3];
    }


On Tue, Sep 18, 2012 at 1:42 PM, Tomeu Vizoso <tomeu at tomeuvizoso.net> wrote:
> We were inverting previously the rects, probably mislead by
> glXCopySubBuffer.
> ---
>  cogl/winsys/cogl-winsys-egl.c | 16 +---------------
>  1 file changed, 1 insertion(+), 15 deletions(-)
>
> diff --git a/cogl/winsys/cogl-winsys-egl.c b/cogl/winsys/cogl-winsys-egl.c
> index dcd17ed..e456f50 100644
> --- a/cogl/winsys/cogl-winsys-egl.c
> +++ b/cogl/winsys/cogl-winsys-egl.c
> @@ -678,27 +678,13 @@ _cogl_winsys_onscreen_bind (CoglOnscreen *onscreen)
>
>  static void
>  _cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen,
> -                                   const int *user_rectangles,
> +                                   const int *rectangles,
>                                     int n_rectangles)
>  {
>    CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context;
>    CoglRenderer *renderer = context->display->renderer;
>    CoglRendererEGL *egl_renderer = renderer->winsys;
>    CoglOnscreenEGL *egl_onscreen = onscreen->winsys;
> -  CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
> -  int framebuffer_height  = cogl_framebuffer_get_height (framebuffer);
> -  int *rectangles = g_alloca (sizeof (int) * n_rectangles * 4);
> -  int i;
> -
> -  /* eglSwapBuffersRegion expects rectangles relative to the
> -   * bottom left corner but we are given rectangles relative to
> -   * the top left so we need to flip them... */
> -  memcpy (rectangles, user_rectangles, sizeof (int) * n_rectangles * 4);
> -  for (i = 0; i < n_rectangles; i++)
> -    {
> -      int *rect = &rectangles[4 * i];
> -      rect[1] = framebuffer_height - rect[1] - rect[3];
> -    }
>
>    /* At least for eglSwapBuffers the EGL spec says that the surface to
>       swap must be bound to the current context. It looks like Mesa
> --
> 1.7.11.4
>
> _______________________________________________
> Cogl mailing list
> Cogl at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/cogl


More information about the Cogl mailing list