#include #include #include #include /* static void draw(cairo_t *cr, int x, int w, int h, cairo_operator_t op) { cairo_t *first_cr, *second_cr; cairo_surface_t *first, *second; first = cairo_surface_create_similar(cairo_get_target(cr), CAIRO_CONTENT_COLOR_ALPHA, w, h); second = cairo_surface_create_similar(cairo_get_target(cr), CAIRO_CONTENT_COLOR_ALPHA, w, h); first_cr = cairo_create(first); cairo_set_source_rgb(first_cr, 0, 0, 0.4); cairo_rectangle(first_cr, x, 20, 50, 50); cairo_fill(first_cr); second_cr = cairo_create(second); cairo_set_source_rgb(second_cr, 0.5, 0.5, 0); cairo_rectangle(second_cr, x+10, 40, 50, 50); cairo_fill(second_cr); cairo_set_operator(first_cr, op); cairo_set_source_surface(first_cr, second, 0, 0); cairo_paint(first_cr); cairo_set_source_surface(cr, first, 0, 0); cairo_paint(cr); cairo_surface_destroy(first); cairo_surface_destroy(second); cairo_destroy(first_cr); cairo_destroy(second_cr); } */ static int draw (cairo_t *cr, int width, int height) { static const struct point { double x; double y; } xy[] = { { 627.016212, 221.749777 }, { 756.120787, 221.749777 }, { 756.120787, 557.602766 }, { 626.952721, 557.602766 }, { 626.548456, 493.315729 }, }; unsigned int i; cairo_set_source_rgb (cr, 0, 0, 0); cairo_paint (cr); for (i = 0; i < sizeof (xy) / sizeof (xy[0]); i++) cairo_line_to (cr, xy[i].x, xy[i].y); cairo_set_source_rgb (cr, 1, 0, 0); cairo_fill_preserve (cr); cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); cairo_set_source_rgb (cr, 0, 1, 0); cairo_fill (cr); return 0; } int main() { cairo_t *cr; cairo_vg_context_t *cairo_ctx; cairo_surface_t *cairo_surf; int width = 400, height=400, x=0, y=0; const char *name = "Test"; EGLint i32WindowWidth, i32WindowHeight; EGLint i32NumConfigs, i32MajorVersion, i32MinorVersion; EGLDisplay eglDisplay = 0; EGLConfig eglConfig = 0; EGLSurface eglSurface = 0; EGLContext eglContext = 0; Display *x_dpy = XOpenDisplay(NULL); Window win; Window root; int scrnum; XVisualInfo *visInfo, visTemplate; int num_visuals; XSetWindowAttributes attr; unsigned long mask; EGLint vid; scrnum = DefaultScreen( x_dpy ); root = RootWindow( x_dpy, scrnum ); float r = 0.1, g = 0.2, b = 0.3; eglDisplay = eglGetDisplay(x_dpy); eglInitialize(eglDisplay, &i32MajorVersion, &i32MinorVersion); eglBindAPI(EGL_OPENVG_API); static const EGLint ai32ConfigAttribs[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT, EGL_NONE }; eglChooseConfig(eglDisplay, ai32ConfigAttribs, &eglConfig, 1, &i32NumConfigs) || (i32NumConfigs != 1); if (!eglGetConfigAttrib(eglDisplay, eglConfig, EGL_NATIVE_VISUAL_ID, &vid)) { printf("Error: eglGetConfigAttrib() failed\n"); exit(1); } /* The X window visual must match the EGL config */ visTemplate.visualid = vid; visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals); if (!visInfo) { printf("Error: couldn't get X visual\n"); exit(1); } /* window attributes */ attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone); attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; win = XCreateWindow( x_dpy, root, 0, 0, width, height, 0, visInfo->depth, InputOutput, visInfo->visual, mask, &attr ); /* set hints and properties */ { XSizeHints sizehints; sizehints.x = x; sizehints.y = y; sizehints.width = width; sizehints.height = height; sizehints.flags = USSize | USPosition; XSetNormalHints(x_dpy, win, &sizehints); XSetStandardProperties(x_dpy, win, name, name, None, (char **)NULL, 0, &sizehints); } eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, win, 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, i32WindowWidth, i32WindowHeight); XMapWindow(x_dpy, win); cr = cairo_create(cairo_surf); static const struct point { double x; double y; } xy[] = { { 627.016212, 221.749777 }, { 756.120787, 221.749777 }, { 756.120787, 557.602766 }, { 626.952721, 557.602766 }, { 626.548456, 493.315729 }, }; unsigned int i; cairo_set_source_rgb (cr, 0, 0, 0); cairo_paint (cr); for (i = 0; i < sizeof (xy) / sizeof (xy[0]); i++) cairo_line_to (cr, xy[i].x, xy[i].y); eglSwapBuffers(eglDisplay, eglSurface); cairo_set_source_rgb (cr, 1, 0, 0); cairo_fill_preserve (cr); eglSwapBuffers(eglDisplay, eglSurface); cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); cairo_set_source_rgb (cr, 0, 1, 0); cairo_fill (cr); eglSwapBuffers(eglDisplay, eglSurface); /* for (i = 0; i<10000; i++) { float inc = (float)i / 10000; r = 1-inc; g = 1+inc/2; b = 1-inc; cairo_set_source_rgb (cr, r, g, b); cairo_rectangle (cr, inc*200, inc*200, 100, 100); cairo_fill (cr); eglSwapBuffers(eglDisplay, eglSurface); } sleep(1); cairo_destroy(cr); */ cr = cairo_create(cairo_surf); // for(x=20, y=20, i=0; i < 6; x+=80, i++) { draw(cr, width, height); eglSwapBuffers(eglDisplay, eglSurface); // } sleep(3); eglDestroyContext(eglDisplay, eglContext); eglDestroySurface(eglDisplay, eglSurface); eglTerminate(eglDisplay); }