[cairo-commit] cairo-demo/X11 cairo-demo.c,1.5,1.6

Jamey Sharp commit at pdx.freedesktop.org
Mon Aug 15 11:12:59 PDT 2005


Committed by: jamey

Update of /cvs/cairo/cairo-demo/X11
In directory pdx:/tmp/cvs-serv30325/X11

Modified Files:
	cairo-demo.c 
Log Message:
Added support for the new Cairo XCB surface backend.


Index: cairo-demo.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/X11/cairo-demo.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** cairo-demo.c	8 Dec 2003 20:58:29 -0000	1.5
--- cairo-demo.c	3 Feb 2004 07:25:48 -0000	1.6
***************
*** 5,17 ****
--- 5,34 ----
  #include <cairo.h>
  
+ #ifdef CAIRO_HAS_XCB_SURFACE
+ #undef CAIRO_HAS_XLIB_SURFACE
+ #endif
+ 
  #define PI 3.1415926535
  
  typedef struct win {
+ #ifndef CAIRO_HAS_XCB_SURFACE
      Display *dpy;
      int scr;
+ #else /* CAIRO_HAS_XCB_SURFACE */
+     XCBConnection *dpy;
+ #endif /* CAIRO_HAS_XCB_SURFACE */
+ #ifndef CAIRO_HAS_XCB_SURFACE
      Window win;
      GC gc;
+ #else /* CAIRO_HAS_XCB_SURFACE */
+     WINDOW win;
+     GCONTEXT gc;
+ #endif /* CAIRO_HAS_XCB_SURFACE */
      int width, height;
+ #ifndef CAIRO_HAS_XCB_SURFACE
      KeyCode quit_code;
+ #else /* CAIRO_HAS_XCB_SURFACE */
+     VISUALTYPE *visual;
+ #endif /* CAIRO_HAS_XCB_SURFACE */
  } win_t;
  
***************
*** 19,26 ****
  static void square(cairo_t *ct);
  static void bowtie(cairo_t *ct);
! static void win_init(win_t *win, Display *dpy);
  static void win_deinit(win_t *win);
  static void win_draw(win_t *win);
- static void win_select_events(win_t *win);
  static void win_handle_events(win_t *win);
  
--- 36,42 ----
  static void square(cairo_t *ct);
  static void bowtie(cairo_t *ct);
! static void win_init(win_t *win);
  static void win_deinit(win_t *win);
  static void win_draw(win_t *win);
  static void win_handle_events(win_t *win);
  
***************
*** 30,41 ****
      win_t win;
  
!     Display *dpy = XOpenDisplay(0);
  
!     if (dpy == NULL) {
! 	fprintf(stderr, "Failed to open display: %s\n", XDisplayName(0));
  	return 1;
      }
  
!     win_init(&win, dpy);
  
      win_draw(&win);
--- 46,61 ----
      win_t win;
  
! #ifndef CAIRO_HAS_XCB_SURFACE
!     win.dpy = XOpenDisplay(0);
! #else /* CAIRO_HAS_XCB_SURFACE */
!     win.dpy = XCBConnectBasic();
! #endif /* CAIRO_HAS_XCB_SURFACE */
  
!     if (win.dpy == NULL) {
! 	fprintf(stderr, "Failed to open display\n");
  	return 1;
      }
  
!     win_init(&win);
  
      win_draw(&win);
***************
*** 45,49 ****
      win_deinit(&win);
  
!     XCloseDisplay(dpy);
  
      return 0;
--- 65,73 ----
      win_deinit(&win);
  
! #ifndef CAIRO_HAS_XCB_SURFACE
!     XCloseDisplay(win.dpy);
! #else /* CAIRO_HAS_XCB_SURFACE */
!     XCBDisconnect(win.dpy);
! #endif /* CAIRO_HAS_XCB_SURFACE */
  
      return 0;
***************
*** 195,206 ****
  #define NUM_DASH 2
      static double dash[NUM_DASH] = {SIZE/4.0, SIZE/4.0};
-     Display *dpy = win->dpy;
      cairo_t *ct;
      Drawable drawable = win->win;
  
!     XClearWindow(dpy, win->win);
  
      ct = cairo_create();
