[cairo] test cairo openvg

yu zhou dylanzhou0 at gmail.com
Tue Dec 8 21:50:07 PST 2009


hello !

I tested the cairo openvg backend with the cairo-vg-test.c demo on my
board.
but I can't get any result and error!
can anybody help me and give me the right direction?

dylan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20091209/cbdda20b/attachment.html 
-------------- next part --------------
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include <VG/openvg.h>
#include <GLES/egl.h>
#include <cairo.h>
#include <cairo-vg.h>

int
main(int argc, char *argv[])
{
   int width = 600, height = 480;
   Display *x_dpy;
   Window win;
   EGLSurface egl_surf;
   EGLContext egl_ctx;
   EGLDisplay egl_dpy;
   char *dpyName = NULL;
   GLboolean printInfo = GL_FALSE;
   EGLint egl_major, egl_minor;
   int i;
   const char *s;

   int scrnum;
   XSetWindowAttributes attr;
   unsigned long mask;
   Window root;
   int num_visuals;
   EGLContext ctx;
   EGLConfig config;
   EGLint num_configs;
   EGLint vid;

   cairo_t *cr;
   cairo_vg_context_t *cairo_ctx;
   cairo_surface_t *cairo_surf;

   static const EGLint attribs[] = {
      EGL_RED_SIZE, 5,
      EGL_GREEN_SIZE, 6,
      EGL_BLUE_SIZE, 5,
      EGL_NONE
   };

   for (i = 1; i < argc; i++) {
      if (strcmp(argv[i], "-display") == 0) {
         dpyName = argv[i+1];
         i++;
      }
      else if (strcmp(argv[i], "-info") == 0) {
         printInfo = GL_TRUE;
      }
      else {
         return -1;
      }
   }

   if (printInfo) {
      printf("VG_RENDERER   = %s\n", (char *) vgGetString(VG_RENDERER));
      printf("VG_VERSION    = %s\n", (char *) vgGetString(VG_VERSION));
      printf("VG_VENDOR     = %s\n", (char *) vgGetString(VG_VENDOR));
   }

   x_dpy = XOpenDisplay(dpyName);
   if (!x_dpy) {
      printf("Error: couldn't open display %s\n",
	     dpyName ? dpyName : getenv("DISPLAY"));
      return -1;
   }

   egl_dpy = eglGetDisplay(x_dpy);
   if (!egl_dpy) {
      printf("Error: eglGetDisplay() failed\n");
      return -1;
   }

   if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) {
      printf("Error: eglInitialize() failed\n");
      return -1;
   }

   scrnum = DefaultScreen( x_dpy );
   root = RootWindow( x_dpy, scrnum );
   if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) {
      printf("Error: couldn't get an EGL visual config\n");
      exit(1);
   }
   
   assert(config);
   assert(num_configs > 0);

   if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
      printf("Error: eglGetConfigAttrib() failed\n");
      exit(1);
   }

   win = XCreateSimpleWindow (x_dpy,
                        root,
                        0, 0,
                        width,height,
                        0, 0,
                        WhitePixel (x_dpy,
                                    scrnum));

   eglBindAPI(EGL_OPENVG_API);

   egl_ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, NULL );
   if (!egl_ctx) {
      printf("Error: eglCreateContext failed\n");
      exit(1);
   }

   egl_surf = eglCreateWindowSurface(egl_dpy, config, win, NULL);

   if (!egl_surf) {
      printf("Error: eglCreateWindowSurface failed\n");
      exit(1);
   }

   XMapWindow(x_dpy, win);
   if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) {
      printf("Error: eglMakeCurrent() failed\n");
      return -1;
   }

   cairo_ctx = cairo_vg_context_create_for_egl (egl_dpy, egl_ctx);
   cairo_surf = cairo_vg_surface_create (cairo_ctx, CAIRO_CONTENT_COLOR, width, height);

   cr = cairo_create(cairo_surf);
   cairo_set_source_rgba(cr, 1,0,0,1);
   cairo_rectangle(cr,200,100,400,300);
   cairo_fill(cr);

   cairo_surface_write_to_png(cairo_surf,"vg-win.png");

   cairo_destroy(cr);
   cairo_surface_destroy(cairo_surf);

   eglDestroyContext(egl_dpy, egl_ctx);
   eglDestroySurface(egl_dpy, egl_surf);
   eglTerminate(egl_dpy);


   XDestroyWindow(x_dpy, win);
   XCloseDisplay(x_dpy);

   return 0;
}


More information about the cairo mailing list