[cairo] OpenVG

Paul Brooker paul at thefunnyfish.net
Thu Aug 19 13:59:36 PDT 2010


Hi there,
Has anyone had any success with the OpenVG backend? Im not sure that im setting up the surface correctly.  Here is the code im using to test with, i 
have verified that EGL+OpenVG works by drawing with OpenVG directly, but cant get cairo to work.

     cairo_t 		*cr;
     cairo_vg_context_t 	*cairo_ctx;
     cairo_surface_t 	*cairo_surf;
	EGLint i32WindowWidth, i32WindowHeight;
	EGLint i32NumConfigs, i32MajorVersion, i32MinorVersion;
	EGLDisplay			eglDisplay	= 0;
	EGLConfig			eglConfig	= 0;
	EGLSurface			eglSurface	= 0;
	EGLContext			eglContext	= 0;

	EGLNativeWindowType sWindow = (EGLNativeWindowType)0;

	eglDisplay = eglGetDisplay((EGLNativeDisplayType) EGL_DEFAULT_DISPLAY);
	eglInitialize(eglDisplay, &i32MajorVersion, &i32MinorVersion);
	eglBindAPI(EGL_OPENVG_API);

	static const EGLint ai32ConfigAttribs[] =
	{
		EGL_LEVEL,      	0,
		EGL_BUFFER_SIZE,     	16,
		EGL_SURFACE_TYPE,   EGL_WINDOW_BIT,
		EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
		EGL_NONE
	};

	eglChooseConfig(eglDisplay, ai32ConfigAttribs, &eglConfig, 1, &i32NumConfigs) || (i32NumConfigs != 1);
	eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, sWindow, NULL);
	eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL);
	eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);

	eglQuerySurface(eglDisplay, eglSurface, EGL_WIDTH, &i32WindowWidth);
	eglQuerySurface(eglDisplay, eglSurface, EGL_HEIGHT, &i32WindowHeight);

	vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);

	VGfloat afClearColor[4];
	afClearColor[0] = 0.0f;
	afClearColor[1] = 0.0f;
	afClearColor[2] = 0.0f;
	afClearColor[3] = 1.0f;

	vgSetfv(VG_CLEAR_COLOR, 4, afClearColor);
	vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_BETTER);
	vgLoadIdentity();
	vgScale((float)i32WindowWidth, (float)i32WindowHeight);
	vgClear(0, 0, i32WindowWidth, i32WindowHeight);

     cairo_ctx = cairo_vg_context_create_for_egl (eglDisplay, eglContext);
     cairo_surf = cairo_vg_surface_create (cairo_ctx, CAIRO_CONTENT_COLOR_ALPHA, i32WindowWidth, i32WindowHeight);

     cr = cairo_create(cairo_surf);

	cairo_set_source_rgb (cr, 1, 0, 0);
	cairo_rectangle (cr, 0, 0, 300, 300);
	cairo_fill (cr);

	eglSwapBuffers(eglDisplay, eglSurface);
	cairo_destroy(cr);

     eglDestroyContext(eglDisplay, eglContext);
     eglDestroySurface(eglDisplay, eglSurface);
     eglTerminate(eglDisplay);

Does anyone have any ideas? Any help would be much appreciated.

Thanx in advance,
Paul


More information about the cairo mailing list