!     cairo_set_target_drawable (ct, dpy, drawable);
      cairo_set_rgb_color(ct, 1, 1, 1);
  
--- 219,242 ----
  #define NUM_DASH 2
      static double dash[NUM_DASH] = {SIZE/4.0, SIZE/4.0};
      cairo_t *ct;
+ #ifndef CAIRO_HAS_XCB_SURFACE
      Drawable drawable = win->win;
+ #else /* CAIRO_HAS_XCB_SURFACE */
+     DRAWABLE drawable;
+     drawable.window = win->win;
+ #endif /* CAIRO_HAS_XCB_SURFACE */
  
! #ifndef CAIRO_HAS_XCB_SURFACE
!     XClearWindow(win->dpy, win->win);
! #else /* CAIRO_HAS_XCB_SURFACE */
!     XCBClearArea(win->dpy, 0, win->win, 0, 0, 0, 0);
! #endif /* CAIRO_HAS_XCB_SURFACE */
  
      ct = cairo_create();
! #ifndef CAIRO_HAS_XCB_SURFACE
!     cairo_set_target_drawable (ct, win->dpy, drawable);
! #else /* CAIRO_HAS_XCB_SURFACE */
!     cairo_set_target_xcb (ct, win->dpy, drawable, win->visual, 0);
! #endif /* CAIRO_HAS_XCB_SURFACE */
      cairo_set_rgb_color(ct, 1, 1, 1);
  
***************
*** 269,293 ****
  }
  
  static void
! win_init(win_t *win, Display *dpy)
  {
      Window root;
  
-     win->dpy = dpy;
      win->width = 400;
      win->height = 400;
  
!     root = DefaultRootWindow(dpy);
!     win->scr = DefaultScreen(dpy);
  
!     win->win = XCreateSimpleWindow(dpy, root, 0, 0,
  				   win->width, win->height, 0,
! 				   BlackPixel(dpy, win->scr), BlackPixel(dpy, win->scr));
  
!     win->quit_code = XKeysymToKeycode(dpy, XStringToKeysym("Q"));
  
!     win_select_events(win);
  
!     XMapWindow(dpy, win->win);
  }
  
--- 305,370 ----
  }
  
+ #ifdef CAIRO_HAS_XCB_SURFACE
+ static int
+ id_to_visual(SCREEN *root, VISUALTYPE **visual)
+ {
+     DEPTHIter di;
+     VISUALTYPE *v;
+ 
+     for(di = SCREENAllowedDepths(root); di.rem; DEPTHNext(&di))
+     {
+ 	int i;
+ 	const int count = DEPTHVisualsLength(di.data);
+ 	v = DEPTHVisuals(di.data);
+ 	for(i = 0; i < count; ++i)
+ 	    if(v->visual_id.id == root->root_visual.id)
+ 	    {
+ 		*visual = v;
+ 		return di.data->depth;
+ 	    }
+     }
+     return 0;
+ }
+ #endif /* CAIRO_HAS_XCB_SURFACE */
+ 
  static void
! win_init(win_t *win)
  {
+ #ifndef CAIRO_HAS_XCB_SURFACE
      Window root;
+ #else /* CAIRO_HAS_XCB_SURFACE */
+     SCREEN *root = XCBConnSetupSuccessRepRoots(XCBGetSetup(win->dpy)).data;
+     CARD32 mask = XCBCWBackPixel | XCBCWEventMask;
+     CARD32 values[] = { root->black_pixel, StructureNotifyMask | ExposureMask };
+     int depth;
+ #endif /* CAIRO_HAS_XCB_SURFACE */
  
      win->width = 400;
      win->height = 400;
  
! #ifndef CAIRO_HAS_XCB_SURFACE
!     root = DefaultRootWindow(win->dpy);
!     win->scr = DefaultScreen(win->dpy);
  
!     win->win = XCreateSimpleWindow(win->dpy, root, 0, 0,
  				   win->width, win->height, 0,
! 				   BlackPixel(win->dpy, win->scr), BlackPixel(win->dpy, win->scr));
  
!     win->quit_code = XKeysymToKeycode(win->dpy, XStringToKeysym("Q"));
  
!     XSelectInput(win->dpy, win->win,
! 		 KeyPressMask
! 		 |StructureNotifyMask
! 		 |ExposureMask);
  
!     XMapWindow(win->dpy, win->win);
! #else /* CAIRO_HAS_XCB_SURFACE */
!     win->win = XCBWINDOWNew(win->dpy);
!     depth = id_to_visual(root, &win->visual);
!     XCBCreateWindow(win->dpy, depth, win->win, root->root, 0, 0, win->width,
! 		    win->height, 0, InputOutput, win->visual->visual_id,
! 		    mask, values);
!     XCBMapWindow(win->dpy, win->win);
! #endif /* CAIRO_HAS_XCB_SURFACE */
  }
  
