[cairo] Could I use cairo with opengles in android?

Henry (Yu) Song - SISA hsong at sisa.samsung.com
Fri May 18 08:40:27 PDT 2012

Hi, Jihe

Since you have the gl surface as a window surface, you can swap buffer on the surface directly - cairo_gl_surface_swapbuffers (surface).

From: cairo-bounces+henry.song=samsung.com at cairographics.org [cairo-bounces+henry.song=samsung.com at cairographics.org] on behalf of Jihe Wei [jihe.wei at gmail.com]
Sent: Friday, May 18, 2012 2:54 AM
To: cairo at cairographics.org
Subject: [cairo] Could I use cairo with opengles in android?

Hi ,
I wonder where can find some samples show use cairo in android device.
rarely found ,so i try it myself, but seems can't render anything
details as below,
     cairo_surface_t *surface = NULL;
     const EGLint attribs[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_BLUE_SIZE,
            EGL_OPENGL_ES2_BIT, EGL_NONE };
    const EGLint ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };

    EGLint format;
    EGLint numConfigs;
    EGLConfig config;
    EGLContext context;
    EGLint err;

    EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    err = eglGetError();
    LOGE("eglGetDisplay err:%d", err);//return 12288

    eglInitialize(display, 0, 0);
    err = eglGetError();
    LOGE("eglInitialize err:%d", err);//return 12288

    eglChooseConfig(display, attribs, &config, 1, &numConfigs);
    err = eglGetError();
    LOGE("eglChooseConfig err:%d", err);

    eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);

    context = eglCreateContext(display, config, EGL_NO_CONTEXT, ctx_attribs);
    err = eglGetError();
    LOGE("eglCreateContext err:%d", err);//return 12288

    cairo_device_t * device = cairo_egl_device_create(display, context);
    cairo_status_t status = cairo_device_status(device);//return success

    surface = cairo_gl_surface_create(device, CAIRO_CONTENT_ALPHA, info->width,
            info->height);//return CAIRO_SURFACE_TYPE_GL type

I use another surface to display the result from surface(gl)
    cairo_set_operator(cr_display, CAIRO_OPERATOR_ADD);
    cairo_set_source_surface(cr_display, surface, 0, 0);

Who could help to figure out? thx

More information about the cairo mailing list