***************
*** 295,308 ****
  win_deinit(win_t *win)
  {
      XDestroyWindow(win->dpy, win->win);
! }
! 
! static void
! win_select_events(win_t *win)
! {
!     XSelectInput(win->dpy, win->win,
! 		 KeyPressMask
! 		 |StructureNotifyMask
! 		 |ExposureMask);
  }
  
--- 372,380 ----
  win_deinit(win_t *win)
  {
+ #ifndef CAIRO_HAS_XCB_SURFACE
      XDestroyWindow(win->dpy, win->win);
! #else /* CAIRO_HAS_XCB_SURFACE */
!     XCBDestroyWindow(win->dpy, win->win);
! #endif /* CAIRO_HAS_XCB_SURFACE */
  }
  
***************
*** 310,319 ****
  win_handle_events(win_t *win)
  {
      XEvent xev;
  
      while (1) {
  	XNextEvent(win->dpy, &xev);
- 
  	switch(xev.type) {
  	case KeyPress:
  	{
--- 382,400 ----
  win_handle_events(win_t *win)
  {
+ #ifndef CAIRO_HAS_XCB_SURFACE
      XEvent xev;
+ #else /* CAIRO_HAS_XCB_SURFACE */
+     XCBGenericEvent *xev;
+ #endif /* CAIRO_HAS_XCB_SURFACE */
  
      while (1) {
+ #ifndef CAIRO_HAS_XCB_SURFACE
  	XNextEvent(win->dpy, &xev);
  	switch(xev.type) {
+ #else /* CAIRO_HAS_XCB_SURFACE */
+ 	xev = XCBWaitEvent(win->dpy);
+ 	switch(xev->response_type) {
+ #endif /* CAIRO_HAS_XCB_SURFACE */
+ #ifdef CAIRO_HAS_XLIB_SURFACE
  	case KeyPress:
  	{
***************
*** 325,331 ****
--- 406,421 ----
  	}
  	break;
+ #endif
+ #ifndef CAIRO_HAS_XCB_SURFACE
  	case ConfigureNotify:
+ #else /* CAIRO_HAS_XCB_SURFACE */
+ 	case XCBConfigureNotify:
+ #endif /* CAIRO_HAS_XCB_SURFACE */
  	{
+ #ifndef CAIRO_HAS_XCB_SURFACE
  	    XConfigureEvent *cev = &xev.xconfigure;
+ #else /* CAIRO_HAS_XCB_SURFACE */
+ 	    XCBConfigureNotifyEvent *cev = (XCBConfigureNotifyEvent *) xev;
+ #endif /* CAIRO_HAS_XCB_SURFACE */
  
  	    win->width = cev->width;
***************
*** 333,339 ****
--- 423,437 ----
  	}
  	break;
+ #ifndef CAIRO_HAS_XCB_SURFACE
  	case Expose:
+ #else /* CAIRO_HAS_XCB_SURFACE */
+ 	case XCBExpose:
+ #endif /* CAIRO_HAS_XCB_SURFACE */
  	{
+ #ifndef CAIRO_HAS_XCB_SURFACE
  	    XExposeEvent *eev = &xev.xexpose;
+ #else /* CAIRO_HAS_XCB_SURFACE */
+ 	    XCBExposeEvent *eev = (XCBExposeEvent *) xev;
+ #endif /* CAIRO_HAS_XCB_SURFACE */
  
  	    if (eev->count == 0)





More information about the cairo-commit mailing list